Esempio n. 1
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)
Esempio n. 2
0
def download_notebook(request, notebook_id, filetype):
    # Validate notebook
    current_notebook = validate_ownership_notebook(request.user, notebook_id)

    # Return file
    if filetype == 'txt':
        return notebook2txtzip(current_notebook)
    elif filetype == 'pdf':
        return notebook2pdfzip(current_notebook)
    else:
        raise Http404('Invalid filetype.')
Esempio n. 3
0
def download_notebook(request, notebook_id, filetype):
    # Validate notebook
    current_notebook = validate_ownership_notebook(request.user, notebook_id)

    # Return file
    if filetype == 'txt':
        return notebook2txtzip_response(current_notebook)
    elif filetype == 'pdf':
        return notebook2pdfzip_response(current_notebook)
    else:
        raise Http404('Invalid filetype.')
Esempio n. 4
0
def delete_notebook(request, notebook_id):
    # Validate notebook
    current_notebook = validate_ownership_notebook(request.user, notebook_id)

    if request.method == 'POST':
        current_notebook.delete()
        return redirect('home')

    # Render
    context = regular_context(request.user)
    context['current_notebook'] = current_notebook
    return render(request, 'delete_notebook.html', context)
Esempio n. 5
0
def delete_notebook(request, notebook_id):
    # Validate notebook
    current_notebook = validate_ownership_notebook(request.user, notebook_id)

    if request.method == 'POST':
        current_notebook.delete()
        return redirect('home')

    # Render
    context = regular_context(request.user)
    context['current_notebook'] = current_notebook
    return render(request, 'delete_notebook.html', context)
Esempio n. 6
0
def search_notebook(request, notebook_id):
    if request.method != 'POST':
        return redirect('home')

    # Validate notebook
    current_notebook = validate_ownership_notebook(request.user, notebook_id)

    # Render
    query = request.POST['query']

    context = regular_context(request.user)
    context['query'] = query
    context['notes'] = search_notes(request.user, query, current_notebook),
    context['current_notebook'] = current_notebook
    return render(request, 'search_notebook.html', context)
Esempio n. 7
0
def search_notebook(request, notebook_id):
    if request.method != 'POST':
        return redirect('home')

    # Validate notebook
    current_notebook = validate_ownership_notebook(request.user, notebook_id)

    # Render
    query = request.POST['query']

    context = regular_context(request.user)
    context['query'] = query
    context['notes'] = Note.objects.search(request.user, query, current_notebook)
    context['current_notebook'] = current_notebook
    return render(request, 'search_notebook.html', context)
Esempio n. 8
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)
Esempio n. 9
0
def edit_notebook(request, notebook_id):
    # Validate notebook
    current_notebook = validate_ownership_notebook(request.user, notebook_id)

    # Create form
    if request.method != 'POST':
        form = NotebookForm(data={
            'title': current_notebook.title,
            'colour': current_notebook.colour
        })
    else:
        form = NotebookForm(data=request.POST)

        if form.update(current_notebook):
            return redirect('home')

    # Render
    context = regular_context(request.user)
    context['form'] = form
    context['current_notebook'] = current_notebook
    return render(request, 'edit_notebook.html', context)
Esempio n. 10
0
def edit_notebook(request, notebook_id):
    # Validate notebook
    current_notebook = validate_ownership_notebook(request.user, notebook_id)

    # Create form
    if request.method != 'POST':
        form = NotebookForm(data={
            'title': current_notebook.title,
            'colour': current_notebook.colour
        })
    else:
        form = NotebookForm(data=request.POST)

        if form.update(current_notebook):
            return redirect('home')

    # Render
    context = regular_context(request.user)
    context['form'] = form
    context['current_notebook'] = current_notebook
    return render(request, 'edit_notebook.html', context)