コード例 #1
0
ファイル: views.py プロジェクト: dibaunaumh/Ecclesia
def add_relation(request, discussion, user, title, slug, speech_act):
    from_story = request.POST.get('from_story', None)
    to_story = request.POST.get('to_story', None)
    if from_story is None or to_story is None:
        resp = HttpResponse(_("Did not get from and to stories."))
        resp.status_code = 500
        return resp
    relation = StoryRelation()
    relation.discussion = discussion
    relation.created_by = user
    relation.title = title
    relation.slug = slug
    relation.speech_act = speech_act
    relation.from_story = Story.objects.get(pk=from_story)
    relation.to_story = Story.objects.get(pk=to_story)
    try:
        try:
            relation.full_clean()
        except ValidationError, e:
            message = DEFAULT_FORM_ERROR_MSG
            if e.message_dict[NON_FIELD_ERRORS] and re.search(UNIQUENESS_ERROR_PATTERN, e.message_dict[NON_FIELD_ERRORS][0]):
                message = _('Oops! A relation with this title was already created inside this discussion.')
            resp = HttpResponse(message)
            resp.status_code = 500
            return resp

        relation.save()
        resp = HttpResponse("%s" % discussion.last_related_update)

        create_notification(text="There is a new relation in %s discussion: %s" % (discussion.slug, title),
                                        entity=relation, acting_user=request.user)
コード例 #2
0
ファイル: tasks.py プロジェクト: dibaunaumh/Ecclesia
def create_notification_task(text, entity, acting_user=None, recipient=None):
    create_notification(text=text, entity=entity, acting_user=acting_user, recipient=recipient)
    logger = create_notification_task.get_logger()
    logger.info("Creating notification %s..." % text)