Exemplo n.º 1
0
def update_position(request, space_url):

    """
    This view saves the new note position in the debate board. Instead of
    reloading all the note form with all the data, we use the partial form
    "UpdateNotePosition" which only handles the column and row of the note.
    """
    place = get_object_or_404(Space, url=space_url)

    if request.method == "POST" and request.is_ajax:
        note = get_object_or_404(Note, pk=request.POST['noteid'])
        debate = get_object_or_404(Debate, pk=note.debate.id)
        position_form = UpdateNotePosition(request.POST or None, instance=note)

        if (request.user.has_perm('admin_space', place) or
            request.user.has_perm('mod_space', place) or
            request.user.has_perm('admin_debate', debate) or
            request.user.has_perm('mod_debate', debate) or
            request.user == note.author):

            if position_form.is_valid():
                position_form_uncommited = position_form.save(commit=False)
                position_form_uncommited.column = get_object_or_404(Column,
                                                pk=request.POST['column'])
                position_form_uncommited.row = get_object_or_404(Row,
                                                pk=request.POST['row'])
                position_form_uncommited.save()
            else:
                return HttpResponseBadRequest(_("There has been an error validating the form."))
        else:
            raise PermissionDenied
    return HttpResponseBadRequest(_("The petition was not POST."))
Exemplo n.º 2
0
def update_position(request, space_url):

    """
    This view saves the new note position in the debate board. Instead of
    reloading all the note form with all the data, we use the partial form
    "UpdateNotePosition" which only handles the column and row of the note.
    """
    note = get_object_or_404(Note, pk=request.POST['noteid'])
    position_form = UpdateNotePosition(request.POST or None, instance=note)

    if request.method == "POST" and request.is_ajax:
        if request.user == note.author or request.user.is_staff:
            if position_form.is_valid():
                position_form_uncommited = position_form.save(commit=False)
                position_form_uncommited.column = get_object_or_404(Column,
                                                pk=request.POST['column'])
                position_form_uncommited.row = get_object_or_404(Row,
                                                pk=request.POST['row'])
                position_form_uncommited.save()
                msg = "The note has been updated."
            else:
                msg = "There has been an error validating the form."
        else:
            msg = "There was some error in the petition."

    return HttpResponse(msg)
Exemplo n.º 3
0
def update_position(request, space_url):
    """
    This view saves the new note position in the debate board. Instead of
    reloading all the note form with all the data, we use the partial form
    "UpdateNotePosition" which only handles the column and row of the note.
    """
    place = get_object_or_404(Space, url=space_url)

    if request.method == "POST" and request.is_ajax():
        note = get_object_or_404(Note, pk=request.POST['noteid'])
        debate = get_object_or_404(Debate, pk=note.debate.id)
        position_form = UpdateNotePosition(request.POST or None, instance=note)

        if (request.user.has_perm('admin_space', place)
                or request.user.has_perm('mod_space', place)
                or request.user.has_perm('admin_debate', debate)
                or request.user.has_perm('mod_debate', debate)
                or request.user == note.author):

            if position_form.is_valid():
                position_form_uncommited = position_form.save(commit=False)
                position_form_uncommited.column = get_object_or_404(
                    Column, pk=request.POST['column'])
                position_form_uncommited.row = get_object_or_404(
                    Row, pk=request.POST['row'])
                position_form_uncommited.save()

                return HttpResponse(_("Note updated"))
            else:
                return HttpResponseBadRequest(
                    _("There has been an error validating the form."))
        else:
            raise PermissionDenied
    else:
        return HttpResponseBadRequest(_("The petition was not POST."))