def wrapper(*args, **kwargs): try: payload = request.get_json() for req_item in required: if req_item in g.__dict__: logger.critical( f"`g` contained `{req_item}` before definition") return INTERNAL_SERVER_ERROR g.__setattr__(req_item, payload[req_item]) except BadRequest: if logger: logger.debug(f"Throwing `BadRequest`") logger.error(f"Could not parse JSON") return make_bad_request(f"Requires JSON Object") except KeyError: if logger: logger.debug(f"Throwing `KeyError`") logger.error(f"Could not acquire {req_item} from request") return make_bad_request(f"Missing Parameter: {req_item}") except Exception as e: if logger: logger.debug(f"Throwing {type(e)}") logger.error("Error parsing request") return make_bad_request(reason=f"Requires JSON Object") return func(*args, **kwargs)
def groundlist(): """所有土地信息列表""" g.__setattr__('action','ground.groundlist') page = int(request.form.get('page',1)) pagesize = int(request.form.get('page_size',10)) action = request.form.get('action','') #查询条件 batch_name = int(request.form.get('batch_name',0)) county = int(request.form.get('county',0)) project_type = int(request.form.get('project_type',0)) industry_type = int(request.form.get('industry_type',0)) used_type = int(request.form.get('used_type',0)) ground_list = Ground.query if batch_name: ground_list = ground_list.filter_by(batch_name=batch_name) if county: ground_list = ground_list.filter_by(county=county) if project_type: ground_list = ground_list.filter_by(project_type=project_type) if industry_type: ground_list = ground_list.filter_by(industry_type=industry_type) if used_type: ground_list = ground_list.filter_by(used_type=used_type) ground_list = ground_list.order_by('id desc').all() # print Ground.query.filter(and_(filter_str)).order_by('id desc') for ground in ground_list: ground.match_target_type = match_target_type_resolution(ground.match_target_type) if action == "export": return redirect(ground_excel_created(ground_list)) print '*'*40,pagesize,page pagination = Pagination(ground_list,page,pagesize) groundlist = pagination.list() return render_template('/ground/groundlist.html', pagination=pagination, page=page, page_size=pagesize, groundlist=groundlist, batchlist = Batch.query.all(), countys=COUNTY_CHOICES, project_types=PROJECT_TYPE_CHOICES, industry_types=INDUSTRY_TYPE_CHOICES, used_types=GROUND_USE_TYPE_CHOICES, _batch_name=batch_name, _county=str(county), _project_type=str(project_type), _industry_type=str(industry_type), _used_type=str(used_type) )
def index(): """添加地块信息""" g.__setattr__('action','ground.index') from forms import addGroundForm form = addGroundForm() if form.validate_on_submit(): ground = Ground() form.populate_obj(ground) match_target_type = '' for typa in request.form.getlist('match_target_type'): match_target_type += typa+"_" total_area = float(request.form.get('total_area',0)) target_area = float(request.form.get('target_area',0)) batch_name = request.form.get('batch_name',0) plough_area = float(request.form.get('plough_area',0)) other_farmland = float(request.form.get('other_farmland',0)) unused_area = float(request.form.get('unused_area',0)) stock_const_area = float(request.form.get('stock_const_area',0)) increased_const_area = float(request.form.get('increased_const_area',0)) # total_area = float(request.form.get('total_area',0)) batch_name = float(request.form.get('batch_name',0)) print '<>'*30,total_area,target_area #将当前地块的各个面积值 加入到 针对该块地对应的批次的各个面积值上 batch = Batch.query.filter_by(id=batch_name).first() setattr(batch,'plough_area',batch.plough_area+plough_area) setattr(batch,'other_farmland',batch.other_farmland+other_farmland) setattr(batch,'unused_area',batch.unused_area+unused_area) setattr(batch,'stock_const_area',batch.stock_const_area+stock_const_area) setattr(batch,'increased_const_area',batch.increased_const_area+increased_const_area) setattr(batch,'total_area',batch.total_area+total_area) #对不能通过form.populate_obj方法初始化的几个属性进行初始化 setattr(ground,'match_target_type',match_target_type) setattr(ground,'total_area',total_area) setattr(ground,'target_area',target_area) db.session.add(ground) db.session.commit() return redirect(url_for('ground.groundlist')) return render_template('/ground/ground.html', form=form, match_target_type=TARGET_TYPE_CHOICES)
def index(): """新增用户""" g.__setattr__('action','member_manage') from forms import MemberForm form = MemberForm() if form.validate_on_submit(): member = Member() form.populate_obj(member) db.session.add(member) db.session.commit() flash(u'添加成功!') members = Member.query.all() return render_template('/member/member.html',form=form,members=members)
def index(): """新增批次""" g.__setattr__('action','batch.typein') from forms import addBatchForm form = addBatchForm() if form.validate_on_submit(): _batch = Batch() form.populate_obj(_batch) db.session.add(_batch) db.session.commit() return redirect(url_for('batch.batchlist')) return render_template('/batch/batch.html', form=form)
def first_examine_add(): """添加初审信息""" g.__setattr__("action", "examine.first_examine_add") from forms import addFirstExaForm form = addFirstExaForm() if form.validate_on_submit(): inquiry = Inquiry() form.populate_obj(inquiry) db.session.add(inquiry) db.session.commit() return redirect(url_for("examine.firstexalist")) return render_template("/examine/addFirstExa.html", form=form)
def pre_examine_add(): """添加预审信息""" g.__setattr__("action", "examine.pre_examine_add") from forms import addPreExaForm form = addPreExaForm() if form.validate_on_submit(): review = Review() form.populate_obj(review) db.session.add(review) db.session.commit() return redirect(url_for("examine.preexalist")) return render_template("/examine/addPreExa.html", form=form)
def batchlist(): """所有批次列表""" g.__setattr__('action','batch.batchlist') page = int(request.form.get('page',1)) pagesize = int(request.form.get('page_size',2)) action = request.form.get('action','') #查询条件 _county = int(request.form.get('county',0)) _year = int(request.form.get('year',0)) print "<>"*40,_county,_year batchlist = Batch.query if _county: batchlist = batchlist.filter_by(county=_county) if _year: batchlist = batchlist.filter_by(year=_year) batchlist = batchlist.order_by('id desc').all() print len(batchlist) # print Ground.query.filter(and_(filter_str)).order_by('id desc') if action == "export": return redirect(batch_excel_created(batchlist)) pagination = Pagination(batchlist,page,pagesize) batchlist = pagination.list() print len(batchlist) return render_template('/batch/batchlist.html', pagination=pagination, page=page, page_size=pagesize, batchlist=batchlist, countys=COUNTY_CHOICES, years=YEAR_CHOICES, _county=str(_county), _year=str(_year) )
def firstexalist(): """初审信息列表""" g.__setattr__("action", "examine.firstexalist") page = int(request.form.get("page", 1)) pagesize = int(request.form.get("page_size", 10)) action = request.form.get("action", "") # 查询条件 _county = int(request.form.get("county", 0)) inquirylist = Inquiry.query if _county: inquirylist = inquirylist.filter_by(project_address1=_county) inquirylist = inquirylist.order_by("apply_time desc").all() for inquiry in inquirylist: inquiry.project_address2 = ( COUNTY_CHOICES.__getitem__(inquiry.project_address1 - 1)[1] + "-" + inquiry.project_address2_time.strftime("%Y-%m-%d") ) inquiry.apply_time = inquiry.apply_time.strftime("%Y-%m-%d") if action == "export": return redirect(inquiry_excel_created(inquirylist)) pagination = Pagination(inquirylist, page, pagesize) inquirylist = pagination.list() return render_template( "/examine/inquirylist.html", inquirylist=inquirylist, countys=COUNTY_CHOICES, pagination=pagination, _county=str(_county), page=page, page_size=pagesize, )
def preexalist(): """预审信息""" g.__setattr__("action", "examine.preexalist") page = int(request.form.get("page", 1)) pagesize = int(request.form.get("page_size", 10)) action = request.form.get("action", "") # 查询条件 _county = int(request.form.get("county", 0)) reviewlist = Review.query if _county: reviewlist = reviewlist.filter_by(project_address1=_county) reviewlist = reviewlist.order_by("apply_time desc").all() for review in reviewlist: review.project_address2 = ( COUNTY_CHOICES.__getitem__(review.project_address1 - 1)[1] + "-" + review.project_address2 ) review.examine_time = review.examine_time.strftime("%Y-%m-%d") review.apply_time = review.apply_time.strftime("%Y-%m-%d") if action == "export": return redirect(review_excel_created(reviewlist)) pagination = Pagination(reviewlist, page, pagesize) reviewlist = pagination.list() return render_template( "/examine/reviewlist.html", reviewlist=reviewlist, countys=COUNTY_CHOICES, pagination=pagination, page=page, page_size=pagesize, _county=str(_county), )
def login(): if request.method == 'POST': username = request.form['username'] password = request.form['password'] db = get_db() error = None user = db.execute('select * from user where username =?', (username, )).fetchone() if user is None: error = 'incorrect username' elif not check_password_hash(user['password'], password): error = 'incorrect password' if error is None: session.clear() session['user_id'] = user['id'] g.__setattr__("user", user) return redirect(url_for('index')) flash(error) return render_template('auth/login.html')
def logout(): g.__setattr__('logged_in', None) flash('You were logged out') return redirect(url_for('show_entries'))
def set_user(key, value): g.__setattr__(key, value)
def logout(): g.__setattr__('logged_in',None) flash('You were logged out') return redirect(url_for('show_entries'))