コード例 #1
0
ファイル: user.py プロジェクト: gitter-badger/secbi-web-app
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='Etc/GMT+5')
    is_administrator = models.BooleanField(_('administrator status'), default=False)
    bio = models.TextField(_("Bio"), max_length=300, blank=True)
    linkedin_url = models.URLField(_("Url perfil likedin"), max_length=200, null=True, blank=True)
    github_username = models.CharField(_("Usuario en github"), max_length=30, null=True, blank=True)
    trello_username = models.CharField(_("Usuario en Trello"), max_length=30, null=True, blank=True)
    web_site = models.URLField(_("Sitio web"), max_length=200, null=True, blank=True)
    company = models.CharField(_("Universidad/Empresa"), max_length=80, null=True, blank=True)
    is_moderator = models.BooleanField(_('moderator status'), default=False)
    # is_verified = models.BooleanField(_('verified'), default=False)
    es_destacado = models.BooleanField(_('Destacado'), 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)
コード例 #2
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('foro:private-list')

        return reverse('foro: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
コード例 #3
0
class Topic(models.Model):

    user = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name=_("user"))
    category = models.ForeignKey('foro.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('foro:private-detail',
                           kwargs={
                               'topic_id': str(self.id),
                               'slug': self.slug
                           })

        return reverse('foro: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
コード例 #4
0
class AutoSlugModel(models.Model):

    slug = AutoSlugField(max_length=50)
コード例 #5
0
class AutoSlugBadPopulateFromModel(models.Model):

    slug = AutoSlugField(populate_from='bad', max_length=50)
コード例 #6
0
class AutoSlugPopulateFromModel(models.Model):

    title = models.CharField(max_length=255, blank=True)
    slug = AutoSlugField(populate_from='title', max_length=50)
コード例 #7
0
class AutoSlugDefaultModel(models.Model):

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