def add_property(): cache.delete('property') # # 新增传进来的form # form = {'prop_name': '肤色', 'label_type_id': 1, 'prop_type': 1, 'property_value': # [{'option_value': 2, 'option_name': '黄'}, # {'option_value': 1, 'option_name': '黑'}, # {'option_value': 3, 'option_name': '白'}]} # # # 修改传进来的form # form = {'prop_id':12, 'property_value': # [{'option_id': 16, 'option_value': 4, 'option_name': '吧lue皮'}, # {'option_value': 5, 'option_name': '花皮'}, # {'option_id':30,'delete':1}]} form = json.loads(request.data) if request.method == 'POST': # 1.将prop_name、label_type、prop_type 插入到property表中 with db.auto_commit(): property = Property() # 如果是修改,form['prop_id']值不为空,则不执行下面的语句 if form.get('prop_id') == None: property.set_attrs(form) db.session.add(property) # 将propery_value中的值插入到property_value表中 with db.auto_commit(): for value in form['property_value']: property_value = Property_value() prop_id = '' # 如果是修改,property.id为空,需要使用传进来的prop_id if property.id is None: prop_id = form['prop_id'] else: prop_id = property.id value['prop_id'] = prop_id # 修改property_value if value.get('option_id'): id = value['option_id'] already_exist = property_value.query.filter_by( id=id).first() # 判断是否要删除 if value.get('delete'): db.session.delete(already_exist) else: already_exist.option_value = value['option_value'] already_exist.option_name = value['option_name'] else: property_value.set_attrs(value) db.session.add(property_value) print('继续执行') return json.dumps({'status': 'success'})
def create_database(self): # initialize database db.drop_all() db.create_all() # create use user = User('test name') db.session.add(user) # create property type property_type = PropertyType('test name') db.session.add(property_type) # create risk risk = Risk('test name') db.session.add(risk) # create property prop= Property('test name', 'test caption', risk.id, property_type.id) db.session.add(prop) # create property option property_option = PropertyOption('test name', prop.id) db.session.add(property_option) # create risk value risk_value = RiskValue('test name', 'test unique code') db.session.add(risk_value) # create property option risk_property_value = PropertyValue('test value',prop.id,risk_value.id) db.session.add(risk_property_value) #commit changes db.session.commit()
def show_property(): # 这里的Label_type不用但是也不能删。因为要使用这个初始化Label_type表 Label_type() # 展示属性 label_properties = Property.get_property() property_values = PropertyCollection() property_values.fill(label_properties) # dict1 = json.loads(json.dumps(property_values, default=lambda o:o.__dict__)) return json.dumps(property_values, default=lambda o: o.__dict__)
class Meta: prefixes = ('api', ) components = ( messages.Messaging, Pagination, ) Model = Property Message = Property.message() pagination_limit = 25 keys = gather_keys(Model)
def create(): data = request.get_json() prop = Property(name=data['name'], caption=data['caption'], risk_id=data['risk_id']) db.session.add(prop) db.session.commit() property_dto = PropertyDto() output = property_dto.dump(prop).data return jsonify(output)
def properties(): properties = db.query(Property) if request.method == 'GET': return render_template('property.html', properties=properties) elif request.method == 'POST': property_ = Property(property_type=request.form.get('property_type'), owner_id=request.form.get('owner_id')) db.add(property_) db.commit() return render_template('property.html', properties=properties)
def new(): form = PropertyForm() if form.validate_on_submit(): property = Property() form.populate_obj(property) send_email('New Deal Notification!', sender='*****@*****.**', recipients=['*****@*****.**'], text_body=render_template('emails/new_deal.txt', property=property), html_body=render_template('emails/new_deal.html', property=property), attachments=[], sync=True) db.session.add(property) db.session.commit() submitter_phone = db.Column(db.String(255)) submitter_email = db.Column(db.String(255)) user_data = { 'email': property.submitter_email, 'phone': property.submitter_phone } return redirect(url_for('.complete', **user_data)) default_step_id = 'selectStepOne' if len(request.args) != 0: default_step_id = 'selectStepTwo' line_1 = request.args.get('line_1') if line_1 is not None: form.address.street_address.data = line_1 locality = request.args.get('city') if locality is not None: form.address.locality.data = locality state_code = request.args.get('state_code') if state_code is not None: form.address.administrative_area_level_1.data = state_code postal_code = request.args.get('postal_code') if postal_code is not None: form.address.postal_code.data = postal_code country = request.args.get('country') if country is not None: form.address.country.data = country return render_template('evaluation/wizard.html', form=form, default_step_id=default_step_id)
def add_property(): # Make sure the json is correct otherwise return 400 # If not a json json_data = request.get_json() if not json_data: return jsonify({"message": "This is not a proper json"}), 400 # Validate and deserialize property data, errors = property_schema.load(json_data) if errors: return jsonify(errors), 422 # Check presence of keys if 'name' not in json_data: return jsonify({"message": "name missing!"}), 400 if 'description' not in json_data: return jsonify({"message": "description missing!"}), 400 if 'city' not in json_data: return jsonify({"message": "city missing!"}), 400 if 'room' not in json_data: return jsonify({"message": "room missing!"}), 400 if 'owner_id' not in json_data: return jsonify({"message": "owner_id missing!"}), 400 # Create new Property in base name = request.json['name'] description = request.json['description'] city = request.json['city'] room = request.json['room'] owner_id = request.json['owner_id'] # Create new instance of Property new_property = Property(name, description, city, room, owner_id) db.session.add(new_property) db.session.commit() return property_schema.jsonify(new_property)
def api_list_all(self): self.context['data'] = Property.list_all()