def imp_by_product_id(fraction_id, year_of_growth, product_id): """render all sets (Sätze) of one procuct that were realised by one fraction in a year """ #is one element of entries pivot? if request.args.get('pivot'): pivot = int(request.args.get('pivot')) else: pivot = 0 fraction = FractionModel(fraction_id) product = ProductModel(product_id, fraction_id) productlist = fraction.get_first_product_list() the_product = product.get_data() #one dict if the_product['tree_diff'] == 1: # is leaf node entries = vegetables_implement_model.get_by_product_id(fraction_id, year_of_growth, product_id) return render_template('implementation/implementation_one.html', entries=entries, productlist=productlist, fraction=fraction, the_product=the_product, year_of_growth=year_of_growth, pivot=pivot) else: return str(the_product)
def save_product(request): na = request.POST.get("p1") pr = request.POST.get("p2") qty = request.POST.get("p3") img = request.FILES["p4"] status = "active" ProductModel(name=na, price=pr, quantity=qty, photo=img, status=status).save() return redirect('admin_products')
def new(fraction_id, year_of_growth, product_id): """ formular """ fraction = FractionModel(fraction_id) product = ProductModel(product_id, fraction_id) diversity = DiversityModel(product_id, fraction_id) growkind = GrowKindModel() the_product = product.get_data() #productlist = fraction.get_productlist() productlist = fraction.get_first_product_list() the_diversity = diversity.get() summary = vegetables_concept_model.get_summary_by_id( fraction_id, year_of_growth, product_id) form = VegetablesConceptionForm(request.form) #before validating wtf choises (<option>) must be given form.diversity_id.choices = diversity.get_wtform_choices() form.area_id.choices = fraction.area.get_wtform_choices() form.grow_kind_id.choices = growkind.get_wtform_choices() if form.validate_on_submit(): new_id = vegetables_concept_model.insert(form) #print(">>>>>>>>> new_id: "+ str(new_id)) if new_id: flash(u'Erfolgreich angelegt:#' + str(new_id), 'success') return redirect( url_for('.by_product_id', fraction_id=fraction.fraction_id, year_of_growth=year_of_growth, product_id=product.product_id, pivot=new_id)) else: abort(500) #manualy poke initial form.values with the_product specs form.name.data = the_product['item_name'] form.fraction_id.data = fraction.fraction_id form.year_of_growth.data = year_of_growth form.product_id.data = the_product['product_id'] form.grow_kind_id.data = (the_product['grow_kind_id']) form.planting_interval.data = the_product['planting_interval'] return render_template('conception/conception_input_form.html', form=form, fraction=fraction, summary=summary, productlist=productlist, the_product=the_product, the_diversity=the_diversity, year_of_growth=year_of_growth, edit=False)
def edit(conception_id): """update""" data = vegetables_concept_model.get_by_id(conception_id) fraction_id = data['fraction_id'] product_id = data['product_id'] year_of_growth = data['year_of_growth'] fraction = FractionModel(fraction_id) product = ProductModel(product_id, fraction_id) diversity = DiversityModel(product_id, fraction_id) growkind = GrowKindModel() #area = AreaModel() the_product = product.get_data() #productlist = fraction.get_productlist() productlist = fraction.get_first_product_list() the_diversity = diversity.get() summary = vegetables_concept_model.get_summary_by_id( fraction_id, year_of_growth, product_id) form = VegetablesConceptionForm(request.form, data=data) #obj=data #before validating choises must be given form.diversity_id.choices = diversity.get_wtform_choices() form.area_id.choices = fraction.area.get_wtform_choices() form.grow_kind_id.choices = growkind.get_wtform_choices() #print('>>>>>>>>>>>>>diversity_ID:'+str(form.diversity_id.data)) if form.validate_on_submit(): check = vegetables_concept_model.update(form, conception_id) if check == 1: flash(u'Erfolgreich geändert', 'success') if check == 0: flash(u'nichts verändert', 'primary') return redirect( url_for('.by_product_id', fraction_id=fraction.fraction_id, year_of_growth=year_of_growth, product_id=product.product_id, pivot=conception_id)) return render_template('conception/conception_input_form.html', form=form, fraction=fraction, summary=summary, productlist=productlist, the_product=the_product, the_diversity=the_diversity, year_of_growth=year_of_growth, edit=True, data=data)
def post(self, request, *args, **kwargs): data = request.body data1 = json.loads(data) print(data1) try: ProductModel(p_no=data1['p_no'], p_name=data1['p_name'], p_price=data1['p_price'], p_quantity=data1['p_qty'], m_id_id=data1['m_id_id']).save() return HttpResponse(status=200) except: pass
def imp_edit(implementation_id): """update""" data = vegetables_implement_model.get_by_id(implementation_id) fraction_id = data['fraction_id'] product_id = data['product_id'] year_of_growth = data['year_of_growth'] fraction = FractionModel(fraction_id) product = ProductModel(product_id, fraction_id) diversity = DiversityModel(product_id, fraction_id) growkind = GrowKindModel() the_product = product.get_data() #productlist = fraction.get_first_product_list() productlist = fraction.cheata_menue() #implement list2nested!!! the_diversity = diversity.get() form = VegetablesImplementationForm(request.form, data=data) #obj=data #before validating choises must be given form.diversity_id.choices = diversity.get_wtform_choices() form.area_id.choices = fraction.area.get_wtform_choices() form.grow_kind_id.choices = growkind.get_wtform_choices() if form.validate_on_submit(): check = vegetables_implement_model.update(form,implementation_id) if check == 1: flash(u'Erfolgreich geändert', 'success') if check == 0: flash(u'nichts verändert', 'primary') return redirect(url_for('.imp_by_product_id', fraction_id=fraction.fraction_id, year_of_growth=year_of_growth, product_id=product.product_id, pivot=conception_id)) return render_template('implementation/implementation_input_form.html', form=form, fraction=fraction, productlist=productlist, the_product=the_product, the_diversity=the_diversity, year_of_growth=year_of_growth)
def by_product_id(fraction_id, year_of_growth, product_id): """render all sets (Sätze) of one product""" start = time.time() #performence time start if request.args.get('pivot'): pivot = int(request.args.get('pivot')) #or_test (trinity operator) else: pivot = 0 fraction = FractionModel(fraction_id) product = ProductModel(product_id, fraction_id) transact = TransactionModel(fraction_id) #productlist = fraction.get_product_list() productlist = fraction.cheata_menue() #implement list2nested!!! the_product = product.get_data() #:one dict area_info = vegetables_concept_model.get_involved_areas( fraction_id, year_of_growth) #t=transact.get_transactions(product_id) #print('Transactions:'+str(t)) if the_product['tree_diff'] == 1: entries = vegetables_concept_model.get_product_by_id( fraction_id, year_of_growth, product_id) summary = vegetables_concept_model.get_summary_by_id( fraction_id, year_of_growth, product_id) end = time.time() #performence time end print('Performence conception.by_product_id:' + str(end - start) + 'sec.') return render_template('conception/conception_one.html', entries=entries, summary=summary, productlist=productlist, fraction=fraction, the_product=the_product, area_info=area_info, year_of_growth=year_of_growth, pivot=pivot) else: return str(the_product)
def getsome(fraction_id, source_fraction_id, product_id): """ GET ready to fire a POST to the acquisitions table the flow is: from source_fraction to fraction WHAT happens IF fraction_id is to drive the boxes and units, like DEPOT wants to have 264' boxes in Pounds of a product??? """ #init destination fractions fraction = FractionModel(fraction_id) #init source fraction source_fraction = FractionModel(source_fraction_id) #init one product product = ProductModel(product_id, source_fraction_id) #dict of product spec data (one db row) product_entries = product.get_data() #init units unit = UnitModel(product_entries['unit_set_id']) #init boxes box = BoxModel(product_entries['boxes_set_id']) #init vehicles vehicle = VehicleModel() #transactionmodel transactions = TransactionModel(fraction_id,source_fraction_id) #the latest entries in acquisitions table #TODO variable count history_entries = transactions.acqusitions_get_last(12) form = Acquisition_Retraction_Form() if 'acquiredate' in session: form.aq_date.raw_data = session['acquiredate'] #before validating wtf choises (<option>) must be given form.unit_id.choices = unit.get_wtform_choices() form.vehicle_id.choices = vehicle.get_wtform_choices() form.box_id.choices = box.get_wtform_choices() #with boxes we css-style <options> in the template (render_kw?) boxset = box.get_set_by_id(product_entries['boxes_set_id']) form.alternate_unit_id.choices = unit.get_wtform_choices() if form.validate_on_submit(): session['acquiredate'] = form.aq_date.raw_data res = transactions.acqusition_insert(form) print(">>>>>>>>>aqcuisition_insert_result: "+ str(res)) if res: flash(u'Die Angaben und Werte wurden erfolgreich übernommen und gespeichert.','success') return redirect(url_for('.getsome', fraction_id=fraction_id, source_fraction_id=source_fraction_id, product_id=product_id)) else: abort(500) #manualy set wtform.data preselected form.fraction_id.data = fraction.fraction_id form.source_fraction_id.data = source_fraction.fraction_id form.product_id.data = product_entries['product_id'] form.unit_id.data = product_entries['unit_pivot_id'] form.box_id.data = product_entries['box_pivot_id'] form.box_count.data = 0 form.vehicle_count.data =0 return render_template('acquisition/acquisition.html', fraction=fraction, source_fraction=source_fraction, product_entries=product_entries, boxset=boxset, history_entries=history_entries, form=form)