models.py
1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# -*- coding: utf-8 -*-
from django.db.models import *
from django.contrib.auth.models import User, Group
from django.utils.translation import gettext as _
from dictionary.models import Vocabulary, PartOfSpeech, editable_vocabularies
MANAGER_GROUPS = ('Obserwator', 'Leksykograf', 'Superleksykograf')
def manager_groups():
return Group.objects.filter(name__in=MANAGER_GROUPS)
class UserSettings(Model):
user = OneToOneField(User)
incremental_search = BooleanField(
default=True,
verbose_name=_(u'incremental search'),
help_text=_(u'Search is automatically performed while the search entry '
u'is being entered. '
u'Not recommended for slow Internet connections.'))
default_owner = ForeignKey(
Vocabulary, blank=True, null=True,
verbose_name=_(u'default owner dictionary of created lexemes'))
default_pos = ForeignKey(
PartOfSpeech, blank=True, null=True,
verbose_name=_(u'default part of speech of created lexemes'))
def views_lexeme(self):
return self.user.has_perm('dictionary.view_lexeme')
def views_all_lexemes(self):
return self.user.has_perm('dictionary.view_all_lexemes')
def changes_lexeme(self):
return self.user.has_perm('dictionary.change_lexeme')
def manages_vocabulary(self):
return self.user.has_perm('dictionary.manage_vocabulary')
def manages_all_vocabs(self):
return self.user.has_perm('dictionary.manage_all_vocabularies')
def get_default_owner(self):
if self.default_owner:
return self.default_owner
editable = editable_vocabularies(self.user)
if len(editable) == 1:
return editable.get()
class Meta:
permissions = (
('create_admin', _(u'Can give any role')),
)