summaryrefslogtreecommitdiff
path: root/views.py
blob: 4bc5bc63aee12b91c5c7842321437adcf5b940bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (C) 2012  Étienne Loks  <etienne.loks_AT_peacefrogsDOTnet>

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# See the file COPYING for details.

from django.conf import settings
from django.shortcuts import render_to_response
from django.template import RequestContext

from forms import MarkerForm

from chimere.actions import actions
from chimere.models import Marker, PropertyModel
from chimere.views import get_edit_page

get_edit_marker = get_edit_page('edit', Marker, MarkerForm)

def edit(request, area_name="", item_id=None, submited=False):
    """
    Edition page
    """
    response, values, sub_categories = get_edit_marker(request, area_name,
                                                       item_id, ['M', 'B'])
    if response:
        return response
    item_id, init_item, response_dct, form, formset_multi, formset_picture = \
                                                                        values
    # get the "manualy" declared_fields. Ie: properties
    declared_fields = form.declared_fields.keys()
    declared_fields = PropertyModel.objects.filter(available=True).all()
    filtered_properties = PropertyModel.objects.filter(available=True,
                                subcategories__id__isnull=False).all()
    response_dct.update({
        'actions':actions,
        'action_selected':('contribute', 'edit'),
        'map_layer':settings.CHIMERE_DEFAULT_MAP_LAYER,
        'form':form,
        'formset_multi':formset_multi,
        'formset_picture':formset_picture,
        'dated':settings.CHIMERE_DAYS_BEFORE_EVENT,
        'extra_head':form.media,
        'marker_id':item_id,
        'sub_categories':sub_categories,
        'point_widget':'',
        'properties':declared_fields,
        'filtered_properties':filtered_properties,
        'submited':submited
    })
    # manualy populate the custom widget
    if 'subcategory' in form.data and form.data['subcategory']:
        response_dct['current_category'] = int(form.data['subcategory'])
    return render_to_response('chimere/edit.html', response_dct,
                              context_instance=RequestContext(request))