Beispiel #1
0
class AbstractForumUser(models.Model):

    slug = AutoSlugField(populate_from="username", db_index=False, blank=True)
    location = models.CharField(_("location"), max_length=75, blank=True)
    last_seen = models.DateTimeField(_("last seen"), auto_now=True)
    last_ip = models.GenericIPAddressField(_("last ip"), blank=True, null=True)
    timezone = models.CharField(_("time zone"),
                                max_length=32,
                                choices=TIMEZONE_CHOICES,
                                default='UTC')
    is_administrator = models.BooleanField(_('administrator status'),
                                           default=False)
    is_moderator = models.BooleanField(_('moderator status'), default=False)
    # is_verified = models.BooleanField(_('verified'), default=False)

    topic_count = models.PositiveIntegerField(_("topic count"), default=0)
    comment_count = models.PositiveIntegerField(_("comment count"), default=0)

    class Meta:
        abstract = True

    def save(self, *args, **kwargs):
        if self.is_superuser:
            self.is_administrator = True

        if self.is_administrator:
            self.is_moderator = True

        super(AbstractForumUser, self).save(*args, **kwargs)
Beispiel #2
0
class AutoSlugPopulateFromModel(models.Model):

    title = models.CharField(max_length=255, blank=True)
    slug = AutoSlugField(populate_from='title', max_length=50)

    class Meta:
        app_label = 'spirit'
Beispiel #3
0
class Topic(models.Model):

    user = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name=_("user"))
    category = models.ForeignKey('spirit.Category', verbose_name=_("category"))

    title = models.CharField(_("title"), max_length=75)
    slug = AutoSlugField(populate_from="title", db_index=False, blank=True)
    date = models.DateTimeField(_("date"), auto_now_add=True)
    last_active = models.DateTimeField(_("last active"), auto_now_add=True)
    is_pinned = models.BooleanField(_("pinned"), default=False)
    is_closed = models.BooleanField(_("closed"), default=False)
    is_removed = models.BooleanField(default=False)

    view_count = models.PositiveIntegerField(_("views count"), default=0)
    comment_count = models.PositiveIntegerField(_("comment count"), default=0)

    objects = TopicManager()

    class Meta:
        ordering = ['-last_active', ]
        verbose_name = _("topic")
        verbose_name_plural = _("topics")

    def get_absolute_url(self):
        if self.category_id == settings.ST_TOPIC_PRIVATE_CATEGORY_PK:
            return reverse('spirit:private-detail', kwargs={'topic_id': str(self.id), 'slug': self.slug})

        return reverse('spirit:topic-detail', kwargs={'pk': str(self.id), 'slug': self.slug})

    @property
    def main_category(self):
        return self.category.parent or self.category

    def __str__(self):
        return self.title
Beispiel #4
0
class Topic(models.Model):

    user = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name=_("user"))
    category = models.ForeignKey('spirit.Category', verbose_name=_("category"))

    title = models.CharField(_("title"), max_length=255)
    slug = AutoSlugField(populate_from="title", db_index=False, blank=True)
    date = models.DateTimeField(_("date"), auto_now_add=True)
    last_active = models.DateTimeField(_("last active"), auto_now_add=True)

    is_pinned = models.BooleanField(_("pinned"), default=False)
    is_globally_pinned = models.BooleanField(_("globally pinned"),
                                             default=False)
    is_closed = models.BooleanField(_("closed"), default=False)
    is_removed = models.BooleanField(default=False)

    view_count = models.PositiveIntegerField(_("views count"), default=0)
    comment_count = models.PositiveIntegerField(_("comment count"), default=0)

    objects = TopicQuerySet.as_manager()

    class Meta:
        ordering = ['-last_active', '-pk']
        verbose_name = _("topic")
        verbose_name_plural = _("topics")

    def __str__(self):
        return self.title

    def get_absolute_url(self):
        if self.category_id == settings.ST_TOPIC_PRIVATE_CATEGORY_PK:
            return reverse('spirit:private-detail',
                           kwargs={
                               'topic_id': str(self.id),
                               'slug': self.slug
                           })
        else:
            return reverse('spirit:topic-detail',
                           kwargs={
                               'pk': str(self.id),
                               'slug': self.slug
                           })

    @property
    def main_category(self):
        return self.category.parent or self.category

    @property
    def bookmark(self):
        # *bookmarks* is dinamically created by manager.with_bookmarks()
        try:
            assert len(self.bookmarks) <= 1, "Panic, too many bookmarks"
            return self.bookmarks[0]
        except (AttributeError, IndexError):
            return
