summaryrefslogtreecommitdiff
path: root/chimere/actions.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@proxience.com>2016-01-05 22:17:44 +0100
committerÉtienne Loks <etienne.loks@proxience.com>2016-01-05 22:17:44 +0100
commit9ce61bc6de5e98397e84c24a00d30002d4e04de5 (patch)
tree8ab9d19530ca3026fb21aff1993982f487dc7a28 /chimere/actions.py
parent2ca084384e6bf0596822938a607a189b507f60ed (diff)
parent89c4baf537a590dbe80c5f6a4c20f202c63ebb15 (diff)
downloadChimère-9ce61bc6de5e98397e84c24a00d30002d4e04de5.tar.bz2
Chimère-9ce61bc6de5e98397e84c24a00d30002d4e04de5.zip
Merge branch 'v2.2'
Conflicts: chimere/actions.py chimere/admin.py chimere/locale/fr/LC_MESSAGES/django.po chimere/models.py chimere/urls.py chimere/utils.py chimere/views.py
Diffstat (limited to 'chimere/actions.py')
-rw-r--r--chimere/actions.py65
1 files changed, 29 insertions, 36 deletions
diff --git a/chimere/actions.py b/chimere/actions.py
index 824b14f..e83d8c3 100644
--- a/chimere/actions.py
+++ b/chimere/actions.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
-# Copyright (C) 2008-2013 Étienne Loks <etienne.loks_AT_peacefrogsDOTnet>
+# Copyright (C) 2008-2010 É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
@@ -22,60 +22,53 @@ Actions available in the main interface
"""
from django.conf import settings
from django.contrib.auth import models
-from django.core.urlresolvers import reverse
+from django.core.urlresolvers import reverse, NoReverseMatch
from django.utils.translation import ugettext_lazy as _
-from chimere.models import Page, Map
+from models import Page
class Action:
- def __init__(self, id, path, label, extra_url_args=[],
- condition=None):
+ def __init__(self, id, path, label, extra_url_args=[]):
self.id, self.path, self.label = id, path, label
self.extra_url_args, self.url = extra_url_args, None
- self.condition = condition
- def update_url(self, map_name):
- self.url = reverse(self.path,
- args=[map_name + '/' if map_name else ''] + self.extra_url_args)
+ def update_url(self, area_name):
+ try:
+ 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)
-DEFAULT_ACTIONS = [[Action('view', 'chimere:index', _('View')), []],
- [Action('contribute', 'chimere:edit', _('Contribute'),
- condition=lambda user, map_name:bool(
- Map.getAvailable(user=user, urn=map_name, single=True,
- propose=True))),
+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'))),
- ],
- ]
+ ),]
+
+if hasattr(settings, 'CHIMERE_DIRECTORY') and settings.CHIMERE_DIRECTORY:
+ default_actions.append((Action('categories', 'chimere:category-directory',
+ _('Directory')), []))
if settings.CHIMERE_FEEDS:
- DEFAULT_ACTIONS.append([Action('rss', 'chimere:feeds-form',
- _('RSS feeds')), []])
+ default_actions.append((Action('rss', 'chimere:feeds-form',
+ _('RSS feeds')), []))
if settings.EMAIL_HOST:
- DEFAULT_ACTIONS.append([Action('contact', 'chimere:contact',
- _('Contact us')), []],)
+ default_actions.append((Action('contact', 'chimere:contact',
+ _('Contact us')), []),)
+
-def actions(user, map_name='', default_actions=DEFAULT_ACTIONS):
- acts, idx = [], -1
+def actions(area_name=''):
+ acts = default_actions[:]
for act, childs in default_actions:
- if act.id not in settings.CHIMERE_DEFAULT_ACTIONS:
- continue
- idx += 1
- if act.condition:
- if not act.condition(user, map_name):
- continue
- act.update_url(map_name)
+ act.update_url(area_name)
for child_act in childs:
- child_act.update_url(map_name)
- if "CHIMERE_DEFAULT_ACTION_LABEL" in dir(settings):
- if len(settings.CHIMERE_DEFAULT_ACTION_LABEL) > idx:
- act.label = settings.CHIMERE_DEFAULT_ACTION_LABEL[idx]
- acts.append((act, childs))
+ child_act.update_url(area_name)
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(map_name)
+ act.update_url(area_name)
acts.append((act, []))
-
return acts