You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

forms.py 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. from django import forms
  2. from django.utils.translation import ugettext_lazy as _
  3. from oscar.core.loading import get_model
  4. from oscar.core.compat import get_user_model
  5. User = get_user_model()
  6. ProductAlert = get_model('customer', 'ProductAlert')
  7. class UserSearchForm(forms.Form):
  8. email = forms.CharField(required=False, label=_("Email"))
  9. name = forms.CharField(required=False, label=_("Name"))
  10. class ProductAlertUpdateForm(forms.ModelForm):
  11. def __init__(self, *args, **kwargs):
  12. super(ProductAlertUpdateForm, self).__init__(*args, **kwargs)
  13. alert = kwargs['instance']
  14. if alert.user:
  15. # Remove 'unconfirmed' from list of available choices when editing
  16. # an alert for a real user
  17. choices = self.fields['status'].choices
  18. del choices[0]
  19. self.fields['status'].choices = choices
  20. class Meta:
  21. model = ProductAlert
  22. exclude = ('product', 'user', 'email', 'key',
  23. 'date_confirmed', 'date_cancelled', 'date_closed')
  24. class ProductAlertSearchForm(forms.Form):
  25. STATUS_CHOICES = (
  26. ('', '------------'),
  27. ) + ProductAlert.STATUS_CHOICES
  28. status = forms.ChoiceField(required=False, choices=STATUS_CHOICES,
  29. label=_('Status'))
  30. name = forms.CharField(required=False, label=_('Name'))
  31. email = forms.EmailField(required=False, label=_('Email'))