Ejemplo n.º 1
0
    def post(self, request, *args, **kwargs):
        try:
            reaction_pk = int(self.kwargs["pk"])
        except (KeyError, ValueError):
            raise Http404("Impossible de convertir l'identifiant en entier.")
        reaction = get_object_or_404(ContentReaction, pk=reaction_pk)

        if len(request.POST["signal_text"].strip()) == 0:
            messages.error(
                request, _("La raison du signalement ne peut pas être vide."))
        else:
            alert = Alert(
                author=request.user,
                comment=reaction,
                scope=reaction.related_content.type,
                text=request.POST["signal_text"],
                pubdate=datetime.now(),
            )
            alert.save()

            messages.success(
                self.request,
                _("Ce commentaire a bien été signalé aux modérateurs."))

        return redirect(reaction.get_absolute_url())
Ejemplo n.º 2
0
    def post(self, request, *args, **kwargs):
        try:
            content_pk = int(self.kwargs["pk"])
        except (KeyError, ValueError):
            raise Http404(
                "Identifiant manquant ou conversion en entier impossible.")
        content = get_object_or_404(PublishableContent, pk=content_pk)

        if len(request.POST["signal_text"].strip()) == 0:
            messages.error(
                request, _("La raison du signalement ne peut pas être vide."))
        else:
            alert = Alert(
                author=request.user,
                content=content,
                scope="CONTENT",
                text=request.POST["signal_text"],
                pubdate=datetime.now(),
            )
            alert.save()

            human_content_type = TYPE_CHOICES_DICT[content.type].lower()
            messages.success(
                self.request,
                _("Ce {} a bien été signalé aux modérateurs.").format(
                    human_content_type))

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

        messages.success(request, _("Une alerte a été envoyée à l'équipe concernant ce message."))
Ejemplo n.º 4
0
    def perform_alert_message(request, post, user, alert_text):
        alert = Alert(author=user,
                      comment=post,
                      scope='FORUM',
                      text=alert_text,
                      pubdate=datetime.now())
        alert.save()

        messages.success(
            request,
            _("Une alerte a été envoyée à l'équipe concernant ce message."))
Ejemplo n.º 5
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.º 6
0
    def perform_alert_message(request, post, user, alert_text):
        if len(alert_text.strip()) == 0:
            messages.error(
                request, _("La raison du signalement ne peut pas être vide."))
        else:
            alert = Alert(author=user,
                          comment=post,
                          scope="FORUM",
                          text=alert_text,
                          pubdate=datetime.now())
            alert.save()

            messages.success(
                request,
                _("Une alerte a été envoyée à l'équipe concernant ce message.")
            )
Ejemplo n.º 7
0
 def post(self, request, *args, **kwargs):
     profile = get_object_or_404(Profile, pk=kwargs["profile_pk"])
     reason = request.POST.get("reason", "")
     if reason == "":
         messages.warning(request, _("Veuillez saisir une raison."))
     else:
         alert = Alert(author=request.user,
                       profile=profile,
                       scope="PROFILE",
                       text=reason,
                       pubdate=datetime.now())
         alert.save()
         messages.success(
             request,
             _("Votre signalement a été transmis à l'équipe de modération. "
               "Merci de votre aide !"))
     return redirect(profile.get_absolute_url())
Ejemplo n.º 8
0
    def post(self, request, *args, **kwargs):
        try:
            reaction_pk = int(self.kwargs['pk'])
        except (KeyError, ValueError):
            raise Http404("Impossible de convertir l'identifiant en entier.")
        reaction = get_object_or_404(ContentReaction, pk=reaction_pk)

        alert = Alert(
            author=request.user,
            comment=reaction,
            scope=reaction.related_content.type,
            text=request.POST['signal_text'],
            pubdate=datetime.now())
        alert.save()

        messages.success(self.request, _('Ce commentaire a bien été signalé aux modérateurs.'))
        return redirect(reaction.get_absolute_url())
Ejemplo n.º 9
0
    def setUp(self):
        self.staff = StaffProfileFactory()
        self.dummy_author = ProfileFactory()

        self.category = CategoryFactory(position=1)
        self.forum = ForumFactory(category=self.category, position_in_category=1)
        self.topic = TopicFactory(forum=self.forum, author=self.dummy_author.user)
        self.post = PostFactory(topic=self.topic, author=self.dummy_author.user, position=1)

        self.alerts = []
        for i in range(20):
            alert = Alert(author=self.dummy_author.user,
                          comment=self.post,
                          scope='FORUM',
                          text='pouet-{}'.format(i),
                          pubdate=(datetime.now() + timedelta(minutes=i)))
            alert.save()
            self.alerts.append(alert)
Ejemplo n.º 10
0
    def setUp(self):
        self.staff = StaffFactory()
        self.dummy_author = ProfileFactory()

        self.category = CategoryFactory(position=1)
        self.forum = ForumFactory(category=self.category, position_in_category=1)
        self.topic = TopicFactory(forum=self.forum, author=self.dummy_author.user)
        self.post = PostFactory(topic=self.topic, author=self.dummy_author.user, position=1)

        self.alerts = []
        for i in range(20):
            alert = Alert(author=self.dummy_author.user,
                          comment=self.post,
                          scope='FORUM',
                          text=u'pouet-{}'.format(i),
                          pubdate=(datetime.now() + timedelta(minutes=i)))
            alert.save()
            self.alerts.append(alert)
