当前位置: 首页>>代码示例>>Python>>正文


Python utils.get_current_user函数代码示例

本文整理汇总了Python中zds.utils.get_current_user函数的典型用法代码示例。如果您正苦于以下问题:Python get_current_user函数的具体用法?Python get_current_user怎么用?Python get_current_user使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了get_current_user函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: mark_read

def mark_read(privatetopic):
    '''
    Mark a private topic as read for the user
    '''
    PrivateTopicRead.objects.filter(privatetopic=privatetopic, user=get_current_user()).delete()
    t = PrivateTopicRead(
        privatepost=privatetopic.last_message, privatetopic=privatetopic, user=get_current_user())
    t.save()
开发者ID:ChantyTaguan,项目名称:zds-site,代码行数:8,代码来源:models.py

示例2: mark_read

def mark_read(article):
    """Mark a article as read for the user."""
    if article.last_reaction is not None:
        ArticleRead.objects.filter(
            article=article,
            user=get_current_user()).delete()
        a = ArticleRead(
            reaction=article.last_reaction,
            article=article,
            user=get_current_user())
        a.save()
开发者ID:Aer-o,项目名称:zds-site,代码行数:11,代码来源:models.py

示例3: never_read

def never_read(topic, user=None):
    """Check if a topic has been read by an user since it last post was
    added."""
    if user is None:
        user = get_current_user()

    return not TopicRead.objects.filter(post=topic.last_message, topic=topic, user=user).exists()
开发者ID:Dryusdan,项目名称:zds-site,代码行数:7,代码来源:models.py

示例4: never_read

def never_read(tutorial, user=None):
    """Check if a topic has been read by an user since it last post was
    added."""
    if user is None:
        user = get_current_user()

    return TutorialRead.objects.filter(note=tutorial.last_note, tutorial=tutorial, user=user).count() == 0
开发者ID:GaaH,项目名称:zds-site,代码行数:7,代码来源:models.py

示例5: first_unread_note

    def first_unread_note(self, user=None):
        """
        :return: Return the first note the user has unread.
        :rtype: ContentReaction
        """
        if user is None:
            user = get_current_user()

        if user and user.is_authenticated():
            try:
                read = ContentRead.objects\
                    .filter(content=self, user__pk=user.pk)\
                    .latest('note__pubdate')

                if read and read.note:
                    last_note = read.note

                    next_note = ContentReaction.objects\
                        .select_related('related_content')\
                        .select_related('related_content__public_version')\
                        .filter(
                            related_content__pk=self.pk,
                            pk__gt=last_note.pk)\
                        .select_related('author').first()

                    if next_note:
                        return next_note
                    else:
                        return last_note

            except ContentRead.DoesNotExist:
                pass

        return self.first_note()
开发者ID:josephcab,项目名称:zds-site,代码行数:34,代码来源:database.py

示例6: mark_read

def mark_read(privatetopic, user=None):
    """
    Mark a private topic as read for the user.

    :param privatetopic: a PrivateTopic to check
    :type privatetopic: PrivateTopic object
    :param user: a user as Django User object. If None, the current user is used
    :type user: User object
    :return: nothing is returned
    :rtype: None
    """
    # If user param is not defined, we get the current user
    if user is None:
        user = get_current_user()

    # Fetch the privateTopicRead concerning the given privateTopic and given (or current) user
    # Set the last read post as the current last post and save
    try:
        topic = PrivateTopicRead.objects.filter(privatetopic=privatetopic, user=user).get()
        topic.privatepost = privatetopic.last_message
    # Or create it if it does not exists yet
    except PrivateTopicRead.DoesNotExist:
        topic = PrivateTopicRead(privatepost=privatetopic.last_message, privatetopic=privatetopic, user=user)

    topic.save()
    signals.content_read.send(sender=privatetopic.__class__, instance=privatetopic, user=user)
开发者ID:josephcab,项目名称:zds-site,代码行数:26,代码来源:models.py

示例7: antispam

    def antispam(self, user=None):
        """Check if the user is allowed to post in an article according to the
        SPAM_LIMIT_SECONDS value.

        If user shouldn't be able to reaction, then antispam is
        activated and this method returns True. Otherwise time elapsed
        between user's last reaction and now is enough, and the method
        will return False.

        """
        if user is None:
            user = get_current_user()

        last_user_reactions = Reaction.objects\
            .filter(article=self)\
            .filter(author=user.pk)\
            .order_by('-pubdate')

        if last_user_reactions \
                and last_user_reactions[0] == self.last_reaction:
            last_user_reaction = last_user_reactions[0]
            t = timezone.now() - last_user_reaction.pubdate
            if t.total_seconds() < settings.SPAM_LIMIT_SECONDS:
                return True
        return False
开发者ID:Aer-o,项目名称:zds-site,代码行数:25,代码来源:models.py

