def dislikes(): if request.method == "PUT": user_id = session['user_id'] post_id = request.form['post_id'] user = db_session.query(User).filter(User.user_id == user_id).first() post = db_session.query(Post).filter(Post.post_id == post_id).first() dislike_found = db_session.query(Dislike).filter( Dislike.post_id == post_id and Dislike.user_id == user_id).first() if dislike_found is None: new_dislike = Dislike() user.user_dislikes.append(new_dislike) post.post_dislikes.append(new_dislike) post.dislike_number += 1 db_session.add(new_dislike) # remove old like old_like = db_session.query(Like).filter( Like.post_id == post_id and Like.user_id == user_id).first() if old_like is not None: db_session.delete(old_like) post.like_number -= 1 db_session.commit() data = {"dislike_post": True} else: dislike = db_session.query(Dislike).filter( Dislike.post_id == post_id and Dislike.user_id == user_id).first() post.dislike_number -= 1 db_session.delete(dislike) db_session.commit() data = {"dislike_post": False} return gen_json_success(data)
def remove_task(user_id, task_id): task = get_task_by_id(task_id) if task is None: return 404 if task.user_id != user_id: return 403 db_session.delete(task) db_session.commit() return 200
def rm_cart(orderid): try: order = Order.query.filter(Order.orderid == orderid).first() print('delete %d' % order.orderid) db_session.delete(order) db_session.commit() return True except Exception as e: print(e) return str(e)
def delete_user(public_id): """* Delete An user """ user = User.query.filter_by(public_id=public_id).first() if not user: return jsonify({'message': 'User not found'}) db_session.delete(user) db_session.commit() return jsonify({'message': 'Delete one record!'})
def user_remove(): if request.method == 'POST': try: remove_user_name = request.form.keys()[0] except IndexError: remove_user_name = '' assouser = db_session.query(GitUser).filter_by( name=remove_user_name).first() assogroup_relation = db_session.query(asso_group_user).filter_by( git_user_id=assouser.id).all() assogroup_list = [] for _ in assogroup_relation: assogroup = db_session.query(GitGroup).filter_by( id=_.git_group_id).first() assogroup_list.append(assogroup) if not assogroup_list: for assogroup in assogroup_list: assouser.git_group.remove(assogroup) db_session.delete(assouser) db_session.delete(assouser) db_session.commit() deleteuser_assogroup = [] for _ in assogroup_list: deleteuser_assogroup_file = BASE_DIR \ + '/conf/groups/' + _.name + '.conf' deleteuser_assogroup.append(deleteuser_assogroup_file) gconf_dict = {} for i in deleteuser_assogroup: with open(i, 'rb') as f: lines = f.readlines() for line in lines: gconf_group = line.split('=')[0].lstrip('@').strip() gconf_user = line.split('=')[1].split() gconf_dict[gconf_group] = gconf_user assouser.name = '.'.join(assouser.name.split('.')[:-1]) assouser_name = str(assouser.name) for each_group in gconf_dict: if assouser_name in gconf_dict[each_group]: gconf_dict[each_group].remove(assouser_name) assogroup_file = BASE_DIR + '/conf/groups/' + each_group \ + '.conf' f = open(assogroup_file, 'wb') f.truncate() f.write('@' + each_group + ' = ' + ' '.join(gconf_dict[each_group])) f.close() db_session.close() user_name_file = os.path.join(KEY_DIR, remove_user_name) os.remove(user_name_file) return redirect(url_for('user'))
def validation_unregister(token): if len(token) < 10: flash("Error") user = User.query.filter_by(token=token).first() if not user: flash("Error") else: # members = Member.query.filter_by(user=user).delete() db_session.delete(user) db_session.commit() flash("Success") return flask.redirect(flask.url_for('index'))
def apiClientDelete(api_client_id): try: client = db_session.query(User_Api_Client).get(api_client_id) db_session.delete(client) db_session.commit() flash("%s was sucessfully Deleted!" % client.name) clients = db_session.query(User_Api_Client).filter_by( user_id=current_user.id).all() return render_template('/apiClients/apiClients.html', clients=clients) except: flash("Something went wrong rolling back transaction!" % client.name) print('some error could not save transaction, rolling back') db_session.rollback() db_session.commit()
def group_remove(): if request.method == 'POST': try: remove_group_name = request.form.keys()[0] except IndexError: remove_group_name = '' group_name_file = BASE_DIR + '/conf/groups/' \ + remove_group_name + '.conf' deletegroup = db_session.query(GitGroup).filter_by( name=remove_group_name).first() db_session.delete(deletegroup) db_session.commit() db_session.close() os.remove(group_name_file) #~ groupdict.pop(remove_group_name) return redirect(url_for('group'))
def deleteRestaurant(restaurant_id): # this page will be for deleting restaurant if request.method == 'POST': restaurant = db_session.query(Restaurant).filter_by( id=restaurant_id).one() menuItems = db_session.query(MenuItem).filter_by( restaurant_id=restaurant_id).all() db_session.delete(restaurant) db_session.commit() flash('The %s Restaurant was successfully deleted!' % restaurant.name) return redirect(url_for('showRestaurants')) restaurant = db_session.query(Restaurant).filter_by(id=restaurant_id).one() return render_template('deleteRestaurant.html', restaurant=restaurant, current_user=current_user)
def customerDelete(customer_id): try: customer = db_session.query(User_Customer).get(customer_id) db_session.delete(customer) db_session.commit() flash("%s was sucessfully Deleted!" % customer.name) customers = db_session.query(User_Customer).filter_by( user_id=current_user.id).all() return render_template('/customers/customers.html', customers=customers) except: print('some error could not save transaction, rolling back') db_session.rollback() db_session.commit() flash("Encountered some errors, rolling back transactions") customers = db_session.query(User_Customer).filter_by( user_id=current_user.id).all() return render_template('/customers/customers.html', customers=customers)
def messageDelete(message_id): try: message = db_session.query(Message).get(message_id) db_session.delete(message) db_session.commit() flash("The message '%s' from %s was sucessfully Deleted!" % (message.message, message.customer.name)) sms_messages = db_session.query(Message).filter_by( user_id=current_user.id).order_by(Message.id.desc()).all() return render_template('/messages/messages.html', sms_messages=sms_messages) except: print('some error could not save transaction, rolling back') db_session.rollback() db_session.commit() flash("Something went wrong, rolling back transaction!") sms_messages = db_session.query(Message).filter_by( user_id=current_user.id).order_by(Message.id.desc()).all() return render_template('/messages/messages.html', sms_messages=sms_messages)
def sub_repo_remove(): if request.method == 'POST': try: remove_sub_repo_name = request.form.get('subRepoName', '') except IndexError: remove_sub_repo_name = '' if remove_sub_repo_name and '/' in remove_sub_repo_name: remove_sub_repo_name = '~'.join(remove_sub_repo_name.split('/')) sub_repo_name_file = BASE_DIR + '/conf/subrepos/' \ + remove_sub_repo_name + '.conf' deletesubrepo = db_session.query(GitSubRepo).filter_by( name=remove_sub_repo_name).first() if deletesubrepo: db_session.delete(deletesubrepo) db_session.commit() db_session.close() os.remove(sub_repo_name_file) tab_page = 1 return redirect(url_for('repo', tab_page=tab_page))
def complete_order(courier_id, order_id, delivered_on: datetime): assigned_order = AssignedOrder.query.filter( AssignedOrder.order_id == order_id and AssignedOrder.courier_id == courier_id ).first() if assigned_order is None: return False last_delivery_time = get_courier(courier_id).last_delivery # Если курьер ничего не доставлял, то расчёт от назначения заказа if last_delivery_time is None: delivery_time = delivered_on - assigned_order.assign_time else: delivery_time = delivered_on - last_delivery_time db_session.add( DeliveredOrder( courier_id, order_id, region_id=get_order(order_id).region_id, delivered_on=delivered_on, delivery_time=int(delivery_time.total_seconds()) ) ) get_order(order_id).set_delivered() db_session.delete(assigned_order) update_courier_rating(courier_id, calculate_courier_rating()) db_session.add( CourierEarning( courier_id=courier_id, order_id=order_id, amount=BASE_PAY * PAY_COEFFICIENTS[get_courier(courier_id).courier_type] ) ) get_courier(courier_id).last_delivery = delivered_on db_session.commit() return True
def attend(): team = current_user event = get_empty_event_or_fail() attending = AttendingTeam.query.filter_by(event=event, team=team).first() form = AttendForm() if form.validate_on_submit(): if datetime.now() > event.registration_end: flash("Registration time is over") return flask.redirect(flask.url_for('attend')) members_to_add = [] def verify_member_form(tpl): if any(tpl): if not all(tpl): return False return True return None def check_3_tuple(tpl): tpl = tuple(t.strip() for t in tpl) if verify_member_form(tpl) is False: flash("Fill all 3 fields for each member") return False # return flask.render_template('attend.html', form=form, members=team.members, attending=attending) elif verify_member_form(tpl) is True: if not tpl[0].endswith("@hs-albsig.de"): # FIXME flash("Please use only university email addresses") return False # return flask.render_template('attend.html', form=form, members=team.members, attending=attending) members_to_add.append(tpl) else: print("Empty 3-tuple") return True # Check form _ = check_3_tuple((form.email1.data, form.surname1.data, form.forename1.data)) if not _: return flask.render_template('attend.html', form=form, members=team.members, attending=attending) _ = check_3_tuple((form.email2.data, form.surname2.data, form.forename2.data)) if not _: return flask.render_template('attend.html', form=form, members=team.members, attending=attending) _ = check_3_tuple((form.email3.data, form.surname3.data, form.forename3.data)) if not _: return flask.render_template('attend.html', form=form, members=team.members, attending=attending) _ = check_3_tuple((form.email4.data, form.surname4.data, form.forename4.data)) if not _: return flask.render_template('attend.html', form=form, members=team.members, attending=attending) _ = check_3_tuple((form.email5.data, form.surname5.data, form.forename5.data)) if not _: return flask.render_template('attend.html', form=form, members=team.members, attending=attending) # delete AttendingTeam if attending is not None: db_session.delete(attending) db_session.commit() # delete all users for m in team.members: db_session.delete(m.user) db_session.delete(m) db_session.commit() for email, surname, forename in members_to_add: test_u = User.query.filter_by(email=email).first() if test_u is not None: flash("User with this email found in database. Please unregister first.") return flask.render_template('attend.html', form=form, members=team.members, attending=attending) else: u = User() u.email = email u.surname = surname u.forename = forename u.ensure_token() db_session.add(u) m = Member() m.team = team m.user = u db_session.add(m) db_session.commit() send_validation_email(u, team) # add AttendingTeam if member count is > 0 if len(members_to_add) > 0: at = AttendingTeam() at.event = event at.team = team at.subnet = first_empty_subnet() db_session.add(at) db_session.commit() flash("Emails were sent to your email addresses. Please follow the instructions in this email.") db_session.commit() return flask.redirect(flask.url_for('attend')) # Send verification links TODO return flask.render_template('attend.html', form=form, members=team.members, attending=attending)
def clean_message(): #清除数据库中Message表的未完成条目(调试用) for mes in Message.query.filter(Message.status==0).all(): db_session.delete(mes) db_session.commit()