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 _
8 from emissions.models import Emission, Episode, NewsItem, NewsCategory, SoundFile
10 class User(AbstractUser):
11 emissions = models.ManyToManyField(Emission, blank=True)
12 news_categories = models.ManyToManyField(NewsCategory, blank=True)
14 phone = models.CharField(_('Phone'), max_length=20, null=True, blank=True)
15 mobile = models.CharField(_('Mobile'), max_length=20, null=True, blank=True)
18 ordering = ['first_name', 'last_name']
20 def can_manage(self, object):
23 if isinstance(object, Emission):
24 return self.has_perm('emissions.change_emission') or object in self.emissions.all()
25 if isinstance(object, Episode):
26 return self.has_perm('emissions.change_episode') or object.emission in self.emissions.all()
27 if isinstance(object, SoundFile):
28 return self.has_perm('emissions.change_soundfile') or object.episode.emission in self.emissions.all()
29 if isinstance(object, NewsItem):
30 return self.has_perm('emissions.change_newsitem') or object.emission in self.emissions.all()
33 def __unicode__(self):
34 s = super(User, self).__unicode__()
37 parts.append(self.first_name)
39 parts.append(self.last_name)
43 return '%s (%s)' % (s, self.mobile)
45 return '%s (%s)' % (s, self.phone)