Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

12345678910111213141516171819202122232425262728293031323334353637383940
  1. from django.core import exceptions
  2. from oscar.apps.offer.models import Range, Condition, Benefit
  3. def _class_path(klass):
  4. return '%s.%s' % (klass.__module__, klass.__name__)
  5. def create_range(range_class):
  6. """
  7. Create a custom range instance
  8. """
  9. if not hasattr(range_class, 'name'):
  10. raise exceptions.ValidationError(
  11. "A custom range must have a name attribute")
  12. return Range.objects.create(
  13. name=range_class.name,
  14. proxy_class=_class_path(range_class))
  15. def create_condition(condition_class):
  16. """
  17. Create a custom condition instance
  18. """
  19. return Condition.objects.create(
  20. proxy_class=_class_path(condition_class))
  21. def create_benefit(benefit_class):
  22. """
  23. Create a custom benefit instance
  24. """
  25. # The custom benefit_class must override __unicode__ and description to
  26. # avoid a recursion error
  27. if benefit_class.description is Benefit.description:
  28. raise RuntimeError("Your custom benefit must implement its own "
  29. "'description' property")
  30. return Benefit.objects.create(
  31. proxy_class=_class_path(benefit_class))