1 # -*- encoding: utf-8 -*-
4 from django.db import models
5 from django.contrib.auth.models import User
6 from django.conf import settings
7 from django.utils.translation import gettext_lazy as _
11 from explorer import fields
13 class EditorSettings(models.Model):
14 """Ustawienia edytora dla użytkownika.
16 Pole settings zawiera obiekt JSON o kluczach:
17 - panels - lista otwartych paneli i ich proporcje
18 - recentFiles - lista otwartych plików i ustawienia dla nich
23 {'name': 'htmleditor', 'ratio': 0.5},
24 {'name': 'gallery', 'ratio': 0.5}
28 'fileId': 'mickiewicz_pan_tadeusz.xml',
30 {'name': 'htmleditor', 'ratio': 0.4},
31 {'name': 'gallery', 'ratio': 0.6}
37 user = models.ForeignKey(User, unique=True)
38 settings = fields.JSONField()
41 verbose_name, verbose_name_plural = _("editor settings"), _("editor settings")
43 def __unicode__(self):
44 return u"Editor settings for %s" % self.user.username
46 class EditorPanel(models.Model):
47 id = models.CharField(max_length=24, primary_key=True)
48 display_name = models.CharField(max_length=128)
50 toolbar_groups = models.ManyToManyField(toolbar.models.ButtonGroup, blank=True)
51 toolbar_extra = models.ForeignKey(toolbar.models.ButtonGroup, null=True, blank=True,
52 unique=True, related_name='main_editor_panels')
54 def __unicode__(self):
55 return self.display_name
57 class Book(models.Model):
60 ("can_add_files", "Can do hg add."),
66 class PullRequest(models.Model):
67 comitter = models.ForeignKey(User) # the user who request the pull
68 file = models.CharField(max_length=256) # the file to request
69 source_rev = models.CharField(max_length=40) # revision number of the commiter
71 comment = models.TextField() # addtional comments to the request
73 # revision number in which the changes were merged (if any)
74 merged_rev = models.CharField(max_length=40, null=True)
76 def __unicode__(self):
77 return u"Pull request from %s, source: %s %s, status: %s." % \
78 (self.commiter, self.file, self.source_rev, \
79 (("merged into "+self.merged_rev) if self.merged_rev else "pending") )
82 def get_image_folders():
83 return sorted(fn for fn in os.listdir(os.path.join(settings.MEDIA_ROOT, settings.IMAGE_DIR)) if not fn.startswith('.'))
86 def get_images_from_folder(folder):
87 return sorted(settings.MEDIA_URL + settings.IMAGE_DIR + u'/' + folder + u'/' + fn.decode('utf-8') for fn
88 in os.listdir(os.path.join(settings.MEDIA_ROOT, settings.IMAGE_DIR, folder))
89 if not fn.decode('utf-8').startswith('.'))