Пример #1
0
def save(request, course=False, id=False):
    if request.method == "POST":
        if id:
            note = get_object_or_404(Note, pk=id)
        else:
            course = get_object_or_404(Course, code=course)
            note = Note(course=course)
        form = NoteForm(request.POST, instance=note)
        if form.is_valid():
            note = form.save()
            for t in form.cleaned_data["tags"]:
                tag = Tag.objects.get_or_create(title=t)[0]
                note.add_tag(tag)
    return HttpResponse("Saved")
Пример #2
0
def save(request, course=False, id=False):
    if request.method == 'POST':
        if id:
            note = get_object_or_404(Note, pk=id)
        else:
            course = get_object_or_404(Course, code=course)
            note = Note(course=course)
        form = NoteForm(request.POST, instance=note)
        if form.is_valid():
            note = form.save()
            for t in form.cleaned_data['tags']:
                tag = Tag.objects.get_or_create(title=t)[0]
                note.add_tag(tag)
    return HttpResponse('Saved')
Пример #3
0
def edit(request, course=False, id=False):
    if id:
        note = get_object_or_404(Note, pk=id)
    else:
        course = get_object_or_404(Course, code=course)
        note = Note(course=course)
    form = NoteForm(instance=note)
    if request.method == "POST":
        form = NoteForm(request.POST, instance=note)
        if form.is_valid():
            note = form.save()
            for t in form.cleaned_data["tags"]:
                tag = Tag.objects.get_or_create(title=t)[0]
                note.add_tag(tag)
    return render_to_response("notes/edit.html", {"note": note, "form": form}, context_instance=RequestContext(request))
Пример #4
0
def edit(request, course=False, id=False):
    if id:
        note = get_object_or_404(Note, pk=id)
    else:
        course = get_object_or_404(Course, code=course)
        note = Note(course=course)
    form = NoteForm(instance=note)
    if request.method == 'POST':
        form = NoteForm(request.POST, instance=note)
        if form.is_valid():
            note = form.save()
            for t in form.cleaned_data['tags']:
                tag = Tag.objects.get_or_create(title=t)[0]
                note.add_tag(tag)
    return render_to_response('notes/edit.html', {
        'note': note,
        'form': form
    },
                              context_instance=RequestContext(request))