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."),
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
47 comment = models.TextField() # addtional comments to the request
49 # revision number in which the changes were merged (if any)
50 merged_rev = models.CharField(max_length=40, null=True)
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") )
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('.'))
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('.'))