Exemple #1
0
 def post(self, userid, args):
     if args['addedon']:
         added = args[
                     'addedon'] / 1000  # Convert timestamp from milliseconds since epoch to seconds(Chrome sends millisecs)
         new_bookmark = bookmark.new(title=urllib.unquote(args['title']), url=urllib.unquote(args['url']),
                                     userid=userid, tags=args['tags'])
     else:
         new_bookmark = bookmark.new(title=urllib.unquote(args['title']), url=urllib.unquote(args['url']),
                                     userid=userid)
     bookmark_tasks.readable_extract.delay(new_bookmark)
     bookmark_tasks.fulltext_extract.delay(new_bookmark)
     bookmark_tasks.fetch_description.delay(new_bookmark)
     return {'message': 'URL bookmarked', 'id': hashids.encode(new_bookmark.id)}, 200
Exemple #2
0
 def post(self, userid, args):
     if args['addedon']:
         added = args[
                     'addedon'] / 1000  # Convert timestamp from milliseconds since epoch to seconds(Chrome sends millisecs)
         new_bookmark = bookmark.new(title=urllib.unquote(args['title']), url=urllib.unquote(args['url']),
                                     user_id=userid, tags=args['tags'])
     else:
         new_bookmark = bookmark.new(title=urllib.unquote(args['title']), url=urllib.unquote(args['url']),
                                     user_id=userid)
     bookmark_tasks.readable_extract.delay(new_bookmark)
     bookmark_tasks.fulltext_extract.delay(new_bookmark)
     bookmark_tasks.fetch_description.delay(new_bookmark)
     return {'message': 'URL bookmarked', 'id': hashids.encode(new_bookmark.id)}, 200
Exemple #3
0
def bookmark_new():
    '''
    BEWARE! No sanitation has been done yet!
    '''
    form = NewBookmarkForm(csrf_enabled=False)
    if request.method == 'GET':
        return render_template("manager/bookmark_new.html", form=form)

    if request.method == 'POST':
        if form.validate_on_submit():
            # If the form is validated, we hand off the new bookmark
            # creation to the bookmark.new function
            new_bookmark = bookmark.new(title=form.title.data,
                                        url=form.main_url.data,
                                        description=form.description.data,
                                        tags=form.tags.data,
                                        user_id=current_user.id)
            # And we queue the async background jobs
            bookmark_tasks.readable_extract.delay(new_bookmark)
            bookmark_tasks.fulltext_extract.delay(new_bookmark)
            # Title and description do not compulsorily need to be provided
            # But we still need them, so if they aren't provided, we'll fetch them ourselves
            if not new_bookmark.description:
                bookmark_tasks.fetch_description.delay(new_bookmark)
            if not new_bookmark.title:
                bookmark_tasks.fetch_title.delay(new_bookmark)
            return redirect(url_for('bookmark_list'))
        else:
            print("%s validation failed" % form.main_url.data)
            return render_template("manager/bookmark_new.html", form=form)
Exemple #4
0
def bookmark_new():
    '''
    BEWARE! No sanitation has been done yet!
    '''
    form = NewBookmarkForm(csrf_enabled=False)
    if request.method == 'GET':
        return render_template("manager/bookmark_new.html", form=form)

    if request.method == 'POST':
        if form.validate_on_submit():
            # If the form is validated, we hand off the new bookmark
            # creation to the bookmark.new function
            new_bookmark = bookmark.new(title=form.title.data,
                                        url=form.main_url.data,
                                        description=form.description.data,
                                        tags=form.tags.data,
                                        userid=current_user.id)
            # And we queue the async background jobs
            bookmark_tasks.readable_extract.delay(new_bookmark)
            bookmark_tasks.fulltext_extract.delay(new_bookmark)
            # Title and description do not compulsorily need to be provided
            # But we still need them, so if they aren't provided, we'll fetch them ourselves
            if not new_bookmark.description:
                bookmark_tasks.fetch_description.delay(new_bookmark)
            if not new_bookmark.title:
                bookmark_tasks.fetch_title.delay(new_bookmark)
            return redirect(url_for('bookmark_list'))
        else:
            print("%s validation failed" % form.main_url.data)
            return render_template("manager/bookmark_new.html", form=form)