def team_join_activity(): a_id = request.args.get('a_id') t_id = request.args.get('t_id') join_activity = models.InsertDB() res = join_activity.join_activity_team(a_id, t_id) print(res) return jsonify(res)
def login(): # login = models.Login() # 实例化login_form类用于获取登录表单信息 # print(session['u_id']) # try: # if session['u_id'] is None or session['u_id'] == '': # return redirect(url_for('static', filename='html/index.html')) # except Exception: # return redirect(url_for('static', filename='html/index.html')) # finally: # pass login_form = forms.LoginForm() form_data = login_form.get_data(request) print(form_data) db_select = models.Query() # 检查数据库中有没有个人信息 # 在数据库中获取u_id u_id = db_select.get_u_id(form_data['u_xh_id']) print(u_id) u_xh_id = form_data['u_xh_id'] u_password = form_data['u_password'] data = {'code': 400, 'data': {}} if u_id and db_select.get_password(u_password): # 登录成功,建立对话 session['u_id'] = u_id session['u_xh_id'] = u_xh_id session['u_password'] = u_password # g.u_id = u_id u_data = db_select.get_login_user(u_id) data['code'] = 200 data['data'] = u_data print('login success!') # print(data) # 登录成功重定向到首页 return jsonify(data) # 爬取数据 try: # 爬取到用户的个人信息 u_data = scraping.crow_date(form_data) except Exception: return jsonify(data) else: # 爬取成功,插入数据库 db_insert = models.InsertDB() db_insert.add_user(u_data, u_password) print("插入成功!") print(u_data) # 向teams和team_user插入数据 u_id = db_select.get_u_id(u_xh_id) db_insert.join_class_team(u_id, u_data) session['u_id'] = u_id session['u_xh_id'] = u_xh_id session['u_password'] = u_password g.u_id = u_id u_data = db_select.get_login_user(u_id) data['code'] = 200 data['data'] = u_data return jsonify(data)
def create_activity(): u_id = session.get('u_id') # u_id = 29 if request.method == 'GET' or u_id is None or u_id == '': return redirect(url_for('static', filename='index_html/index.html')) # print(request.form['a_name']) activity = Activity() # 从表单中获取到数据 activity_data = activity.get_data(request) # 添加发起者信息 print(activity_data) # 判断该活动是由个人还是团队创建 # if activity_data['creator_level'] == 1: if activity_data['a_creator'] != 1: activity_data['creator_level'] = 1 activity_data['a_imgs'] = file_path print(file_path) # 将数据插入数据库 new_activity = models.InsertDB() a_id = new_activity.create_activity(activity_data) print("添加活动的状态:{}".format(a_id)) if a_id != 0: # 将创建的活动添加到活动关联表中 t_id = activity_data['a_creator'] flag = models.InsertDB().join_activity_team(a_id, t_id) print(flag) else: print('file_path') print(file_path) print(file_path) activity_data['a_creator'] = u_id activity_data['a_imgs'] = file_path # 将数据插入数据库 new_activity = models.InsertDB() a_id = new_activity.create_activity(activity_data) print("添加活动的状态:{}".format(a_id)) if a_id != 0: # 将创建的活动添加到活动关联表中 flag = models.InsertDB().join_activity(a_id, u_id) print(flag) return jsonify({'a_id': a_id})
def join_activity(): data = {'code': 400, 'success': 0} u_id = session.get('u_id') # u_id = 29 # if u_id is None or u_id == '': # return redirect(url_for('index')) a_id = request.args.get('a_id') # a_id = 1000 insert_activity = models.InsertDB() insert_activity.join_activity(u_id, a_id) data['code'] = 200 data['success'] = 1 return jsonify(data)
def send_message(): # u_id = session.get('u_id') u_id = 29 message = Message().get_message_data(request) # 插入数据库 db = models.InsertDB() db.add_message(message) # 将留言与被流言方关联 be_m_level = message['be_m_level'] be_m_id = message['be_m_id'] if be_m_level == 1: table_name = 'users' db.message_to_table( table_name, be_m_id, )