Ejemplo n.º 1
0
    def create(self, request):
        """
        Creates a new bookmark.
        """
        form = request.form
        bookmark = form.save(commit=False)
        bookmark.owner = request.user
        if not bookmark.title:
            bookmark.title = utils.get_title_by_url(bookmark.url)
        bookmark.save()
        form.save_m2m()

        utils.update_bk_screen_shot_async(bookmark)

        return bookmark
Ejemplo n.º 2
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