1 # -*- coding: utf-8 -*-
3 # This file is part of FNP-Redakcja, licensed under GNU Affero GPLv3 or later.
4 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
6 from django.db import models
7 from django.utils.translation import ugettext_lazy as _
9 from dvcs import models as dvcs_models
13 logger = logging.getLogger("fnp.wiki")
16 class Document(models.Model):
17 """ A document edited on the wiki """
19 slug = models.CharField(_('slug'))
20 title = models.CharField(_('displayed title'), blank=True)
21 data = models.ForeignKey(dvcs_models.Document)
22 gallery = models.CharField(_('scan gallery name'), blank=True)
28 from wiki import settings, constants
29 from slughifi import slughifi
31 from django.http import Http404
36 class Document(object):
38 def add_tag(self, tag, revision, author):
39 """ Add document specific tag """
40 logger.debug("Adding tag %s to doc %s version %d", tag, self.name, revision)
41 self.storage.vstorage.add_page_tag(self.name, revision, tag, user=author)
45 return re.sub(self.META_REGEX, '', self.text, 1)
50 m = re.match(self.META_REGEX, self.text)
52 for line in m.group(1).split('\n'):
54 k, v = line.split(':', 1)
55 result[k.strip()] = v.strip()
59 gallery = result.get('gallery', slughifi(self.name.replace(' ', '_')))
61 if gallery.startswith('/'):
62 gallery = os.path.basename(gallery)
64 result['gallery'] = gallery
68 return self.storage.vstorage.page_meta(self.name, self.revision)
73 class Theme(models.Model):
74 name = models.CharField(_('name'), max_length=50, unique=True)
78 verbose_name = _('theme')
79 verbose_name_plural = _('themes')
81 def __unicode__(self):
85 return "Theme(name=%r)" % self.name