Remove Officials

This commit is contained in:
Aarni Halinen
2020-11-07 18:39:58 +00:00
parent 2359743b20
commit d06c24bde0
9 changed files with 70 additions and 281 deletions
-104
View File
@@ -171,105 +171,6 @@ class BaseRole(models.Model):
return '{} ({})'.format(n, _('board member')) if self.is_board else n
class PresetRole(BaseRole):
"""Model representing a preset occupation in the guild."""
description = models.TextField(_('Description'))
class Committee(models.Model):
"""
Committee model
Has many Roles found under variable roles
"""
class Meta:
verbose_name = _('Committee')
verbose_name_plural = _('Committees')
def __str__(self):
return _('Committee: {}').format(self.name)
name = models.CharField(_("Name"), max_length=255)
@property
def current_roles(self):
return self.roles.all().filter(end_date__gte=timezone.now()).filter(start_date__lte=timezone.now())
class Role(PresetRole):
"""
Model representing an active or historical occupation
in the guild.
"""
class Meta:
verbose_name = _('Role')
verbose_name_plural = _('Roles')
committee = models.ForeignKey('Committee', related_name='roles', on_delete=models.SET_NULL, null=True)
def __str__(self):
return '{} (Hallitus: {}) ({})'.format(self.name, _("Yes") if self.is_board else _("No"), self.committee)
class Occupation(models.Model):
"""
Model for a occupation in guild.
Model links Official into a role he/she has or has had in the guild.
"""
class Meta:
verbose_name = _('Occupation')
verbose_name_plural = _('Occupations')
start_date = models.DateField(_('Start date'))
end_date = models.DateField(_('End date'))
role = models.ForeignKey('Role', on_delete=models.SET_NULL, null=True)
@staticmethod
def by_year(year):
return Occupation.objects.filter(
end_date__gte=timezone.datetime(year, 1, 1)).filter(
start_date__lte=timezone.datetime(year, 12, 31))
def __str__(self):
return '{}: {} - {}'.format(self.role.name, self.start_date, self.end_date)
class Official(models.Model):
"""Model representing a guild official."""
class Meta:
verbose_name = _('Official')
verbose_name_plural = _('Officials')
user = models.OneToOneField(User, on_delete=models.CASCADE)
first_name = models.CharField(_('First name'), max_length=30)
last_name = models.CharField(_('Last name'), max_length=150)
email = models.EmailField(_('Email address'))
phone_number = PhoneNumberField(_('Phone number'))
role_history = models.ManyToManyField('Occupation', 'officials', blank=True)
image = models.ImageField(blank=True, null=True)
@staticmethod
def by_year(year):
return Official.objects.filter(
role_history__in=Occupation.occupations_by_year(year)).distinct()
def __str__(self):
return '{} {}'.format(self.first_name, self.last_name)
@receiver(post_save, sender=Official)
def save_user_official(sender, instance, **kwargs):
instance.user.first_name = instance.first_name
instance.user.last_name = instance.last_name
instance.user.email = instance.email
instance.user.save()
class JobAd(models.Model):
"""Job advertisements shown on Corporate relations page"""
@@ -291,9 +192,4 @@ auditlog.register(Feed)
auditlog.register(Event)
auditlog.register(SignupForm)
auditlog.register(Signup)
auditlog.register(PresetRole)
auditlog.register(Role)
auditlog.register(Committee)
auditlog.register(Occupation)
auditlog.register(Official)
auditlog.register(JobAd)