Beispiel #1
0
class AbstractProduct(AbstractProductBase):
    class Meta:
        abstract = True
        app_label = 'shop'
        ordering = ['name']
        verbose_name_plural = _('products')
        verbose_name = _('product')

    slug = AutoSlugField(_('URL'), populate_from='name', unique=True)
    section = models.ForeignKey('shop.ProductSection',
                                verbose_name=_('Section'),
                                related_name='products')
    manufacturer = models.ForeignKey('shop.ProductManufacturer',
                                     verbose_name=_('Manufacturer'),
                                     related_name='manufacturer_products',
                                     null=True,
                                     blank=True)
    labels = models.ManyToManyField('shop.ProductLabel',
                                    verbose_name=_('Labels'),
                                    related_name='label_products',
                                    blank=True)
    code = models.CharField(_('Code'), max_length=100, blank=True, default='')
    short_description = RteField(_('Short description'),
                                 blank=True,
                                 default='')
    residue = models.IntegerField(_('Residue'), default=1)
    price = models.DecimalField(verbose_name=_('Price'),
                                decimal_places=2,
                                max_digits=10,
                                default=0)
    image = models.ImageField(_('Image'),
                              upload_to='shop/product/%Y/%m/%d',
                              null=True,
                              blank=True)
Beispiel #2
0
class AbstractFeedItem(models.Model):
    class Meta:
        app_label = 'feeds'
        ordering = ['-date_published']
        abstract = True
        verbose_name = _('Feed item')
        verbose_name_plural = _('Feed items')

    @property
    def search_content_type(self):
        return self.feed.type.slug

    def __unicode__(self):
        return self.name

    slug = AutoSlugField(_('URL'), populate_from='name', unique=True)
    feed = models.ForeignKey(Feed,
                             verbose_name=_('Feed'),
                             on_delete=models.PROTECT)
    name = models.CharField(max_length=1024, verbose_name=_('Title'))
    short_text = RteField(verbose_name=_('Short Text'))
    full_text = RteField(verbose_name=_('Full Text'))
    picture = models.ImageField(verbose_name=_('Picture'),
                                upload_to='feeds/%Y/%m/%d',
                                null=True,
                                blank=True)
    seo_keywords = models.TextField(
        verbose_name=_('Keywords'),
        help_text=_('Do not use more than 255 symbols'),
        blank=True)
    seo_description = models.TextField(
        verbose_name=_('Description'),
        help_text=_('Do not use more than 1024 symbols'),
        blank=True)
    is_visible = models.BooleanField(default=True,
                                     verbose_name=_('Show on Site'))
    is_main = models.BooleanField(default=True, verbose_name=_('Is Main'))
    date_published = models.DateTimeField(
        default=datetime.datetime.now, verbose_name=_('Date of Publication'))
    date_created = models.DateTimeField(auto_now_add=True,
                                        verbose_name=_('Date of Creation'))
Beispiel #3
0
class AbstractOrderStatus(models.Model):
    class Meta:
        abstract = True
        app_label = 'shop'
        verbose_name = _('order status')
        verbose_name_plural = _('order statuses')
        ordering = ['sort']

    def __unicode__(self):
        return self.name

    slug = models.SlugField(_('URL'), unique=True)
    name = models.CharField(_('Name'), max_length=100)
    description = RteField(_('Description'), blank=True, default='')
    is_enabled = models.BooleanField(_('Is enabled'), default=True)
    sort = models.IntegerField(default=1)
    date_created = models.DateTimeField(auto_now_add=True)
Beispiel #4
0
class AbstractProductBase(models.Model):
    class Meta:
        abstract = True
        app_label = 'shop'

    def __unicode__(self):
        return self.name

    name = models.CharField(_('Name'), max_length=255)
    description = RteField(_('Description'), blank=True, default='')
    seo_keywords = models.TextField(_('Keywords (meta keywords)'),
                                    default='',
                                    blank=True)
    seo_description = models.TextField(_('Description (meta description)'),
                                       default='',
                                       blank=True)
    is_visible = models.BooleanField(_('Is Visible'), default=True)
    date_created = models.DateTimeField(auto_now_add=True)
