예제 #1
0
def view_note(request, note_id):
    # Validate note
    current_note = validate_ownership_note(request.user, note_id)

    # Render
    current_note.rendered_content = render_markdown(current_note.content)

    context = trash_context(request.user)
    context['current_note'] = current_note
    return render(request, 'view_trash_note.html', context)
예제 #2
0
파일: views.py 프로젝트: dozmus/notes
def view_note(request, note_id):
    # Validate note
    current_note = validate_ownership_note(request.user, note_id)

    # Render
    current_note.rendered_content = render_markdown(current_note.content)

    context = trash_context(request.user)
    context['current_note'] = current_note
    return render(request, 'view_trash_note.html', context)
예제 #3
0
파일: views.py 프로젝트: dozmus/notes
def delete_all_notes(request):
    notes = TrashNote.objects.for_user(request.user)

    if request.method == 'POST':
        Note.delete_all(notes)
        return redirect('trash:trash')

    # Render
    context = trash_context(request.user)
    context['notes'] = notes
    context['current_note_ids'] = ','.join([str(note.id) for note in notes])
    return render(request, 'delete_all_notes.html', context)
예제 #4
0
파일: views.py 프로젝트: dozmus/notes
def delete_note(request, note_id):
    # Validate note
    note = validate_ownership_note(request.user, note_id)

    if request.method == 'POST':
        note.delete()
        return redirect('trash:trash')

    # Render
    context = trash_context(request.user)
    context['current_note'] = note
    return render(request, 'permanent_delete_note.html', context)
예제 #5
0
def delete_note(request, note_id):
    # Validate note
    note = validate_ownership_note(request.user, note_id)

    if request.method == 'POST':
        note.delete()
        return redirect('trash:trash')

    # Render
    context = trash_context(request.user)
    context['current_note'] = note
    return render(request, 'permanent_delete_note.html', context)
예제 #6
0
def restore_all_notes(request):
    notes = TrashNote.objects.for_user(request.user)

    if request.method == 'POST':
        Note.untrash_all(notes)
        return redirect('trash:trash')

    # Render
    context = trash_context(request.user)
    context['notes'] = notes
    context['current_note_ids'] = ','.join([str(note.id) for note in notes])
    return render(request, 'restore_all_notes.html', context)
예제 #7
0
파일: views.py 프로젝트: dozmus/notes
def restore_note(request, note_id):
    # Validate note
    note = validate_ownership_note(request.user, note_id)

    if request.method == 'POST':
        note.trash = False
        note.save()
        return redirect('trash:trash')

    # Render
    context = trash_context(request.user)
    context['current_note'] = note
    return render(request, 'restore_note.html', context)
예제 #8
0
def restore_note(request, note_id):
    # Validate note
    note = validate_ownership_note(request.user, note_id)

    if request.method == 'POST':
        note.trash = False
        note.save()
        return redirect('trash:trash')

    # Render
    context = trash_context(request.user)
    context['current_note'] = note
    return render(request, 'restore_note.html', context)
예제 #9
0
def delete_all_notes(request):
    notes = Note.objects.filter(notebook__owner=request.user, trash=True)

    if request.method == 'POST':
        for note in notes:
            note.delete()
        return redirect('trash:trash')

    # Render
    context = trash_context(request.user)
    context['notes'] = notes
    context['current_note_ids'] = ','.join([str(note.id) for note in notes])
    return render(request, 'delete_all_notes.html', context)
예제 #10
0
파일: views.py 프로젝트: dozmus/notes
def delete_notes(request, note_ids):
    # Validate notes
    note_id_array = note_ids.split(',')
    notes = validate_ownership_notes(request.user, note_id_array)

    if request.method == 'POST':
        Note.delete_all(notes)
        return redirect('trash:trash')

    # Render
    context = trash_context(request.user)
    context['notes'] = notes
    context['current_note_ids'] = note_ids
    return render(request, 'permanent_delete_notes.html', context)
예제 #11
0
def delete_notes(request, note_ids):
    # Validate notes
    note_id_array = note_ids.split(',')
    notes = validate_ownership_notes(request.user, note_id_array)

    if request.method == 'POST':
        Note.delete_all(notes)
        return redirect('trash:trash')

    # Render
    context = trash_context(request.user)
    context['notes'] = notes
    context['current_note_ids'] = note_ids
    return render(request, 'permanent_delete_notes.html', context)
예제 #12
0
def restore_notes(request, note_ids):
    # Validate notes
    note_id_array = note_ids.split(',')
    notes = validate_ownership_notes(request.user, note_id_array)

    if request.method == 'POST':
        for note in notes:
            note.trash = False
            note.save()
        return redirect('trash:trash')

    # Render
    context = trash_context(request.user)
    context['notes'] = notes
    context['current_note_ids'] = note_ids
    return render(request, 'restore_notes.html', context)
예제 #13
0
def trash(request):
    # Create form
    notes = Note.objects.filter(notebook__owner=request.user,
                                trash=True).order_by('id')

    if request.method != 'POST':
        form = SelectNotesForm()
        form.set_choices(notes)
    else:
        form = SelectNotesForm(data=request.POST)
        form.set_choices(notes)

        if form.is_valid():
            # Collect valid nodes
            valid_notes = validate_ownership_notes(request.user,
                                                   form.cleaned_data['picked'])

            if len(valid_notes) > 0:
                # Download
                if 'downloadtxts' in request.POST:
                    return notes2txtzip_response(valid_notes,
                                                 'notes-trash-all')

                # Download
                if 'downloadpdfs' in request.POST:
                    return notes2pdfzip_response(valid_notes,
                                                 'notes-trash-all')

                # Move
                if 'restore' in request.POST:
                    note_ids = ','.join([str(note.id) for note in valid_notes])
                    return HttpResponseRedirect(
                        reverse('trash:restore-notes',
                                kwargs={'note_ids': note_ids}))

                # Delete
                if 'delete' in request.POST:
                    note_ids = ','.join([str(note.id) for note in valid_notes])
                    return HttpResponseRedirect(
                        reverse('trash:permanent-delete-notes',
                                kwargs={'note_ids': note_ids}))

    # Render
    context = trash_context(request.user)
    context['form'] = form
    context['notes'] = notes
    return render(request, 'view_trash.html', context)
예제 #14
0
파일: views.py 프로젝트: dozmus/notes
def trash(request):
    # Create form
    notes = TrashNote.objects.for_user(request.user)

    if request.method != 'POST':
        form = SelectNotesForm()
        form.set_choices(notes)
    else:
        form = SelectNotesForm(data=request.POST)
        form.set_choices(notes)

        if form.is_valid():
            # Collect valid nodes
            valid_notes = validate_ownership_notes(request.user, form.cleaned_data['picked'])
            note_ids = ','.join([str(note.id) for note in valid_notes])

            if len(valid_notes) > 0:
                # Download
                if 'downloadtxts' in request.POST:
                    return notes2txtzip_response(valid_notes, 'notes-trash-all')

                # Download
                if 'downloadpdfs' in request.POST:
                    return notes2pdfzip_response(valid_notes, 'notes-trash-all')

                # Move
                if 'restore' in request.POST:
                    return HttpResponseRedirect(reverse('trash:restore-notes', kwargs={'note_ids': note_ids}))

                # Delete
                if 'delete' in request.POST:
                    return HttpResponseRedirect(reverse('trash:permanent-delete-notes', kwargs={'note_ids': note_ids}))

    # Render
    context = trash_context(request.user)
    context['form'] = form
    context['notes'] = notes
    return render(request, 'view_trash.html', context)