Beispiel #1
0
def delete_tag(tag_id):
    db = DBSession()
    data = db.query(Tag).get(tag_id)
    db.delete(data)
    db.commit()
    db.close()
    return {'status': 'OK'}
Beispiel #2
0
def publish_comment(comment_id):
    db = DBSession()
    data = db.query(Comment).get(comment_id)
    data.publish = 1
    db.commit()
    db.close()
    return True
Beispiel #3
0
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
Beispiel #4
0
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
Beispiel #5
0
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
Beispiel #6
0
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
Beispiel #7
0
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
Beispiel #8
0
def inactive_user(user_id):
    db = DBSession()
    user = db.query(User).get(user_id)
    if user:
        user.status = 3
        db.commit()
        db.close()
        return user.status
    return None
Beispiel #9
0
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
Beispiel #10
0
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")
Beispiel #11
0
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
Beispiel #12
0
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
Beispiel #13
0
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
Beispiel #14
0
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
Beispiel #15
0
def make_admin(email, token):
    db = DBSession()
    user = db.query(User).filter(User.email == email).first()
    if user:
        user.rank = 0
        user.status = 0
        user.token = token
        db.commit()
    db.close()
    return user
Beispiel #16
0
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
Beispiel #17
0
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
Beispiel #18
0
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
Beispiel #19
0
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
Beispiel #20
0
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
Beispiel #21
0
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
Beispiel #22
0
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'}
Beispiel #23
0
def change_password(user_id, new_password, old_password):
    db = DBSession()
    user = db.query(User).get(user_id)

    if user and user.password == old_password:
        user.password = new_password
        db.commit()
        data = user.to_dict()
        db.close()
        return data
    print("Gecersiz kullanıcı adı veya token")
    return None
Beispiel #24
0
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'}
Beispiel #25
0
def change_password(name, password, new_password):
    s = DBSession()
    u = s.query(User).filter(User.name == name,
                             User.password == password).first()

    if not u:
        result = False
    else:
        u.password = new_password
        result = True
        s.commit()
    s.close()
    return result
Beispiel #26
0
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")
Beispiel #27
0
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
Beispiel #28
0
def new_user():
    username = request.form.get("username").strip()
    password = request.form.get("password").strip()
    # Database icin bir session oluşturuldu.
    db = DBSession()
    exists = db.query(User).filter(User.username == username).first()
    if not exists:
        u = User(username=username,
                 password=password,
                 status=1)
        db.add(u)
        db.commit()
        u = db.query(User).filter(User.username == username).first()
        session['id'] = u.id
        print(u.id)
        session['user'] = username
        db.close()

        print("{} kisisi kaydoldu".format(session['user']))
    else:
        print("\'{}\' kisisi zaten var".format(username))
        db.close()
    return redirect('/')
Beispiel #29
0
def del_user(name, password):
    s = DBSession()
    u = s.query(User).filter(User.name == name,
                             User.password == password).first()
    print(u)

    if not u:
        result = False
    else:
        s.delete(u)
        s.commit()
        result = True
    s.close()
    return result
Beispiel #30
0
def update_todo(data):
    db_session = DBSession()
    todo = db_session.query(Todo).filter(Todo.id == data['id']).first()
    if not todo:
        result = {'messages': 'Todo not found'}
    else:
        todo.title = data['title']
        todo.content = data['content']
        todo.due_date = data['due_date']
        todo.checked = data['checked']
        db_session.commit()
        db_session.close()
        result = {'message': 'todo güncellendi.'}

    return result