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


Python models.notify函数代码示例

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


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

示例1: form_valid

    def form_valid(self, document_form, revision_form):
        """Saves both the document and it's revision."""
        doc, metadata, revision = save_document_forms(
            document_form,
            revision_form,
            self.category,
            created_by=self.request.user)

        message_text = '''You created the document
                       <a href="%(url)s">%(key)s (%(title)s)</a>'''
        message_data = {
            'url': doc.get_absolute_url(),
            'key': doc.document_key,
            'title': doc.title
        }
        notify(self.request.user, _(message_text) % message_data)

        activity_log.send(
            verb='created',
            target=None,
            action_object=doc,
            sender=None,
            actor=self.request.user)

        return HttpResponseRedirect(self.get_success_url())
开发者ID:providenz,项目名称:phase,代码行数:25,代码来源:views.py

示例2: post

    def post(self, request, *args, **kwargs):
        if not self.request.user.is_external:
            return HttpResponseForbidden(
                'Only contractors can acknowledge receipt of transmittals')

        document_ids = request.POST.getlist('document_ids')
        transmittals = self.get_queryset() \
            .filter(document_id__in=document_ids) \
            .filter(ack_of_receipt_date__isnull=True)
        revision_ids = list(
            transmittals.values_list('latest_revision_id', flat=True))

        # Update transmittal data
        transmittals.update(
            ack_of_receipt_date=timezone.now(),
            ack_of_receipt_author=self.request.user)

        # Update ES index
        _revision_class = self.category.revision_class()
        revisions = _revision_class.objects.filter(id__in=revision_ids)
        index_revisions(revisions)

        update_count = len(revision_ids)

        if update_count > 0:
            msg = _('You have successfully acknowledged receipt '
                    'of %s transmittals.') % update_count
        else:
            msg = _('We failed to acknowledge receipt of any transmittal.')

        notify(self.request.user, msg)

        return HttpResponseRedirect(self.get_redirect_url())
开发者ID:providenz,项目名称:phase,代码行数:33,代码来源:views.py

示例3: comment_action_hook

def comment_action_hook(sender, instance, created, **kwargs):
    """
    Action hook for comments - inform other people about the fact that
    this comment was created and increase the amount of user points
    accordingly.
    """
    if not created:
        return True
    prof = UserProfile.objects.get(user=instance.user)
    prof.rank_pts += 3
    prof.save()
    # Send action for user and location activity streams
    action.send(
        instance.user,
        action_object = instance,
        target = instance.content_object,
        verb = _(u"commented"),
        comment = instance.comment,
        comment_url = instance.content_object.get_absolute_url()
    )
    # Send notification to parent comment author (if this is answer for comment)
    if instance.parent is not None:
        notify(
            instance.user,
            instance.parent.user,
            key="customcomment",
            verb=_(u"answered your comment"),
            action_object=instance,
            action_target=instance.parent
        )
开发者ID:v0y,项目名称:CivilHub,代码行数:30,代码来源:actstreams.py

示例4: pay

    def pay(self, operator, recipient):
        """
        Procède au paiement de l'évenement par les participants.
        Une seule vente, un seul paiement mais plusieurs débits sur compte
        (un par participant)
        :param operator: user qui procède au paiement
        :param recipient: user qui recoit les paiements (AE_ENSAM)
        :return:
        """

        # Calcul du prix par weight
        total_weight = self.get_total_weights_participants()
        final_price_per_weight = round(self.price / total_weight, 2)

        for e in self.weightsuser_set.all():
            e.user.debit(final_price_per_weight * e.weights_participation)
            if (e.user.balance < 0):
			    # If negative balance after event
		        # We notify
                notify(notification_class_name='negative_balance',
                   actor=operator,
                   recipient=e.user,
                   target_object=self
                )


        self.done = True
        self.datetime = now()
        self.remark = 'Paiement par Borgia'
        self.save()
开发者ID:AlexandrePalo,项目名称:borgia,代码行数:30,代码来源:models.py

示例5: add_follower