示例8: first_unread_post

    def first_unread_post(self, user=None):
        """
        Get the first PrivatePost the user has unread.

        :param user: The user is reading the PrivateTopic. If None, the current user is used.
        :type user: User object
        :return: first PrivatePost unread
        :rtype: PrivatePost object or None
        """
        # If user param is not defined, we get the current user
        if user is None:
            user = get_current_user()

        try:
            last_post = PrivateTopicRead.objects \
                .select_related() \
                .filter(privatetopic=self, user=user) \
                .latest('privatepost__position_in_topic').privatepost

            next_post = PrivatePost.objects.filter(
                privatetopic__pk=self.pk,
                position_in_topic__gt=last_post.position_in_topic).first()

            return next_post
        except (PrivatePost.DoesNotExist, PrivateTopicRead.DoesNotExist):
            return self.first_post()
开发者ID:josephcab,项目名称:zds-site,代码行数:26,代码来源:models.py

示例9: follow_by_email

def follow_by_email(topic, user=None):
    """Toggle following of a topic for an user."""
    ret = None
    if user is None:
        user=get_current_user()
    try:
        existing = TopicFollowed.objects.get(
            topic=topic, \
            user=user
        )
    except TopicFollowed.DoesNotExist:
        existing = None

    if not existing:
        # Make the user follow the topic
        t = TopicFollowed(
            topic=topic,
            user=user,
            email = True
        )
        t.save()
        ret = True
    else:
        existing.email = not existing.email
        existing.save()
        ret = existing.email
    return ret
开发者ID:Aer-o,项目名称:zds-site,代码行数:27,代码来源:models.py

示例10: get_commit_author

def get_commit_author():
    """get a dictionary that represent the commit author with ``author`` and ``comitter`` key. If there is no users,
    bot account pk is used.

    :return: correctly formatted commit author for ``repo.index.commit()``
    :rtype: dict
    """
    user = get_current_user()

    if user and user.is_authenticated():
        aut_user = str(user.pk)
        aut_email = None

        if hasattr(user, 'email'):
            aut_email = user.email

    else:
        try:
            aut_user = str(User.objects.filter(username=settings.ZDS_APP['member']['bot_account']).first().pk)
        except AttributeError:  # if nothing is found, `first` returns None, which does not have attribute pk
            aut_user = '0'

        aut_email = None

    if aut_email is None or not aut_email.strip():
        aut_email = _('[email protected]{}').format(settings.ZDS_APP['site']['dns'])

    return {'author': Actor(aut_user, aut_email), 'committer': Actor(aut_user, aut_email)}
开发者ID:josephcab,项目名称:zds-site,代码行数:28,代码来源:utils.py

示例11: toggle_follow

    def toggle_follow(self, content_object, user=None, by_email=False):
        """
        Toggle following of a resource notifiable for a user.

        :param content_object: A resource notifiable.
        :param user: A user. If undefined, the current user is used.
        :param by_email: Get subscription by email or not.
        :return: subscription of the user for the content.
        """
        if not user:
            user = get_current_user()
        if by_email:
            existing = self.get_existing(user, content_object, is_active=True, by_email=True)
        else:
            existing = self.get_existing(user, content_object, is_active=True)
        if not existing:
            subscription = self.get_or_create_active(user, content_object)
            if by_email:
                subscription.activate_email()
            return subscription
        signals.content_read.send(sender=content_object.__class__, instance=content_object, user=user,
                                  target=content_object.__class__)
        if by_email:
            existing.deactivate_email()
        else:
            existing.deactivate()
        return existing
开发者ID:josephcab,项目名称:zds-site,代码行数:27,代码来源:managers.py

示例12: follow

def follow(topic, user=None):
    """Toggle following of a topic for an user."""
    ret = None
    if user is None:
        user=get_current_user()
    try:
        existing = TopicFollowed.objects.get(
            topic=topic, user=user
        )
    except TopicFollowed.DoesNotExist:
        existing = None

    if not existing:
        # Make the user follow the topic
        t = TopicFollowed(
            topic=topic,
            user=user
        )
        t.save()
        ret = True
    else:
        # If user is already following the topic, we make him don't anymore
        existing.delete()
        ret = False
    return ret
开发者ID:Aer-o,项目名称:zds-site,代码行数:25,代码来源:models.py

示例13: never_read

def never_read(article, user=None):
    """Check if a topic has been read by an user since it last post was
    added."""
    if user is None:
        user = get_current_user()

    return ArticleRead.objects\
        .filter(reaction=article.last_reaction, article=article, user=user)\
        .count() == 0
开发者ID:Aer-o,项目名称:zds-site,代码行数:9,代码来源:models.py

示例14: last_read_reaction

 def last_read_reaction(self):
     """Return the last post the user has read."""
     try:
         return ArticleRead.objects\
             .select_related()\
             .filter(article=self, user=get_current_user())\
             .latest('reaction__pubdate').reaction
     except Reaction.DoesNotExist:
         return self.first_post()
开发者ID:Aer-o,项目名称:zds-site,代码行数:9,代码来源:models.py

示例15: last_read_note

 def last_read_note(self):
     """Return the last post the user has read."""
     try:
         return TutorialRead.objects\
             .select_related()\
             .filter(tutorial=self, user=get_current_user())\
             .latest('note__pubdate').note
     except Note.DoesNotExist:
         return self.first_post()
开发者ID:Ge0,项目名称:zds-site,代码行数:9,代码来源:models.py


注:本文中的zds.utils.get_current_user函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。