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 _
10 from explorer import fields
12 class EditorSettings(models.Model):
13 user = models.ForeignKey(User, unique=True)
14 settings = fields.JSONField()
17 verbose_name, verbose_name_plural = _("editor settings"), _("editor settings")
19 def __unicode__(self):
20 return u"Editor settings for %s" % self.user.username
22 class EditorPanel(models.Model):
23 id = models.CharField(max_length=24, primary_key=True)
24 display_name = models.CharField(max_length=128)
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')
30 def __unicode__(self):
31 return self.display_name
33 class Book(models.Model):
36 ("can_add_files", "Can do hg add."),
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
46 comment = models.TextField() # addtional comments to the request
48 # revision number in which the changes were merged (if any)
49 merged_rev = models.CharField(max_length=40, null=True)
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") )
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('.'))
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('.'))