summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2016-05-27 12:16:40 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2016-05-27 12:16:40 +0200
commit9fe603b08813a2a0f95a5f2db702dac66adb4e15 (patch)
tree2b3f1b15de0c4bb33a3a10757b75271e16127364
parent9e477fbeb6e9fb811968f31f937df5877b816aa7 (diff)
downloadChimère-9fe603b08813a2a0f95a5f2db702dac66adb4e15.tar.bz2
Chimère-9fe603b08813a2a0f95a5f2db702dac66adb4e15.zip
Check that an action available and redirect
-rw-r--r--chimere/forms.py3
-rw-r--r--chimere/views.py42
2 files changed, 40 insertions, 5 deletions
diff --git a/chimere/forms.py b/chimere/forms.py
index e9239a0..e17e3c9 100644
--- a/chimere/forms.py
+++ b/chimere/forms.py
@@ -296,8 +296,7 @@ class MarkerAdminFormBase(forms.ModelForm):
self.fields['end_date'].widget = DatePickerWidget()
if subcategories:
self.fields['categories'].choices = subcategories
- elif hasattr(self, 'categories_choices'):
- self.fields['categories'].choices = self.categories_choices
+ self.fields['categories'].choices = []
# auto select if there is only one category
choices = list(self.fields['categories'].choices)
self.fields['categories'].choices = choices
diff --git a/chimere/views.py b/chimere/views.py
index 9c9de11..9f24767 100644
--- a/chimere/views.py
+++ b/chimere/views.py
@@ -330,6 +330,23 @@ def get_edit_page(redirect_url, item_cls, item_form,
formset_picture), subcategories
return func
+
+def action_do_redirect(action_name, available_actions):
+ # redirect to an edit
+ is_edit = 'edit' in action_name
+ redir = None
+ for action, subactions in available_actions:
+ if action.id == action_name:
+ return
+ if not redir and action.id != action_name:
+ redir = action.url
+ for subaction in subactions:
+ if subaction.id == action_name:
+ return
+ if is_edit and 'edit' not in redir:
+ redir = subaction.url
+ return redir
+
get_edit_marker = get_edit_page('chimere:edit', Marker, MarkerForm)
@@ -343,6 +360,13 @@ def edit(request, area_name="", item_id=None, submited=False):
return response
item_id, init_item, response_dct, form, formset_multi, formset_picture = \
values
+
+ # verify action is available
+ current_actions = actions(response_dct['area_name'])
+ redir = action_do_redirect('edit-polygon', current_actions)
+ if redir:
+ return redirect(redir)
+
# get the "manualy" declared_fields. Ie: properties
querys = PropertyModel.getAvailable(area_name=area_name)
declared_fields, filtered_properties = [], []
@@ -354,7 +378,7 @@ def edit(request, area_name="", item_id=None, submited=False):
if request.POST and request.POST.get('point'):
point_value = request.POST.get('point')
response_dct.update({
- 'actions': actions(response_dct['area_name']),
+ 'actions': current_actions,
'action_selected': ('contribute', 'edit'),
'map_layer': settings.CHIMERE_DEFAULT_MAP_LAYER,
'form': form,
@@ -459,6 +483,12 @@ def editRoute(request, area_name="", item_id=None, submited=False):
item_id, init_item, response_dct, form, formset_multi, formset_picture = \
values
+ # verify action is available
+ current_actions = actions(response_dct['area_name'])
+ redir = action_do_redirect('edit-polygon', current_actions)
+ if redir:
+ return redirect(redir)
+
# get the "manualy" declared_fields. Ie: properties
declared_fields = form.declared_fields.keys()
if 'description' in declared_fields:
@@ -467,7 +497,7 @@ def editRoute(request, area_name="", item_id=None, submited=False):
if request.POST and request.POST.get('route'):
route_value = request.POST.get('route')
response_dct.update({
- 'actions': actions(response_dct['area_name']),
+ 'actions': current_actions,
'action_selected': ('contribute', 'edit-route'),
'error_message': '',
'map_layer': settings.CHIMERE_DEFAULT_MAP_LAYER,
@@ -503,6 +533,12 @@ def editPolygon(request, area_name="", item_id=None, submited=False):
item_id, init_item, response_dct, form, formset_multi, formset_picture = \
values
+ # verify action is available
+ current_actions = actions(response_dct['area_name'])
+ redir = action_do_redirect('edit-polygon', current_actions)
+ if redir:
+ return redirect(redir)
+
# get the "manualy" declared_fields. Ie: properties
querys = PropertyModel.getAvailable(area_name=area_name)
declared_fields, filtered_properties = [], []
@@ -514,7 +550,7 @@ def editPolygon(request, area_name="", item_id=None, submited=False):
if request.POST and request.POST.get('polygon'):
polygon_value = request.POST.get('polygon')
response_dct.update({
- 'actions': actions(response_dct['area_name']),
+ 'actions': current_actions,
'action_selected': ('contribute', 'edit-polygon'),
'error_message': '',
'map_layer': settings.CHIMERE_DEFAULT_MAP_LAYER,