Ejemplo n.º 1
0
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)
Ejemplo n.º 2
0
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)
Ejemplo n.º 3
0
    def _get_games(*args):
        ptype = args[0]
        sport_type = 0
        page_n = 1

        if ptype == 'all' or ptype == 'old':
            page_n = args[1]
        elif ptype == 'sport':
            sport_type = args[1]
            page_n = args[2]

        with dbutils.dbopen() as db:
            count = len(
                games.get_recent(sport_type=sport_type,
                                 count=slice(0, 99999),
                                 old=ptype == 'old',
                                 dbconnection=db))  # TODO: REWORK
            total_pages = count // GAMES_PER_PAGE + (
                1 if count % GAMES_PER_PAGE != 0 else 0)
            if page_n > total_pages and count > 0:
                if not bottle.request.is_ajax:
                    raise bottle.HTTPError(404)
                else:
                    return {"stop": True, "games": list()}

            sports = sport_types.get(0, dbconnection=db)

            if not count:
                if not bottle.request.is_ajax:
                    return pages.PageBuilder("games",
                                             games=list(),
                                             sports=sports,
                                             bysport=sport_type,
                                             old=ptype == 'old',
                                             total_count=0)
                else:
                    return {"stop": True, "games": list()}

            allgames = games.get_recent(
                sport_type=sport_type,
                old=ptype == 'old',
                count=slice(*modules.pager(page_n, count=GAMES_PER_PAGE)),
                dbconnection=db)

            if not bottle.request.is_ajax:
                return pages.PageBuilder('games',
                                         games=allgames,
                                         sports=sports,
                                         total_count=count,
                                         bysport=sport_type,
                                         old=ptype == 'old')
            else:
                data = {"stop": page_n >= total_pages, "games": list()}
                page = pages.PageBuilder("game", tab_name="all")
                for game in allgames:
                    page.add_param("game", game)
                    game_tpl = page.template()
                    data["games"].append(game_tpl)
                return data
def add():
    with dbutils.dbopen() as 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('addcourt',
                                 sport_types=_sport_types,
                                 cities=_cities,
                                 court_types=_court_types)
Ejemplo n.º 5
0
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 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)
Ejemplo n.º 7
0
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)
Ejemplo n.º 8
0
    def _get_games(*args):
        ptype = args[0]
        sport_type = 0
        page_n = 1

        if ptype == 'all' or ptype == 'old':
            page_n = args[1]
        elif ptype == 'sport':
            sport_type = args[1]
            page_n = args[2]

        with dbutils.dbopen() as db:
            count = len(games.get_recent(sport_type=sport_type,
                                         count=slice(0, 99999),
                                         old=ptype == 'old',
                                         dbconnection=db))  # TODO: REWORK
            total_pages = count // GAMES_PER_PAGE + (1 if count % GAMES_PER_PAGE != 0 else 0)
            if page_n > total_pages and count>0:
                if not bottle.request.is_ajax:
                    raise bottle.HTTPError(404)
                else:
                    return {"stop": True, "games": list()}

            sports = sport_types.get(0, dbconnection=db)

            if not count:
                if not bottle.request.is_ajax:
                    return pages.PageBuilder("games", games=list(), sports=sports, bysport=sport_type,
                                             old=ptype == 'old', total_count=0)
                else:
                    return {"stop": True, "games": list()}

            allgames = games.get_recent(sport_type=sport_type, old=ptype == 'old',
                                        count=slice(*modules.pager(page_n, count=GAMES_PER_PAGE)), dbconnection=db)

            if not bottle.request.is_ajax:
                return pages.PageBuilder('games', games=allgames, sports=sports, total_count=count, bysport=sport_type, old=ptype == 'old')
            else:
                data = {"stop": page_n >= total_pages, "games": list()}
                page = pages.PageBuilder("game", tab_name="all")
                for game in allgames:
                    page.add_param("game", game)
                    game_tpl = page.template()
                    data["games"].append(game_tpl)
                return data
Ejemplo n.º 9
0
    def __init__(self, game_finances_list:list, db:dbutils.DBConnection):
        self.games = game_finances_list
        self.games_dict = {game.game_id():game for game in self.games}
        self.sports = {sport.sport_id():sport for sport in sport_types.get(0, dbconnection=db)}
        self.real_games = db.execute("SELECT * FROM games WHERE game_id IN ({})".format(
            ', '.join(list(map(str, self.games_dict.keys())))), dbutils.dbfields['games']) if len(self.games)>0 else list()
        self.real_games_dict = {game['game_id']:game for game in self.real_games}
        summ = lambda field: sum([getattr(game, field)() for game in self.games])

        self.ideal_income = summ('ideal_income')
        self.empty = summ('empty')
        self.lost_empty = summ('lost_empty')
        self.notvisited = summ('notvisited')
        self.lost_notvisited = summ('lost_notvisited')
        self.notpayed = summ('notpayed')
        self.lost_notpayed = summ('lost_notpayed')
        self.real_income = summ('real_income')
        self.rent_charges = summ('rent_charges')
        self.additional_charges = summ('additional_charges')
        self.profit = summ('profit')
        self.responsible_salary = summ('responsible_salary')
        self.real_profit = summ('real_profit')

        self.game_by_responsible = group(lambda x: x.responsible_user_id(), self.games)

        a = db.execute("SELECT * FROM responsible_games_salary WHERE game_id IN ({})".format(
            ', '.join([str(game.game_id()) for game in self.games])), dbutils.dbfields['responsible_games_salary']) if len(self.games)>0 else list()
        self.salary = group(lambda x: x['user_id'], a)
        self.users_get = users.get

        self.sport_games = group(lambda x: x.sport_id(), self.games)

        self.sport_money = dict()
        for sport_id in self.sport_games:
            self.sport_money[sport_id] = sum([game.real_profit() for game in self.sport_games[sport_id]])

        a = db.execute("SELECT * FROM finance_balance WHERE user_id!=0 AND YEAR(date)={} AND MONTH(date)={}".format(
            self.games[-1].datetime().date().year, self.games[0].datetime().date().month
        ), dbutils.dbfields['finance_balance']) if len(self.games)>0 else list()
        self.user_salary = {i['user_id']:i['value'] for i in a}
Ejemplo n.º 10
0
def groupadd():
    with dbutils.dbopen() as db:
        _sport_types = sport_types.get(0, dbconnection=db)
        return pages.PageBuilder('groupadd', sports=_sport_types)
Ejemplo n.º 11
0
def spam():
    with dbutils.dbopen() as db:
        _sport_types = sport_types.get(0, dbconnection=db)
        return pages.PageBuilder('spam', sports=_sport_types)
def groupadd():
    with dbutils.dbopen() as db:
        _sport_types = sport_types.get(0, dbconnection=db)
        return pages.PageBuilder('groupadd', sports=_sport_types)
def spam():
    with dbutils.dbopen() as db:
        _sport_types = sport_types.get(0, dbconnection=db)
        return pages.PageBuilder('spam', sports=_sport_types)
 def sport_type(sport_id: int, db: dbutils.DBConnection) -> dict:
     return sport_types.get(sport_id, dbconnection=db)._sport_type