Ejemplo n.º 1
0
    def perform_alert_message(request, post, user, alert_text):
        alert = Alert()
        alert.author = user
        alert.comment = post
        alert.scope = 'FORUM'
        alert.text = alert_text
        alert.pubdate = datetime.now()
        alert.save()

        messages.success(request, _(u'Une alerte a été envoyée à l\'équipe concernant ce message.'))
Ejemplo n.º 2
0
 def test_intervention_filter_for_tribunes(self):
     author = ProfileFactory()
     opinion = PublishedContentFactory(type='OPINION', author_list=[author.user])
     alerter = ProfileFactory()
     staff = StaffProfileFactory()
     alert = Alert()
     alert.scope = 'CONTENT'
     alert.author = alerter.user
     alert.content = opinion
     alert.pubdate = datetime.datetime.now()
     alert.text = 'Something to say.'
     alert.save()
     filter_result = get_header_notifications(staff.user)['alerts']
     self.assertEqual(1, filter_result['total'])
     self.assertEqual(alert.text, filter_result['list'][0]['text'])
Ejemplo n.º 3
0
 def test_intervention_filter_for_tribunes(self):
     author = ProfileFactory()
     opinion = PublishedContentFactory(type="OPINION", author_list=[author.user])
     alerter = ProfileFactory()
     staff = StaffProfileFactory()
     alert = Alert()
     alert.scope = "CONTENT"
     alert.author = alerter.user
     alert.content = opinion
     alert.pubdate = datetime.datetime.now()
     alert.text = "Something to say."
     alert.save()
     filter_result = get_header_notifications(staff.user)["alerts"]
     self.assertEqual(1, filter_result["total"])
     self.assertEqual(alert.text, filter_result["list"][0]["text"])
Ejemplo n.º 4
0
 def test_intervention_filter_for_tribunes(self):
     author = ProfileFactory()
     opinion = PublishedContentFactory(type='OPINION', author_list=[author.user])
     alerter = ProfileFactory()
     staff = StaffProfileFactory()
     alert = Alert()
     alert.scope = 'CONTENT'
     alert.author = alerter.user
     alert.content = opinion
     alert.pubdate = datetime.datetime.now()
     alert.text = 'Something to say.'
     alert.save()
     filter_result = get_header_notifications(staff.user)['alerts']
     self.assertEqual(1, filter_result['total'])
     self.assertEqual(alert.text, filter_result['list'][0]['text'])
Ejemplo n.º 5
0
    def post(self, request, *args, **kwargs):
        try:
            note_pk = int(self.kwargs['pk'])
        except (KeyError, ValueError):
            raise Http404(u"Impossible de convertir l'identifiant en entier.")
        note = get_object_or_404(ContentReaction, pk=note_pk)
        alert = Alert()
        alert.author = request.user
        alert.comment = note
        alert.scope = Alert.SCOPE_CHOICES_DICT[note.related_content.type]
        alert.text = request.POST['signal_text']
        alert.pubdate = datetime.now()
        alert.save()

        messages.success(self.request, _(u'Ce commentaire a bien été signalé aux modérateurs.'))
        return redirect(note.get_absolute_url())
Ejemplo n.º 6
0
    def post(self, request, *args, **kwargs):
        try:
            note_pk = int(self.kwargs["pk"])
        except (KeyError, ValueError):
            raise Http404("Cannot convert the pk into int.")
        note = get_object_or_404(ContentReaction, pk=note_pk)
        alert = Alert()
        alert.author = request.user
        alert.comment = note
        alert.scope = Alert.CONTENT
        alert.text = request.POST["signal_text"]
        alert.pubdate = datetime.now()
        alert.save()

        messages.success(
            self.request,
            _(u"Ce commentaire a bien été signalé aux modérateurs"))
        return redirect(note.get_absolute_url())
