Пример #1
0
def acquire_twopack(fraction_id, source_fraction_id):
    #print('acquire_twopack'+str(fraction_id)+'/'+str(source_fraction_id))
    fraction = FractionModel(fraction_id)
    source_fraction = FractionModel(source_fraction_id)
    transactions = TransactionModel(fraction_id,source_fraction_id)
    
    #get all transactions for the actuall date
    if 'acquiredate' in session:
        #print('ACQIREacquiredateInSession:',(session.get('acquiredate')))
        trdata = transactions.get_simple(date=session.get('acquiredate'))
        #trdata = False
    else:
        trdata = False
    #get last inputs    
    history_entries = transactions.acqusitions_get_last_inserts(12)
        
    # track productgroup
    if request.args.get('productgroup',''):
        session['productgroup']= request.args.get('productgroup','')

    
    
    return render_template('transaction/acquisition.html',
                           fraction=fraction,
                           source_fraction=source_fraction,
                           history_entries=history_entries,
                           transactions= trdata)
Пример #2
0
def retract_twopack(fraction_id, source_fraction_id):
    """ two fractions are defined
    """
    if request.args.get('acquiredate'):
        session['acquiredate']= request.args.get('acquiredate')
        
    fraction = FractionModel(fraction_id)
    source_fraction = FractionModel(source_fraction_id)
    transaction_model = TransactionModel(fraction_id,source_fraction_id)
    

        #print('req.arg:'+request.args.get('acquiredate'))
    if 'acquiredate' in session:
        #print('RETRACTacquiredateInSession:',session.get('acquiredate'))
        transactions = transaction_model.get_simple(date=str(session.get('acquiredate')))
    else:
        transactions = None
        
    #print(str(transactions))  
    
    nav_dates = transaction_model.acqusitions_get_last_dates()
    
    return render_template('transaction/retraction.html',
                            fraction=fraction,
                            source_fraction=source_fraction,
                            nav_dates=nav_dates,
                            transactions=transactions
                            )
Пример #3
0
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')
Пример #4
0
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)
Пример #5
0
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)
Пример #6
0
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')
Пример #7
0
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)
Пример #8
0
def product(fraction_id, product_id):
    
    fraction = FractionModel(fraction_id)
    transactions = TransactionModel(fraction_id)
    
    return render_template('transtest.html',fraction=fraction,
                           transactions=transactions,
                           product_id=product_id)
Пример #9
0
def conception_implant(fraction_id, year_of_growth):
    fraction = FractionModel(fraction_id)
    entries = conception_model.implant(fraction_id, year_of_growth)

    return render_template('vegetables/conception_implant.html',
                           fraction=fraction,
                           year_of_growth=year_of_growth,
                           entries=entries)
Пример #10
0
def acquire_onepack(fraction_id):
    
    fraction = FractionModel(fraction_id)
    
    if request.args.get('productgroup',''):
        session['productgroup']= request.args.get('productgroup','')
    
    print(str('calling acquire_onepack'))
    return render_template('transaction/acquisition.html', fraction=fraction)
Пример #11
0
def conception_field(fraction_id, year_of_growth, area_id=None):
    """ demand on prepared soil per week"""
    fraction = FractionModel(fraction_id)
    entries = conception_model.conception_field(fraction_id, year_of_growth,
                                                area_id)

    return render_template('vegetables/conception_field.html',
                           fraction=fraction,
                           year_of_growth=year_of_growth,
                           entries=entries)
Пример #12
0
def conception_culture(fraction_id, year_of_growth):
    """Flächenbelegung/Kulturen auf Flächen """
    fraction = FractionModel(fraction_id)

    entries = conception_model.conception_culture(fraction_id, year_of_growth)

    return render_template('vegetables/conception_culture.html',
                           fraction=fraction,
                           year_of_growth=year_of_growth,
                           entries=entries)
Пример #13
0
def conception_create(fraction_id, year_of_growth):
    """creates a veggie Plan for a fraction at one year
    make the farmland right and hack manualy
    import a pre existing plan [1997] acording with croprotation and/or
    croprotate manualy....
    """

    fraction = FractionModel(fraction_id)

    return 'Begin planing on' + str(
        fraction.name) + ' anno ' + str(year_of_growth)
Пример #14
0
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)
Пример #15
0
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)
Пример #16
0
def conception_table_print(fraction_id, year_of_growth):
    """ Table of it all 
    for printing """

    fraction = FractionModel(fraction_id)
    entries = conception_model.ex_plan(fraction_id, year_of_growth)
    ts = conception_model.last_modified(fraction_id, year_of_growth)

    return render_template('vegetables/conception_plan_print.html',
                           entries=entries,
                           year_of_growth=year_of_growth,
                           fraction=fraction,
                           ts=ts)
Пример #17
0
def conception_table(fraction_id, year_of_growth):
    """ Table of it all """

    if request.values.get('pivot'):
        pivot = int(request.values.get('pivot'))  #or_test (trinity operator)
    else:
        pivot = 0

    fraction = FractionModel(fraction_id)
    entries = conception_model.ex_plan(fraction_id, year_of_growth)
    ts = conception_model.last_modified(fraction_id, year_of_growth)

    return render_template('vegetables/conception_plan.html',
                           entries=entries,
                           year_of_growth=year_of_growth,
                           fraction=fraction,
                           ts=ts,
                           pivot=pivot)