Beispiel #5
0
class Category(models.Model):

    parent = models.ForeignKey('self',
                               verbose_name=_("category parent"),
                               null=True,
                               blank=True)

    title = models.CharField(_("title"), max_length=75)
    slug = AutoSlugField(populate_from="title", db_index=False, blank=True)
    description = models.CharField(_("description"),
                                   max_length=255,
                                   blank=True)
    is_closed = models.BooleanField(_("closed"), default=False)
    is_removed = models.BooleanField(_("removed"), default=False)
    is_private = models.BooleanField(_("private"), default=False)

    # topic_count = models.PositiveIntegerField(_("topic count"), default=0)

    objects = CategoryManager()

    class Meta:
        ordering = [
            'title',
        ]
        verbose_name = _("category")
        verbose_name_plural = _("categories")

    def get_absolute_url(self):
        if self.pk == settings.ST_TOPIC_PRIVATE_CATEGORY_PK:
            return reverse('spirit:private-list')

        return reverse('spirit:category-detail',
                       kwargs={
                           'pk': str(self.id),
                           'slug': self.slug
                       })

    @property
    def is_subcategory(self):
        if self.parent_id:
            return True
        else:
            return False

    def __str__(self):
        if self.parent:
            return "%s, %s" % (self.parent.title, self.title)
        else:
            return self.title
Beispiel #6
0
class Category(models.Model):

    parent = models.ForeignKey('self', verbose_name=_("category parent"), null=True, blank=True)

    title = models.CharField(_("title"), max_length=75)
    slug = AutoSlugField(populate_from="title", db_index=False, blank=True)
    description = models.CharField(_("description"), max_length=255, blank=True)
    is_closed = models.BooleanField(_("closed"), default=False)
    is_removed = models.BooleanField(_("removed"), default=False)
    is_private = models.BooleanField(_("private"), default=False)

    #topic_count = models.PositiveIntegerField(_("topic count"), default=0)

    objects = CategoryManager()

    class Meta:
        app_label = 'spirit'
        ordering = ['title', ]
        verbose_name = _("category")
        verbose_name_plural = _("categories")

    def get_absolute_url(self):
        return reverse('spirit:category-detail', kwargs={'pk': str(self.id), 'slug': self.slug})

    @property
    def is_subcategory(self):
        if self.parent_id:
            return True
        else:
            return False

    def __unicode__(self):
        if self.parent:
            return "%s, %s" % (self.parent.title, self.title)
        else:
            return self.title


#def topic_posted_handler(sender, topic, **kwargs):
#    if topic.category.is_subcategory:
#        category = Category.objects.filter(pk__in=[topic.category.pk, topic.category.parent.pk])
#    else:
#        category = Category.objects.filter(pk=topic.category.pk)
#
#    category.update(topic_count=F('topic_count') + 1)


#topic_posted.connect(topic_posted_handler, dispatch_uid=__name__)
Beispiel #7
0
class AutoSlugModel(models.Model):

    slug = AutoSlugField(max_length=50)
Beispiel #8
0
class AutoSlugBadPopulateFromModel(models.Model):

    slug = AutoSlugField(populate_from='bad', max_length=50)
Beispiel #9
0
class AutoSlugDefaultModel(models.Model):

    slug = AutoSlugField(max_length=50, default="foo")
Beispiel #10
0
class AutoSlugModel(models.Model):

    slug = AutoSlugField(max_length=50)

    class Meta:
        app_label = 'spirit'
Beispiel #11
0
class AutoSlugBadPopulateFromModel(models.Model):

    slug = AutoSlugField(populate_from='bad', max_length=50)

    class Meta:
        app_label = 'spirit'
Beispiel #12
0
class AutoSlugDefaultModel(models.Model):

    slug = AutoSlugField(max_length=50, default="foo")

    class Meta:
        app_label = 'spirit'