# Path: cmsplugin_shop/price.py
# class Price(BasePrice, namedtuple('Price', 'net gross rate')):
# 
#     def __new__(cls, price, rate=0):
#         price = Decimal(price)
#         rate  = Decimal(rate)
#         if rate:
#             if PRICE_TYPE == 'gross':
#                 gross   = quantize(price)
#                 net     = quantize(gross / rate)
#             else:
#                 net     = quantize(price)
#                 gross   = quantize(net * rate)
#         else:
#             gross = net = quantize(price)
#         return super(Price, cls).__new__(cls, net, gross, rate)
# 
#     def __mul__(self, other):
#         try:
#             other = Decimal(other)
#             if PRICE_TYPE == 'gross':
#                 return Price(self.gross * other, self.rate)
#             else:
#                 return Price(self.net   * other, self.rate)
#         except TypeError:
#             return NotImplemented
# 
#     def __add__(self, other):
#         if isinstance(other, Price):
#             return ComplexPrice((self, other))
#         elif isinstance(other, ComplexPrice):
#             return ComplexPrice((self,) + other.prices)
#         else:
#             try:
#                 return self + Price(other, self.rate)
#             except TypeError:
#                 return NotImplemented
# 
# Path: cmsplugin_shop/utils.py
# def get_rand_hash(length=32, stringset=string.ascii_letters+string.digits):
#     return ''.join([stringset[i%len(stringset)] for i in [ord(x) for x in os.urandom(length)]])
# 
# def get_html_field():
#     return import_string(getattr(settings.settings,
#         'CMSPLUGIN_SHOP_HTML_FIELD',
#         'djangocms_text_ckeditor.fields.HTMLField',
#     ))


import tagging
from cms.models import CMSPlugin
from django.contrib.sites.models import Site
from django.core.exceptions import ValidationError
from django.core.mail import send_mail
from django.core.urlresolvers import reverse
from django.core.validators import RegexValidator
from django.db import models
from django.template import Context
from django.template.loader import get_template
from django.utils.encoding import python_2_unicode_compatible, smart_text
from django.utils.functional import cached_property
from django.utils.translation import ugettext_lazy as _
from filer.fields.image import FilerImageField
from mptt.fields import TreeForeignKey
from mptt.models import MPTTModelBase
from . import settings
from .price import Price
from .utils import get_rand_hash, get_html_field
    def send_customer_mail(self):
        send_mail(
            _('Order accepted'),
            get_template('cmsplugin_shop/order_customer_mail.txt').render(Context({
                'site':  Site.objects.get_current(),
                'order': self,
            })),
            settings.SHOP_EMAIL,
            [self.email],
            **settings.SEND_MAIL_KWARGS
        )

    def send_manager_mail(self):
        send_mail(
            _('New order received'),
            get_template('cmsplugin_shop/order_manager_mail.txt').render(Context({
                'site':  Site.objects.get_current(),
                'order': self,
            })),
            settings.SHOP_EMAIL,
            map(lambda m: u'"{}" <{}>'.format(m[0], m[1]), settings.settings.MANAGERS),
            **settings.SEND_MAIL_KWARGS
        )

    def save(self, *args, **kwargs):
        if self.slug:
            super(Order, self).save(*args, **kwargs)
        else:
            tries = 10
            while True:

# Path: cmsplugin_shop/price.py
# class Price(BasePrice, namedtuple('Price', 'net gross rate')):
# 
#     def __new__(cls, price, rate=0):
#         price = Decimal(price)
#         rate  = Decimal(rate)
#         if rate:
#             if PRICE_TYPE == 'gross':
#                 gross   = quantize(price)
#                 net     = quantize(gross / rate)
#             else:
#                 net     = quantize(price)
#                 gross   = quantize(net * rate)
#         else:
#             gross = net = quantize(price)
#         return super(Price, cls).__new__(cls, net, gross, rate)
# 
#     def __mul__(self, other):
#         try:
#             other = Decimal(other)
#             if PRICE_TYPE == 'gross':
#                 return Price(self.gross * other, self.rate)
#             else:
#                 return Price(self.net   * other, self.rate)
#         except TypeError:
#             return NotImplemented
# 
#     def __add__(self, other):
#         if isinstance(other, Price):
#             return ComplexPrice((self, other))
#         elif isinstance(other, ComplexPrice):
#             return ComplexPrice((self,) + other.prices)
#         else:
#             try:
#                 return self + Price(other, self.rate)
#             except TypeError:
#                 return NotImplemented
# 
# Path: cmsplugin_shop/utils.py
# def get_rand_hash(length=32, stringset=string.ascii_letters+string.digits):
#     return ''.join([stringset[i%len(stringset)] for i in [ord(x) for x in os.urandom(length)]])
# 
# def get_html_field():
#     return import_string(getattr(settings.settings,
#         'CMSPLUGIN_SHOP_HTML_FIELD',
#         'djangocms_text_ckeditor.fields.HTMLField',
#     ))


# Path: cmsplugin_shop/models.py
import tagging
from cms.models import CMSPlugin
from django.contrib.sites.models import Site
from django.core.exceptions import ValidationError
from django.core.mail import send_mail
from django.core.urlresolvers import reverse
from django.core.validators import RegexValidator
from django.db import models
from django.template import Context
from django.template.loader import get_template
from django.utils.encoding import python_2_unicode_compatible, smart_text
from django.utils.functional import cached_property
from django.utils.translation import ugettext_lazy as _
from filer.fields.image import FilerImageField
from mptt.fields import TreeForeignKey
from mptt.models import MPTTModelBase
from . import settings
from .price import Price
from .utils import get_rand_hash, get_html_field

    def send_customer_mail(self):
        send_mail(
            _('Order accepted'),
            get_template('cmsplugin_shop/order_customer_mail.txt').render(Context({
                'site':  Site.objects.get_current(),
                'order': self,
            })),
            settings.SHOP_EMAIL,
            [self.email],
            **settings.SEND_MAIL_KWARGS
        )

    def send_manager_mail(self):
        send_mail(
            _('New order received'),
            get_template('cmsplugin_shop/order_manager_mail.txt').render(Context({
                'site':  Site.objects.get_current(),
                'order': self,
            })),
            settings.SHOP_EMAIL,
            map(lambda m: u'"{}" <{}>'.format(m[0], m[1]), settings.settings.MANAGERS),
            **settings.SEND_MAIL_KWARGS
        )

    def save(self, *args, **kwargs):
        if self.slug:
            super(Order, self).save(*args, **kwargs)
        else:
            tries = 10
            while True:

                self.slug = get_rand_hash()