diff options
author | Luke Shumaker <lukeshu@sbcglobal.net> | 2015-04-15 17:15:17 -0400 |
---|---|---|
committer | Luke Shumaker <lukeshu@sbcglobal.net> | 2015-04-15 17:15:17 -0400 |
commit | 86bd3d5e4920fd6d57ac51ed3abf02d2f368f2a7 (patch) | |
tree | 7d2f4688eafc26e5ce821d576a4028e986b70f10 /devel | |
parent | 7a8b5707b277f052b712c51574b0e28834b5a5f8 (diff) | |
parent | 5bfe138a86a98b52f0b6746b900af6431cd4d17a (diff) |
Merge tag 'release_2014-11-02' into archweb-generic
Staff groups
Diffstat (limited to 'devel')
-rw-r--r-- | devel/admin.py | 8 | ||||
-rw-r--r-- | devel/migrations/0002_staffgroup.py | 31 | ||||
-rw-r--r-- | devel/models.py | 37 |
3 files changed, 63 insertions, 13 deletions
diff --git a/devel/admin.py b/devel/admin.py index c8f80f95..d1729fe3 100644 --- a/devel/admin.py +++ b/devel/admin.py @@ -2,7 +2,7 @@ from django.contrib import admin from django.contrib.auth.admin import UserAdmin from django.contrib.auth.models import User -from .models import UserProfile, MasterKey, DeveloperKey, PGPSignature +from .models import UserProfile, StaffGroup, MasterKey, DeveloperKey, PGPSignature class UserProfileInline(admin.StackedInline): @@ -15,6 +15,11 @@ class UserProfileAdmin(UserAdmin): list_filter = ('is_staff', 'is_superuser', 'is_active') +class StaffGroupAdmin(admin.ModelAdmin): + list_display = ('name', 'group', 'sort_order', 'member_title', 'slug') + prepopulated_fields = {'slug': ('name',)} + + class MasterKeyAdmin(admin.ModelAdmin): list_display = ('pgp_key', 'owner', 'created', 'revoker', 'revoked') search_fields = ('pgp_key', 'owner__username', 'revoker__username') @@ -36,6 +41,7 @@ class PGPSignatureAdmin(admin.ModelAdmin): admin.site.unregister(User) admin.site.register(User, UserProfileAdmin) +admin.site.register(StaffGroup, StaffGroupAdmin) admin.site.register(MasterKey, MasterKeyAdmin) admin.site.register(DeveloperKey, DeveloperKeyAdmin) diff --git a/devel/migrations/0002_staffgroup.py b/devel/migrations/0002_staffgroup.py new file mode 100644 index 00000000..5679e6a3 --- /dev/null +++ b/devel/migrations/0002_staffgroup.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('auth', '0001_initial'), + ('devel', '0001_initial'), + ] + + operations = [ + migrations.CreateModel( + name='StaffGroup', + fields=[ + ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), + ('name', models.CharField(max_length=100)), + ('slug', models.SlugField(unique=True, max_length=100)), + ('sort_order', models.PositiveIntegerField()), + ('member_title', models.CharField(max_length=100)), + ('description', models.TextField(blank=True)), + ('group', models.OneToOneField(to='auth.Group')), + ], + options={ + 'ordering': ('sort_order',), + }, + bases=(models.Model,), + ), + ] 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): |