diff options
Diffstat (limited to 'chimere/actions.py')
| -rw-r--r-- | chimere/actions.py | 34 | 
1 files changed, 29 insertions, 5 deletions
diff --git a/chimere/actions.py b/chimere/actions.py index 9b66492..49f4a90 100644 --- a/chimere/actions.py +++ b/chimere/actions.py @@ -24,7 +24,7 @@ from django.conf import settings  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: @@ -66,13 +66,37 @@ 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' 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  | 
