def edit(game_id: int): with dbutils.dbopen() as db: game = games.get_by_id(game_id, dbconnection=db) if len(game) == 0: raise bottle.HTTPError(404) if pages.auth.current().user_id() != game.created_by() and \ pages.auth.current().user_id() != game.responsible_user_id() and \ not pages.auth.current().userlevel.admin(): return pages.templates.permission_denied() _sport_types = sport_types.get(0, dbconnection=db) _game_types = game_types.get(0, dbconnection=db) _cities = cities.get(0, dbconnection=db) _courts = courts.get(0, dbconnection=db) responsibles = users.get(0, 2, dbconnection=db) unsubscribed = games.get_unsubscribed_users(game_id, dbconnection=db) unsubscribed_list = list() db.execute( "SELECT * FROM users WHERE user_id IN (SELECT DISTINCT user_id FROM reports WHERE user_id!=0 AND status=2 AND game_id IN (SELECT game_id FROM games WHERE deleted=0 AND datetime+INTERVAL duration MINUTE < NOW() AND court_id='{}' AND sport_type='{}' AND game_type='{}'))" .format( # as long as my dick game.court_id(), game.sport_type(), game.game_type()), dbutils.dbfields['users']) last_users = list(map(lambda x: User(x, db), db.last())) for i in unsubscribed: user = users.get(i[0], dbconnection=db) dt = i[1] unsubscribed_list.append((user, dt)) return pages.PageBuilder('editgame', game=game, sports=_sport_types, game_types=_game_types, cities=_cities, courts=_courts, responsibles=responsibles, unsubscribed=unsubscribed_list, last_users=last_users)
def edit(game_id:int): with dbutils.dbopen() as db: game = games.get_by_id(game_id, dbconnection=db) if len(game) == 0: raise bottle.HTTPError(404) if pages.auth.current().user_id() != game.created_by() and \ pages.auth.current().user_id() != game.responsible_user_id() and \ not pages.auth.current().userlevel.admin(): return pages.templates.permission_denied() _sport_types = sport_types.get(0, dbconnection=db) _game_types = game_types.get(0, dbconnection=db) _cities = cities.get(0, dbconnection=db) _courts = courts.get(0, dbconnection=db) responsibles = users.get(0, 2, dbconnection=db) unsubscribed = games.get_unsubscribed_users(game_id, dbconnection=db) unsubscribed_list = list() db.execute("SELECT * FROM users WHERE user_id IN (SELECT DISTINCT user_id FROM reports WHERE user_id!=0 AND status=2 AND game_id IN (SELECT game_id FROM games WHERE deleted=0 AND datetime+INTERVAL duration MINUTE < NOW() AND court_id='{}' AND sport_type='{}' AND game_type='{}'))".format( # as long as my dick game.court_id(), game.sport_type(), game.game_type()), dbutils.dbfields['users']) last_users = list(map(lambda x: User(x, db), db.last())) for i in unsubscribed: user = users.get(i[0], dbconnection=db) dt = i[1] unsubscribed_list.append((user, dt)) return pages.PageBuilder('editgame', game=game, sports=_sport_types, game_types=_game_types, cities=_cities, courts=_courts, responsibles=responsibles, unsubscribed=unsubscribed_list, last_users=last_users)
def add(): with dbutils.dbopen() as db: _sports = sport_types.get(0, dbconnection=db) _game_types = game_types.get(0, dbconnection=db) _cities = cities.get(0, dbconnection=db) _courts = courts.get(0, dbconnection=db) responsibles = users.get(0, 2, dbconnection=db) return pages.PageBuilder("addgame", sports=_sports, game_types=_game_types, cities=_cities, courts=_courts, responsibles=responsibles)
def court(court_id: int, db: dbutils.DBConnection) -> dict: court = courts.get(court_id, dbconnection=db) if len(court) == 0: return None court_dict = court._court.copy() keys = set(court_dict.keys()) keys.difference_update(_available_fields['courts_get']['restricted']) court_dict = {key: court_dict[key] for key in keys} formatters.court(court_dict, db) return court_dict
def edit(court_id: int): with dbutils.dbopen() as db: court = courts.get(court_id, dbconnection=db) _sport_types = sport_types.get(0, dbconnection=db) _cities = cities.get(0, dbconnection=db) _court_types = court_types.get(0, dbconnection=db) return pages.PageBuilder('editcourt', sport_types=_sport_types, cities=_cities, court=court, court_types=_court_types)
def get_by_id(court_id: int): with dbutils.dbopen() as db: court = courts.get(court_id, dbconnection=db) if not court: raise bottle.HTTPError(404) return pages.PageBuilder('courts', court=court)
def get_courts_map(): with dbutils.dbopen() as db: city = cities.get(1, dbconnection=db) courts_list = courts.get(0, city_id=city.city_id(), dbconnection=db) _games = games.get_recent(dbconnection=db) colors = [ 'redPoint', 'greenPoint', 'bluePoint', 'yellowPoint', 'orangePoint', 'darkbluePoint', 'greyPoint', 'whitePoint', 'lightbluePoint' ] court_games = { court.court_id(): list(filter(lambda x: x.court_id() == court.court_id(), _games)) for court in courts_list } _sport_types = { sport_type.title(): sport_type for court in courts_list for sport_type in court.sport_types(True) } group_string = 'createGroup("{title}", [{courts}], "default#{color}")' court_string = 'createPlacemark(new YMaps.GeoPoint({geopoint}), "{title} <br> {address}", "<a href=\'/courts/{court_id}\' target=\'_blank\'>Подробнее...</a>")' games_string = '<br><br>Ближайшие игры:' game_string = '<br>{n}. <a href=\'/games/{game_id}\' target=\'_blank\'>{datetime} | {sport_type} - {game_type}</a>' def create_group(courts: list, color_n: int, name: str) -> str: court_strings = [] for court in courts: court_string_f = court_string.format( geopoint=court.geopoint(), title='\\"'.join(court.title().split('"')), address=','.join(court.address().split(',')[-3:]), court_id=court.court_id()) if len(court_games[court.court_id()]) > 0: court_string_f = court_string_f[:-2] + games_string for n, game in enumerate(court_games[court.court_id()], 1): court_string_f += game_string.format( datetime=game.datetime.beautiful, sport_type=game.sport_type(True).title(), game_type=game.game_type(True).title(), game_id=game.game_id(), n=n) court_string_f += '")' court_string_f = court_string_f[:-1] court_string_f += ',' + ('false', 'true')[len( list( filter(lambda x: x.sport_type(True).title() == name, court_games[court.court_id()]) ) if name != 'Все' else court_games[court.court_id()]) > 0] dic = { game.sport_type(): game.sport_type(True).title() for game in court_games[court.court_id()] } court_string_f += ', [{}]'.format(','.join([ '[{}, "{}"]'.format(sport_type_id, dic[sport_type_id]) for sport_type_id in dic ])) court_string_f += ')' court_strings.append(court_string_f) return group_string.format(title=name, courts=','.join(court_strings), color=colors[color_n]) groups = [create_group(courts_list, -1, 'Все')] for n, sport_type_title in enumerate(_sport_types): sport_type = _sport_types[sport_type_title] court_list = [ court for court in courts_list if sport_type.title() in {sport_type.title() for sport_type in court.sport_types(True)} ] groups.append(create_group(court_list, n, sport_type_title)) return pages.PageBuilder('courtsmap', groups=groups, city=city)