Created
November 7, 2012 15:00
-
-
Save slezica/4032093 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class OrderFilterForm(Form): | |
name = CharField(required = False) | |
email = CharField(required = False) | |
aec = CharField(required = False) | |
date_created_from = DateField(required = False) | |
date_created_to = DateField(required = False) | |
def process(self): | |
data = lambda key: self.cleaned_data.get(key, '') | |
query = Q() | |
for word in data('name').split(): | |
query &= ( | |
Q(user__user__first_name__icontains = word) | |
| Q(user__user__last_name__icontains = word) | |
) | |
if data('aec'): | |
query &= Q(subdeal__deal__aec__icontains = data('aec')) | |
if data('email'): | |
query &= ( | |
Q(user__user__email__icontains = data('email').strip()) | |
| ( | |
Q(mporder__isnull = False) | |
& Q(mporder__their_email__icontains = data('email')) | |
) | |
) | |
if data('date_created_from'): | |
query &= Q(date_created__gte = data('date_created_from')) | |
if data('date_created_to'): | |
query &= Q(date_created__lte = data('date_created_to')) | |
return query |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment