Example #1
0
def bookmark_context(bookmark_id):
    bookmark_id = hashids.decode(bookmark_id)[0]
    query = db.session.query(Bookmark.id).filter_by(user=current_user.id, deleted=False).order_by(Bookmark.added_on.desc()).all()
    count = query.index((bookmark_id,)) + 1
    page_num = int(count/(current_user.bookmarks_per_page) + 1)
    bookmark_id = hashids.encode(bookmark_id)
    return redirect(url_for('bookmark_list', page=page_num, bid=bookmark_id))
Example #2
0
 def post(self, userid, args):
     if args['url'] is not None:
         parsed_url = urlparse.urlparse(args['url'])
         url_scheme = "{}://".format(parsed_url.scheme)
         parsed_url = parsed_url.geturl().replace(url_scheme, '', 1)
         query = Bookmark.query.filter(
             Bookmark.main_url.endswith(parsed_url),
             Bookmark.user == userid, Bookmark.deleted == False).order_by(
                 Bookmark.added_on.desc()).first()
         if query:
             current_tags = None
             if query.tags:
                 current_tags = ','.join(query.tags)
             user_tags = Tag.query.filter(Tag.user == userid,
                                          Tag.count > 0).all()
             user_tags.sort(key=lambda k: k.text.lower())
             [user_tags.remove(tag) for tag in user_tags if tag.text == '']
             if user_tags:
                 user_tags = ','.join([tag.text for tag in user_tags])
             return {
                 'message': 'You have this URL bookmarked',
                 'tags': current_tags,
                 'tagopts': user_tags,
                 'id': hashids.encode(query.id)
             }, 200
         else:
             return {'message': 'You do not have this URL bookmarked'}, 404
Example #3
0
def bookmark_context(bookmark_id):
    bookmark_id = hashids.decode(str(bookmark_id))[0]
    query = db.session.query(Bookmark.id).filter_by(user=current_user.id, deleted=False).order_by(Bookmark.added_on.desc()).all()
    count = query.index((bookmark_id,)) + 1
    page_num = int(count/(current_user.bookmarks_per_page) + 1)
    bookmark_id = hashids.encode(bookmark_id)
    return redirect(url_for('bookmark_list', page=page_num, bid=bookmark_id))
Example #4
0
 def post(self, userid, args):
     if args['url'] is not None:
         parsed_url = urlparse.urlparse(urllib.unquote(args['url']))
         url_scheme = "{}://".format(parsed_url.scheme)
         parsed_url = parsed_url.geturl().replace(url_scheme, '', 1)
         query = Bookmark.query.filter(Bookmark.main_url.endswith(parsed_url), Bookmark.user == userid,
                                       Bookmark.deleted == False).order_by(Bookmark.added_on.desc()).first()
         if query:
             return {'message': 'You have this URL bookmarked', 'added': arrow.get(query.added_on).humanize(),
                     'timestamp': arrow.get(query.added_on).strftime("%Y-%m-%dT%H:%M:%SZ"),
                     'id': hashids.encode(query.id)}, 200
         else:
             return {'message': 'You do not have this URL bookmarked'}, 404
Example #5
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
Example #6
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
Example #7
0
 def post(self, userid, args):
     if args['url'] is not None:
         parsed_url = urlparse.urlparse(urllib.unquote(args['url']))
         url_scheme = "{}://".format(parsed_url.scheme)
         parsed_url = parsed_url.geturl().replace(url_scheme, '', 1)
         query = Bookmark.query.filter(Bookmark.main_url.endswith(parsed_url), Bookmark.user == userid,
                                       Bookmark.deleted == False).order_by(Bookmark.added_on.desc()).first()
         if query:
             return {'message': 'You have this URL bookmarked', 'added': arrow.get(query.added_on).humanize(),
                     'timestamp': arrow.get(query.added_on).strftime("%Y-%m-%dT%H:%M:%SZ"),
                     'id': hashids.encode(query.id)}, 200
         else:
             return {'message': 'You do not have this URL bookmarked'}, 404
Example #8
0
 def post(self, userid, args):
     if args['url'] is not None:
         parsed_url = urlparse.urlparse(args['url'])
         url_scheme = "{}://".format(parsed_url.scheme)
         parsed_url = parsed_url.geturl().replace(url_scheme, '', 1)
         query = Bookmark.query.filter(Bookmark.main_url.endswith(parsed_url), Bookmark.user == userid,
                                       Bookmark.deleted == False).order_by(Bookmark.added_on.desc()).first()
         if query:
             current_tags = ','.join(query.tags)
             user_tags = db.session.query(Tag).join(tags, Tag.id == tags.c.tag_id).join(
                 Bookmark, Bookmark.id == tags.c.bookmark_id).filter(Bookmark.user == userid).all()
             [user_tags.remove(tag) for tag in user_tags if tag.text == '']
             user_tags = ','.join([tag.text for tag in user_tags])
             return {'message': 'You have this URL bookmarked', 'tags': current_tags, 'tagopts': user_tags,
                     'id': hashids.encode(query.id)}, 200
         else:
             return {'message': 'You do not have this URL bookmarked'}, 404
Example #9
0
 def hash_id(_id):
     return hashids.encode(_id)
Example #10
0
 def hash_id(_id):
     return hashids.encode(_id)