Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#690 #498 #497 Make the check_purchase work #695

Merged
merged 16 commits into from
Jan 20, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions shopelectro/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,18 +136,21 @@ class ProductFeedback(models.Model):
default='', blank=True, verbose_name=_('limitations'))


class PairIterEnum(enum.EnumMeta):
class ItemsEnum(enum.EnumMeta):
"""
Provide dict-like `items` method.

def __iter__(self):
for i in super().__iter__():
yield i.name, i.value
https://docs.python.org/3/library/enum.html#enum-classes
"""
def items(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so, let's implement keys() and values()?
Up to you

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now these methods aren't needed anywhere, so it will be redundant

return [(i.name, i.value) for i in self]

def __repr__(self):
keys = ', '.join(next(zip(*PaymentOptions)))
return f"<enum '{self.__name__}: {names}'>"
fields = ', '.join(i.name for i in self)
return f"<enum '{self.__name__}: {fields}'>"


class PaymentOptions(enum.Enum, metaclass=PairIterEnum):
class PaymentOptions(enum.Enum, metaclass=ItemsEnum):
cash = 'Наличные'
cashless = 'Безналичные и денежные переводы'
AC = 'Банковская карта'
Expand All @@ -164,7 +167,7 @@ class Order(ecommerce_models.Order):
address = models.TextField(blank=True, default='')
payment_type = models.CharField(
max_length=255,
choices=list(PaymentOptions),
choices=PaymentOptions.items(),
default=PaymentOptions.default().name,
)
comment = models.TextField(blank=True, default='')
Expand Down