Exemplo n.º 1
0
class ArticleForObject(models.Model):

    objects = managers.ArticleFkManager()

    article = models.ForeignKey("Article", on_delete=models.CASCADE)
    # Same as django.contrib.comments
    content_type = models.ForeignKey(
        ContentType,
        on_delete=models.CASCADE,
        verbose_name=_("content type"),
        related_name="content_type_set_for_%(class)s",
    )
    object_id = models.PositiveIntegerField(_("object ID"))
    content_object = GenericForeignKey("content_type", "object_id")

    is_mptt = models.BooleanField(default=False, editable=False)

    def __str__(self):
        return str(self.article)

    class Meta:
        verbose_name = _("Article for object")
        verbose_name_plural = _("Articles for object")
        # Do not allow several objects
        unique_together = ("content_type", "object_id")
Exemplo n.º 2
0
class Attachment(ReusablePlugin):

    objects = managers.ArticleFkManager()

    current_revision = models.OneToOneField(
        'AttachmentRevision', 
        verbose_name=_(u'current revision'),
        blank=True, null=True, related_name='current_set',
        help_text=_(u'The revision of this attachment currently in use (on all articles using the attachment)'),
    )
    
    original_filename = models.CharField(max_length=256, verbose_name=_(u'original filename'), blank=True, null=True)

    def can_write(self, user):
        if not settings.ANONYMOUS and (not user or user.is_anonymous()):
            return False
        return ReusablePlugin.can_write(self, user)
    
    def can_delete(self, user):
        return self.can_write(user)
    
    class Meta:
        verbose_name = _(u'attachment')
        verbose_name_plural = _(u'attachments')
        app_label = settings.APP_LABEL 
    
    def __unicode__(self):
        return "%s: %s" % (self.article.current_revision.title, self.original_filename)    
Exemplo n.º 3
0
class ArticleRevision(BaseRevisionMixin, models.Model):

    """This is where main revision data is stored. To make it easier to
    copy, do NEVER create m2m relationships."""

    objects = managers.ArticleFkManager()

    article = models.ForeignKey(
        "Article", on_delete=models.CASCADE, verbose_name=_("article")
    )

    # This is where the content goes, with whatever markup language is used
    content = models.TextField(blank=True, verbose_name=_("article contents"))

    # This title is automatically set from either the article's title or
    # the last used revision...
    title = models.CharField(
        max_length=512,
        verbose_name=_("article title"),
        null=False,
        blank=False,
        help_text=_(
            "Each revision contains a title field that must be filled out, even if the title has not changed"
        ),
    )

    # TODO:
    # Allow a revision to redirect to another *article*. This
    # way, we can have redirects and still maintain old content.
    # redirect = models.ForeignKey('Article', null=True, blank=True,
    #                             verbose_name=_('redirect'),
    #                             help_text=_('If set, the article will redirect to the contents of another article.'),
    #                             related_name='redirect_set')

    def __str__(self):
        return "%s (%d)" % (self.title, self.revision_number)

    def clean(self):
        # Enforce DOS line endings \r\n. It is the standard for web browsers,
        # but when revisions are created programatically, they might
        # have UNIX line endings \n instead.
        self.content = self.content.replace("\r", "").replace("\n", "\r\n")

    def inherit_predecessor(self, article):
        """
        Inherit certain properties from predecessor because it's very
        convenient. Remember to always call this method before
        setting properties :)"""
        predecessor = article.current_revision
        self.article = predecessor.article
        self.content = predecessor.content
        self.title = predecessor.title
        self.deleted = predecessor.deleted
        self.locked = predecessor.locked

    class Meta:
        get_latest_by = "revision_number"
        ordering = ("created",)
        unique_together = ("article", "revision_number")
Exemplo n.º 4
0
class Attachment(ReusablePlugin):

    objects = managers.ArticleFkManager()

    current_revision = models.OneToOneField(
        "AttachmentRevision",
        verbose_name=_("current revision"),
        blank=True,
        null=True,
        related_name="current_set",
        on_delete=models.CASCADE,
        help_text=
        _("The revision of this attachment currently in use (on all articles using the attachment)"
          ),
    )

    original_filename = models.CharField(max_length=256,
                                         verbose_name=_("original filename"),
                                         blank=True,
                                         null=True)

    def can_write(self, user):
        if not settings.ANONYMOUS and (not user or user.is_anonymous):
            return False
        return ReusablePlugin.can_write(self, user)

    def can_delete(self, user):
        return self.can_write(user)

    class Meta:
        verbose_name = _("attachment")
        verbose_name_plural = _("attachments")
        # Matches label of upcoming 0.1 release
        db_table = "wiki_attachments_attachment"

    def __str__(self):
        from wiki.models import Article

        try:
            return "%s: %s" % (
                self.article.current_revision.title,
                self.original_filename,
            )
        except Article.DoesNotExist:
            return "Attachment for non-existing article"
Exemplo n.º 5
0
class ArticleForObject(models.Model):

    objects = managers.ArticleFkManager()

    article = models.ForeignKey('Article', on_delete=models.CASCADE)
    # Same as django.contrib.comments
    content_type   = models.ForeignKey(ContentType,
                                       verbose_name=_('content type'),
                                       related_name="content_type_set_for_%(class)s")
    object_id      = models.PositiveIntegerField(_('object ID'))
    content_object = generic.GenericForeignKey("content_type", "object_id")

    is_mptt = models.BooleanField(default=False, editable=False)

    class Meta:
        app_label = settings.APP_LABEL
        verbose_name = _(u'Article for object')
        verbose_name_plural = _(u'Articles for object')
        # Do not allow several objects
        unique_together = ('content_type', 'object_id')