0927152615381f578b858f1f92120677acf4460f
[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     pass
39
40
41 class PullRequest(models.Model):
42     comitter = models.ForeignKey(User) # the user who request the pull 
43     file = models.CharField(max_length=256) # the file to request
44     source_rev = models.CharField(max_length=40) # revision number of the commiter
45
46     comment = models.TextField() # addtional comments to the request
47
48     # revision number in which the changes were merged (if any)
49     merged_rev = models.CharField(max_length=40, null=True) 
50     
51     def __unicode__(self):
52         return u"Pull request from %s, source: %s %s, status: %s." % \
53             (self.commiter, self.file, self.source_rev, \
54                 (("merged into "+self.merged_rev) if self.merged_rev else "pending") )
55
56     
57 def get_image_folders():
58     return sorted(fn for fn in os.listdir(os.path.join(settings.MEDIA_ROOT, settings.IMAGE_DIR)) if not fn.startswith('.'))
59
60
61 def get_images_from_folder(folder):
62     return sorted(settings.MEDIA_URL + settings.IMAGE_DIR + u'/' + folder + u'/' + fn.decode('utf-8') for fn
63             in os.listdir(os.path.join(settings.MEDIA_ROOT, settings.IMAGE_DIR, folder))
64             if not fn.decode('utf-8').startswith('.'))
65