Beispiel #1
0
def school_form(school_id=INVALID_ID):
    if not session.get('program_id'):
        return redirect(url_for('program'))
    if school_id == INVALID_ID:
        id_of_school_being_added = DatabaseManager.id_of_school_being_added(FILL_STR_SCHOOL)
        if not id_of_school_being_added:
            new_school = School(nick=FILL_STR_SCHOOL, name=FILL_STR_SCHOOL,
                                address=FILL_STR_SCHOOL,
                                city=FILL_STR_SCHOOL, regon=FILL_STR_SCHOOL,
                                email=FILL_STR_SCHOOL, responsible_person=FILL_STR_SCHOOL + FILL_BY_SCHOOL,
                                phone=FILL_STR_SCHOOL + FILL_BY_SCHOOL)
            if DatabaseManager.add_row(new_school):
                return redirect(url_for('school_form', school_id=new_school.id, School=new_school))
            else:
                return redirect(url_for('school_form', school_id=INVALID_ID))
        else:
            return redirect(
                url_for('school_form', school_id=id_of_school_being_added.id, School=id_of_school_being_added))

    current_school = DatabaseManager.get_school(school_id)
    if request.method == 'POST':
        data_to_update = {"nick": empty_if_none(request.form["nick"]), "name": empty_if_none(request.form["name"]),
                          "address": empty_if_none(request.form["address"]),
                          "city": empty_if_none(request.form["city"]),
                          "nip": empty_if_none(request.form["nip"]), "regon": empty_if_none(request.form["regon"]),
                          "email": empty_if_none(request.form["email"]), "phone": empty_if_none(request.form["phone"]),
                          "responsible_person": empty_if_none(request.form["responsible_person"]),
                          "representative": empty_if_none(request.form["representative"]),
                          "representative_nip": empty_if_none(request.form["representative_nip"]),
                          "representative_regon": empty_if_none(request.form["representative_regon"])}
        school_id = DatabaseManager.update_school_data(current_school, **data_to_update)
        return redirect(url_for('school_form', school_id=current_school.id))
    return render_template("school_form.html", School=current_school,
                           Contracts=DatabaseManager.get_all_contracts(school_id, session.get('program_id')))
 def create_new(self):
     application_data = dict()
     application_data['summary_id'] = self.summary.id
     application_data['school_id'] = self.school.id
     application_data.update(self.product_data)
     application = Application(**application_data)
     return DatabaseManager.add_row(application)
 def create_new(self):
     number = SummaryCreator.get_next_number(self.program_id)
     summary = Summary(no=number,
                       year=SummaryCreator._get_current_year(),
                       program_id=self.program_id,
                       weeks=self.weeks)
     if DatabaseManager.add_row(summary):
         self.summary = DatabaseManager.get_summary(self.program_id, number)
    def create_new(self):
        record = Record(date=self.date,
                        state=RecordState.NOT_DELIVERED,
                        product_id=self.product.id,
                        contract_id=self.contract.id,
                        week_id=DatabaseManager.get_week_by_date(self.date).id,
                        generation_date=self.generation_date)

        return DatabaseManager.add_row(record)
 def create_new(self):
     annex = Contract(contract_no=self.contract_no,
                      contract_year=self.contract_year,
                      contract_date=self.contract_date,
                      validity_date=self.validity_date,
                      fruitVeg_products=self.fruitVeg_products,
                      dairy_products=self.dairy_products,
                      is_annex=True,
                      school_id=self.school.id,
                      program_id=self.program_id)
     return DatabaseManager.add_row(annex)
Beispiel #6
0
 def create_new(self):
     contract = Contract(contract_no=self.contract_no,
                         contract_year=self.contract_year,
                         contract_date=self.contract_date,
                         validity_date=self.contract_date,
                         fruitVeg_products=0,
                         dairy_products=0,
                         is_annex=False,
                         school_id=self.school.id,
                         program_id=self.program.id)
     return DatabaseManager.add_row(contract)
