Ignore:
Timestamp:
Mar 31, 2012, 4:15:52 PM (14 years ago)
Author:
Alex Dehnert <adehnert@…>
Branches:
master, space-access, stable, stage
Children:
e49def5
Parents:
747c960
git-author:
Alex Dehnert <adehnert@…> (03/31/12 16:15:52)
git-committer:
Alex Dehnert <adehnert@…> (03/31/12 16:15:52)
Message:

Implement GroupFilter? default values better

This solves a problem where if you subclass GroupFilter? and add a required
field, the form will always be seen as bound, and consequently it will
give a validation error on initial load. We now use a "more right"
way to implement default values.

Also, as a convenience, if you pass in an empty data dictionary, we interpret
it as though it were none, so your form will not be bound if you use the
idiom of passing in request.GET regardless of whether your form has actually
been submitted.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • asadb/groups/views.py

    r747c960 r7415a15  
    564564
    565565    def __init__(self, data=None, *args, **kwargs):
    566         if data is None: data = {}
    567         else: data = data.copy()
     566        if not data: data = None
     567        super(GroupFilter, self).__init__(data, *args, **kwargs)
    568568        active_pk = groups.models.GroupStatus.objects.get(slug='active').pk
    569         data.setdefault('group_status', active_pk, )
    570         super(GroupFilter, self).__init__(data, *args, **kwargs)
     569        self.form.initial['group_status'] = active_pk
    571570
    572571
Note: See TracChangeset for help on using the changeset viewer.