コード例 #1
0
 def transfer(self,
              title,
              url,
              date,
              user,
              tags,
              description=None,
              commit=False):
     with db.session.no_autoflush:  # F-SA has autoflush on by default, which causes severe performance degradation
         import_bookmark = Bookmark()
         import_bookmark.main_url = url[:2000]
         import_bookmark.title = title[:1024]
         import_bookmark.description = None
         import_bookmark.user = user
         import_bookmark.added_on = date
         if description is None:
             import_bookmark.description = None
         else:
             import_bookmark.description = description[:256]
         import_bookmark.deleted = False
         for tag in tags:  # Append the tag object from the tags dict.
             # Doing append on the assoc. proxy causes new tags to be created
             import_bookmark.tags_relationship.append(self.tags_dict[tag]['obj'])
         db.session.add(import_bookmark)
         if commit is True:
             db.session.commit()
コード例 #2
0
def new(url, user_id, description=None, tags=None, title=None, added=None):
    new_bookmark = Bookmark()
    new_bookmark.main_url = url[:2000]
    if title is not None:
        new_bookmark.title = title[:1024]
    if description is not None:
        new_bookmark.description = description[:256]
    new_bookmark.user = user_id
    if added is None:
        new_bookmark.added_on = datetime.utcnow()
    else:
        try:
            datetime.datetime.utcfromtimestamp(added)
            new_bookmark.added_on = added  # UNIX timestamp in seconds since epoch, only
        except ValueError:
            new_bookmark.added_on = datetime.utcnow()
    new_bookmark.deleted = False
    if tags is not None:
        tags = tags.split(',')
        new_bookmark.tags = tags
        for tag in tags:
            # If tag is present, increment counter by one, or create if not present
            get_tag = Tag.query.filter_by(text=tag,
                                          user=user_id).first()
            if not get_tag:
                new_tag = Tag(text=tag, user=user_id)
                new_tag.count = 1
                db.session.add(new_tag)
            else:
                get_tag.count += 1
    db.session.add(new_bookmark)
    db.session.commit()
    # Send off for archiving
    archive.do_archives(new_bookmark)
    return new_bookmark
コード例 #3
0
 def transfer(self,
              title,
              url,
              date,
              user,
              tags,
              commit=False):
     with db.session.no_autoflush:
         import_bookmark = Bookmark()
         import_bookmark.main_url = url[:2000]
         import_bookmark.title = title[:1024]
         import_bookmark.user = user
         import_bookmark.added_on = date
         import_bookmark.description = None
         import_bookmark.deleted = False
         for tag in tags:
             import_bookmark.tags_relationship.append(self.tags_dict[tag]['obj'])
         db.session.add(import_bookmark)
         if commit is True:
             db.session.commit()