Add category support to groups, Fixes #281

This commit is contained in:
2012-08-14 21:33:19 +01:00
parent 7161b2833b
commit 4dd67ada40
4 changed files with 44 additions and 12 deletions

View File

@@ -1,7 +1,7 @@
from django.contrib import admin from django.contrib import admin
from django.contrib.auth.models import Group from django.contrib.auth.models import Group
from django.contrib.auth.admin import GroupAdmin from django.contrib.auth.admin import GroupAdmin
from groups.models import GroupInformation, GroupRequest from groups.models import GroupInformation, GroupRequest, GroupCategory
class GroupRequestAdmin(admin.ModelAdmin): class GroupRequestAdmin(admin.ModelAdmin):
list_display = ('group', 'user', 'status', 'created_date', 'changed_by', 'changed_date') list_display = ('group', 'user', 'status', 'created_date', 'changed_by', 'changed_date')
@@ -9,6 +9,7 @@ class GroupRequestAdmin(admin.ModelAdmin):
list_filter = ('status',) list_filter = ('status',)
admin.site.register(GroupRequest, GroupRequestAdmin) admin.site.register(GroupRequest, GroupRequestAdmin)
admin.site.register(GroupCategory, admin.ModelAdmin)
class SSOGroupInformationInline(admin.StackedInline): class SSOGroupInformationInline(admin.StackedInline):
model = GroupInformation model = GroupInformation

View File

@@ -4,11 +4,22 @@ from django.contrib.auth.models import Group, User
from groups.app_defines import * from groups.app_defines import *
class GroupCategory(models.Model):
"""Category to put groups into"""
name = models.CharField('Category Name', max_length="250")
def __unicode__(self):
return self.name
class GroupInformation(models.Model): class GroupInformation(models.Model):
""" Extended group information """ """ Extended group information """
group = models.OneToOneField(Group) group = models.OneToOneField(Group)
category = models.ForeignKey(GroupCategory, related_name='groups', null=True)
type = models.IntegerField("Group Type", choices=GROUP_TYPE_CHOICES, default=GROUP_TYPE_PERMISSION) type = models.IntegerField("Group Type", choices=GROUP_TYPE_CHOICES, default=GROUP_TYPE_PERMISSION)
admins = models.ManyToManyField(User, blank=True) admins = models.ManyToManyField(User, blank=True)
public = models.BooleanField("Public", default=False, help_text="Indicates if the group is visible to all") public = models.BooleanField("Public", default=False, help_text="Indicates if the group is visible to all")

View File

@@ -9,22 +9,33 @@
<p>This is the list of your current groups, and groups you can request to be a member of.</p> <p>This is the list of your current groups, and groups you can request to be a member of.</p>
{% if group_list %} {% if group_list %}
{% regroup group_list by category as groups_by_category %}
{% for category in groups_by_category %}
{% if category.grouper %}
<p>
<h2>{{ category.grouper }}</h2>
</p>
{% endif %}
<table class="zebra-striped" id="groups"> <table class="zebra-striped" id="groups">
<thead> <thead>
<tr><th>Group Name</th><th>Description</th><th>Status</th><th>Actions</th></tr> <tr><th>Group Name</th><th>Description</th><th>Status</th><th>Actions</th></tr>
</thead> </thead>
<tbody> <tbody>
{% for id, group, description, status, requestable, fixed, pending, moderated in group_list %} {% for group in category.list %}
<tr><td>{{ group }}</td> <tr><td style="width: 20%">{{ group.group }}</td>
<td>{{ description }}</td> <td>{{ group.description }}</td>
<td>{% if pending %}Request Pending{% else %}{% if status %}{{ status }}{% endif %}{% endif %}</td> <td style="width: 15%">{% if group.pending %}Request Pending{% else %}{% if group.status %}{{ group.status }}{% endif %}{% endif %}</td>
<td>{% ifequal status None %}{% if requestable %}<a href="{% url groups.views.create_request id %}">{% if moderated %}Request Membership{% else %}Join{% endif %}</a>{% endif %}{% endifequal %} <td style="width: 20%">{% ifequal group.status None %}{% if requestable %}<a href="{% url groups.views.create_request group.id %}">{% if group.moderated %}Request Membership{% else %}Join{% endif %}</a>{% endif %}{% endifequal %}
{% if not fixed and status %}<a href="{% url groups.views.kick_member id request.user.id %}">Leave</a>&nbsp;{% endif %} {% if not group.fixed and group.status %}<a href="{% url groups.views.kick_member group.id request.user.id %}">Leave</a>&nbsp;{% endif %}
{% if status == 'Admin' or request.user.is_superuser %}{% if not fixed %}<a href="{% url groups.views.admin_group id %}">Admin</a>{% endif %}{% endif %}</td> {% if group.status == 'Admin' or request.user.is_superuser %}{% if not group.fixed %}<a href="{% url groups.views.admin_group group.id %}">Admin</a>{% endif %}{% endif %}</td>
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>
</table> </table>
{% endfor %}
{% else %} {% else %}
<b>No groups are available.</b> <b>No groups are available.</b>
{% endif %} {% endif %}

View File

@@ -55,10 +55,19 @@ def group_list(request):
fixed = not group.groupinformation.type == GROUP_TYPE_PERMISSION fixed = not group.groupinformation.type == GROUP_TYPE_PERMISSION
pending = group.requests.filter(status=REQUEST_PENDING,user=request.user).count() pending = group.requests.filter(status=REQUEST_PENDING,user=request.user).count()
group_list.append((group.id, group.name, group.groupinformation.description, status, requestable, fixed, pending, group.groupinformation.moderated)) group_list.append({
'id': group.id,
group_list = sorted(group_list, key=lambda name: name[1].lower()) 'group': group.name,
'category': group.groupinformation.category or 'Other',
'description': group.groupinformation.description,
'status': status,
'requestable': requestable,
'fixed': fixed,
'pending': pending,
'moderated': group.groupinformation.moderated,
})
group_list = sorted(group_list, key=lambda k: "%s-%s" % (k['category'], k['group']))
return render_to_response('groups/group_list.html', locals(), context_instance=RequestContext(request)) return render_to_response('groups/group_list.html', locals(), context_instance=RequestContext(request))