#83: Show total number and percent value of filtered participants.

This commit is contained in:
Emanuel Schuetze 2012-04-02 07:47:38 +02:00
parent a8fcba0f69
commit 95bf4c1cc8
2 changed files with 23 additions and 1 deletions

View File

@ -49,7 +49,11 @@
</select> </select>
</form> </form>
</p> </p>
{{ users|length }} {% trans "Participant" %} {% if users|length == allusers|length %}
{{ users|length }} {% trans "Participants" %}
{% else %}
{{ users|length }} {% trans "of" %} {{ allusers|length }} {% trans "Participants" %} (= {{ percent }} %)
{% endif %}
<table> <table>
<tr> <tr>
<th><a href="?sort=first_name&reverse={% if 'first_name' in sortfilter.sort and 'reverse' not in sortfilter %}1{% else %}---{%endif%}">{%trans "First Name" %}</a></th> <th><a href="?sort=first_name&reverse={% if 'first_name' in sortfilter.sort and 'reverse' not in sortfilter %}1{% else %}---{%endif%}">{%trans "First Name" %}</a></th>

View File

@ -91,6 +91,7 @@ def get_overview(request):
if 'reverse' in sortfilter: if 'reverse' in sortfilter:
query = query.reverse() query = query.reverse()
# list of filtered users (with profile)
userlist = query.all() userlist = query.all()
users = [] users = []
for user in userlist: for user in userlist:
@ -99,10 +100,27 @@ def get_overview(request):
users.append(user) users.append(user)
except Profile.DoesNotExist: except Profile.DoesNotExist:
pass pass
# list of all existing users (with profile)
allusers = []
for user in User.objects.all():
try:
user.get_profile()
allusers.append(user)
except Profile.DoesNotExist:
pass
# quotient of selected users and all users
if len(allusers) > 0:
percent = float(len(users)) * 100 / float(len(allusers))
else:
percent = 0
# list of all existing groups
groups = [p['group'] for p in Profile.objects.values('group').exclude(group='').distinct()] groups = [p['group'] for p in Profile.objects.values('group').exclude(group='').distinct()]
# list of all existing committees
committees = [p['committee'] for p in Profile.objects.values('committee').exclude(committee='').distinct()] committees = [p['committee'] for p in Profile.objects.values('committee').exclude(committee='').distinct()]
return { return {
'users': users, 'users': users,
'allusers': allusers,
'percent': round(percent, 1),
'groups': groups, 'groups': groups,
'committees': committees, 'committees': committees,
'cookie': ['participant_sortfilter', urlencode(decodedict(sortfilter), doseq=True)], 'cookie': ['participant_sortfilter', urlencode(decodedict(sortfilter), doseq=True)],