e104cda6e6ae9d747d83884d60cb7cbf82b55a82
[redakcja.git] / apps / explorer / models.py
1 # -*- encoding: utf-8 -*-
2 import os
3
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 _
8
9 import toolbar.models
10
11 from explorer import fields
12
13 class EditorSettings(models.Model):
14     """Ustawienia edytora dla użytkownika.
15     
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
19     
20     Przykład:
21     {
22         'panels': [
23             {'name': 'htmleditor',
24             'ratio': 0.5},
25             {'name': 'gallery', 'ratio': 0.5}
26         ],
27         'recentFiles': [
28             {
29                 'fileId': 'mickiewicz_pan_tadeusz.xml',
30                 'panels': [
31                     {'name': 'htmleditor', 'ratio': 0.4},
32                     {'name': 'gallery', 'ratio': 0.6}
33                 ]
34             }
35         ]
36     }
37     """
38     user = models.ForeignKey(User, unique=True)
39     settings = fields.JSONField()
40     
41     class Meta:
42         verbose_name, verbose_name_plural = _("editor settings"), _("editor settings")
43
44     def __unicode__(self):
45         return u"Editor settings for %s" % self.user.username
46
47 class EditorPanel(models.Model):
48     id = models.CharField(max_length=24, primary_key=True)
49     display_name = models.CharField(max_length=128)
50
51     toolbar_groups = models.ManyToManyField(toolbar.models.ButtonGroup, blank=True)
52     toolbar_extra = models.ForeignKey(toolbar.models.ButtonGroup, null=True, blank=True,
53         unique=True, related_name='main_editor_panels')
54
55     def __unicode__(self):
56         return self.display_name
57   
58
59 # Yes, this is intentionally unnormalized !
60 class GalleryForDocument(models.Model):
61     name = models.CharField(max_length=100, blank=True)
62
63     # document associated with the gallery
64     document = models.CharField(max_length=255, unique=True)
65         
66     # directory containing scans under MEDIA_ROOT/
67     subpath = models.CharField(max_length=255)
68
69     def __unicode__(self):
70         return u"%s:%s" % (self.subpath, self.document)
71