def get_todos(): db_session = DBSession() todos = db_session.query(Todo).all() if not todos: result = {'message': 'todolist boş'} result = [d.to_dict() for d in todos] db_session.close() return result
def get_tag(tag_name): db = DBSession() data = db.query(Tag).filter(Tag.name == tag_name).first() db.close() if data: return data return None
def get_toplist(size=20): db = DBSession() best_users = db.query(User).order_by(User.best_point.desc()).limit(size) best_users = [b.to_dict() for b in best_users] db.close() return best_users
def get_tag_article(tag_id, post_id): db = DBSession() data = db.query(ArticleTag).filter( ArticleTag.tag_id == tag_id, ArticleTag.article_id == post_id).first() db.close() if data: return data.id return None
def user_profile_show(): if 'user' in session: db = DBSession() post_list = db.query(Post).filter(Post.user_id == session['id']).all() print(session['id']) db.close() return render_template("profile.html", posts=post_list) else: print("Once giris yapiniz")
def get_redirection_value(redirection_hash): s = DBSession() r = s.query(Redirection).filter( Redirection.redirect_hash == redirection_hash).first() if not r: result = None else: result = r.redirect_value s.close() return result
def get_redirections(user_id): s = DBSession() u = s.query(User).get(user_id) print(u) if not u: result = None else: result = [r.to_dict() for r in u.redirections] s.close() return result
def get_user(token): db = DBSession() user = db.query(User).filter(User.token == token).first() if user: data = user.to_dict() else: data = None db.close() return data
def get_user(email): db = DBSession() user = db.query(User).filter(User.email == email).first() if user: data = user.to_dict() else: data = None db.close() return data
def get_user(user_id): db_session = DBSession() user = db_session.query(User).filter(User.id == user_id).first() if not user: result = {'status': 'error'} else: result = [user.to_dict()] db_session.close() return result
def delete_tag(tag_id): db = DBSession() data = db.query(Tag).get(tag_id) db.delete(data) db.commit() db.close() return {'status': 'OK'}
def get_users(): try: db_session = DBSession() users = db_session.query(User).all() if not users: result = {'message': 'User yok'} result = [d.to_dict() for d in users] except: result = {'status': 'error'} db_session.close() return result
def get_user_with_credentials(email, password): db = DBSession() u = db.query(User).filter(User.email == email, User.password == password).first() if u: data = u.to_dict() else: data = None db.close() return data
def delete_comment(comment_id): db = DBSession() data = db.query(Comment).get(comment_id) if data: db.delete(data) db.commit() db.close() return data
def is_owner(user_id, comment_id): db = DBSession() data = db.query(Comment).filter(Comment.id == comment_id and Comment.user_id == user_id).first() db.delete(data) db.commit() db.close() return True
def get_todo(todo_id): if not todo_id: result = {'status': 'error'} else: db_session = DBSession() todo = db_session.query(Todo).filter(Todo.id == todo_id).first() if not todo: result = {'message': 'todo listede yok'} else: result = [todo.to_dict()] db_session.close() return result
def user_todos(user_id): if not user_id: result = {'status': 'Error'} else: db_session = DBSession() user_todos = db_session.query(Todo).filter( Todo.user_id == user_id).all() if not user_todos: result = {'message': 'User a ait bir todo yok'} result = [d.to_dict() for d in user_todos] db_session.close() return result
def get_question(question_id): db = DBSession() question = db.query(Question).get(question_id) if question: true_id = question.to_dict()['true_answer'] data = question.to_frontend() data['options'][true_id]['is_correct'] = True else: data = None db.close() return data
def create_tag(tag_name): db = DBSession() p = Tag(name=tag_name) db.add(p) db.commit() db.close() return
def add_comment(text, date, user_id, post_id): db = DBSession() p = Comment(text=text, date=date, user_id=user_id, article_id=post_id) db.add(p) try: db.commit() status = True except IntegrityError: db.rollback() status = None db.close() return status
def create_user(name, password): try: s = DBSession() u = User(name=name, password=password) s.add(u) s.commit() result = True except: s.rollback() result = False s.close() return result
def create_tag_article(tag_id, post_id): db = DBSession() p = ArticleTag(tag_id=tag_id, article_id=post_id) db.add(p) db.commit() db.close() return
def create_redirection(owner_id, url): print(owner_id, url) s = DBSession() r = Redirection(owner_id=owner_id, redirect_value=url) r.redirect_hash = uuid4().hex s.add(r) try: s.commit() result = True except IntegrityError: s.rollback() result = False s.close() return result
def delete_redirection(redirection_id): s = DBSession() r = s.query(Redirection).get(redirection_id) if not r: result = False else: s.delete(r) s.commit() result = True s.close() return result
def delete_user(user_id): if not user_id: return {'status': 'error'} else: db_session = DBSession() user = db_session.query(User).filter(User.id == user_id).first() if not user: abort(404, 'bu id ye sahip bir user yok.') db_session.delete(user) db_session.commit() db_session.close() return {'message': 'user silindi'}
def create_user(email, password, fullname, userinfo="..."): db = DBSession() user = User(email=email, password=password, fullname=fullname, userinfo=userinfo) db.add(user) try: db.commit() except IntegrityError: print("Bu kullanıcı zaten var") db.rollback() user = None data = user.to_dict() if user else None db.close() return data
def delete_todo(todo_id): if not todo_id: return {'status': 'Error'} else: db_session = DBSession() todo = db_session.query(Todo).filter(Todo.id == todo_id).first() if not todo: abort(404, 'bu id ye sahip bir todo yok.') else: db_session.delete(todo) db_session.commit() db_session.close() return {'status': 'OK'}
def post_delete(): post_id = request.args.get('id') db = DBSession() p = db.query(Post).get(int(post_id)) if p: db.delete(p) db.commit() print("Post silindi") else: print("Silinemedi") db.close() return redirect("/user/profile")
def create_user(email): data = get_user(email) if not data: print('Yeni kullanıcı eklendi') db = DBSession() user = User(email=email) db.add(user) try: db.commit() except IntegrityError: print('Veritabanı commit esnasında hata oluştu') db.rollback() user = None data = user.to_dict() if user else None db.close() return data
def is_authorized(token, post_id): status = is_admin(token) if status: return True user = get_user(token) db = DBSession() status = db.query(Article).filter(Article.user_id == user['id'], Article.id == post_id).first() db.close() if status: return True print("Yetkili Degil veya Post yok") return False
def bootstrap(app): from app.models import DBSession, Company, User user = User(document=1128417376, name=u'Willington Vega', email=u'*****@*****.**', password=u'password') company = Company.create(nit=9003671435, name=u'Inv. Sinapsis S.A.S', user=user) DBSession.add(user) DBSession.add(company) DBSession.commit() # environ = { # 'path': '/company/create', # 'method': 'POST', # 'data': { # 'nit': '9003671435', # 'name': 'Inv. Sinapsis S.A.S', # 'document': '1128417376', # 'username': '******', # 'email': '*****@*****.**', # 'password': '******', # 'confirm': 'password' # } # }