Exemple #1
0
def save_post_reject_reason(request):
    """saves post reject reason and returns the reason id
    if reason_id is not given in the input - a new reason is created,
    otherwise a reason with the given id is edited and saved
    """
    form = forms.EditRejectReasonForm(request.POST)
    if form.is_valid():
        title = form.cleaned_data['title']
        details = form.cleaned_data['details']
        if form.cleaned_data['reason_id'] is None:
            reason = request.user.create_post_reject_reason(
                title = title, details = details
            )
        else:
            reason_id = form.cleaned_data['reason_id']
            reason = models.PostFlagReason.objects.get(id = reason_id)
            request.user.edit_post_reject_reason(
                reason, title = title, details = details
            )
        return {
            'reason_id': reason.id,
            'title': title,
            'details': details
        }
    else:
        raise Exception(forms.format_form_errors(form))
Exemple #2
0
def save_post_reject_reason(request):
    """saves post reject reason and returns the reason id
    if reason_id is not given in the input - a new reason is created,
    otherwise a reason with the given id is edited and saved
    """
    form = forms.EditRejectReasonForm(request.POST)
    if form.is_valid():
        title = form.cleaned_data['title']
        details = form.cleaned_data['details']
        if form.cleaned_data['reason_id'] is None:
            reason = request.user.create_post_reject_reason(
                title = title, details = details
            )
        else:
            reason_id = form.cleaned_data['reason_id']
            reason = models.PostFlagReason.objects.get(id = reason_id)
            request.user.edit_post_reject_reason(
                reason, title = title, details = details
            )
        return {
            'reason_id': reason.id,
            'title': title,
            'details': details
        }
    else:
        raise Exception(forms.format_form_errors(form))
Exemple #3
0
def moderate_suggested_tag(request):
    """accepts or rejects a suggested tag
    if thread id is given, then tag is
    applied to or removed from only one thread,
    otherwise the decision applies to all threads
    """
    form = forms.ModerateTagForm(request.POST)
    if form.is_valid():
        tag_id = form.cleaned_data['tag_id']
        thread_id = form.cleaned_data.get('thread_id', None)

        lang = translation.get_language()

        try:
            tag = models.Tag.objects.get(
                id=tag_id, language_code=lang)  # can tag not exist?
        except models.Tag.DoesNotExist:
            return

        if thread_id:
            thread_list = models.Thread.objects.filter(id=thread_id,
                                                       language_code=lang)
        else:
            thread_list = tag.threads.none()

        if form.cleaned_data['action'] == 'accept':
            # TODO: here we lose ability to come back
            # to the tag moderation and approve tag to
            # other thread_list later for the case where tag.used_count > 1
            tag.status = models.Tag.STATUS_ACCEPTED
            tag.save()
            for thread in thread_list:
                thread.add_tag(tag_name=tag.name,
                               user=tag.created_by,
                               timestamp=timezone.now(),
                               silent=True)
        else:
            if tag.threads.count() > thread_list.count():
                for thread in thread_list:
                    thread.tags.remove(tag)
                tag.used_count = tag.threads.count()
                tag.save()
            elif tag.status == models.Tag.STATUS_SUGGESTED:
                tag.delete()
    else:
        raise Exception(forms.format_form_errors(form))
Exemple #4
0
def moderate_suggested_tag(request):
    """accepts or rejects a suggested tag
    if thread id is given, then tag is
    applied to or removed from only one thread,
    otherwise the decision applies to all threads
    """
    form = forms.ModerateTagForm(request.POST)
    if form.is_valid():
        tag_id = form.cleaned_data['tag_id']
        thread_id = form.cleaned_data.get('thread_id', None)

        lang = translation.get_language()

        try:
            tag = models.Tag.objects.get(id=tag_id, language_code=lang)  # can tag not exist?
        except models.Tag.DoesNotExist:
            return

        if thread_id:
            thread_list = models.Thread.objects.filter(id=thread_id, language_code=lang)
        else:
            thread_list = tag.threads.none()

        if form.cleaned_data['action'] == 'accept':
            # TODO: here we lose ability to come back
            # to the tag moderation and approve tag to
            # other thread_list later for the case where tag.used_count > 1
            tag.status = models.Tag.STATUS_ACCEPTED
            tag.save()
            for thread in thread_list:
                thread.add_tag(tag_name=tag.name, user=tag.created_by, timestamp=timezone.now(), silent=True)
        else:
            if tag.threads.count() > thread_list.count():
                for thread in thread_list:
                    thread.tags.remove(tag)
                tag.used_count = tag.threads.count()
                tag.save()
            elif tag.status == models.Tag.STATUS_SUGGESTED:
                tag.delete()
    else:
        raise Exception(forms.format_form_errors(form))