]> git.0d.be Git - panikdb.git/blob - panikdb/aa/models.py
add option to not share contact details
[panikdb.git] / panikdb / aa / models.py
1 import re
2
3 from django.contrib.auth.models import AbstractUser
4 from django.core import validators
5 from django.db import models
6 from django.utils.translation import ugettext_lazy as _
7
8 from emissions.models import Emission, Episode, NewsItem, NewsCategory, SoundFile
9
10
11 class User(AbstractUser):
12     emissions = models.ManyToManyField(Emission, blank=True)
13     news_categories = models.ManyToManyField(NewsCategory, blank=True)
14
15     phone = models.CharField(_('Phone'), max_length=20, null=True, blank=True)
16     mobile = models.CharField(_('Mobile'), max_length=20, null=True, blank=True)
17     share_contact_details = models.BooleanField(_('Share contact detais with members'), default=True)
18
19     class Meta:
20         ordering = ['first_name', 'last_name']
21
22     def can_manage(self, object):
23         if self.is_staff:
24             return True
25         if isinstance(object, Emission):
26             return self.has_perm('emissions.change_emission') or object in self.emissions.all()
27         if isinstance(object, Episode):
28             return self.has_perm('emissions.change_episode') or object.emission in self.emissions.all()
29         if isinstance(object, SoundFile):
30             return self.has_perm('emissions.change_soundfile') or object.episode.emission in self.emissions.all()
31         if isinstance(object, NewsItem):
32             return self.has_perm('emissions.change_newsitem') or object.emission in self.emissions.all()
33         return False
34
35     def __unicode__(self):
36         s = super(User, self).__unicode__()
37         parts = []
38         if self.first_name:
39             parts.append(self.first_name)
40         if self.last_name:
41             parts.append(self.last_name)
42         if parts:
43             s = ' '.join(parts)
44         return s