Пример #1
0
def init():
    try:
        path = os.path.dirname(consts.KEYWORDJOURNAL_DB_PATH)
        os.mkdir(path)
    except OSError:
        pass

    Base.metadata.create_all(bind=engine)
    db.add(user1)
    db.add(user2)
    db.commit()
Пример #2
0
def create(user_id, post_title, post_body):
    posted_keywords = parser.find_all_keywords_with_args(post_body)
    user_keywords_rs = user_keyword_resource.get_all_keywords_with_args(user_id)
    posted_keywords_rs = _construct_posted_keywords(posted_keywords, user_keywords_rs)

    post = Post(
        user_id=user_id,
        text=post_body,
        header=post_title,
        datetime=datetime.datetime.now(),
        posted_keywords=posted_keywords_rs,
    )

    db.add(post)
    db.commit()
Пример #3
0
def create(user_id, post_title, post_body):
    posted_keywords = parser.find_all_keywords_with_args(post_body)
    user_keywords_rs = user_keyword_resource.get_all_keywords_with_args(
        user_id)
    posted_keywords_rs = _construct_posted_keywords(posted_keywords,
                                                    user_keywords_rs)

    post = Post(
        user_id=user_id,
        text=post_body,
        header=post_title,
        datetime=datetime.datetime.now(),
        posted_keywords=posted_keywords_rs,
    )

    db.add(post)
    db.commit()

    return post
Пример #4
0
def create(keyword, user_id):

    keyword_res = resources.keyword.get(keyword)
    if keyword_res is None:
        # Possible race condition
        try:
            keyword_res = resources.keyword.create(keyword)
        except IntegrityError:
            db.rollback()
            keyword_res = resources.keyword.get(keyword)

    user_keyword = UserKeyword(
        keyword_id=keyword_res.id,
        user_id=user_id,
    )

    try:
        db.add(user_keyword)
        db.commit()
        return user_keyword
    except IntegrityError:
        db.rollback()
        return None
Пример #5
0
# Author: Daniel Kinney
# All rights reserved


from keywordjournal.kwj_flask.connection.manager import db, engine

from keywordjournal.models.db import *


keyword1 = Keyword(word="kw1")

keyword2 = Keyword(word="kw2")

user1 = User(
    email="*****@*****.**",
    password="******",
    user_keywords=[UserKeyword(keyword=keyword1, user_args=[UserArg(param_name="x"), UserArg(param_name="y")])],
)

user2 = User(email="*****@*****.**", password="******")


if __name__ == "__main__":
    Base.metadata.create_all(bind=engine)
    db.add(user1)
    db.add(user2)
    db.commit()
Пример #6
0
def create(word):
    new_keyword = Keyword(word=word)
    db.add(new_keyword)
    db.commit()
    return new_keyword