Wydzielanie utworów. Closes #79 Closes #98
[redakcja.git] / apps / explorer / models.py
1 import os
2
3 from django.db import models
4 from django.contrib.auth.models import User
5 from django.conf import settings
6 from django.utils.translation import gettext_lazy as _
7
8 import toolbar.models
9
10 from explorer import fields
11
12 class EditorSettings(models.Model):
13     user = models.ForeignKey(User, unique=True)
14     settings = fields.JSONField()
15     
16     class Meta:
17         verbose_name, verbose_name_plural = _("editor settings"), _("editor settings")
18
19     def __unicode__(self):
20         return u"Editor settings for %s" % self.user.username
21
22 class EditorPanel(models.Model):
23     id = models.CharField(max_length=24, primary_key=True)
24     display_name = models.CharField(max_length=128)
25
26     toolbar_groups = models.ManyToManyField(toolbar.models.ButtonGroup, blank=True)
27     toolbar_extra = models.ForeignKey(toolbar.models.ButtonGroup, null=True, blank=True,
28         unique=True, related_name='main_editor_panels')
29
30     def __unicode__(self):
31         return self.display_name
32     
33 class Book(models.Model):
34     class Meta:
35         permissions = (
36             ("can_add_files", "Can do hg add."),
37         )
38         abstract=True
39     pass
40
41
42 class PullRequest(models.Model):
43     comitter = models.ForeignKey(User) # the user who request the pull 
44     file = models.CharField(max_length=256) # the file to request
45     source_rev = models.CharField(max_length=40) # revision number of the commiter
46
47     comment = models.TextField() # addtional comments to the request
48
49     # revision number in which the changes were merged (if any)
50     merged_rev = models.CharField(max_length=40, null=True) 
51     
52     def __unicode__(self):
53         return u"Pull request from %s, source: %s %s, status: %s." % \
54             (self.commiter, self.file, self.source_rev, \
55                 (("merged into "+self.merged_rev) if self.merged_rev else "pending") )
56
57     
58 def get_image_folders():
59     return sorted(fn for fn in os.listdir(os.path.join(settings.MEDIA_ROOT, settings.IMAGE_DIR)) if not fn.startswith('.'))
60
61
62 def get_images_from_folder(folder):
63     return sorted(settings.MEDIA_URL + settings.IMAGE_DIR + u'/' + folder + u'/' + fn.decode('utf-8') for fn
64             in os.listdir(os.path.join(settings.MEDIA_ROOT, settings.IMAGE_DIR, folder))
65             if not fn.decode('utf-8').startswith('.'))
66