Ejemplo n.º 7
0
def edit_post(request):
    """Edit the given user's post."""

    try:
        post_pk = request.GET["message"]
    except KeyError:
        raise Http404
    post = get_object_or_404(Post, pk=post_pk)
    if not post.topic.forum.can_read(request.user):
        raise PermissionDenied
    g_topic = None
    if post.position <= 1:
        g_topic = get_object_or_404(Topic, pk=post.topic.pk)

    # Making sure the user is allowed to do that. Author of the post must to be
    # the user logged.

    if post.author != request.user \
            and not request.user.has_perm("forum.change_post") and "signal_message" \
            not in request.POST:
        raise PermissionDenied
    if post.author != request.user and request.method == "GET" \
            and request.user.has_perm("forum.change_post"):
        messages.warning(request,
                         u'Vous \xe9ditez ce message en tant que '
                         u'mod\xe9rateur (auteur : {}). Soyez encore plus '
                         u'prudent lors de l\'\xe9dition de celui-ci !'
                         .format(post.author.username))
    if request.method == "POST":
        if "delete_message" in request.POST:
            if post.author == request.user \
                    or request.user.has_perm("forum.change_post"):
                post.alerts.all().delete()
                post.is_visible = False
                if request.user.has_perm("forum.change_post"):
                    post.text_hidden = request.POST["text_hidden"]
                post.editor = request.user
                messages.success(request, u"Le message est désormais masqué")
        if "show_message" in request.POST:
            if request.user.has_perm("forum.change_post"):
                post.is_visible = True
                post.text_hidden = ""
        if "signal_message" in request.POST:
            alert = Alert()
            alert.author = request.user
            alert.comment = post
            alert.scope = Alert.FORUM
            alert.text = request.POST['signal_text']
            alert.pubdate = datetime.now()
            alert.save()
            messages.success(request,
                             u'Une alerte a été envoyée '
                             u'à l\'équipe concernant '
                             u'ce message')

        # Using the preview button

        if "preview" in request.POST:
            if g_topic:
                form = TopicForm(initial={"title": request.POST["title"],
                                          "subtitle": request.POST["subtitle"],
                                          "text": request.POST["text"]})
            else:
                form = PostForm(post.topic, request.user,
                                initial={"text": request.POST["text"]})
            form.helper.form_action = reverse("zds.forum.views.edit_post") \
                + "?message=" + str(post_pk)
            return render_template("forum/post/edit.html", {
                "post": post,
                "topic": post.topic,
                "text": request.POST["text"],
                "form": form,
            })

        if "delete_message" not in request.POST and "signal_message" \
                not in request.POST and "show_message" not in request.POST:
            # The user just sent data, handle them

            if request.POST["text"].strip() != "":
                post.text = request.POST["text"]
                post.text_html = emarkdown(request.POST["text"])
                post.update = datetime.now()
                post.editor = request.user

            # Modifying the thread info

            if g_topic:
                (tags, title) = get_tag_by_title(request.POST["title"])
                g_topic.title = title
                g_topic.subtitle = request.POST["subtitle"]
                g_topic.save()
                g_topic.tags.clear()

                # add tags

                g_topic.add_tags(tags)
        post.save()
        return redirect(post.get_absolute_url())
    else:
        if g_topic:
            prefix = u""
            for tag in g_topic.tags.all():
                prefix += u"[{0}]".format(tag.title)
            form = TopicForm(
                initial={
                    "title": u"{0} {1}".format(
                        prefix,
                        g_topic.title).strip(),
                    "subtitle": g_topic.subtitle,
                    "text": post.text})
        else:
            form = PostForm(post.topic, request.user,
                            initial={"text": post.text})
        form.helper.form_action = reverse("zds.forum.views.edit_post") \
            + "?message=" + str(post_pk)
        return render_template("forum/post/edit.html", {
            "post": post,
            "topic": post.topic,
            "text": post.text,
            "form": form,
        })
