コード例 #1
0
 def create(self):
     application = DatabaseManager.get_application(self.school.id,
                                                   self.summary.id)
     if len(application) > 1:
         app.logger.error(
             "Application serious error: should never be returned more than one item in this list"
         )
         return False
     if not application:
         self.summary.set_number_of_weeks(
             self.common_data.get_week_numbers())
         if self.create_new():
             app.logger.info(
                 "Application for summary {0}/{1} for school {2} added".
                 format(self.summary.no, self.summary.year,
                        self.school.nick))
             self.__increase_in_summary()
         return True
     else:
         if DatabaseManager.remove_application(application[0].id):
             app.logger.info(
                 "Application {3} for summary {0}/{1} for school {2} removed"
                 .format(self.summary.no, self.summary.year,
                         self.school.nick, application[0].id))
         return self.create()
コード例 #2
0
ファイル: views.py プロジェクト: mariakoszula/ryko-manager
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)