Added view to add or remove users from group, merged common code and moved it to common.utils

This commit is contained in:
Roberto Rosario
2011-05-08 04:15:29 -04:00
parent 5a156bf23d
commit 7cc768305f
8 changed files with 125 additions and 31 deletions

View File

@@ -8,6 +8,8 @@ from django.utils.http import urlencode as django_urlencode
from django.utils.datastructures import MultiValueDict
from django.conf import settings
from django.utils.translation import ugettext_lazy as _
from django.contrib.contenttypes.models import ContentType
from django.contrib.auth.models import User
def urlquote(link=None, get=None):
@@ -311,3 +313,21 @@ def parse_range(astr):
x = part.split(u'-')
result.update(range(int(x[0]), int(x[-1]) + 1))
return sorted(result)
def generate_choices_w_labels(choices, display_object_type=True):
results = []
for choice in choices:
ct_label = ContentType.objects.get_for_model(choice).name
label = unicode(choice)
if isinstance(choice, User):
label = choice.get_full_name() if choice.get_full_name() else choice
if display_object_type:
verbose_name = unicode(getattr(choice._meta, u'verbose_name', ct_label))
results.append((u'%s,%s' % (ct_label, choice.pk), u'%s: %s' % (verbose_name, label)))
else:
results.append((u'%s,%s' % (ct_label, choice.pk), u'%s' % (label)))
#Sort results by the label not the key value
return sorted(results, key=lambda x: x[1])