Exemple #1
0
def edit(request, bookmark_id: int):
    bookmark = Bookmark.objects.get(pk=bookmark_id)

    if request.method == 'POST':
        form = BookmarkForm(request.POST, instance=bookmark)
        return_url = form.data['return_url']
        if form.is_valid():
            update_bookmark(form.save(commit=False), form.data['tag_string'],
                            request.user)
            return HttpResponseRedirect(return_url)
    else:
        return_url = request.GET.get('return_url')
        form = BookmarkForm(instance=bookmark)

    return_url = return_url if return_url else reverse('bookmarks:index')

    form.initial['tag_string'] = build_tag_string(bookmark.tag_names, ' ')
    form.initial['return_url'] = return_url
    all_tags = get_user_tags(request.user)

    context = {
        'form': form,
        'bookmark_id': bookmark_id,
        'all_tags': all_tags,
        'return_url': return_url
    }

    return render(request, 'bookmarks/edit.html', context)
Exemple #2
0
def edit(request, bookmark_id: int):
    bookmark = Bookmark.objects.get(pk=bookmark_id)
    if request.method == 'POST':
        form = BookmarkForm(request.POST, instance=bookmark)
        if form.is_valid():
            update_bookmark(form, request.user)
            return HttpResponseRedirect(reverse('bookmarks:index'))
    else:
        form = BookmarkForm(instance=bookmark)

    form.initial['tag_string'] = build_tag_string(bookmark.tag_names, ' ')

    all_tags = get_user_tags(request.user)
    context = {'form': form, 'bookmark_id': bookmark_id, 'all_tags': all_tags}

    return render(request, 'bookmarks/edit.html', context)
Exemple #3
0
 def update(self, instance: Bookmark, validated_data):
     instance.url = validated_data['url']
     instance.title = validated_data['title']
     instance.description = validated_data['description']
     tag_string = build_tag_string(validated_data['tag_names'], ' ')
     return update_bookmark(instance, tag_string, self.context['user'])