diff options
author | Luke Shumaker <lukeshu@sbcglobal.net> | 2015-04-15 21:55:11 -0400 |
---|---|---|
committer | Luke Shumaker <lukeshu@sbcglobal.net> | 2015-04-15 21:55:11 -0400 |
commit | 29ffe1b85ba4bf077d529603982d5bd810c68a1f (patch) | |
tree | 9bb2ea435ac5b7554bfc555b3c3877ea26e43087 /devel/models.py | |
parent | ce1f17e5104d44fa833090c47dd76466a2d7f743 (diff) | |
parent | 86bd3d5e4920fd6d57ac51ed3abf02d2f368f2a7 (diff) |
Merge branch 'archweb-generic'
Diffstat (limited to 'devel/models.py')
-rw-r--r-- | devel/models.py | 37 |
1 files changed, 25 insertions, 12 deletions
diff --git a/devel/models.py b/devel/models.py index 5c4d4fe7..b05800a5 100644 --- a/devel/models.py +++ b/devel/models.py @@ -1,9 +1,10 @@ # -*- coding: utf-8 -*- import pytz +from django.core.urlresolvers import reverse from django.db import models from django.db.models.signals import pre_save -from django.contrib.auth.models import User +from django.contrib.auth.models import User, Group from django_countries.fields import CountryField from .fields import PGPKeyField @@ -54,17 +55,29 @@ class UserProfile(models.Model): verbose_name_plural = 'additional profile data' def get_absolute_url(self): - # TODO: this is disgusting. find a way to consolidate this logic with - # public.views.userlist among other places, and make some constants or - # something so we aren't using copies of string names everywhere. - group_names = self.user.groups.values_list('name', flat=True) - if "Developers" in group_names: - prefix = "developers" - elif "Trusted Users" in group_names: - prefix = "trustedusers" - else: - prefix = "fellows" - return '/%s/#%s' % (prefix, self.user.username) + user = self.user + group = StaffGroup.objects.filter(group=user.groups.all()).first() + if group: + return '%s#%s' % (group.get_absolute_url(), user.username) + return None + + +class StaffGroup(models.Model): + name = models.CharField(max_length=100) + slug = models.SlugField(max_length=100, unique=True) + group = models.OneToOneField(Group) + sort_order = models.PositiveIntegerField() + member_title = models.CharField(max_length=100) + description = models.TextField(blank=True) + + class Meta: + ordering = ('sort_order',) + + def __unicode__(self): + return self.name + + def get_absolute_url(self): + return reverse('people', args=[self.slug]) class MasterKey(models.Model): |