summaryrefslogtreecommitdiff
path: root/chimere/actions.py
diff options
context:
space:
mode:
Diffstat (limited to 'chimere/actions.py')
-rw-r--r--chimere/actions.py61
1 files changed, 46 insertions, 15 deletions
diff --git a/chimere/actions.py b/chimere/actions.py
index 8ce3e2a..ecbd07a 100644
--- a/chimere/actions.py
+++ b/chimere/actions.py
@@ -21,11 +21,11 @@
Actions available in the main interface
"""
from django.conf import settings
-from django.contrib.auth import models
from django.core.urlresolvers import reverse, NoReverseMatch
from django.utils.translation import ugettext_lazy as _
-from models import Page
+from models import Page, Area
+
class Action:
def __init__(self, id, path, label, extra_url_args=[]):
@@ -34,18 +34,24 @@ class Action:
def update_url(self, area_name):
try:
- self.url = reverse(self.path,
- args=[area_name if area_name else ''] + self.extra_url_args)
+ self.url = reverse(
+ self.path,
+ args=[area_name + '/' if area_name else '']
+ + self.extra_url_args)
except NoReverseMatch:
# backward url management
- self.url = reverse(self.path,
- args=[area_name + '/' if area_name else ''] + self.extra_url_args)
+ self.url = reverse(
+ self.path,
+ args=[area_name if area_name else ''] + self.extra_url_args)
-default_actions = [(Action('view', 'chimere:index', _('View')), []),
- (Action('contribute', 'chimere:edit', _('Contribute')),
- (Action('edit', 'chimere:edit', _('Add a new point of interest')),
- Action('edit-route', 'chimere:editroute', _('Add a new route'))),
- ),]
+default_actions = [
+ (Action('view', 'chimere:index', _('View')), []),
+ (Action('contribute', 'chimere:edit', _('Contribute')),
+ (Action('edit-marker', 'chimere:editmarker',
+ _('Add a new point of interest')),
+ Action('edit-route', 'chimere:editroute', _('Add a new route')),
+ Action('edit-polygon', 'chimere:editpolygon', _('Add a new polygon'))),
+ )]
if hasattr(settings, 'CHIMERE_DIRECTORY') and settings.CHIMERE_DIRECTORY:
default_actions.append((Action('categories', 'chimere:category-directory',
@@ -62,13 +68,38 @@ if settings.EMAIL_HOST:
def actions(area_name=''):
acts = default_actions[:]
- for act, childs in default_actions:
- act.update_url(area_name)
+ area, q = None, None
+ if area_name:
+ q = Area.objects.filter(urn=area_name)
+ if not q.count():
+ q = Area.objects.filter(name=area_name)
+ if not q or not q.count():
+ q = Area.objects.filter(default=True)
+ if q.count():
+ area = q.all()[0]
+
+ real_acts = []
+ for act, childs in acts:
+ real_childs = []
for child_act in childs:
+ if area:
+ if (child_act.id == 'edit-marker'
+ and not area.allow_point_edition) \
+ or (child_act.id == 'edit-route'
+ and not area.allow_route_edition) \
+ or (child_act.id == 'edit-polygon'
+ and not area.allow_polygon_edition):
+ continue
+ real_childs.append(child_act)
+ if childs and not real_childs:
+ continue
+ act.update_url(area_name)
+ for child_act in real_childs:
child_act.update_url(area_name)
+ real_acts.append((act, real_childs))
for page in Page.objects.filter(available=True).order_by('order'):
act = Action(page.mnemonic, 'chimere:extra_page', page.title,
[page.mnemonic])
act.update_url(area_name)
- acts.append((act, []))
- return acts
+ real_acts.append((act, []))
+ return real_acts