def add_follower(request, pk):
    """ Add user to locations followers. """
    location = get_object_or_404(Location, pk=pk)
    user = request.user
    location.users.add(user)
    if user != location.creator:
        notify(user,
            location.creator,
            verb=_(u"joined to your location"),
            key="follower",
            action_target=location
        )
    try:
        location.save()
        follow(user, location, actor_only = False)
        response = {
            'success': True,
            'message': _('You follow this location'),
        }
    except:
        response = {
            'success': False,
            'message': _('Something, somewhere went terribly wrong'),
        }
    return HttpResponse(json.dumps(response))
开发者ID:14mmm,项目名称:CivilHub,代码行数:25,代码来源:views.py

示例6: comment_notification

def comment_notification(sender, instance, created, **kwargs):
    """
    Send notification for commented object creator. Handles special case of
    task participants, when we want to notify them all at once.
    """
    if not created or instance.parent is not None:
        # this is edited comment or answer for other comment
        # They have their own hooks in places_core.actions.
        return True
    if instance.content_object.__class__.__name__ == 'Task':
        # Special case - send notifications to all task participants
        for user in instance.content_object.participants.exclude(
            pk=instance.user.pk):
            notify(instance.user, user,
                   key="comment",
                   verb=_(u"commented task"),
                   action_object=instance,
                   action_target=instance.content_object)

    target_user = None
    if hasattr(instance.content_object, 'creator'):
        target_user = instance.content_object.creator
    elif hasattr(instance.content_object, 'author'):
        target_user = instance.content_object.author

    if target_user is not None and instance.user != target_user:
        notify(instance.user, target_user,
               key="customcomment",
               verb=_(u"commented your {}".format(
                   instance.content_object._meta.verbose_name.title())),
               action_object=instance,
               action_target=instance.content_object)
开发者ID:v0y,项目名称:CivilHub,代码行数:32,代码来源:models.py

示例7: create

 def create(self, request):
     if self.check_valid_vote(self.request.user, self.request.POST['comment']):
         vote = CommentVote(vote=True if self.request.POST.get('vote') == 'up' else False,
                            user=self.request.user,
                            date_voted = timezone.now(),
                            comment=CustomComment.objects.get(pk=self.request.POST['comment']))
         vote.save()
         action.send(
             request.user,
             action_object=vote.comment,
             verb= _(u"voted on"),
             vote = True if request.POST.get('vote') == 'up' else False
         )
         suff = "up" if vote.vote else "down"
         notify(
             request.user,
             vote.comment.user,
             action_object=vote,
             action_target=vote.comment,
             verb=_(u"voted {} for your comment".format(suff)),
             key="vote"
         )
         return Response({
             'success': True,
             'message': _('Vote saved')
         })
     else:
         return Response({
             'success': False,
             'message': _('Already voted on this comment')
         })
开发者ID:14mmm,项目名称:CivilHub,代码行数:31,代码来源:views.py

示例8: comment_notification

def comment_notification(sender, instance, created, **kwargs):
    """
    Send notification for commented object creator. Handles special case of
    task participants, when we want to notify them all at once.
    """
    if not created or instance.parent is not None:
        # this is edited comment or answer for other comment
        # They have their own hooks in places_core.actions.
        return True
    if instance.content_object.__class__.__name__ == 'Task':
        # Special case - send notifications to all task participants
        for user in instance.content_object.participants.exclude(
            pk=instance.user.pk):
            notify(instance.user, user,
                key="comment",
                verb=_(u"commented task"),
                action_object=instance,
                action_target=instance.content_object)

    # Get target user to notify depending on commented object's type.
    target_user = None
    if hasattr(instance.content_object, 'creator'):
        # Regular content objects usually have 'creator' field
        target_user = instance.content_object.creator
    elif hasattr(instance.content_object, 'author'):
        # Projects and some other models that use other convention
        target_user = instance.content_object.author

    # Notify users only when someone else commented their objects.
    if target_user is not None and instance.user != target_user:
        notify(instance.user, target_user,
            key="customcomment",
            verb="commented your",
            action_object=instance,
            action_target=instance.content_object)
开发者ID:gboule35,项目名称:CivilHub,代码行数:35,代码来源:models.py

示例9: notify_about_news_deletion

def notify_about_news_deletion(sender, instance, **kwargs):
    """ Notify newss author about that his news was deleted. """
    # For now we assume that only superuser could delete news entries.
    admin = User.objects.filter(is_superuser=True)[0]
    notify(admin, instance.creator,
        key="deletion",
        verb="deleted your blog entry",
        action_object=instance
    )