Beispiel #5
0
class AbstractOrderShippingType(models.Model):
    class Meta:
        abstract = True
        app_label = 'shop'
        verbose_name = _('shipping type')
        verbose_name_plural = _('shipping types')
        ordering = ['sort']

    def __unicode__(self):
        return u'%s (%s)' % (self.name, self.cost)

    slug = models.SlugField(_('URL'), unique=True)
    name = models.CharField(_('Name'), max_length=100)
    description = RteField(_('Description'), blank=True, default='')
    cost = models.DecimalField(_('Cost'),
                               decimal_places=2,
                               max_digits=10,
                               default=0)
    is_enabled = models.BooleanField(_('Is enabled'), default=True)
    sort = models.IntegerField(default=1)
    date_created = models.DateTimeField(auto_now_add=True)
Beispiel #6
0
class AbstractPage(MPTTModel):
    """
    Base page model. In common cases, you should not re-declare this class, since it have all necessary features.
    It holds base information about site's pages - urls, names, functional features, parents and childrens etc.
    """
    class Meta:
        app_label = 'pages'
        abstract = True
        ordering = ['sort']
        verbose_name = _('page')
        verbose_name_plural = _('pages')
        unique_together = ['module', 'slug']

    def __unicode__(self):
        """
        Constructs breadcrumbs-like page name.
        """
        parent = self.parent
        page_names = [self.title]
        while parent:
            page_names.append(parent.title)
            parent = parent.parent
        return ' / '.join(reversed(page_names))

    parent = TreeForeignKey('self',
                            null=True,
                            related_name='children',
                            verbose_name=_('Parent Page'),
                            blank=True)

    title = models.CharField(max_length=255,
                             verbose_name=_('Title'),
                             help_text=_('Shows inside the title tag'))
    header = models.CharField(max_length=255, verbose_name=_('Page Header'))

    menu_name = models.CharField(max_length=255,
                                 default='',
                                 verbose_name=_('Menu name'))
    redirect_url = models.CharField(max_length=255,
                                    blank=True,
                                    default='',
                                    verbose_name=_('URL for Redirect'))

    slug = models.SlugField(default='', verbose_name=_('URL'), blank=True)
    url = models.CharField(max_length=512, unique=True)

    sort = models.IntegerField(default=1)

    module = models.ForeignKey('pages.PageModule',
                               verbose_name=_('Module'),
                               related_name='%(app_label)s_%(class)s_related')
    module_params = models.CharField(max_length=128,
                                     blank=True,
                                     null=True,
                                     default=None,
                                     verbose_name=_('Module parameters'))

    before_content = RteField(default='',
                              blank=True,
                              verbose_name=_('Before Content'))
    after_content = RteField(default='',
                             blank=True,
                             verbose_name=_('After Content'))

    seo_keywords = models.TextField(default='',
                                    blank=True,
                                    verbose_name=_('Keywords (meta keywords)'))
    seo_description = models.TextField(
        default='',
        blank=True,
        verbose_name=_('Description (meta description)'))

    ad_section = models.ForeignKey(
        'ads.AdSection',
        verbose_name=_('Ads'),
        null=True,
        blank=True,
        related_name='%(app_label)s_%(class)s_related')

    security_type = models.CharField(max_length=16,
                                     verbose_name=_('Security type'),
                                     choices=SECURITY_TYPE_CHOICES,
                                     default='BY_PARENT')
    user_groups = models.ManyToManyField(UserGroup,
                                         verbose_name=_('User groups'))

    is_enabled = models.BooleanField(default=True,
                                     verbose_name=_('Is Enabled'))
    is_in_menu = models.BooleanField(default=True,
                                     verbose_name=_('Show in Menu'))

    date_created = models.DateTimeField(auto_now_add=True)

    def get_security_type(self):
        if self.security_type == 'BY_PARENT' and self.parent:
            parent = self.parent
            while parent:
                if parent.security_type == 'BY_PARENT':
                    parent = parent.parent
                else:
                    break
            return parent.security_type
        else:
            return self.security_type

    def delete(self):
        if not self.parent:
            pass
        else:
            return super(AbstractPage, self).delete()

    @property
    def menu_url(self):
        lang = get_language()
        prefix = '' if lang == settings.LANGUAGE_CODE else '/%s' % lang
        return self.redirect_url if self.redirect_url else prefix + self.url

    @property
    def page_url(self):
        if not self.parent:
            return '/'
        return '/%s/%s/' % (self.module.slug, self.slug)

    def serializable_object(self):
        obj = {
            'pk': self.pk,
            'parent_id': self.parent_id,
            'title': self.title,
            'module': str(self.module),
            'url': self.url,
            'children': []
        }
        for child in self.get_children():
            obj['children'].append(child.serializable_object())
        return obj