def insert_list(): form = ListForm(request.form) if request.method == 'POST': list = List(name=form.name.data) db_session.add(list) db_session.commit() return redirect(url_for('home'))
def delete_list(id): data = db_session.query(List).get(id) for task in data.tasks: db_session.delete(task) db_session.delete(data) db_session.commit() return redirect(url_for('home'))
def update_list(): form = ListForm(request.form) if request.method == 'POST': list = db_session.query(List).get(request.form.get('id')) list.name = form.name.data db_session.add(task) db_session.commit() return redirect(url_for('home'))
def delete_task(id): print("Delete method called as get") if request.method == 'POST': print("Delete Task Post Method") data = db_session.query(Task).get(id) print("Deleting ", data) db_session.delete(data) db_session.commit() return redirect(url_for('home'))
def update_task(): form = TaskForm(request.form) if request.method == 'POST': task = db_session.query(Task).get(request.form.get('id')) task.subject = form.subject.data task.description = form.description.data task.assigned_to = form.assigned_to.data task.status = form.status.data print(task) db_session.add(task) db_session.commit() return redirect(url_for('home'))
def delete(self, *args, **kwargs): """ :return: ошибку или подтверждение о удалении комментария QueryString параметры - comment_id """ comment_id = int(request.args.get('comment_id', None)) if self.check_comment(comment_id, auth.username()): data = db_session.query(Comments).filter_by(id=comment_id).first() db_session.delete(data) db_session.commit() return {'delete': 'True'}, 200 return {'error': 'permission denied'}, 404
def insert_task(): form = TaskForm(request.form) if request.method == 'POST': task = Task(list=form.list.data, subject=form.subject.data, description=form.description.data, assigned_to=form.assigned_to.data, status=form.status.data, date_created=datetime.datetime.now()) print(task) db_session.add(task) db_session.commit() return redirect(url_for('home'))
def post(self, *args, **kwargs): """ :return: Ошибка или подтверждение о прохождении регистрации Метод регистрации пользователя """ passwd = generate_password_hash(request.args.get('passwd', None)) email, username = self.check_data() if None in [email, username]: return (email or username), 404 u = User(email, username, passwd) db_session.add(u) db_session.commit() return {'register': 'True'}, 200
def createTask(): form = TaskForm(request.form) if not form.validate_on_submit(): return render_template('public/createTask.html', form=form) if request.method == 'POST': task = Task(subject=form.subject.data, description=form.description.data, assigned_to=form.assigned_to.data, status=form.status.data, date_created=datetime.datetime.now()) print(task) db_session.add(task) db_session.commit() return redirect(url_for('createTask'))
def signup(): # TODO: Use B Crypt to safely store passwords form = UserForm(request.form) if not form.validate_on_submit(): return render_template('public/sign_up.html', form=form) if request.method == "POST": user = User(username=form.username.data, email=form.email.data, password=form.password.data, date_joined=datetime.datetime.now()) username = form.username.data db_session.add(user) db_session.commit() return redirect(url_for('home', user=username)) else: return render_template("public/sign_up.html")
def put(self, *args, **kwargs): """ :return: ошибку или подтверждение о изменении комментария QueryString параметры - comment_id, title, content """ comment_id = int(request.args.get('comment_id', None)) title = request.args.get('title', None) content = request.args.get('content', None) if self.check_post(comment_id, auth.username()) and None not in [title, content]: data = db_session.query(Comments).filter_by(id=comment_id).first() data.title = title data.content = content db_session.commit() return {'update_data': 'True'}, 200 return {'error': 'permission denied'}, 404
def post(self, *args, **kwargs): """ :return: Ошибку или подтверждение добавления поста QueryString параметры - title, content """ author_id = db_session.query(User).filter_by( username=auth.username()).first().id title = request.args.get('title', None) content = request.args.get('content', None) if author_id is None: return {'error': 'authorisation error'}, 404 if None in [title, content]: return { 'error': 'title and content should not have null values' }, 404 p = Posts(author_id, title, content) db_session.add(p) db_session.commit() return {'post_create': 'True'}, 200
def post(self, *args, **kwargs): """ :return: ошибку или подтверждение создания комментария QueryString параметры - post_id, title, content """ post_id = int(request.args.get('post_id', None)) author_id = db_session.query(User).filter_by( username=auth.username()).first().id title = request.args.get('title', None) content = request.args.get('content', None) if post_id is None: return {'error': 'post not found'}, 404 if author_id is None: return {'error': 'authorisation error'}, 404 if None in [title, content]: return { 'error': 'title and content should not have null values' }, 404 p = Comments(post_id, author_id, title, content) db_session.add(p) db_session.commit() return {'comment_create': 'True'}, 200