Ejemplo n.º 8
0
def edit_post(request):
    """Edit the given user's post."""

    try:
        post_pk = request.GET["message"]
    except:
        # problem in variable format
        raise Http404
    post = get_object_or_404(Post, pk=post_pk)
    if not post.topic.forum.can_read(request.user):
        raise PermissionDenied
    g_topic = None
    if post.position <= 1:
        g_topic = get_object_or_404(Topic, pk=post.topic.pk)

    # Making sure the user is allowed to do that. Author of the post must to be
    # the user logged.

    if post.author != request.user \
            and not request.user.has_perm("forum.change_post") and "signal_message" \
            not in request.POST:
        raise PermissionDenied
    if post.author != request.user and request.method == "GET" \
            and request.user.has_perm("forum.change_post"):
        messages.warning(request,
                         u'Vous \xe9ditez ce message en tant que '
                         u'mod\xe9rateur (auteur : {}). Soyez encore plus '
                         u'prudent lors de l\'\xe9dition de celui-ci !'
                         .format(post.author.username))
    if request.method == "POST":
        if "delete_message" in request.POST:
            if post.author == request.user \
                    or request.user.has_perm("forum.change_post"):
                post.alerts.all().delete()
                post.is_visible = False
                if request.user.has_perm("forum.change_post"):
                    post.text_hidden = request.POST["text_hidden"]
                post.editor = request.user
                messages.success(request, u"Le message est désormais masqué")
        if "show_message" in request.POST:
            if request.user.has_perm("forum.change_post"):
                post.is_visible = True
                post.text_hidden = ""
        if "signal_message" in request.POST:
            alert = Alert()
            alert.author = request.user
            alert.comment = post
            alert.scope = Alert.FORUM
            alert.text = request.POST['signal_text']
            alert.pubdate = datetime.now()
            alert.save()
            messages.success(request,
                             u'Une alerte a été envoyée '
                             u'à l\'équipe concernant '
                             u'ce message')

        # Using the preview button

        if "preview" in request.POST:
            if g_topic:
                form = TopicForm(initial={"title": request.POST["title"],
                                          "subtitle": request.POST["subtitle"],
                                          "text": request.POST["text"]})
            else:
                form = PostForm(post.topic, request.user,
                                initial={"text": request.POST["text"]})
            form.helper.form_action = reverse("zds.forum.views.edit_post") \
                + "?message=" + str(post_pk)
            return render_template("forum/post/edit.html", {
                "post": post,
                "topic": post.topic,
                "text": request.POST["text"],
                "form": form,
            })

        if "delete_message" not in request.POST and "signal_message" \
                not in request.POST and "show_message" not in request.POST:
            # The user just sent data, handle them

            if request.POST["text"].strip() != "":
                post.text = request.POST["text"]
                post.text_html = emarkdown(request.POST["text"])
                post.update = datetime.now()
                post.editor = request.user

            # Modifying the thread info

            if g_topic:
                (tags, title) = get_tag_by_title(request.POST["title"])
                g_topic.title = title
                g_topic.subtitle = request.POST["subtitle"]
                g_topic.save()
                g_topic.tags.clear()

                # add tags

                g_topic.add_tags(tags)
        post.save()
        return redirect(post.get_absolute_url())
    else:
        if g_topic:
            prefix = u""
            for tag in g_topic.tags.all():
                prefix += u"[{0}]".format(tag.title)
            form = TopicForm(
                initial={
                    "title": u"{0} {1}".format(
                        prefix,
                        g_topic.title).strip(),
                    "subtitle": g_topic.subtitle,
                    "text": post.text})
        else:
            form = PostForm(post.topic, request.user,
                            initial={"text": post.text})
        form.helper.form_action = reverse("zds.forum.views.edit_post") \
            + "?message=" + str(post_pk)
        return render_template("forum/post/edit.html", {
            "post": post,
            "topic": post.topic,
            "text": post.text,
            "form": form,
        })
Ejemplo n.º 9
0
def edit_reaction(request):
    """Edit the given user's reaction."""

    try:
        reaction_pk = request.GET['message']
    except KeyError:
        raise Http404
    reaction = get_object_or_404(Reaction, pk=reaction_pk)

    g_article = None
    if reaction.position >= 1:
        g_article = get_object_or_404(Article, pk=reaction.article.pk)

    # Making sure the user is allowed to do that. Author of the reaction
    # must to be the user logged.
    if reaction.author != request.user \
            and not request.user.has_perm('article.change_reaction') \
            and 'signal_message' not in request.POST:
        raise PermissionDenied

    if reaction.author != request.user \
            and request.method == 'GET' \
            and request.user.has_perm('article.change_reaction'):
        messages.add_message(
            request, messages.WARNING,
            u'Vous éditez ce message en tant que modérateur (auteur : {}).'
            u' Soyez encore plus prudent lors de l\'édition de celui-ci !'.
            format(reaction.author.username))
        reaction.alerts.all().delete()

    if request.method == 'POST':

        if 'delete_message' in request.POST:
            if reaction.author == request.user \
                    or request.user.has_perm('article.change_reaction'):
                reaction.alerts.all().delete()
                reaction.is_visible = False
                if request.user.has_perm('article.change_reaction'):
                    reaction.text_hidden = request.POST['text_hidden']
                reaction.editor = request.user

        if 'show_message' in request.POST:
            if request.user.has_perm('article.change_reaction'):
                reaction.is_visible = True
                reaction.text_hidden = ''

        if 'signal_message' in request.POST:
            alert = Alert()
            alert.author = request.user
            alert.comment = reaction
            alert.scope = Alert.ARTICLE
            alert.text = request.POST['signal_text']
            alert.pubdate = datetime.now()
            alert.save()

        # Using the preview button
        if 'preview' in request.POST:
            form = ReactionForm(g_article,
                                request.user,
                                initial={'text': request.POST['text']})
            form.helper.form_action = reverse(
                'zds.article.views.edit_reaction') + \
                '?message=' + \
                str(reaction_pk)
            return render_template('article/reaction/edit.html', {
                'reaction': reaction,
                'article': g_article,
                'form': form
            })

        if 'delete_message' not in request.POST \
                and 'signal_message' not in request.POST \
                and 'show_message' not in request.POST:
            # The user just sent data, handle them
            if request.POST['text'].strip() != '':
                reaction.text = request.POST['text']
                reaction.text_html = emarkdown(request.POST['text'])
                reaction.update = datetime.now()
                reaction.editor = request.user

        reaction.save()

        return redirect(reaction.get_absolute_url())

    else:
        form = ReactionForm(g_article,
                            request.user,
                            initial={'text': reaction.text})
        form.helper.form_action = reverse(
            'zds.article.views.edit_reaction') + '?message=' + str(reaction_pk)
        return render_template('article/reaction/edit.html', {
            'reaction': reaction,
            'article': g_article,
            'form': form
        })
