Ejemplo n.º 1
0
def addnote(request, pk):
    form = dict()
    form['form'] = AddNote()
    form['icons'] = Icon.objects.all()
    form['directory'] = Genre.objects.get(id=pk)
    note_name = Note.objects.all()
    form['notes'] = note_name
    form['username'] = auth.get_user(request).username
    form['parent'] = Genre.objects.get(id=pk)
    form['tree'] = Genre.objects.filter(parent_id=pk, user_id=auth.get_user(request).id)
    form['tree_files'] = Note.objects.filter(parent_id=pk, user_id=auth.get_user(request).id)
    if request.POST:
        new_add_note = Note()
        new_add_note.note_name = request.POST['note_name']
        new_add_note.note_text = request.POST['note_text']
        new_add_note.user = User.objects.get(username=auth.get_user(request).username)
        new_add_note.parent = Genre.objects.get(id=pk)
        if new_add_note.valid():
            new_add_note.save()
            for icon in request.POST.getlist('checkbox'):
                new_add_note.icon_name.add(Icon.objects.get(id=icon))
            form['saved'] = 'Сохранено в базе данных'
        else:
            form['saved'] = 'Название заметки обязательное поле'
        return render(request, 'app/boot_index.html', form)

    return render(request, 'app/add.html', form)
Ejemplo n.º 2
0
def addnote(request):
    form = dict()
    form['form'] = AddNote()
    note_name = Note.objects.all()
    form['notes'] = note_name
    if request.POST:
        new_add_note = Note()
        new_add_note.note_name = request.POST['name']
        new_add_note.note_text = request.POST['text']
        new_add_note.user = User.objects.get(username=auth.get_user(request).username)
        new_add_note.save()
        form['saved'] = 'Сохранено в базе данных'
        return render(request, 'app/index.html', form)

    return render(request, 'app/add.html', form)