Ejemplo n.º 11
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.º 12
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.º 13
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.º 14
0
    def post(self, request, *args, **kwargs):
        try:
            content_pk = int(self.kwargs['pk'])
        except (KeyError, ValueError):
            raise Http404(u"Impossible de convertir l'identifiant en entier.")
        content = get_object_or_404(PublishableContent, pk=content_pk)

        alert = Alert(author=request.user,
                      content=content,
                      scope='CONTENT',
                      text=request.POST['signal_text'],
                      pubdate=datetime.now())
        alert.save()

        human_content_type = TYPE_CHOICES_DICT[content.type].lower()
        messages.success(
            self.request,
            _(u'Ce {} a bien été signalé aux modérateurs.').format(
                human_content_type))
        return redirect(content.get_absolute_url_online())
Ejemplo n.º 15
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.º 16
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.º 17
0
    def perform_edit_post(request, post, user, text):
        original_text = post.text
        # create an archive
        edit = CommentEdit()
        edit.comment = post
        edit.editor = user
        edit.original_text = original_text
        edit.save()

        post.update_content(
            text,
            on_error=lambda m: messages.error(
                request,
                _("Erreur du serveur Markdown:\n{}").format("\n- ".join(m))),
        )
        post.hat = get_hat_from_request(request, post.author)
        post.update = datetime.now()
        post.editor = user
        post.save()

        # Save topic to update update_index_date
        if post.position == 1:
            post.topic.save()

        # If this post is marked as potential spam, we open an alert to notify the staff that
        # the post was edited. If an open alert already exists for this reason, we update the
        # date of this alert to avoid lots of them stacking up.
        if original_text != text and post.is_potential_spam and post.editor == post.author:
            bot = get_object_or_404(
                User, username=settings.ZDS_APP["member"]["bot_account"])
            alert_text = _(
                "Ce message, soupçonné d'être un spam, a été modifié.")

            try:
                alert = post.alerts_on_this_comment.filter(
                    author=bot, text=alert_text, solved=False).latest()
                alert.pubdate = datetime.now()
                alert.save()
            except Alert.DoesNotExist:
                Alert(author=bot,
                      comment=post,
                      scope="FORUM",
                      text=alert_text,
                      pubdate=datetime.now()).save()

        return post
Ejemplo n.º 18
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.º 19
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.º 20
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.º 21
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
    if reaction.author != request.user:
        if 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-reaction' 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-reaction' in request.POST:
            if request.user.has_perm('article.change_reaction'):
                reaction.is_visible=True
                reaction.text_hidden=''
                    
        if 'signal-reaction' in request.POST:
            if reaction.author != request.user :
                alert = Alert()
                alert.author = request.user
                alert.text=request.POST['signal-text']
                alert.pubdate = datetime.now()
                alert.save()
                reaction.alerts.add(alert)
        # Using the preview button
        if 'preview' in request.POST:
            return render_template('article/edit_reaction.html', {
                'reaction': reaction, 'article': g_article, 'text': request.POST['text'],
            })
        
        if not 'delete-reaction' in request.POST and not 'signal-reaction' in request.POST and not 'show-reaction' 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:
        return render_template('article/edit_reaction.html', {
            'reaction': reaction, 'article': g_article, 'text': reaction.text
        })
Ejemplo n.º 22
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.º 23
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
    if reaction.author != request.user:
        if 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-reaction' 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-reaction' in request.POST:
            if request.user.has_perm('article.change_reaction'):
                reaction.is_visible = True
                reaction.text_hidden = ''

        if 'signal-reaction' in request.POST:
            if reaction.author != request.user:
                alert = Alert()
                alert.author = request.user
                alert.text = request.POST['signal-text']
                alert.pubdate = datetime.now()
                alert.save()
                reaction.alerts.add(alert)
        # Using the preview button
        if 'preview' in request.POST:
            return render_template(
                'article/edit_reaction.html', {
                    'reaction': reaction,
                    'article': g_article,
                    'text': request.POST['text'],
                })

        if not 'delete-reaction' in request.POST and not 'signal-reaction' in request.POST and not 'show-reaction' 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:
        return render_template('article/edit_reaction.html', {
            'reaction': reaction,
            'article': g_article,
            'text': reaction.text
        })
Ejemplo n.º 24
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)

    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
    if post.author != request.user:
        if request.method == 'GET' and request.user.has_perm(
                'forum.change_post'):
            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(post.author.username))
            post.alerts.all().delete()

    if request.method == 'POST':

        if 'delete-post' 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

        if 'show-post' in request.POST:
            if request.user.has_perm('forum.change_post'):
                post.is_visible = True
                post.text_hidden = ''

        if 'signal-post' in request.POST:
            if post.author != request.user:
                alert = Alert()
                alert.author = request.user
                alert.text = request.POST['signal-text']
                alert.pubdate = datetime.now()
                alert.save()
                post.alerts.add(alert)
        # Using the preview button
        if 'preview' in request.POST:
            if g_topic:
                g_topic = Topic(title=request.POST['title'],
                                subtitle=request.POST['subtitle'])
            return render_template('forum/edit_post.html', {
                'post': post,
                'topic': g_topic,
                'text': request.POST['text'],
            })

        if not 'delete-post' in request.POST and not 'signal-post' in request.POST and not 'show-post' 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:
                g_topic.title = request.POST['title']
                g_topic.subtitle = request.POST['subtitle']
                g_topic.save()

        post.save()

        return redirect(post.get_absolute_url())

    else:
        return render_template('forum/edit_post.html', {
            'post': post,
            'topic': g_topic,
            'text': post.text
        })