]> git.openstreetmap.org Git - osqa.git/blob - forum/models/page.py
removing score sort option from the bulk management tool in the administration, it...
[osqa.git] / forum / models / page.py
1 from base import *
2 from django.utils.translation import ugettext as _
3
4 def silent_permalink(func):
5     """
6     Decorator that calls urlresolvers.reverse() to return a URL using
7     parameters returned by the decorated function "func".
8
9     "func" should be a function that returns a tuple in one of the
10     following formats:
11         (viewname, viewargs)
12         (viewname, viewargs, viewkwargs)
13     """
14     from django.core.urlresolvers import reverse
15     def inner(*args, **kwargs):
16         bits = func(*args, **kwargs)
17         try:
18             return reverse(bits[0], None, *bits[1:3])
19         except:
20             return "javascript:alert('Configure this page URL in the urls.py file');"
21     return inner
22
23 class Page(Node):
24     friendly_name = _("page")
25
26     @property
27     def published(self):
28         return self.marked
29
30     @property
31     def html(self):
32         return self._as_markdown(self.body)
33
34     def save(self, *args, **kwargs):
35         old_options = self._original_state.get('extra', None)
36
37         super(Page, self).save(*args, **kwargs)
38
39         registry = settings.STATIC_PAGE_REGISTRY
40
41         if old_options:
42             registry.pop(old_options.get('path', ''), None)
43
44         registry[self.extra['path']] = self.id
45
46
47         settings.STATIC_PAGE_REGISTRY.set_value(registry)
48
49     @property
50     def headline(self):
51         if self.published:
52             return self.title
53         else:
54             return _("[Unpublished] %s") % self.title
55
56     @silent_permalink
57     def get_absolute_url(self):
58         return ('static_page', (), {'path': self.extra['path']})
59         
60     def activate_revision(self, user, revision, extensions=['urlize']):
61         self.title = revision.title
62         self.tagnames = revision.tagnames        
63         self.body = revision.body
64
65         self.active_revision = revision
66         self.update_last_activity(user)
67
68         self.save()
69
70     class Meta(Node.Meta):
71         proxy = True
72
73