Commit fa86be39133a5298d8a12a699969b36117bd83fc

Authored by hitier
1 parent 74494ea1

Enhance error catching in feed_periods

Showing 1 changed file with 9 additions and 4 deletions   Show diff stats
app/commands/commands.py
... ... @@ -88,14 +88,19 @@ def feed_from_lesia():
88 88  
89 89  
90 90 @bp.cli.command("feed_periods")
91   -def feed_periods():
92   - """ Fill in the periods name in the database. """
93   - for y in range(2014, 2023):
  91 +@click.option('--begin-year', '-b', 'begin_year', default=2005, help="the start year to begin periods with")
  92 +@click.option('--end-year', '-e', 'end_year', default=2025, help="the last year to end periods with")
  93 +def feed_periods(begin_year, end_year):
  94 + """ Fill in the periods names in the database. """
  95 + for y in range(begin_year, end_year):
94 96 for s in ['S1', 'S2']:
95 97 period_name = "{}_{}".format(y, s)
96 98 p = Period(name=period_name)
97 99 db.session.add(p)
98   - db.session.commit()
  100 + try:
  101 + db.session.commit()
  102 + except IntegrityError:
  103 + current_app.logger.error("Periods already exist")
99 104  
100 105  
101 106 @bp.cli.command("feed_random_charges")
... ...