Beispiel #7
0
def program_form(program_id=INVALID_ID):
    config_parser.read(config_file)
    if program_id == INVALID_ID:
        id_of_program_being_added = DatabaseManager.id_of_program_being_added(FILL_STR)
        if not id_of_program_being_added:
            default_date = DateConverter.to_string(datetime.datetime.now())
            new_program = Program(semester_no=FILL_STR, school_year=FILL_STR, fruitVeg_price=FILL_STR,
                                  dairy_price=FILL_STR, start_date=DateConverter.to_date(default_date),
                                  end_date=DateConverter.to_date(default_date),
                                  dairy_min_per_week=FILL_STR, fruitVeg_min_per_week=FILL_STR, dairy_amount=FILL_STR,
                                  fruitVeg_amount=FILL_STR)
            if DatabaseManager.add_row(new_program):
                return redirect(url_for('program_form', program_id=new_program.id))
            else:
                return redirect(url_for('program_form', program_id=INVALID_ID))
        else:
            return redirect(url_for('program_form', program_id=id_of_program_being_added.id))

    current_program = DatabaseManager.get_program(program_id)
    school_without_summary = None
    summaries_data = None
    if is_current_program_set(current_program, config_parser):
        schools_with_contract = DatabaseManager.get_all_schools_with_contract(current_program.id)
        available_summary = get_current_summaries(current_program.id)
        summaries_data = dict()
        if not available_summary:
            school_without_summary = schools_with_contract
        else:
            school_without_summary = [school for school in schools_with_contract
                                      if not any(
                    [DatabaseManager.get_application(school.id, summary.id) for summary in available_summary])]
            summaries_data = {
                k: ", ".join(
                    [application.school.nick for application in DatabaseManager.get_school_with_summary(k.id) if
                     application.school])
                for k in available_summary}

    if request.method == 'POST':
        data_to_update = {"semester_no": empty_if_none(request.form["semester_no"]),
                          "school_year": empty_if_none(request.form["school_year"]),
                          "fruitVeg_price": empty_if_none(request.form["fruitVeg_price"]),
                          "dairy_price": empty_if_none(request.form["dairy_price"]),
                          "start_date": empty_if_none(DateConverter.to_date(request.form["start_date"])),
                          "end_date": empty_if_none(DateConverter.to_date(request.form["end_date"])),
                          "dairy_min_per_week": empty_if_none(request.form["dairy_min_per_week"]),
                          "fruitVeg_min_per_week": empty_if_none(request.form["fruitVeg_min_per_week"]),
                          "dairy_amount": empty_if_none(request.form["dairy_amount"]),
                          "fruitVeg_amount": empty_if_none(request.form["fruitVeg_amount"])}
        program_id = DatabaseManager.update_program_data(current_program, **data_to_update)
        return redirect(url_for('program_form', program_id=program_id))
    return render_template("program_form.html", Program=current_program, Schools=school_without_summary,
                           Summary=summaries_data)
Beispiel #8
0
def add_week(program_id):
    current_program = request.args.get('program')
    if not current_program:
        current_program = DatabaseManager.get_program(program_id)
    if request.method == 'POST':
        if not request.form['week_no'] or not request.form['start_date'] or not request.form['end_date']:
            flash('Uzupełnij wszystkie dane', 'error')
        else:
            new_week = Week(week_no=request.form['week_no'],
                            start_date=DateConverter.to_date(request.form['start_date']),
                            end_date=DateConverter.to_date(request.form['end_date']), program_id=current_program.id)
            if DatabaseManager.add_row(new_week):
                return redirect(url_for("program_form", program_id=current_program.id))
    return render_template("add_week.html", program_id=program_id, program=current_program)
Beispiel #9
0
def add_product(program_id, product_type):
    current_program = DatabaseManager.get_program(program_id)
    if request.method == 'POST':
        if not product_type:
            product_type = request.form['type']
            return redirect(url_for("add_product", program_id=current_program.id, product_type=product_type,
                                    program=current_program))
        if product_type:
            if not request.form['name'] or not request.form['min_amount']:
                flash('Uzupełnij nazwe i liczbe podań', 'error')
            else:
                new_product = Product(name=ProductName(int(request.form['name'])).name,
                                      type=ProductType(int(product_type)).name,
                                      min_amount=int(request.form['min_amount']), program_id=current_program.id)
                if DatabaseManager.add_row(new_product):
                    return redirect(url_for("program_form", program_id=current_program.id))
    return render_template("add_product.html", program_id=current_program.id, program=current_program,
                           product_type=product_type)