from django.contrib.auth.models import AbstractUser
from django.core import validators
from django.db import models
+from django.utils.translation import ugettext_lazy as _
+
+from emissions.models import Emission, Episode, NewsItem, NewsCategory, SoundFile
-from emissions.models import Emission
class User(AbstractUser):
- emissions = models.ManyToManyField(Emission, null=True, blank=True)
+ emissions = models.ManyToManyField(Emission, blank=True)
+ news_categories = models.ManyToManyField(NewsCategory, blank=True)
+
+ phone = models.CharField(_('Phone'), max_length=20, null=True, blank=True)
+ mobile = models.CharField(_('Mobile'), max_length=20, null=True, blank=True)
+ share_contact_details = models.BooleanField(_('Share contact detais with members'), default=True)
+
+ class Meta:
+ ordering = ['first_name', 'last_name']
+
+ def can_manage(self, object):
+ if self.is_staff:
+ return True
+ if isinstance(object, Emission):
+ return self.has_perm('emissions.change_emission') or object in self.emissions.all()
+ if isinstance(object, Episode):
+ return self.has_perm('emissions.change_episode') or object.emission in self.emissions.all()
+ if isinstance(object, SoundFile):
+ return self.has_perm('emissions.change_soundfile') or object.episode.emission in self.emissions.all()
+ if isinstance(object, NewsItem):
+ return self.has_perm('emissions.change_newsitem') or object.emission in self.emissions.all()
+ return False
+ def __unicode__(self):
+ s = super(User, self).__unicode__()
+ parts = []
+ if self.first_name:
+ parts.append(self.first_name)
+ if self.last_name:
+ parts.append(self.last_name)
+ if parts:
+ s = ' '.join(parts)
+ return s