コード例 #1
0
ファイル: tests_utils.py プロジェクト: leroivi/zds-site
    def test_last_participation_is_old(self):
        article = PublishedContentFactory(author_list=[self.user_author], type="ARTICLE")
        new_user = ProfileFactory().user
        reac = ContentReaction(author=self.user_author, position=1, related_content=article)
        reac.update_content("I will find you.")
        reac.save()
        article.last_note = reac
        article.save()

        self.assertFalse(last_participation_is_old(article, new_user))
        ContentRead(user=self.user_author, note=reac, content=article).save()
        reac = ContentReaction(author=new_user, position=2, related_content=article)
        reac.update_content("I will find you.")
        reac.save()
        article.last_note = reac
        article.save()
        ContentRead(user=new_user, note=reac, content=article).save()
        self.assertFalse(last_participation_is_old(article, new_user))
        self.assertTrue(last_participation_is_old(article, self.user_author))
コード例 #2
0
def mark_read(content, user=None):
    """Mark the last tutorial note as read for the user.

    :param content: the content to mark
    :param user: user that read the content, if ``None`` will use currrent user
    """

    from zds.tutorialv2.models.database import ContentRead
    from zds.tutorialv2.models.database import ContentReaction

    if not user:
        user = get_current_user()

    if user and user.is_authenticated():
        if content.last_note is not None:
            ContentRead.objects.filter(content__pk=content.pk,
                                       user__pk=user.pk).delete()
            a = ContentRead(note=content.last_note, content=content, user=user)
            a.save()
            signals.content_read.send(sender=content.__class__,
                                      instance=content,
                                      user=user,
                                      target=ContentReaction)
コード例 #3
0
ファイル: utils.py プロジェクト: josephcab/zds-site
def mark_read(content, user=None):
    """Mark the last tutorial note as read for the user.

    :param content: the content to mark
    :param user: user that read the content, if ``None`` will use currrent user
    """

    from zds.tutorialv2.models.database import ContentRead
    from zds.tutorialv2.models.database import ContentReaction

    if not user:
        user = get_current_user()

    if user and user.is_authenticated():
        if content.last_note is not None:
            ContentRead.objects.filter(
                content__pk=content.pk,
                user__pk=user.pk).delete()
            a = ContentRead(
                note=content.last_note,
                content=content,
                user=user)
            a.save()
            signals.content_read.send(sender=content.__class__, instance=content, user=user, target=ContentReaction)