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 _
8 from explorer import fields
11 class EditorSettings(models.Model):
12 user = models.ForeignKey(User, unique=True)
13 settings = fields.JSONField()
16 verbose_name, verbose_name_plural = _("editor settings"), _("editor settings")
18 def __unicode__(self):
19 return u"Editor settings for %s" % self.user.username
22 class Book(models.Model):
25 ("can_add_files", "Can do hg add."),
30 class PullRequest(models.Model):
31 comitter = models.ForeignKey(User) # the user who request the pull
32 file = models.CharField(max_length=256) # the file to request
33 source_rev = models.CharField(max_length=40) # revision number of the commiter
35 comment = models.TextField() # addtional comments to the request
37 # revision number in which the changes were merged (if any)
38 merged_rev = models.CharField(max_length=40, null=True)
40 def __unicode__(self):
41 return u"Pull request from %s, source: %s %s, status: %s." % \
42 (self.commiter, self.file, self.source_rev, \
43 (("merged into "+self.merged_rev) if self.merged_rev else "pending") )
46 def get_image_folders():
47 return sorted(fn for fn in os.listdir(os.path.join(settings.MEDIA_ROOT, settings.IMAGE_DIR)) if not fn.startswith('.'))
50 def get_images_from_folder(folder):
51 return sorted(settings.MEDIA_URL + settings.IMAGE_DIR + '/' + folder + '/' + fn for fn
52 in os.listdir(os.path.join(settings.MEDIA_ROOT, settings.IMAGE_DIR, folder))
53 if not fn.startswith('.'))
55 def user_branch(user):
56 return 'personal_'+user.username