예제 #1
0
class Author(User):
    """
    Proxy model around :class:`django.contrib.auth.models.get_user_model`.
    """
    # author = models.ForeignKey(User, unique=True)
    # objects = get_user_model()._default_manager
    objects = User._default_manager
    published = EntryRelatedPublishedManager()

    def entries_published(self):
        """
        Returns author's published entries.
        """
        return entries_published(self.entries)

    @models.permalink
    def get_absolute_url(self):
        """
        Builds and returns the author's URL based on his username.
        """
        return ('zinnia_author_detail', [self.get_username()])

    def __str__(self):
        """
        If the user has a full name, use it instead of the username.
        """
        return self.get_full_name() or self.get_username()

    class Meta:
        """
        Author's meta informations.
        """
        app_label = 'zinnia'
        proxy = True
예제 #2
0
class BaseCategory(MPTTModel):
    title = models.CharField(_('title'), max_length=255)

    slug = models.SlugField(_('slug'),
                            unique=True,
                            max_length=255,
                            help_text=_("Used to build the category's URL."))

    description = models.TextField(_('description'), blank=True)

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

    objects = TreeManager()
    published = EntryRelatedPublishedManager()

    class Meta:
        ordering = ('title', )
        abstract = True

    class MPTTMeta:
        order_insertion_by = ('title', )

    def __unicode__(self):
        return self.title
예제 #3
0
파일: gallery.py 프로젝트: ivansons/mp_cms
class ModelCategory(MPTTModel):
    """
    Simple model for categorizing model entries.
    """

    title = models.CharField(_('title'), max_length=255)

    slug = models.SlugField(_('slug'),
                            unique=True,
                            max_length=255,
                            help_text=_("Used to build the category's URL."))

    description = models.TextField(_('description'), blank=True)

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

    objects = TreeManager()
    published = EntryRelatedPublishedManager()

    class Meta:
        """
        ModelCategory's meta informations.
        """
        ordering = ['title']
        verbose_name = _('model category')
        verbose_name_plural = _('model categories')

    class MPTTMeta:
        """
        Category MPTT's meta informations.
        """
        order_insertion_by = ['title']

    def __unicode__(self):
        return self.title

    @property
    def tree_path(self):
        """
        Returns category's tree path
        by concatening the slug of his ancestors.
        """
        if self.parent_id:
            return '/'.join(
                [ancestor.slug
                 for ancestor in self.get_ancestors()] + [self.slug])
        return self.slug

    def get_absolute_url(self):
        """
        Builds and returns the category's URL
        based on his tree path.
        """
        return reverse('gallery_model_in_category', args=(self.slug, ))
예제 #4
0
class AuthorPublishedManager(models.Model):
    """
    Proxy model manager to avoid overriding of
    the default User's manager and issue #307.
    """
    published = EntryRelatedPublishedManager()

    class Meta:
        abstract = True
예제 #5
0
class Category(MPTTModel):
    """
    Simple model for categorizing entries.
    """

    title = models.CharField(_('title'), max_length=255)

    slug = models.SlugField(_('slug'),
                            unique=True,
                            max_length=255,
                            help_text=_("Used to build the category's URL."))

    description = models.TextField(_('description'), blank=True)

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

    objects = TreeManager()
    published = EntryRelatedPublishedManager()

    def entries_published(self):
        """
        Returns category's published entries.
        """
        return entries_published(self.entries)

    @property
    def tree_path(self):
        """
        Returns category's tree path
        by concatening the slug of his ancestors.
        """
        if self.parent_id:
            return '/'.join(
                [ancestor.slug
                 for ancestor in self.get_ancestors()] + [self.slug])
        return self.slug

    @models.permalink
    def get_absolute_url(self):
        """
        Builds and returns the category's URL
        based on his tree path.
        """
        return ('zinnia:category_detail', (self.tree_path, ))

    def __str__(self):
        return self.title

    class Meta:
        """
        Category's meta informations.
        """
        app_label = 'zinnia'
        ordering = ['title']
        verbose_name = _('category')
        verbose_name_plural = _('categories')

    class MPTTMeta:
        """
        Category MPTT's meta informations.
        """
        order_insertion_by = ['title']
예제 #6
0
class Category(MPTTModel):
    """
    Simple model for categorizing entries.
    """
    LANGUAGE_CHOICES = ((CHINESE, _('zh_CN')), (ENGLISH, _('en')))

    ENTRY_TYPE_CHOICES = ((TYPE_BLOG, _('Blog')), (TYPE_ANNOUNCEMENT,
                                                   _('Announcement')))

    title = models.CharField(_('title'), max_length=255)

    slug = models.SlugField(_('slug'),
                            unique=True,
                            max_length=255,
                            help_text=_("Used to build the category's URL."))

    description = models.TextField(_('description'), blank=True)

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

    language = models.IntegerField(_('language'),
                                   choices=LANGUAGE_CHOICES,
                                   default=ENGLISH,
                                   db_index=True,
                                   help_text=_('Language'))

    entry_type = models.IntegerField(_('Entry type'),
                                     choices=ENTRY_TYPE_CHOICES,
                                     default=TYPE_BLOG,
                                     db_index=True,
                                     help_text=_('Entry type'))

    objects = TreeManager()
    published = EntryRelatedPublishedManager()

    def entries_published(self):
        """
        Returns category's published entries.
        """
        return entries_published(self.entries)

    @property
    def tree_path(self):
        """
        Returns category's tree path
        by concatening the slug of his ancestors.
        """
        if self.parent_id:
            return '/'.join(
                [ancestor.slug
                 for ancestor in self.get_ancestors()] + [self.slug])
        return self.slug

    @models.permalink
    def get_absolute_url(self):
        """
        Builds and returns the category's URL
        based on his tree path.
        """
        return ('zinnia:category_detail', (self.tree_path, ))

    def __str__(self):
        return self.title

    class Meta:
        """
        Category's meta informations.
        """
        app_label = 'zinnia'
        ordering = ['title']
        verbose_name = _('category')
        verbose_name_plural = _('categories')

    class MPTTMeta:
        """
        Category MPTT's meta informations.
        """
        order_insertion_by = ['title']