Example #1
0
def write_future_notifications(user_id: int,
                               game_id: int,
                               dbconnection: dbutils.DBConnection = None):
    game = get_by_id(game_id, dbconnection=dbconnection)
    if not game.datetime.tommorow and not game.datetime.today:
        message = 'До игры "{}" осталось 2 дня!'.format(create_link.game(game))
        utils.spool_func(
            notificating.site.subscribed, user_id, message, 0, game_id,
            'TIMESTAMP("{}")-INTERVAL 2 DAY'.format(game.datetime))
    if not game.datetime.today:
        message = 'Завтра состоится игра "{}"<br>Не пропустите!'.format(
            create_link.game(game))
        utils.spool_func(
            notificating.site.subscribed, user_id, message, 0, game_id,
            'TIMESTAMP("{}")-INTERVAL 1 DAY'.format(game.datetime))
Example #2
0
def unsubscribe(user_id: int,
                game_id: int,
                dbconnection: dbutils.DBConnection = None):
    dbconnection.execute(
        "SELECT status FROM usergames WHERE user_id={} AND game_id={}".format(
            user_id, game_id))
    if len(dbconnection.last()) == 0:
        return
    status = dbconnection.last()[0][0]
    if status == 2 or status == 1:
        if status == 2:
            delete_future_notifications(user_id,
                                        game_id,
                                        dbconnection=dbconnection)
        usergames_unsubscribe(user_id, game_id, dbconnection=dbconnection)
    elif status == 0:
        return

    game = get_by_id(game_id, dbconnection=dbconnection)
    if game.reserved() > 0 and len(game.reserved_people()) > 0:
        for user_id in game.reserved_people():
            utils.spool_func(
                notificating.site.subscribed,
                user_id, 'В игре "{}" освободилось место!'.format(
                    create_link.game(game)), 1, game_id)
            utils.spool_func(notificating.mail.tpl.notify_reserved, game,
                             user_id)
def subscribe(game_id: int):
    with dbutils.dbopen() as db:
        user = current_user(db, detalized=True)
        game = games.get_by_id(game_id, dbconnection=db)
        if user.banned():
            raise Error.game_conflict(2)
        if 0 < game.capacity() == len(game.subscribed()):
            raise Error.game_conflict(4)
        if user.user_id() in set(game.subscribed()):
            raise Error.game_conflict(5)
        another_game = games.user_game_intersection(user.user_id(),
                                                    game,
                                                    dbconnection=db)
        if another_game:
            raise Error.game_conflict(1, another_game.game_id())
        games.subscribe(user.user_id(), game_id, dbconnection=db)
        if game.datetime.tommorow or game.datetime.today:
            user = users.get(user.user_id(), dbconnection=db) if user.user_id(
            ) != pages.auth.current().user_id() else pages.auth.current()
            message = 'На игру "{}" записался {}'.format(
                create_link.game(game), create_link.user(user))
            utils.spool_func(
                notificating.site.responsible,
                game.responsible_user_id(),
                message,
                1,
                game_id,
            )
        return {'status': 'ok'}
def admin_unsubscribe(game_id:int, user_id:int):
    resp = unsubscribe(user_id, game_id, suspress=True)
    if 'conflict' in resp:
        if bottle.request.is_ajax:
            return json.dumps({'error_code':resp.param('conflict')})
        return pages.templates.message('Ошибка', 'Конфликт: {}'.format(resp.param('conflict')))
    if bottle.request.is_ajax:
        return json.dumps({'error_code':0})
    game = games.get_by_id(game_id)
    notificating.site.subscribed(user_id, "Вы были отписаны от игры {}".format(create_link.game(game)), 1, game_id)
    raise bottle.redirect(pages.referer('/games/{}'.format(game_id)))
def admin_unsubscribe(game_id: int, user_id: int):
    resp = unsubscribe(user_id, game_id, suspress=True)
    if 'conflict' in resp:
        if bottle.request.is_ajax:
            return json.dumps({'error_code': resp.param('conflict')})
        return pages.templates.message(
            'Ошибка', 'Конфликт: {}'.format(resp.param('conflict')))
    if bottle.request.is_ajax:
        return json.dumps({'error_code': 0})
    game = games.get_by_id(game_id)
    notificating.site.subscribed(
        user_id, "Вы были отписаны от игры {}".format(create_link.game(game)),
        1, game_id)
    raise bottle.redirect(pages.referer('/games/{}'.format(game_id)))
def unsubscribe(user_id:int, game_id:int, suspress:bool=False):
    with dbutils.dbopen() as db:
        game = games.get_by_id(game_id, dbconnection=db)
        if game.datetime.passed: raise bottle.HTTPError(404)
        if user_id not in set(game.subscribed()):
            return pages.PageBuilder("game", game=game, conflict=6)
        if not suspress and game.datetime.tommorow and game.datetime.time().hour<=12 and datetime.datetime.now().hour>=20:
            return pages.PageBuilder("game", game=game, conflict=11)
        games.unsubscribe(user_id, game_id, dbconnection=db)
        if datetime.datetime.now()-game.datetime()<datetime.timedelta(days=3):
            user = users.get(user_id, dbconnection=db) if user_id!=pages.auth.current().user_id() else pages.auth.current()
            message = '{} отписался от игры "{}"'.format(create_link.user(user), create_link.game(game))
            utils.spool_func(notificating.site.responsible, game.responsible_user_id(), message, 1, game_id)
        game = games.get_by_id(game_id, dbconnection=db)
        return pages.PageBuilder("game", game=game)
