X-Git-Url: https://git.openstreetmap.org./osqa.git/blobdiff_plain/9308d78c7f1e4d2a4faf3b98d1b24c262f3b6287..bd65d9583dbb436bbc1a790e7649531742b8386a:/forum/models/page.py diff --git a/forum/models/page.py b/forum/models/page.py index ff3b1a4..dcb9dfd 100644 --- a/forum/models/page.py +++ b/forum/models/page.py @@ -1,6 +1,25 @@ from base import * from django.utils.translation import ugettext as _ +def silent_permalink(func): + """ + Decorator that calls urlresolvers.reverse() to return a URL using + parameters returned by the decorated function "func". + + "func" should be a function that returns a tuple in one of the + following formats: + (viewname, viewargs) + (viewname, viewargs, viewkwargs) + """ + from django.core.urlresolvers import reverse + def inner(*args, **kwargs): + bits = func(*args, **kwargs) + try: + return reverse(bits[0], None, *bits[1:3]) + except: + return "javascript:alert('Configure this page URL in the urls.py file');" + return inner + class Page(Node): friendly_name = _("page") @@ -8,6 +27,10 @@ class Page(Node): def published(self): return self.marked + @property + def html(self): + return self._as_markdown(self.body) + def save(self, *args, **kwargs): old_options = self._original_state.get('extra', None) @@ -30,11 +53,21 @@ class Page(Node): else: return _("[Unpublished] %s") % self.title - @models.permalink + @silent_permalink def get_absolute_url(self): return ('static_page', (), {'path': self.extra['path']}) + + def activate_revision(self, user, revision, extensions=['urlize']): + self.title = revision.title + self.tagnames = revision.tagnames + self.body = revision.body + + self.active_revision = revision + self.update_last_activity(user) + + self.save() class Meta(Node.Meta): proxy = True - \ No newline at end of file +