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

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. from django import forms
  2. from django.utils.translation import ugettext_lazy as _, pgettext_lazy
  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(
  10. required=False, label=pgettext_lazy(u"User's name", u"Name"))
  11. class ProductAlertUpdateForm(forms.ModelForm):
  12. def __init__(self, *args, **kwargs):
  13. super(ProductAlertUpdateForm, self).__init__(*args, **kwargs)
  14. alert = kwargs['instance']
  15. if alert.user:
  16. # Remove 'unconfirmed' from list of available choices when editing
  17. # an alert for a real user
  18. choices = self.fields['status'].choices
  19. del choices[0]
  20. self.fields['status'].choices = choices
  21. class Meta:
  22. model = ProductAlert
  23. exclude = ('product', 'user', 'email', 'key',
  24. 'date_confirmed', 'date_cancelled', 'date_closed')
  25. class ProductAlertSearchForm(forms.Form):
  26. STATUS_CHOICES = (
  27. ('', '------------'),
  28. ) + ProductAlert.STATUS_CHOICES
  29. status = forms.ChoiceField(required=False, choices=STATUS_CHOICES,
  30. label=_('Status'))
  31. name = forms.CharField(required=False, label=_('Name'))
  32. email = forms.EmailField(required=False, label=_('Email'))