Changeset 1de230f


Ignore:
Timestamp:
Aug 24, 2011, 2:42:50 AM (15 years ago)
Author:
Alex Dehnert <adehnert@…>
Branches:
master, space-access, stable, stage, test-hooks
Children:
7b57a9b
Parents:
3107c52
git-author:
Alex Dehnert <adehnert@…> (08/24/11 02:42:35)
git-committer:
Alex Dehnert <adehnert@…> (08/24/11 02:42:50)
Message:

Add group search

This introduces a dependency on django-filters ---
https://github.com/alex/django-filter.

Location:
asadb
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • asadb/groups/views.py

    r3107c52 r1de230f  
    2424import form_utils.forms
    2525import reversion.models
     26import django_filters
    2627
    2728from util.db_form_utils import StaticWidget
     
    170171    }
    171172    return render_to_response('groups/group_change_main.html', context, context_instance=RequestContext(request), )
     173
     174
     175class GroupFilter(django_filters.FilterSet):
     176    name = django_filters.CharFilter(lookup_type='icontains', label="Name contains")
     177    abbreviation = django_filters.CharFilter(lookup_type='iexact', label="Abbreviation is")
     178
     179    class Meta:
     180        model = groups.models.Group
     181        fields = [
     182            'name',
     183            'abbreviation',
     184            'activity_category',
     185            'group_class',
     186            'group_status',
     187            'group_funding',
     188        ]
     189
     190
     191class GroupListView(ListView):
     192    model = groups.models.Group
     193    template_object_name = 'group'
     194
     195    def get(self, *args, **kwargs):
     196        qs = super(GroupListView, self).get_queryset()
     197        self.filterset = GroupFilter(self.request.GET, qs)
     198        return super(GroupListView, self).get(*args, **kwargs)
     199
     200    def get_queryset(self, ):
     201        qs = self.filterset.qs
     202        return qs
     203
     204    def get_context_data(self, **kwargs):
     205        context = super(GroupListView, self).get_context_data(**kwargs)
     206        # Add in the publisher
     207        context['pagename'] = 'groups'
     208        context['filter'] = self.filterset
     209        return context
    172210
    173211
  • asadb/settings.py

    rf07e84b r1de230f  
    55SITE_ROOT = os.path.normpath(os.path.dirname(__file__))
    66SITE_WEB_PATH = ''
    7 
    87
    98DEBUG = False
     
    105104    'django.contrib.sites',
    106105    'form_utils',
     106    'django_filters',
    107107    'reversion',
    108108    'south',
  • asadb/template/groups/group_list.html

    r94c79bd r1de230f  
    55
    66<h1>MIT Student Groups</h1>
     7
     8<h2>Search</h2>
     9
     10<form action="" method="get">
     11    <table class='pretty-table'>
     12    {{ filter.form.as_table }}
     13    </table>
     14    <input type="submit" value="Search" />
     15</form>
     16
     17<h2>The Groups</h2>
    718
    819<table class='pretty-table'>
  • asadb/urls.py

    r9879d18 r1de230f  
    3636
    3737    # Group list
    38     url(
    39         r'^groups/$',
    40         list_detail.object_list,
    41         {
    42             'queryset': groups.models.Group.objects.all(),
    43             'template_object_name': 'group',
    44             'extra_context': {'pagename': 'groups', },
    45         },
    46         name='group-list',
    47     ),
     38    url(r'^groups/$', groups.views.GroupListView.as_view(), name='group-list', ),
    4839    url(r'^group/(?P<pk>\d+)/$', groups.views.GroupDetailView.as_view(), name='group-detail', ),
    4940    url(r'^groups/recent_changes/$', groups.views.GroupHistoryView.as_view(), name='groups-manage-history', ),
Note: See TracChangeset for help on using the changeset viewer.