示例#1
0
文件: views.py 项目: dozmus/notes
def new_share_link(request, note_id):
    # Validate note
    current_note = validate_ownership_note(request.user, note_id)

    if request.method != 'POST':
        form = SharableLinkForm()

        # Generate unique code
        unique_code = '%32x' % random.getrandbits(16 * 8)
        entry = SharableLink.objects.filter(code=unique_code)

        while entry.exists():
            unique_code = '%32x' % random.getrandbits(16 * 8)
            entry = SharableLink.objects.filter(code=unique_code)

        form.set_code(unique_code)
    else:
        form = SharableLinkForm(data=request.POST)

        if form.create(note_id):
            return HttpResponseRedirect(reverse('share:share-note', kwargs={'note_id': note_id}))

    # Render
    context = regular_context(request.user)
    context['form'] = form
    context['current_note'] = current_note
    return render(request, 'new_share_link.html', context)
示例#2
0
def edit_share_link(request, note_id, code):
    # Validate note
    current_note = validate_ownership_note(request.user, note_id)
    link = SharableLink.objects.filter(code=code).filter(note_id=note_id).get()

    if request.method != 'POST':
        form = EditSharableLinkForm(data={
            'permissions': link.permissions,
            'expiry_date': link.expiry_date
        })
    else:
        form = EditSharableLinkForm(data=request.POST)

        if form.is_valid():
            link.permissions = form.cleaned_data['permissions']
            link.expiry_date = form.cleaned_data['expiry_date']
            link.save()
            return redirect('home')

    # Render
    context = regular_context(request.user)
    context['form'] = form
    context['current_note'] = current_note
    context['code'] = code
    return render(request, 'edit_share_link.html', context)
示例#3
0
def edit_note(request, note_id):
    # Validate note
    current_note = validate_ownership_note(request.user, note_id)

    # Create form
    if request.method != 'POST':
        form = NoteForm(
            data={
                'title': current_note.title,
                'notebook': current_note.notebook,
                'content': current_note.content,
                'tags': current_note.tags,
            })
        form.restrict_to_user(request.user)
    else:
        form = NoteForm(data=request.POST)
        form.restrict_to_user(request.user)

        if form.update(current_note):
            return HttpResponseRedirect(
                reverse('view-note', kwargs={'note_id': note_id}))

    # Render
    context = regular_context(request.user)
    context['form'] = form
    context['current_note'] = current_note
    return render(request, 'edit_note.html', context)
示例#4
0
文件: views.py 项目: dozmus/notes
def new_share_link(request, note_id):
    # Validate note
    current_note = validate_ownership_note(request.user, note_id)

    if request.method != 'POST':
        form = SharableLinkForm()

        # Generate unique code
        unique_code = '%32x' % random.getrandbits(16 * 8)
        entry = SharableLink.objects.filter(code=unique_code)

        while entry.exists():
            unique_code = '%32x' % random.getrandbits(16 * 8)
            entry = SharableLink.objects.filter(code=unique_code)

        form.set_code(unique_code)
    else:
        form = SharableLinkForm(data=request.POST)

        if form.create(note_id):
            return HttpResponseRedirect(
                reverse('share:share-note', kwargs={'note_id': note_id}))

    # Render
    context = regular_context(request.user)
    context['form'] = form
    context['current_note'] = current_note
    return render(request, 'new_share_link.html', context)
示例#5
0
文件: views.py 项目: dozmus/notes
def edit_note(request, note_id):
    # Validate note
    current_note = validate_ownership_note(request.user, note_id)

    # Create form
    if request.method != 'POST':
        form = NoteForm(data={
            'title': current_note.title,
            'notebook': current_note.notebook,
            'content': current_note.content,
            'tags': current_note.tags,
        })
        form.restrict_to_user(request.user)
    else:
        form = NoteForm(data=request.POST)
        form.restrict_to_user(request.user)

        if form.update(current_note):
            return HttpResponseRedirect(reverse('view-note', kwargs={'note_id': note_id}))

    # Render
    context = regular_context(request.user)
    context['form'] = form
    context['current_note'] = current_note
    return render(request, 'edit_note.html', context)
示例#6
0
def edit_note(request, note_id):
    # Validate note
    current_note = validate_ownership_note(request.user, note_id)

    # Create form
    if request.method != 'POST':
        form = NoteForm(data={
            'title': current_note.title,
            'notebook': current_note.notebook,
            'content': current_note.content,
            'tags': current_note.tags,
        })
        form.restrict_to_user(request.user)
    else:
        form = NoteForm(data=request.POST)

        if form.is_valid():
            current_note.title = form.cleaned_data['title']
            current_note.notebook = form.cleaned_data['notebook']
            current_note.content = form.cleaned_data['content']
            current_note.tags = form.cleaned_data['tags']
            current_note.save()
            return redirect('home')

    # Render
    context = regular_context(request.user)
    context['form'] = form
    context['current_note'] = current_note
    return render(request, 'edit_note.html', context)
