Exemplo n.º 1
0
def create_note(request, space_url):
    """
    This function creates a new note inside the debate board. It receives the
    order from the createNote() AJAX function. To create the note first we
    create the note in the DB, and if successful we return some of its
    parameters to the debate board for the user. In case the petition had
    errors, we return the error message that will be shown by jsnotify.

    .. versionadded:: 0.1.5
    """
    note_form = NoteForm(request.POST or None)
    place = get_object_or_404(Space, url=space_url)

    if request.method == "POST" and request.is_ajax():
        debate = get_object_or_404(Debate, pk=request.POST['debateid'])

        # This is not the best approach, but I don't want to think in
        # another solution right now, we need this and we need it now
        if ((debate.private and request.user.has_perm('view_debate', debate))
                or (not debate.private
                    and request.user.has_perm('view_space', place))):

            if note_form.is_valid():
                note_form_uncommited = note_form.save(commit=False)
                note_form_uncommited.author = request.user
                note_form_uncommited.debate = get_object_or_404(
                    Debate, pk=request.POST['debateid'])
                note_form_uncommited.title = request.POST['title']
                note_form_uncommited.message = request.POST['message']
                note_form_uncommited.column = get_object_or_404(
                    Column, pk=request.POST['column'])
                note_form_uncommited.row = get_object_or_404(
                    Row, pk=request.POST['row'])
                note_form_uncommited.save()

                response_data = {}
                response_data['id'] = note_form_uncommited.id
                response_data['message'] = note_form_uncommited.message
                response_data['title'] = note_form_uncommited.title
                msg = "The note has been created."
                return HttpResponse(json.dumps(response_data),
                                    mimetype="application/json")
            else:
                return HttpResponseBadRequest(
                    _("The note form didn't validate. This fields gave errors: "
                      ) + str(note_form.errors))
        else:
            raise PermissionDenied
    else:
        return HttpResponseBadRequest(_("The petition was not POST."))
Exemplo n.º 2
0
def create_note(request, space_url):

    """
    This function creates a new note inside the debate board. It receives the
    order from the createNote() AJAX function. To create the note first we
    create the note in the DB, and if successful we return some of its
    parameters to the debate board for the user. In case the petition had
    errors, we return the error message that will be shown by jsnotify.

    .. versionadded:: 0.1.5
    """
    note_form = NoteForm(request.POST or None)
    place = get_object_or_404(Space, url=space_url)

    if request.method == "POST" and request.is_ajax():
        debate = get_object_or_404(Debate, pk=request.POST['debateid'])

        # This is not the best approach, but I don't want to think in
        # another solution right now, we need this and we need it now
        if ((debate.private and request.user.has_perm('view_debate', debate)) or
            (not debate.private and request.user.has_perm('view_space', place))):

            if note_form.is_valid():
                note_form_uncommited = note_form.save(commit=False)
                note_form_uncommited.author = request.user
                note_form_uncommited.debate = get_object_or_404(Debate,
                    pk=request.POST['debateid'])
                note_form_uncommited.title = request.POST['title']
                note_form_uncommited.message = request.POST['message']
                note_form_uncommited.column = get_object_or_404(Column,
                    pk=request.POST['column'])
                note_form_uncommited.row = get_object_or_404(Row,
                    pk=request.POST['row'])
                note_form_uncommited.save()

                response_data = {}
                response_data['id'] = note_form_uncommited.id
                response_data['message'] = note_form_uncommited.message
                response_data['title'] = note_form_uncommited.title
                msg = "The note has been created."
                return HttpResponse(json.dumps(response_data),
                                mimetype="application/json")
            else:
                return HttpResponseBadRequest(_("The note form didn't validate. This fields gave errors: ") + str(note_form.errors))
        else:
            raise PermissionDenied
    else:
        return HttpResponseBadRequest(_("The petition was not POST."))
Exemplo n.º 3
0
def create_note(request, space_url):

    """
    This function creates a new note inside the debate board. It receives the
    order from the createNote() AJAX function. To create the note first we
    create the note in the DB, and if successful we return some of its
    parameters to the debate board for the user. In case the petition had
    errors, we return the error message that will be shown by jsnotify.

    .. versionadded:: 0.1.5
    """
    note_form = NoteForm(request.POST or None)
    place = get_object_or_404(Space, url=space_url)

    if request.method == "POST" and request.is_ajax:
        if has_operation_permission(request.user, place, 'note.add_note',
        allow=['admins', 'mods', 'users']):
            if note_form.is_valid():
                note_form_uncommited = note_form.save(commit=False)
                note_form_uncommited.author = request.user
                note_form_uncommited.debate = get_object_or_404(Debate,
                    pk=request.POST['debateid'])
                note_form_uncommited.title = request.POST['title']
                note_form_uncommited.message = request.POST['message']
                note_form_uncommited.column = get_object_or_404(Column,
                    pk=request.POST['column'])
                note_form_uncommited.row = get_object_or_404(Row,
                    pk=request.POST['row'])
                note_form_uncommited.save()

                response_data = {}
                response_data['id'] = note_form_uncommited.id
                response_data['message'] = note_form_uncommited.message
                response_data['title'] = note_form_uncommited.title
                msg = "The note has been created."
                return HttpResponse(json.dumps(response_data),
                                    mimetype="application/json")

            else:
                msg = "The note form didn't validate. This fields gave errors: " + str(note_form.errors)
        else:
            msg = "The petition was not POST."

    return HttpResponse(json.dumps(msg), mimetype="application/json")
Exemplo n.º 4
0
def create_note(request, space_url):

    """
    This function creates a new note inside the debate board. It receives the
    order from the createNote() AJAX function. To create the note first we
    create the note in the DB, and if successful we return some of its
    parameters to the debate board for the user. In case the petition had
    errors, we return the error message that will be shown by jsnotify.

    .. versionadded:: 0.1.5
    """
    note_form = NoteForm(request.POST or None)
        
    if request.method == "POST" and request.is_ajax:        
        if note_form.is_valid():
            note_form_uncommited = note_form.save(commit=False)
            note_form_uncommited.author = request.user
            note_form_uncommited.debate = get_object_or_404(Debate,
                pk=request.POST['debateid'])
            note_form_uncommited.title = request.POST['title']
            note_form_uncommited.message = request.POST['message']
            note_form_uncommited.column = get_object_or_404(Column,
                pk=request.POST['column'])
            note_form_uncommited.row = get_object_or_404(Row,
                pk=request.POST['row'])
            note_form_uncommited.save()

            response_data = {}
            response_data['id'] = note_form_uncommited.id
            response_data['message'] = note_form_uncommited.message
            response_data['title'] = note_form_uncommited.title
            return HttpResponse(json.dumps(response_data),
                                mimetype="application/json")

        else:
            msg = "The note form didn't validate. This fields gave errors: " \
            + str(note_form.errors)
    else:
        msg = "The petition was not POST."
        
    return HttpResponse(json.dumps(msg), mimetype="application/json")