Ejemplo n.º 10
0
def edit_reaction(request):
    """Edit the given user's reaction."""

    try:
        reaction_pk = request.GET['message']
    except KeyError:
        raise Http404
    reaction = get_object_or_404(Reaction, pk=reaction_pk)

    g_article = None
    if reaction.position >= 1:
        g_article = get_object_or_404(Article, pk=reaction.article.pk)

    # Making sure the user is allowed to do that. Author of the reaction
    # must to be the user logged.
    if reaction.author != request.user \
            and not request.user.has_perm('article.change_reaction') \
            and 'signal_message' not in request.POST:
        raise PermissionDenied

    if reaction.author != request.user \
            and request.method == 'GET' \
            and request.user.has_perm('article.change_reaction'):
        messages.add_message(
            request, messages.WARNING,
            u'Vous éditez ce message en tant que modérateur (auteur : {}).'
            u' Soyez encore plus prudent lors de l\'édition de celui-ci !'
            .format(reaction.author.username))
        reaction.alerts.all().delete()

    if request.method == 'POST':

        if 'delete_message' in request.POST:
            if reaction.author == request.user \
                    or request.user.has_perm('article.change_reaction'):
                reaction.alerts.all().delete()
                reaction.is_visible = False
                if request.user.has_perm('article.change_reaction'):
                    reaction.text_hidden = request.POST['text_hidden']
                reaction.editor = request.user

        if 'show_message' in request.POST:
            if request.user.has_perm('article.change_reaction'):
                reaction.is_visible = True
                reaction.text_hidden = ''

        if 'signal_message' in request.POST:
            alert = Alert()
            alert.author = request.user
            alert.comment = reaction
            alert.scope = Alert.ARTICLE
            alert.text = request.POST['signal_text']
            alert.pubdate = datetime.now()
            alert.save()

        # Using the preview button
        if 'preview' in request.POST:
            form = ReactionForm(g_article, request.user, initial={
                'text': request.POST['text']
            })
            form.helper.form_action = reverse(
                'zds.article.views.edit_reaction') + \
                '?message=' + \
                str(reaction_pk)
            return render_template('article/reaction/edit.html', {
                'reaction': reaction,
                'article': g_article,
                'form': form
            })

        if 'delete_message' not in request.POST \
                and 'signal_message' not in request.POST \
                and 'show_message' not in request.POST:
            # The user just sent data, handle them
            if request.POST['text'].strip() != '':
                reaction.text = request.POST['text']
                reaction.text_html = emarkdown(request.POST['text'])
                reaction.update = datetime.now()
                reaction.editor = request.user

        reaction.save()

        return redirect(reaction.get_absolute_url())

    else:
        form = ReactionForm(g_article, request.user, initial={
            'text': reaction.text
        })
        form.helper.form_action = reverse(
            'zds.article.views.edit_reaction') + '?message=' + str(reaction_pk)
        return render_template('article/reaction/edit.html', {
            'reaction': reaction,
            'article': g_article,
            'form': form
        })