示例#7
0
def new_share_link(request, note_id):
    # Validate note
    current_note = validate_ownership_note(request.user, note_id)

    if request.method != 'POST':
        form = SharableLinkForm()

        # Generate unique code
        unique_code = '%32x' % random.getrandbits(16 * 8)
        entry = SharableLink.objects.filter(code=unique_code)

        while entry.exists():
            unique_code = '%32x' % random.getrandbits(16 * 8)
            entry = SharableLink.objects.filter(code=unique_code)

        form.set_code(unique_code)
    else:
        form = SharableLinkForm(data=request.POST)

        if form.is_valid():
            SharableLink.objects.create(
                note_id=note_id,
                code=form.cleaned_data['code'],
                permissions=form.cleaned_data['permissions'],
                expiry_date=form.cleaned_data['expiry_date'])
            return redirect('home')

    # Render
    context = regular_context(request.user)
    context['form'] = form
    context['current_note'] = current_note
    return render(request, 'new_share_link.html', context)
示例#8
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)
示例#9
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)
示例#10
0
def download_note(request, note_id, filetype):
    # Validate note
    current_note = validate_ownership_note(request.user, note_id)

    # Return file
    if filetype == 'txt':
        return note2txt_response(current_note)
    elif filetype == 'pdf':
        return note2pdf_response(request, current_note)
    else:
        raise Http404('Invalid filetype.')
示例#11
0
文件: views.py 项目: dozmus/notes
def download_note(request, note_id, filetype):
    # Validate note
    current_note = validate_ownership_note(request.user, note_id)

    # Return file
    if filetype == 'txt':
        return note2txt_response(current_note)
    elif filetype == 'pdf':
        return note2pdf_response(request, current_note)
    else:
        raise Http404('Invalid filetype.')
示例#12
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)
示例#13
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)
示例#14
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)
示例#15
0
文件: views.py 项目: dozmus/notes
def delete_note(request, note_id):
    # Validate note
    current_note = validate_ownership_note(request.user, note_id)

    if request.method == 'POST':
        current_note.trash = True
        current_note.save()
        return redirect('home')

    # Render
    context = regular_context(request.user)
    context['current_note'] = current_note
    return render(request, 'delete_note.html', context)
示例#16
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)
示例#17
0
def delete_note(request, note_id):
    # Validate note
    current_note = validate_ownership_note(request.user, note_id)

    if request.method == 'POST':
        current_note.trash = True
        current_note.save()
        return redirect('home')

    # Render
    context = regular_context(request.user)
    context['current_note'] = current_note
    return render(request, 'delete_note.html', context)
示例#18
0
文件: views.py 项目: dozmus/notes
def share_note(request, note_id):
    # Validate note
    current_note = validate_ownership_note(request.user, note_id)

    # Render
    sharable_links = current_note.sharablelink_set.all()

    for link in sharable_links:
        args = {'note_id': current_note.id, 'code': link.code}
        link.full_url = request.build_absolute_uri(reverse('share:view-note', kwargs=args))

    current_note.rendered_content = render_markdown(current_note.content)

    context = regular_context(request.user)
    context['current_note'] = current_note
    context['sharable_links'] = sharable_links
    return render(request, 'share_note.html', context)
示例#19
0
def share_note(request, note_id):
    # Validate note
    current_note = validate_ownership_note(request.user, note_id)

    # Render
    sharable_links = current_note.sharablelink_set.all()

    for link in sharable_links:
        args = {'note_id': current_note.id, 'code': link.code}
        link.full_url = request.build_absolute_uri(
            reverse('share:view-note', kwargs=args))

    current_note.rendered_content = render_markdown(current_note.content)

    context = regular_context(request.user)
    context['current_note'] = current_note
    context['sharable_links'] = sharable_links
    return render(request, 'share_note.html', context)
示例#20
0
文件: views.py 项目: dozmus/notes
def edit_share_link(request, note_id, code):
    # Validate note
    current_note = validate_ownership_note(request.user, note_id)
    link = SharableLink.objects.filter(code=code).filter(note_id=note_id).get()

    if request.method != 'POST':
        form = EditSharableLinkForm(data={
            'permissions': link.permissions,
            'expiry_date': link.expiry_date
        })
    else:
        form = EditSharableLinkForm(data=request.POST)

        if form.update(link):
            return HttpResponseRedirect(reverse('share:share-note', kwargs={'note_id': note_id}))

    # Render
    context = regular_context(request.user)
    context['form'] = form
    context['current_note'] = current_note
    context['code'] = code
    return render(request, 'edit_share_link.html', context)
示例#21
0
文件: views.py 项目: dozmus/notes
def edit_share_link(request, note_id, code):
    # Validate note
    current_note = validate_ownership_note(request.user, note_id)
    link = SharableLink.objects.filter(code=code).filter(note_id=note_id).get()

    if request.method != 'POST':
        form = EditSharableLinkForm(data={
            'permissions': link.permissions,
            'expiry_date': link.expiry_date
        })
    else:
        form = EditSharableLinkForm(data=request.POST)

        if form.update(link):
            return HttpResponseRedirect(
                reverse('share:share-note', kwargs={'note_id': note_id}))

    # Render
    context = regular_context(request.user)
    context['form'] = form
    context['current_note'] = current_note
    context['code'] = code
    return render(request, 'edit_share_link.html', context)