コード例 #1
0
    def test_001_seq(self):

        self.assertEqual('u00000', sequencer.seq('users'))
        self.assertEqual('u00001', sequencer.seq('users'))

        self.assertEqual('p0000000', sequencer.seq('posts'))

        with self.assertRaises(sequencer.SequencerUnknownTableException):
            sequencer.seq('xxx')
コード例 #2
0
ファイル: blog.py プロジェクト: garabinovic/edu
def add_article(slug, title, id_user, id_category, content):
    # add article with given params

    if not check_slug_and_title(title):
        raise TitleNotValidException

    if not check_slug_and_title(slug):
        raise SlugNotValidException

    if len(slug) == 0:
        slug = title.replace(' ', '-')
        slug = generate_slug(slug)

    slug.lower()

    try:
        import sequencer
        pid = sequencer.seq('posts', sequencer.mock_seq)
        print(pid)
        article = db.Article(pid, id_user, slug, title, id_category, content)
        db.session.add(article)
        db.session.commit()

    except sqlalchemy.exc.IntegrityError:
        db.session.rollback()
        raise ArticleAlreadyExistsException

    return pid
コード例 #3
0
ファイル: blog.py プロジェクト: digital-cube/edu
    def make_tag_if_not_exists_and_return_tag_object(self, tag_name):
        res = self.get_tag(tag_name)
        if not res:
            res = Tag(seq('tags'), tag_name)
            self.session.add(res)

        return res
コード例 #4
0
def add_comment(id_user, id_article, email_of_non_registerd_user,
                name_of_non_registered_user, comment_text):
    import sequencer
    pid = sequencer.seq('comments', sequencer.mock_seq)

    if not id_user:
        import socket
        ip_user = socket.gethostbyname(socket.gethostname())
        id_comment = pid

        try:
            ip_2_comment = db.ip_2_Comm(ip_user, id_comment,
                                        email_of_non_registerd_user,
                                        name_of_non_registered_user)
            db.session.add(ip_2_comment)
            print(ip_2_comment)
        except:
            db.session.rollback()
            raise Exception

    try:

        comment = db.Comment(pid, id_user, id_article, comment_text)
        db.session.add(comment)
        db.session.commit()

    except sqlalchemy.exc.IntegrityError:
        db.session.rollback()
        raise ArticleAlreadyExistsException

    return pid
コード例 #5
0
    def add_comment(self, author, text):

        comment = Comment(seq('comments'), author.id, self, text)
        try:
            session.add(comment)
            session.commit()
        except:
            session.rollback()
            raise ErrorAddingCommentException

        return True
コード例 #6
0
    def add_post(self, id_author, slug, title, content):

        post = Post(seq('posts'), id_author, slug, title, content)

        if not self.check_slug_aviability(slug):
            raise InvalidSlugException

        self.session.add(post)
        try:
            self.session.commit()
        except sqlalchemy.exc.IntegrityError:

            self.session.rollback()
コード例 #7
0
    def create_user(self, email, password, fname=None, lname=None):
        author = User(seq('users'), email, password, fname, lname)

        if not self.check_password(password):
            raise UserPasswordNotStrongEnough

        try:
            self.session.add(author)
            self.session.commit()
        except sqlalchemy.exc.IntegrityError:
            self.session.rollback()

            raise UsernameAlreadyExistsException
コード例 #8
0
ファイル: blog.py プロジェクト: garabinovic/edu
def add_user(email):
    # add user with given email

    check_email(email)

    try:
        import sequencer
        uid = sequencer.seq('users', sequencer.mock_seq)
        user = db.User(uid, email)
        db.session.add(user)
        db.session.commit()
    except sqlalchemy.exc.IntegrityError:
        db.session.rollback()
        raise UserAlreadyExistsException

    return uid
コード例 #9
0
        self.session.add(post)
        try:
            self.session.commit()
        except sqlalchemy.exc.IntegrityError:

            self.session.rollback()


def get_blog():

    if not hasattr(get_blog, 'blog'):
        get_blog.blog = Blog(session)

    return get_blog.blog


if __name__ == "__main__":

    mladen = User(seq('users'), '*****@*****.**')
    aca = User(seq('users'), '*****@*****.**')
    munira = User(seq('users'), '*****@*****.**')

    session.add(mladen)
    session.add(aca)
    session.add(munira)
    session.commit()

    # mladen = session.query(User).filter(User.id=='uMAzOn').one_or_none()
    #
    # session.commit()