Exemplo n.º 1
0
def bookmark_create(request):
    if request.method == 'POST':
        form = BookmarkForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect('bookmark:list')
    else:
        form = BookmarkForm()
    return render(request, 'bookmark/bookmark_create.html', {'form': form})
Exemplo n.º 2
0
def bookmark_update(request, pk):
    bookmark = get_object_or_404(Bookmark, pk=pk)
    if request.method == 'POST':
        form = BookmarkForm(request.POST, instance=bookmark)
        if form.is_valid():
            form.save()
            return redirect('bookmark:detail', bookmark.pk)

    else:
        form = BookmarkForm(instance=bookmark)

    return render(request, 'bookmark/bookmark_update.html', {
        'bookmark': bookmark,
        'form': form,
    })
Exemplo n.º 3
0
def edit(request, pk):
    ctx = {}
    template_name = 'bookmark/form.html'
    bookmark = get_object_or_404(Bookmark, pk=pk)
    if not bookmark.created_by==request.user:
        return HttpResponse(u'您没有权限执行该操作')
    ctx['bml'] = bookmark
    form = BookmarkForm(instance=bookmark)
    if request.method == "POST":
        form = BookmarkForm(request.POST, instance=bookmark)
        if form.is_valid():
            form.save()
            messages.info(request, u'成功编辑')
            return redirect('bookmark_detail', bookmark.pk)
    ctx['form'] = form
    ctx['bml'] = bookmark
    return render(request, template_name, ctx)
Exemplo n.º 4
0
def new(request):
    ctx = {}
    template_name = 'bookmark/form.html'
    form = BookmarkForm()
    if request.method == "POST":
        form = BookmarkForm(request.POST)
        if form.is_valid():
            bookmark = form.save(created_by=request.user)
            return redirect('bookmark_last', bookmark.pk)
    ctx['form'] = form
    return render(request, template_name, ctx)
Exemplo n.º 5
0
    def update(self, request, bookmark_id):
        # Get bookmark first, if not return NOT_FOUND
        try:
            bookmark = Bookmark.objects.get(pk = int(bookmark_id), owner=request.user)
            oldUrl = bookmark.url
            form = BookmarkForm(request.PUT, instance=bookmark)
            bookmark = form.save()

            if not bookmark.title:
                bookmark.title = utils.get_title_by_url(bookmark.url)
                bookmark.save()

            # update screen shot
            if oldUrl != bookmark.url:
                utils.update_bk_screen_shot_async(bookmark)

            return bookmark
        except ObjectDoesNotExist:
            return rc.NOT_FOUND