Changeset f610262


Ignore:
Timestamp:
Mar 23, 2013, 11:36:03 PM (13 years ago)
Author:
Alex Dehnert <adehnert@…>
Branches:
master, space-access, stable, stage
Children:
1cfab5a
Parents:
26826c9
git-author:
Alex Dehnert <adehnert@…> (03/23/13 23:36:03)
git-committer:
Alex Dehnert <adehnert@…> (03/23/13 23:36:03)
Message:

Allow sorting and filtering the midway page

Location:
asadb
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • asadb/forms/views.py

    r26826c9 rf610262  
    2222from django.db import connection
    2323from django.db.models import Q, Count
     24
     25import django_filters
    2426
    2527import forms.models
     
    564566
    565567
     568class MidwayAssignmentFilter(django_filters.FilterSet):
     569    name = django_filters.CharFilter(name='group__name', lookup_type='icontains', label="Name contains")
     570    abbreviation = django_filters.CharFilter(name='group__abbreviation', lookup_type='iexact', label="Abbreviation is")
     571    activity_category = django_filters.ModelChoiceFilter(
     572        label='Activity category',
     573        name='group__activity_category',
     574        queryset=groups.models.ActivityCategory.objects,
     575    )
     576
     577    class Meta:
     578        model = forms.models.MidwayAssignment
     579        fields = [
     580            'name',
     581            'abbreviation',
     582            'activity_category',
     583        ]
     584        order_by = (
     585            ('group__name', 'Name', ),
     586            ('group__abbreviation', 'Abbreviation', ),
     587            ('group__activity_category__name', 'Activity category', ),
     588            ('location', 'Location', ),
     589        )
    566590
    567591class MidwayMapView(DetailView):
     
    574598        context = super(MidwayMapView, self).get_context_data(**kwargs)
    575599       
    576         midway = context['midway']
    577         assignments = forms.models.MidwayAssignment.objects.filter(midway=midway)
    578         context['assignments'] = assignments
     600        filterset = MidwayAssignmentFilter(self.request.GET)
     601        context['assignments'] = filterset.qs
     602        context['filter'] = filterset
    579603        context['pagename'] = 'midway'
    580604
  • asadb/template/midway/map.html

    rcf509c0 rf610262  
    1616<tr>
    1717    <th>Group</th>
    18     <th>Table</th>
     18    <th>Category</th>
     19    <th>Location</th>
    1920    <th>Website</th>
    2021</tr>
     
    2223<tr>
    2324    <th>{{assignment.group}}</th>
     25    <td>{% if assignment.group.activity_category %}{{assignment.group.activity_category}}{% endif %}</td>
    2426    <td>{{assignment.location}}</td>
    2527    <td>{% if assignment.group.website_url %}<a href='{{assignment.group.website_url}}'>Website</a>{% endif %}</td>
     
    2830</table>
    2931
     32<h2>Sort the assignments</h2>
     33
     34<form action="" method="get">
     35    <table class='pretty-table'>
     36    {{ filter.form.as_table }}
     37    </table>
     38    <input type="submit" value="Search" />
     39</form>
     40
    3041{% endblock %}
Note: See TracChangeset for help on using the changeset viewer.