def conception_index(fraction_id, year_of_growth): """collects overview of all products with succsesions(Sätze) of one fraction in one year_of_growth """ fraction = FractionModel(fraction_id) product_list = fraction.get_product_list() productlist = fraction.cheata_menue() #implement list2nested!!! entries = conception_model.get_overview(fraction_id, year_of_growth) summary = conception_model.get_overview_summary(fraction_id, year_of_growth) ts = conception_model.last_modified(fraction_id, year_of_growth) area_info = conception_model.get_involved_areas(fraction_id, year_of_growth) if not entries: return redirect( url_for('.conception_create', fraction_id=fraction_id, year_of_growth=year_of_growth)) else: return render_template('vegetables/conception_index.html', entries=entries, productlist=productlist, summary=summary, ts=ts, area_info=area_info, fraction=fraction, year_of_growth=year_of_growth)
def implementation_new(fraction_id, year_of_growth, product_id): """formular to enter a new vegetables growing action """ fraction = FractionModel(fraction_id) product = ProductModel(product_id, fraction_id) diversity = DiversityModel(product_id, fraction_id) cultivation = CultivationModel() growkind = GrowKindModel() seed = SeedModel() contacts = ContactsModel() #productlist = fraction.get_productlist() productlist = fraction.cheata_menue() #implement list2nested!!! the_product = product.get_data() the_diversity = diversity.get() form = VegetablesImplementationForm(request.form) #before validating choices 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() form.unit_of_seed.choices = seed.get_wtform_unit_choices() form.art_of_cultivation.choices = cultivation.get_wtform_choices() form.company_id.choices = contacts.get_wtform_choices() if form.validate_on_submit(): new_id = implementation_model.insert(form) print(">>>>>>>>> new_id: " + str(new_id)) if new_id: flash(u'Erfolgreich angelegt:#' + str(new_id), 'success') return redirect( url_for('.implementation_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('vegetables/implementation_input_form.html', form=form, fraction=fraction, productlist=productlist, the_product=the_product, the_diversity=the_diversity, year_of_growth=year_of_growth, flag='new')
def implementation_edit(implementation_id): """update""" data = implementation_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) cultivation = CultivationModel() growkind = GrowKindModel() seed = SeedModel() contacts = ContactsModel() 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 choices must be given form.diversity_id.choices = diversity.get_wtform_choices() form.area_id.choices = fraction.area.get_wtform_choices() form.art_of_cultivation.choices = cultivation.get_wtform_choices() form.grow_kind_id.choices = growkind.get_wtform_choices() form.unit_of_seed.choices = seed.get_wtform_unit_choices() form.company_id.choices = contacts.get_wtform_choices() if form.validate_on_submit(): check = implementation_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('.implementation_by_product_id', fraction_id=fraction.fraction_id, year_of_growth=year_of_growth, product_id=product.product_id, pivot=implementation_id)) return render_template('vegetables/implementation_input_form.html', form=form, fraction=fraction, productlist=productlist, the_product=the_product, the_diversity=the_diversity, year_of_growth=year_of_growth, data=data, flag='edit')
def implementation_index(fraction_id, year_of_growth): fraction = FractionModel(fraction_id) #productlist = fraction.get_first_product_list() productlist = fraction.cheata_menue() entries = implementation_model.get_overview(fraction_id, year_of_growth) print(fraction.name) print(fraction.fraction_id) return render_template('vegetables/implementation_index.html', entries=entries, productlist=productlist, fraction=fraction, year_of_growth=year_of_growth)
def conception_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 = conception_model.get_involved_areas(fraction_id, year_of_growth) #t=transact.get_transactions(product_id) #print('Transactions:'+str(t)) #and the_product[0]['has_data'] == fraction_id if the_product['has_data'] == fraction_id: entries = conception_model.get_product_by_id(fraction_id, year_of_growth, product_id) summary = conception_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('vegetables/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) elif the_product['tree_diff'] != 1 or the_product['has_data'] < 0: return str(the_product)
def conception_area(fraction_id, year_of_growth, area_id=None): """ plan on one area can go to conception_index and route "area" is to prepare area """ fraction = FractionModel(fraction_id) #productlist = fraction.get_product_list() productlist = fraction.cheata_menue() #implement list2nested!!! entries = conception_model.get_overview(fraction_id, year_of_growth, area_id) area = fraction.area.get_by_id(area_id) area_info = conception_model.get_involved_areas(fraction_id, year_of_growth) return render_template('vegetables/conception_area.html', entries=entries, fraction=fraction, year_of_growth=year_of_growth, productlist=productlist, area=area, area_info=area_info)
def implementation_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.cheata_menue() #implement list2nested!!! #productlist = fraction.get_product_list() the_product = product.get_data() #one dict #if the_product['tree_diff'] == 1: # is leaf node if the_product['has_data'] == fraction_id: imp_entries = implementation_model.get_product_by_id( fraction_id, year_of_growth, product_id) con_entries = conception_model.get_product_by_id( fraction_id, year_of_growth, product_id) imp_summary = implementation_model.get_summary_by_id( fraction_id, year_of_growth, product_id) con_summary = conception_model.get_summary_by_id( fraction_id, year_of_growth, product_id) return render_template('vegetables/implementation_one.html', con_entries=con_entries, imp_entries=imp_entries, con_summary=con_summary, imp_summary=imp_summary, productlist=productlist, fraction=fraction, the_product=the_product, year_of_growth=year_of_growth, pivot=pivot) elif the_product['tree_diff'] != 1 or the_product['has_data'] < 0: return str(the_product)
def implementation_create_from_conception(conception_id): """provides a form with prefilled conception values""" conception_data = conception_model.get_by_id(conception_id) fraction_id = conception_data['fraction_id'] product_id = conception_data['product_id'] year_of_growth = conception_data['year_of_growth'] fraction = FractionModel(fraction_id) the_product = ProductModel(product_id, fraction_id) productlist = fraction.cheata_menue() #implement list2nested!!! the_diversity = DiversityModel(product_id, fraction_id) cultivation = CultivationModel() growkind = GrowKindModel() seed = SeedModel() contacts = ContactsModel() form = VegetablesImplementationForm(request.form) #before validating choices must be given form.diversity_id.choices = the_diversity.get_wtform_choices() form.area_id.choices = fraction.area.get_wtform_choices() form.grow_kind_id.choices = growkind.get_wtform_choices() form.unit_of_seed.choices = seed.get_wtform_unit_choices() form.art_of_cultivation.choices = cultivation.get_wtform_choices() form.company_id.choices = contacts.get_wtform_choices() if form.validate_on_submit(): new_id = implementation_model.insert(form) print(">>>>>>>>> new_id: " + str(new_id)) if new_id: flash(u'Durchführung erfolgreich angelegt:#' + str(new_id), 'success') upd = conception_model.lock_entrie(conception_id) if upd == 1: flash(u'Planungseintrag archiviert', 'primary') return redirect( url_for('.implementation_by_product_id', fraction_id=fraction.fraction_id, year_of_growth=year_of_growth, product_id=the_product.product_id, pivot=new_id)) else: abort(500) #manualy poke form.field.data with conception_data #rule number one: NEVER map manualy #just data=conception_data form.conception_id.data = conception_data['id'] form.fraction_id.data = conception_data['fraction_id'] form.product_id.data = conception_data['product_id'] form.year_of_growth.data = conception_data['year_of_growth'] form.name.data = conception_data['name'] form.diversity_id.data = conception_data['diversity_id'] form.area_id.data = conception_data['area_id'] form.grow_kind_id.data = conception_data['grow_kind_id'] form.art_of_cultivation.data = conception_data['art_of_cultivation'] form.amount_of_grow_kind_units.data = conception_data[ 'amount_of_grow_kind_units'] form.hint.data = conception_data['hint'] form.amount_of_plants.data = conception_data['amount_of_plants'] form.planting_interval.data = conception_data['planting_interval'] form.length_of_field.data = conception_data['length_of_field'] form.square_of_field.data = conception_data['square_of_field'] form.plants_per_square.data = conception_data['plants_per_square'] return render_template('vegetables/implementation_input_form.html', form=form, fraction=fraction, productlist=productlist, the_product=the_product, the_diversity=the_diversity, year_of_growth=year_of_growth, conception_data=conception_data, flag='cfc')
def conception_edit(conception_id): """update an entrie by id""" #next = get_redirect_target() data = conception_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) cultivation = CultivationModel() growkind = GrowKindModel() seed = SeedModel() #area = AreaModel() productlist = fraction.cheata_menue() #implement list2nested!!! #productlist = fraction.get_product_list() the_product = product.get_data() the_diversity = diversity.get() summary = conception_model.get_summary_by_id(fraction_id, year_of_growth, product_id) #aside conceptions_micro = conception_model.get_micro_by_product_id( fraction_id, year_of_growth, product_id) form = VegetablesConceptionForm(request.form, data=data) #obj=data #before validating choices 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() form.art_of_cultivation.choices = cultivation.get_wtform_choices() form.unit_of_seed.choices = seed.get_wtform_unit_choices() #print('>>>>>>>>>>>>>diversity_ID:'+str(form.diversity_id.data)) if form.validate_on_submit(): next = get_redirect_target() check = conception_model.update(form, conception_id) if check == 1: flash(u'Erfolgreich geändert', 'success') if check == 0: flash(u'Nichts verändert', 'primary') #print('ValidOnSubmit>>>>>>>>>>>>>>>'+str(next)) #redirect to next here or default to here #TODO use redirect_back() if next: #redirect(next+'?pivot='+str(conception_id)) print('NExT conc_edit##>' + str(next)) return redirect(next) else: return redirect( url_for('.conception_by_product_id', fraction_id=fraction.fraction_id, year_of_growth=year_of_growth, product_id=product.product_id, pivot=conception_id)) next = get_redirect_target() if next == request.base_url: return redirect( url_for('.conception_by_product_id', fraction_id=fraction.fraction_id, year_of_growth=year_of_growth, product_id=product.product_id, pivot=conception_id)) else: #print('req.base_url'+str(request.base_url)) print('NExT before render conception_input_form:' + str(next)) return render_template('vegetables/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, conceptions_micro=conceptions_micro, edit=True, data=data, next=next)
def conception_new(fraction_id, year_of_growth, product_id): """create one new entrie for one product (fraction,year) and do an insert """ fraction = FractionModel(fraction_id) product = ProductModel(product_id, fraction_id) diversity = DiversityModel(product_id, fraction_id) cultivation = CultivationModel() growkind = GrowKindModel() seed = SeedModel() productlist = fraction.cheata_menue() #implement list2nested!!! #productlist = fraction.get_first_product_list() the_product = product.get_data() the_diversity = diversity.get() summary = conception_model.get_summary_by_id(fraction_id, year_of_growth, product_id) #aside conceptions_micro = conception_model.get_micro_by_product_id( fraction_id, year_of_growth, product_id) form = VegetablesConceptionForm(request.form) #before validating wtf choices (<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() form.art_of_cultivation.choices = cultivation.get_wtform_choices() form.unit_of_seed.choices = seed.get_wtform_unit_choices() if form.validate_on_submit(): new_id = conception_model.insert(form) #print(">>>>>>>>> new_id: "+ str(new_id)) if new_id: flash(u'Erfolgreich angelegt:#' + str(new_id), 'success') return redirect( url_for('.conception_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('vegetables/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, conceptions_micro=conceptions_micro, edit=False)