Tworzenie domyślnych katalogów current i previous w setup w fabfile.py.
[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 class Document(models.Model):
59     class Meta:
60         permissions = (            
61             ("can_share", "Can share documents without pull requests."),
62         )
63         
64     pass
65
66 class PullRequest(models.Model):    
67     REQUEST_STATUSES = (
68         ("N", "Pending for resolution"),
69         ("R", "Rejected"),
70         ("A", "Accepted & merged"),
71     )
72
73     comitter = models.ForeignKey(User) # the user who request the pull
74     comment = models.TextField() # addtional comments to the request
75
76     # document to merge
77     document = models.CharField(max_length=255)
78
79     # revision to be merged into the main branch
80     source_revision = models.CharField(max_length=40, unique=True)
81
82     # current status
83     status = models.CharField(max_length=1, choices=REQUEST_STATUSES)
84
85     # comment to the status change of request (if applicable)
86     response_comment = models.TextField(blank=True)
87
88     # revision number in which the changes were merged (if any)
89     merged_rev = models.CharField(max_length=40, blank=True, null=True)
90
91     def __unicode__(self):
92         return unicode(self.comitter) + u':' + self.document
93
94 # Yes, this is intentionally unnormalized !
95 class GalleryForDocument(models.Model):
96     name = models.CharField(max_length=100)
97     
98     # directory containing scans under MEDIA_ROOT/
99     subpath = models.CharField(max_length=255)
100
101     # document associated with the gallery
102     document = models.CharField(max_length=255)
103
104     def __unicode__(self):
105         return u"%s:%s" % (self.subpath, self.document)