Exemple #1
0
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)
Exemple #2
0
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)
Exemple #3
0
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)
Exemple #4
0
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)
Exemple #5
0
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)
Exemple #6
0
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)