Пример #18
0
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)
Пример #19
0
def retract_getsome(fraction_id,source_fraction_id,product_id,unit_id):
    """Hit the retraction Table
    date is handled over session-cookie
    first get the entrie in the acquire data from that retour what you want
    we could restrict boxes ID  to acquire data but the user could retour in
    boxes of another date, years ago.
    """
    fraction = FractionModel(fraction_id)
    source_fraction = FractionModel(source_fraction_id)
    product = ProductModel(product_id, source_fraction_id)
    product_entries = product.get_data()
    unit = UnitModel(product_entries['unit_set_id'])
    box = BoxModel(product_entries['boxes_set_id'])
    vehicle = VehicleModel()
    transaction_model = TransactionModel(fraction_id,source_fraction_id)
    #Do I repeat myself?
    
    if request.args.get('acquiredate'):
        session['acquiredate']= request.args.get('acquiredate')
        
    if 'acquiredate' in session:
        the_date = str(session.get('acquiredate'))
    #
    acquire_data = transaction_model.acquisitions_get_summary_by_date_product_unit(the_date,product_id,unit_id)

    form = Acquisition_Retraction_Form()
    
    form.unit_id.choices = unit.get_wtform_choices()
    form.vehicle_id.choices = vehicle.get_wtform_choices()
    form.box_id.choices = box.get_wtform_choices()
    form.alternate_unit_id.choices = unit.get_wtform_choices()
    
    #prefill formdata
    form.aq_date.data = datetime.strptime(the_date,form.aq_date.format).date()
    form.product_id.data = product_id
    form.fraction_id.data = fraction_id
    form.source_fraction_id.data = source_fraction_id
    form.unit_id.data = acquire_data['unit_id']
    form.unit_id.render_kw={"disabled":"disabled"}
    
    form.box_id.data = acquire_data['box_id']
    #form.box_id.render_kw={"disabled":"disabled"}
    
    if acquire_data['alternatesum'] and acquire_data['alternate_unit_id'] in [item[0] for item in form.alternate_unit_id.choices] :
        form.alternate_unit_id.data = acquire_data['alternate_unit_id']
    else:
        form.alternate_unit_id.data = 1 #defaults to KG (Datenmüll)
    
    if form.validate_on_submit():
        
        result = transaction_model.retraction_insert(form)
        if type(result) is str:
            flash(result, 'alert')
        elif result:
            flash(u'Übernommen!','success')
            
            return redirect(url_for('.retract_twopack', fraction_id=fraction_id,
                                    source_fraction_id=source_fraction_id))
        else:
            abort(500)
            
    if form.csrf_token.errors:
        flash(u'Zeitüberschreitung. Das Formular wird nach einer Stunde warten ungültig. Nichts gespeichert. Gleich nochmal versuchen.','warning')
        
        
    return render_template('transaction/retraction.html',
                            fraction=fraction,
                            source_fraction=source_fraction,
                            product_entries=product_entries,
                            acquire_data=acquire_data,
                            form=form
                            )
Пример #20
0
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)
Пример #21
0
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')
Пример #22
0
def acquire_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)

    product = ProductModel(product_id, source_fraction_id)
    #dict of product spec data (one db row)
    product_entries = product.get_data()
    unit = UnitModel(product_entries['unit_set_id'])
    box = BoxModel(product_entries['boxes_set_id'])
    vehicle = VehicleModel()
    transactions = TransactionModel(fraction_id, source_fraction_id)
    #the latest entries in acquisitions table
    #TODO variable count
    history_entries = transactions.acqusitions_get_last_inserts(12)    
    
    form = Acquisition_Retraction_Form()
    #print('dateFORMAT:'+str(form.aq_date.format))
    #print('Session::acquiredate:'+str(session.get('acquiredate')))
    
        
        #form.aq_date.data = session.get('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'] = str(form.aq_date.data)
        
        #print('form-data:'+str(form.aq_date.data))
        #print('sessionACQUIREdate:'+str(session.get('acquiredate')))
        
        result = transactions.acqusition_insert(form)
        
        #print('>>>>>>>>>aqcuisition_insert_result: '+ str(result))
        if type(result) is str:
            flash(result, 'alert')
        elif result:
            flash(u'Die Angaben und Werte wurden erfolgreich übernommen und gespeichert.','success')
 
            return redirect(url_for('.acquire_getsome', fraction_id=fraction_id,
                     source_fraction_id=source_fraction_id,
                     product_id=product_id))
        else:
            abort(500)

    if form.csrf_token.errors:
        flash(u'Zeitüberschreitung. Das Formular wird nach einer Stunde warten ungültig. Nichts gespeichert. Gleich nochmal versuchen.','warning')
    
    #manualy set wtform.data initial_preselected
    if not form.is_submitted():
        #print("FORM SUBMIT!")
        if 'acquiredate' in session:
            set_date = datetime.strptime(session.get('acquiredate'),form.aq_date.format).date()
            form.aq_date.data = set_date
            
        form.fraction_id.data = fraction.fraction_id
        form.source_fraction_id.data = source_fraction.fraction_id
        form.product_id.data = product_entries['product_id']
        if  request.args.get('unit_id',''):
            #print('UNIT_ID!!!!'+str(request.args.get('unit_id',''))+str(type(request.args.get('unit_id',''))))
            if int(request.args.get('unit_id','')) in[item[0] for item in form.unit_id.choices]:
                form.unit_id.data=int(request.args.get('unit_id',''))
        else:
            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('transaction/acquisition.html',
                           fraction=fraction,
                           source_fraction=source_fraction,
                           product_entries=product_entries,
                           boxset=boxset,
                           history_entries=history_entries,
                           form=form)