def unsubscribe(game_id: int):
    with dbutils.dbopen() as db:
        user = current_user(db, detalized=True)
        game = games.get_by_id(game_id, dbconnection=db)
        if user.user_id() not in set(game.subscribed()):
            return pages.PageBuilder("game", game=game, conflict=6)
        if game.datetime.tommorow and game.datetime.time(
        ).hour <= 12 and datetime.datetime.now().hour >= 20:
            return pages.PageBuilder("game", game=game, conflict=11)
        games.unsubscribe(user.user_id(), game_id, dbconnection=db)
        if datetime.datetime.now() - game.datetime() < datetime.timedelta(
                days=3):
            user = users.get(user.user_id(), dbconnection=db) if user.user_id(
            ) != pages.auth.current().user_id() else pages.auth.current()
            message = '{} отписался от игры "{}"'.format(
                create_link.user(user), create_link.game(game))
            utils.spool_func(notificating.site.responsible,
                             game.responsible_user_id(), message, 1, game_id)
        return {'status': 'ok'}
def unsubscribe(user_id: int, game_id: int, suspress: bool = False):
    with dbutils.dbopen() as db:
        game = games.get_by_id(game_id, dbconnection=db)
        if game.datetime.passed: raise bottle.HTTPError(404)
        if user_id not in set(game.subscribed()):
            return pages.PageBuilder("game", game=game, conflict=6)
        if not suspress and game.datetime.tommorow and game.datetime.time(
        ).hour <= 12 and datetime.datetime.now().hour >= 20:
            return pages.PageBuilder("game", game=game, conflict=11)
        games.unsubscribe(user_id, game_id, dbconnection=db)
        if datetime.datetime.now() - game.datetime() < datetime.timedelta(
                days=3):
            user = users.get(user_id,
                             dbconnection=db) if user_id != pages.auth.current(
                             ).user_id() else pages.auth.current()
            message = '{} отписался от игры "{}"'.format(
                create_link.user(user), create_link.game(game))
            utils.spool_func(notificating.site.responsible,
                             game.responsible_user_id(), message, 1, game_id)
        game = games.get_by_id(game_id, dbconnection=db)
        return pages.PageBuilder("game", game=game)
def subscribe(user_id:int, game_id:int):
    with dbutils.dbopen() as db:
        game = games.get_by_id(game_id, dbconnection=db)
        if game.datetime.passed: raise bottle.HTTPError(404)
        if pages.auth.current().banned():
            return pages.PageBuilder("game", game=game, conflict=2)
        #if not pages.auth.current().activated():
        #    return pages.PageBuilder("game", game=game, conflict=3)
        if game.capacity() > 0 and len(game.subscribed()) == game.capacity():
            return pages.PageBuilder("game", game=game, conflict=4)
        if user_id in set(game.subscribed()):
            return pages.PageBuilder("game", game=game, conflict=5)
        another_game = games.user_game_intersection(user_id, game, dbconnection=db)
        if another_game:
            return pages.PageBuilder("game", game=game, conflict=1, conflict_data=another_game)
        games.subscribe(user_id, game_id, dbconnection=db)
        if game.datetime.tommorow or game.datetime.today:
            user = users.get(user_id, dbconnection=db) if user_id!=pages.auth.current().user_id() else pages.auth.current()
            message = 'На игру "{}" записался {}'.format(create_link.game(game), create_link.user(user))
            utils.spool_func(notificating.site.responsible, game.responsible_user_id(), message, 1, game_id,)
        game = games.get_by_id(game_id, dbconnection=db)
        return pages.PageBuilder("game", game=game)
def subscribe(user_id: int, game_id: int):
    with dbutils.dbopen() as db:
        game = games.get_by_id(game_id, dbconnection=db)
        if game.datetime.passed: raise bottle.HTTPError(404)
        if pages.auth.current().banned():
            return pages.PageBuilder("game", game=game, conflict=2)
        #if not pages.auth.current().activated():
        #    return pages.PageBuilder("game", game=game, conflict=3)
        if game.capacity() > 0 and len(game.subscribed()) == game.capacity():
            return pages.PageBuilder("game", game=game, conflict=4)
        if user_id in set(game.subscribed()):
            return pages.PageBuilder("game", game=game, conflict=5)
        another_game = games.user_game_intersection(user_id,
                                                    game,
                                                    dbconnection=db)
        if another_game:
            return pages.PageBuilder("game",
                                     game=game,
                                     conflict=1,
                                     conflict_data=another_game)
        games.subscribe(user_id, game_id, dbconnection=db)
        if game.datetime.tommorow or game.datetime.today:
            user = users.get(user_id,
                             dbconnection=db) if user_id != pages.auth.current(
                             ).user_id() else pages.auth.current()
            message = 'На игру "{}" записался {}'.format(
                create_link.game(game), create_link.user(user))
            utils.spool_func(
                notificating.site.responsible,
                game.responsible_user_id(),
                message,
                1,
                game_id,
            )
        game = games.get_by_id(game_id, dbconnection=db)
        return pages.PageBuilder("game", game=game)