Пример #1
0
def new_note(request):
    if request.method == 'POST' and 'b2' in request.POST :
        form = NewNote(request.POST)
        if form.is_valid():
            new = Note()
            new.owner = request.session['username']
            new.head = form.cleaned_data["heading"]
            new.content = form.cleaned_data["content"]
            con = Markdown()
            new.md = con.convert(new.content)
            new.save()
            return HttpResponseRedirect("./")
    if request.method == 'POST' and 'b1' in request.POST :
        form = NewNote(request.POST)
        if form.is_valid():
            con=Markdown()
            request.session['temp'] = con.convert(form.cleaned_data['content'])

            return HttpResponseRedirect('preview')
    data = [i for i in Note.objects.all() if i.owner == request.session['username']]

    context = dict()
    context['data'] = data
    context['form'] = NewNote()
    context['username'] = request.session['username']
    temp = loader.get_template('notes/newnote.html')
    return HttpResponse(temp.render(context, request))
Пример #2
0
def handle_add_notes(username):
    """ Display form to add notes for the logged in user.
        Add new note and redirect to user detail.
    """

    if session.get('user_id') != username:
        flash("You are not authorized to add notes to this user!")
        return redirect('/')

    form = NoteForm()

    if form.validate_on_submit():

        new_note = Note()
        form.populate_obj(new_note)
        new_note.owner = username

        db.session.add(new_note)
        db.session.commit()

        flash("Note has been added")

        return redirect(f"/users/{username}")
    else:
        return render_template("add_notes.html", form=form)