예제 #1
0
def download_trash(request, filetype):
    notes = TrashNote.objects.for_user(request.user)

    # Return file
    if filetype == 'txt':
        return notes2txtzip_response(notes)
    elif filetype == 'pdf':
        return notes2pdfzip_response(notes)
    else:
        raise Http404('Invalid filetype.')
예제 #2
0
파일: views.py 프로젝트: dozmus/notes
def download_trash(request, filetype):
    notes = TrashNote.objects.for_user(request.user)

    # Return file
    if filetype == 'txt':
        return notes2txtzip_response(notes)
    elif filetype == 'pdf':
        return notes2pdfzip_response(notes)
    else:
        raise Http404('Invalid filetype.')
예제 #3
0
def download_trash(request, filetype):
    notes = Note.objects.filter(notebook__owner=request.user, trash=True)

    # Return file
    if filetype == 'txt':
        return notes2txtzip_response(notes)
    elif filetype == 'pdf':
        return notes2pdfzip_response(notes)
    else:
        raise Http404('Invalid filetype.')
예제 #4
0
def view_notebook(request, notebook_id):
    # Validate notebook
    current_notebook = validate_ownership_notebook(request.user, notebook_id)

    # Create form
    notes = Note.objects.filter(notebook_id=notebook_id,
                                trash=False).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'])
            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-%s-partial' % current_notebook.title)

                # Download
                if 'downloadpdfs' in request.POST:
                    return notes2pdfzip_response(
                        valid_notes,
                        'notes-%s-partial' % current_notebook.title)

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

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

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

    # Render
    context = regular_context(request.user)
    context['form'] = form
    context['notes'] = notes
    context['current_notebook'] = current_notebook
    return render(request, 'view_notebook.html', context)
예제 #5
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)
예제 #6
0
파일: views.py 프로젝트: dozmus/notes
def view_notebook(request, notebook_id):
    # Validate notebook
    current_notebook = validate_ownership_notebook(request.user, notebook_id)

    # Create form
    notes = Note.objects.filter(notebook_id=notebook_id, trash=False).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'])
            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-%s-partial' % current_notebook.title)

                # Download
                if 'downloadpdfs' in request.POST:
                    return notes2pdfzip_response(valid_notes, 'notes-%s-partial' % current_notebook.title)

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

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

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

    # Render
    context = regular_context(request.user)
    context['form'] = form
    context['notes'] = notes
    context['current_notebook'] = current_notebook
    return render(request, 'view_notebook.html', context)
예제 #7
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)