开发者ID:oskarm91,项目名称:CivilHub,代码行数:9,代码来源:models.py

示例10: response_notification

def response_notification(sender, instance, created, **kwargs):
    """ Notify discussion creator about every new answer. """
    if not created or instance.creator == instance.discussion.creator:
        return True
    notify(instance.creator, instance.discussion.creator,
        key="answer",
        verb=_(u"answered for your discussion"),
        action_object=instance,
        action_target=instance.discussion
    )
开发者ID:oskarm91,项目名称:CivilHub,代码行数:10,代码来源:models.py

示例11: form_valid

    def form_valid(self, document_form, revision_form):
        """Saves both the document and it's revision."""
        doc, metadata, revision = save_document_forms(document_form, revision_form, self.category)

        message_text = """You created the document
                       <a href="%(url)s">%(key)s (%(title)s)</a>"""
        message_data = {"url": doc.get_absolute_url(), "key": doc.document_key, "title": doc.title}
        notify(self.request.user, _(message_text) % message_data)

        return HttpResponseRedirect(self.get_success_url())
开发者ID:thibault,项目名称:phase,代码行数:10,代码来源:views.py

示例12: vote_notification

def vote_notification(sender, instance, created, **kwargs):
    """ Notify users that someone voted for their ideas. """
    if instance.user == instance.idea.creator or not created:
        return True
    suff = "up" if instance.status == 1 else "down"
    notify(instance.user, instance.idea.creator,
           key="vote",
           verb="voted for your idea",
           action_object=instance,
           action_target=instance.idea)
开发者ID:cristianlp,项目名称:CivilHub,代码行数:10,代码来源:models.py

示例13: batch_cancel_reviews

def batch_cancel_reviews(user_id, category_id, contenttype_id, document_ids):
    contenttype = ContentType.objects.get_for_id(contenttype_id)
    document_class = contenttype.model_class()

    docs = document_class.objects \
        .select_related() \
        .filter(document__category_id=category_id) \
        .filter(document_id__in=document_ids)

    ok = []
    nok = []
    counter = float(1)
    nb_reviews = docs.count()

    for doc in docs:

        # Update progress counter
        progress = counter / nb_reviews * 100
        current_task.update_state(
            state='PROGRESS',
            meta={'progress': progress})

        try:
            if not doc.latest_revision.is_under_review():
                raise RuntimeError()

            doc.latest_revision.cancel_review()
            user = User.objects.get(pk=user_id)
            activity_log.send(verb=Activity.VERB_CANCELLED_REVIEW,
                              target=doc.latest_revision,
                              sender=batch_cancel_reviews,
                              actor=user)
            ok.append(doc)
        except:  # noqa
            nok.append(doc)

        counter += 1

    if len(ok) > 0:
        ok_message = ugettext('You canceled the review for the following documents:')
        ok_list = '</li><li>'.join('<a href="%s">%s</a>' % (doc.get_absolute_url(), doc) for doc in ok)
        notify(user_id, '{} <ul><li>{}</li></ul>'.format(
            ok_message,
            ok_list
        ))

    if len(nok) > 0:
        nok_message = ugettext("We failed to cancel the review for the following documents:")
        nok_list = '</li><li>'.join('<a href="%s">%s</a>' % (doc.get_absolute_url(), doc) for doc in nok)
        notify(user_id, '{} <ul><li>{}</li></ul>'.format(
            nok_message,
            nok_list
        ))

    return 'done'
开发者ID:Talengi,项目名称:phase,代码行数:55,代码来源:tasks.py

示例14: finished_task

def finished_task(user, task):
    """
    The user has finished the task.
    """
    task_action(user, task, _(u"finished task"))
    for participant in task.participants.all():
        notify(user, participant,
            verb=_(u"finished task"),
            key="project",
            action_tartget=task
        )
开发者ID:cristianlp,项目名称:CivilHub,代码行数:11,代码来源:actions.py

示例15: joined_to_task

def joined_to_task(user, task):
    """
    The user has joined the task.
    """
    if user != task.creator:
        task_action(user, task, _(u"joined to task"))
        notify(user, task.creator,
            verb=_(u"joined to your task"),
            key="follower",
            action_target=task
        )
开发者ID:cristianlp,项目名称:CivilHub,代码行数:11,代码来源:actions.py


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