def post_sync(self): # Parses the entered date and updates the model self.model.tournament_dt = datetime.datetime.strptime(self.formatted_tournament_dt.value, DT_FORMAT).date() # Reshuffles the tournaments so that they are still ordered by date Season.get(self.model.season_id).reorder_tournaments()
def save_conferences_and_divisions(): # conferences = Conference.objects.all().delete() # div = Division.objects.all().delete() conferences = Conference.objects.all() div = Division.objects.all() if not conferences: west_conference = Conference() west_conference.name = "West" west_conference.name_br = "Oeste" west_conference.save() east_conference = Conference() east_conference.name = "East" east_conference.name_br = "Leste" east_conference.save() southeast_division = Division() southeast_division.conference = east_conference southeast_division.name = "Southeast" southeast_division.name_br = "Sudeste" southeast_division.save() atlantic_division = Division() atlantic_division.conference = east_conference atlantic_division.name = "Atlantic" atlantic_division.name_br = "Atlantico" atlantic_division.save() central_division = Division() central_division.conference = east_conference central_division.name = "Central" central_division.name_br = "Centro" central_division.save() southwest_division = Division() southwest_division.conference = west_conference southwest_division.name = "Southwest" southwest_division.name_br = "Sudoeste" southwest_division.save() northwest_division = Division() northwest_division.conference = west_conference northwest_division.name = "Northwest" northwest_division.name_br = "Noroeste" northwest_division.save() pacific_division = Division() pacific_division.conference = west_conference pacific_division.name = "Pacific" pacific_division.name_br = "Pacífico" pacific_division.save() season = Season() season.year = "2017/18" season.save()
def add_show(id): zipped = requests.get("%s/%s/series/%s/all/en.zip" % (API_PATH, settings.TVDB_API_KEY, id)).content content = zipfile.ZipFile(BytesIO(zipped)).read("en.xml") xml = etree.fromstring(content) series = xml.find("Series") name = series.find("SeriesName").text banner = series.find("banner") if banner is None: banner = "" else: banner = banner.text status = series.find("Status").text first_aired = series.find("FirstAired") if first_aired is not None: first_aired = datetime.strptime(first_aired.text, "%Y-%m-%d") imdb = series.find("IMDB_ID") if imdb is None: imdb = "" else: imdb = imdb.text try: show = Show.objects.get(tvdbid=id) show.tvdbid = id show.name = name show.status = status show.banner = banner show.first_aired = first_aired show.imdb = imdb except Show.DoesNotExist: show = Show(tvdbid=id, name=name, status=status, banner=banner, first_aired=first_aired, imdb=imdb) show.save() for e in xml.findall("Episode"): season_number = e.find("SeasonNumber").text if season_number == "0": # Ignore specials for now continue try: season = Season.objects.get(show=show, number=season_number) except Season.DoesNotExist: season = Season(number=season_number, show=show) season.save() episode_number = e.find("EpisodeNumber").text first_aired = datetime.strptime(e.find("FirstAired").text, "%Y-%m-%d") try: episode = Episode.objects.get(number=episode_number, season=season) episode.air_date = first_aired except Episode.DoesNotExist: episode = Episode(number=episode_number, air_date=first_aired, season=season) episode.save() return show
def __init__(self, mapping, fvars): # Parent constructor web.application.__init__(self, mapping, fvars) #@UndefinedVariable # The views are bound once for all to the configuration config.views = web.template.render("app/views/", globals={ "all_seasons": lambda: Season.all(), "all_polls": lambda: Poll.all(), "webparts": webparts, "formatting": formatting, "dates": dates, "zip": zip, "getattr": getattr, "hasattr": hasattr, "class_name": lambda x: x.__class__.__name__, "namedtuple": collections.namedtuple, "config": config, "result_statuses": Result.STATUSES, "Events": Events }) # The ORM is bound once since it dynamically loads the engine from the configuration config.orm = meta.init_orm(lambda : config.engine) # Binds the hooking mechanism & the SQL Alchemy processor self.add_processor(web.loadhook(http.init_hooks)) self.add_processor(web.unloadhook(http.execute_hooks)) self.add_processor(http.sqlalchemy_processor) # Binds the webparts initialization mechanism self.add_processor(web.loadhook(webparts.init_webparts))
def __init__(self): # Grid initialization super(EditSeasonsGrid, self).__init__(Season, Season.all(order_by_clause=Season.start_year)) #@UndefinedVariable # Grid configuration inc = [ID_READONLY(self.id), START_YEAR(self.start_year), END_YEAR(self.end_year)] self.configure(include=inc)
def car(car_id): car = Car.query.get(car_id) last_season = Season.query.filter(Season.ended_at.isnot(None)).order_by( Season.ended_at.desc()).first() return render_template('car.html', title='Auto', car=car, last_season=last_season, current_season=Season.current())
def racers(): racers = Racer.query.all() last_season = Season.query.filter(Season.ended_at.isnot(None)).order_by( Season.ended_at.desc()).first() app.logger.info('got racers:' + repr(racers)) return render_template('racers.html', title='Fahrer', racers=racers, last_season=last_season, current_season=Season.current())
def f(value, field): # Step 1 : general format check with the standard library year = _generic_dt_validator(value, dt_format) # Step 2 : year check selected_season = Season.get(field.parent.season_id.value) allowed_years = (selected_season.start_year, selected_season.end_year) if not year in allowed_years: raise validators.ValidationError("Year should be %s" % " or ".join(map(str,allowed_years)))
def post_sync(self): # Parses the entered date and updates the model self.model.tournament_dt = datetime.datetime.strptime(self.formatted_tournament_dt.value, DT_FORMAT).date() # Appends the tournament in the end of the collection (i.e. in last position) # The tournament should be appended to the season and not just be added to the session : # see the collection_class used at the Season level to store tournaments season = Season.get(self.model.season_id) season.tournaments.append(self.model) # Reshuffles the tournaments so that they are still ordered by date season.reorder_tournaments()
def new_season(): form = SeasonForm() if form.validate_on_submit(): season = Season(description=form.description.data, started_at=form.started_at.data, ended_at=form.ended_at.data) db.session.add(season) db.session.commit() flash(_l('New season created')) return redirect(url_for('seasons')) return render_template('season_edit.html', title='Saison anlegen', form=form)
def GET(self, season_id): season = Season.get(int(season_id)) results = [] # Groups the results by user (works because the results are ordered) for _, iter_raw_results_by_player in groupby(season.raw_results, lambda r: r.tournament_id): results.append({ raw_result.user_id: raw_result.score for raw_result in iter_raw_results_by_player }) return { "players": {player.id: player.pseudonym for player in season.players}, "results": results }
def GET(self, season_id): season = Season.get(int(season_id)) results = [] # Groups the results by user (works because the results are ordered) for _, iter_raw_results_by_player in groupby( season.raw_results, lambda r: r.tournament_id): results.append({ raw_result.user_id: raw_result.score for raw_result in iter_raw_results_by_player }) return { "players": {player.id: player.pseudonym for player in season.players}, "results": results }
def GET(self, season_id): season = Season.get(int(season_id)) return config.views.layout( config.views.season(season, config.views.results(season)))
def season_edit(id): season = Season.query.filter_by(id=id).first() form = EditSeasonForm(season=season) all_seasons = Season.query.order_by(Season.start_date.desc()).all() if form.submit_new.data and form.validate(): new_season = Season(season_name=form.season_name.data, start_date=form.start_date.data, end_date=form.end_date.data, calendar_link=form.calendar_link.data) db.session.add(new_season) db.session.commit() for m in Match.query.all(): m.set_season() db.session.add(m) db.session.commit() for p in Player.query.all(): p.update_player_stats(season='all') flash('Season {} added and matches updated!'.format( new_season.season_name)) return redirect(url_for('main.season_edit')) if form.submit_edit.data and form.validate() and season is not None: season.season_name = form.season_name.data season.start_date = form.start_date.data season.end_date = form.end_date.data season.calendar_link = form.calendar_link.data db.session.add(season) db.session.commit() for m in Match.query.all(): m.set_season() db.session.add(m) db.session.commit() for p in Player.query.all(): p.update_player_stats(season='all') flash('Season {} updated!'.format(season.season_name)) return redirect(url_for('main.season_edit', id=season.id)) if form.submit_delete.data and season is not None: db.session.delete(season) db.session.commit() for m in Match.query.all(): m.set_season() db.session.add(m) db.session.commit() for p in Player.query.all(): p.update_player_stats(season='all') flash('Season {} deleted!'.format(season.season_name), 'danger') return redirect(url_for('main.season_edit')) if request.method == 'GET' and season is not None: form.load_season(season) return render_template('edit_season.html', title='Season Editor', form=form, season=season, all_seasons=all_seasons)
def test_all(self): all_seasons = Season.all() self.assertEqual(len(all_seasons), 2) # Checks the order by clause self.assertEqual(all_seasons[0].id, 2) self.assertEqual(all_seasons[1].id, 1)
def __init__(self): # FieldSet initialization super(NewTournamentFieldSet, self).__init__(Tournament) # Creation of a customized date field to edit the tournament's date self.append(create_date_field("formatted_tournament_dt", "tournament_dt", DT_FORMAT)) # FieldSet configuration season_options = [("Saison %s (%s - %s)" %(season.id, season.start_year, season.end_year), season.id) for season in Season.all()] inc = [SEASON(self.season, season_options), FORMATTED_DT(self.formatted_tournament_dt), BUYIN(self.buyin)] self.configure(include=inc)
def GET(self, season_id): season = Season.get(int(season_id)) return config.views.layout( config.views.season(season, config.views.results(season)) )
def quick_race(): if not race_handler.attach_quick_race(): flash(_l('No control unit connection!')) return render_template('quick_race.html', title='Quick Race', current_season=Season.current())