def ban(user_id: int, reason: str, dbconnection: dbutils.DBConnection = None):
    if banned(user_id, dbconnection=dbconnection):
        raise ValueError("User already banned")
    dbconnection.execute(
        "INSERT INTO banned (user_id, reason) VALUES (user_id, '{}')".format(
            user_id, reason))
    cacher.drop_by_table_name('banned', 'user_id', user_id)
示例#2
0
def edit_post():
    params = {i: bottle.request.forms.get(i) for i in bottle.request.forms}
    city_title = params['city']
    params.pop('city')
    if 'ampluas[]' in params:
        params.pop('ampluas[]')
        params['ampluas'] = bottle.request.forms.getall('ampluas[]')
        params['ampluas'] = '|' + '|'.join(params['ampluas']) + '|'
    else:
        params['ampluas'] = ''
    if 'avatar' in params:
        if isinstance(params['avatar'], str):
            images.delete_avatar(pages.auth.current().user_id())
        params.pop('avatar')
    elif 'avatar' in bottle.request.files:
        images.save_avatar(pages.auth.current().user_id(),
                           bottle.request.files.get('avatar'))
    with dbutils.dbopen() as db:
        db.execute(
            "SELECT city_id FROM cities WHERE title='{}'".format(city_title))
        if len(db.last()) > 0:
            params['city_id'] = db.last()[0][0]
        else:
            params['city_id'] = 1
        sql = "UPDATE users SET {} WHERE user_id={}".format(
            ', '.join(['{}="{}"'.format(i, params[i]) for i in params]),
            pages.auth.current().user_id())
        db.execute(sql)
    cacher.drop_by_table_name('users', 'user_id',
                              pages.auth.current().user_id())
    raise bottle.redirect('/profile')
def edit_post():
    params = {i: bottle.request.forms.get(i) for i in bottle.request.forms}
    city_title = params['city']
    params.pop('city')
    if 'ampluas[]' in params:
        params.pop('ampluas[]')
        params['ampluas'] = bottle.request.forms.getall('ampluas[]')
        params['ampluas'] = '|' + '|'.join(params['ampluas']) + '|'
    else:
        params['ampluas'] = ''
    if 'avatar' in params:
        if isinstance(params['avatar'], str):
            images.delete_avatar(pages.auth.current().user_id())
        params.pop('avatar')
    elif 'avatar' in bottle.request.files:
        images.save_avatar(pages.auth.current().user_id(), bottle.request.files.get('avatar'))
    with dbutils.dbopen() as db:
        db.execute("SELECT city_id FROM cities WHERE title='{}'".format(city_title))
        if len(db.last()) > 0:
            params['city_id'] = db.last()[0][0]
        else:
            params['city_id'] = 1
        sql = "UPDATE users SET {} WHERE user_id={}".format(
            ', '.join(['{}="{}"'.format(i, params[i]) for i in params]),
            pages.auth.current().user_id())
        db.execute(sql)
    cacher.drop_by_table_name('users', 'user_id', pages.auth.current().user_id())
    raise bottle.redirect('/profile')
示例#4
0
def remove_friend(user_id: int,
                  friend_id: int,
                  dbconnection: dbutils.DBConnection = None):
    if not are_friends(user_id, friend_id, dbconnection=dbconnection):
        raise ValueError("User <{}> do not have friend <{}>".format(
            user_id, friend_id))
    dbconnection.execute(
        "DELETE FROM friends WHERE user_id1={} AND user_id2={}".format(
            user_id, friend_id))
    cacher.drop_by_table_name('friends', 'user_id', user_id)
示例#5
0
def add_friend(user_id: int,
               friend_id: int,
               dbconnection: dbutils.DBConnection = None):
    if are_friends(user_id, friend_id, dbconnection=dbconnection):
        raise ValueError("User <{}> already have friend <{}>".format(
            user_id, friend_id))
    dbconnection.execute(
        "INSERT INTO friends (user_id1, user_id2) VALUES ({},{})".format(
            user_id, friend_id))
    cacher.drop_by_table_name('friends', 'user_id', user_id)
def edit_post(court_id: int):
    params = {i: bottle.request.forms.get(i) for i in bottle.request.forms}
    params.pop('submit_edit')
    if 'photo' in params:
        params.pop('photo')
    params['sport_types'] = ','.join(bottle.request.forms.getall('sport_type'))
    params.pop('sport_type')
    params['phone'] = params['phone'] if params['phone'] else 'Не указан'
    sql = 'UPDATE courts SET {} WHERE court_id={}'.format(
        ', '.join(["{}='{}'".format(i, params[i]) for i in params]), court_id)
    with dbutils.dbopen() as db:
        db.execute(sql)
    if 'photo' in bottle.request.files:
        images.save_court_photo(court_id, bottle.request.files.get('photo'))
    cacher.drop_by_table_name('courts', 'court_id', court_id)
    raise bottle.redirect('/courts/{}'.format(court_id))
示例#7
0
def usergames_set(user_id: int,
                  game_id: int,
                  status: int,
                  dbconnection: dbutils.DBConnection = None):
    dbconnection.execute(
        "SELECT COUNT(*) FROM usergames WHERE user_id={} AND game_id={}".
        format(user_id, game_id))
    if dbconnection.last()[0][0] == 0:
        sql = "INSERT INTO usergames (user_id, game_id, status) VALUES ({}, {}, {})".format(
            user_id, game_id, status)
    else:
        sql = "UPDATE usergames SET status={} WHERE user_id={} AND game_id={}".format(
            status, user_id, game_id)
    dbconnection.execute(sql)
    games_cache.drop(game_id)
    cacher.drop_by_table_name('usergames', 'game_id', game_id)
示例#8
0
def post(game_id:int):
    game = games.get_by_id(game_id)
    if game.created_by() != pages.auth.current().user_id() and game.responsible_user_id() != pages.auth.current().user_id() and not pages.auth.current().userlevel.admin():
        return pages.templates.permission_denied()
    if game.reported() or game.deleted(): return pages.templates.message('Чё', 'Эээ')
    users_ = {int(user_id.split('=')[-1]): {"status": bottle.request.forms.get(user_id)} for user_id in
              filter(lambda x: x.startswith("status"), bottle.request.forms)}
    registered = {user_id: users_[user_id] for user_id in filter(lambda x: x > 0, users_)}
    unregistered = {user_id: users_[user_id] for user_id in filter(lambda x: x < 0, users_)}
    for user_id in unregistered:
        info = {key.split('=')[0]: bottle.request.forms.get(key) for key in
                filter(lambda x: x.endswith(str(user_id)), bottle.request.forms)}
        unregistered[user_id] = info
    report = dict()
    report['registered'] = {'count': len(registered), 'users': registered}
    report['unregistered'] = {'count': len(unregistered), 'users': unregistered}
    report['additional_charges'] = {int(i.split('=')[1]):(bottle.request.forms.get(i), bottle.request.forms.get('amount'+i.split('=')[1])) for i in filter(lambda x: x.startswith('description'), bottle.request.forms)}
    with dbutils.dbopen() as db:
        for user_id in report['unregistered']['users']:
            user = report['unregistered']['users'][user_id]
            name = user['first_name'].strip()+' '+user['last_name'].strip()
            reports.report_unregistered(game_id, user['status'], name, user['phone'], dbconnection=db)
        for user_id in report['registered']['users']:
            user = report['registered']['users'][user_id]
            status = user['status']
            reports.report(game_id, user_id, status, dbconnection=db)
        for n in report['additional_charges']:
            reports.report_additional_charges(game_id, *report['additional_charges'][n], dbconnection=db)
    if "photo" in bottle.request.files:
        images.save_report(game_id, bottle.request.files.get("photo"))
    if pages.auth.current().user_id() != game.created_by():
        notificating.site.responsible(game.created_by(), 'Ответственный "{}" отправил отчет по игре "{}"'.format(
            modules.create_link.user(users.get(pages.auth.current().user_id())),
            modules.create_link.game(game)), game_id)
    finances.add_game_finances(game_id, dbconnection=db)
    cacher.drop_by_table_name('games', 'game_id', game_id)
    raise bottle.redirect('/games/report/{}?ask_autocreate'.format(game_id))
def register(email:str, dbconnection:dbutils.DBConnection=None):
    dbconnection.execute("UPDATE activation SET activated=2 WHERE email='{}'".format(email))
    cacher.drop_by_table_name('activation', 'email', email)
示例#10
0
def remove_friend(user_id:int, friend_id:int, dbconnection:dbutils.DBConnection=None):
    if not are_friends(user_id, friend_id, dbconnection=dbconnection):
        raise ValueError("User <{}> do not have friend <{}>".format(user_id, friend_id))
    dbconnection.execute("DELETE FROM friends WHERE user_id1={} AND user_id2={}".format(user_id, friend_id))
    cacher.drop_by_table_name('friends', 'user_id', user_id)
示例#11
0
def add_friend(user_id:int, friend_id:int, dbconnection:dbutils.DBConnection=None):
    if are_friends(user_id, friend_id, dbconnection=dbconnection):
        raise ValueError("User <{}> already have friend <{}>".format(user_id, friend_id))
    dbconnection.execute("INSERT INTO friends (user_id1, user_id2) VALUES ({},{})".format(user_id, friend_id))
    cacher.drop_by_table_name('friends', 'user_id', user_id)
示例#12
0
def post(game_id: int):
    game = games.get_by_id(game_id)
    if game.created_by() != pages.auth.current(
    ).user_id() and game.responsible_user_id() != pages.auth.current().user_id(
    ) and not pages.auth.current().userlevel.admin():
        return pages.templates.permission_denied()
    if game.reported() or game.deleted():
        return pages.templates.message('Чё', 'Эээ')
    users_ = {
        int(user_id.split('=')[-1]): {
            "status": bottle.request.forms.get(user_id)
        }
        for user_id in filter(lambda x: x.startswith("status"),
                              bottle.request.forms)
    }
    registered = {
        user_id: users_[user_id]
        for user_id in filter(lambda x: x > 0, users_)
    }
    unregistered = {
        user_id: users_[user_id]
        for user_id in filter(lambda x: x < 0, users_)
    }
    for user_id in unregistered:
        info = {
            key.split('=')[0]: bottle.request.forms.get(key)
            for key in filter(lambda x: x.endswith(str(user_id)),
                              bottle.request.forms)
        }
        unregistered[user_id] = info
    report = dict()
    report['registered'] = {'count': len(registered), 'users': registered}
    report['unregistered'] = {
        'count': len(unregistered),
        'users': unregistered
    }
    report['additional_charges'] = {
        int(i.split('=')[1]):
        (bottle.request.forms.get(i),
         bottle.request.forms.get('amount' + i.split('=')[1]))
        for i in filter(lambda x: x.startswith('description'),
                        bottle.request.forms)
    }
    with dbutils.dbopen() as db:
        for user_id in report['unregistered']['users']:
            user = report['unregistered']['users'][user_id]
            name = user['first_name'].strip() + ' ' + user['last_name'].strip()
            reports.report_unregistered(game_id,
                                        user['status'],
                                        name,
                                        user['phone'],
                                        dbconnection=db)
        for user_id in report['registered']['users']:
            user = report['registered']['users'][user_id]
            status = user['status']
            reports.report(game_id, user_id, status, dbconnection=db)
        for n in report['additional_charges']:
            reports.report_additional_charges(game_id,
                                              *report['additional_charges'][n],
                                              dbconnection=db)
    if "photo" in bottle.request.files:
        images.save_report(game_id, bottle.request.files.get("photo"))
    if pages.auth.current().user_id() != game.created_by():
        notificating.site.responsible(
            game.created_by(),
            'Ответственный "{}" отправил отчет по игре "{}"'.format(
                modules.create_link.user(
                    users.get(pages.auth.current().user_id())),
                modules.create_link.game(game)), game_id)
    finances.add_game_finances(game_id, dbconnection=db)
    cacher.drop_by_table_name('games', 'game_id', game_id)
    raise bottle.redirect('/games/report/{}?ask_autocreate'.format(game_id))
def register(email: str, dbconnection: dbutils.DBConnection = None):
    dbconnection.execute(
        "UPDATE activation SET activated=2 WHERE email='{}'".format(email))
    cacher.drop_by_table_name('activation', 'email', email)
示例#14
0
def ban(user_id:int, reason:str, dbconnection:dbutils.DBConnection=None):
    if banned(user_id, dbconnection=dbconnection):
        raise ValueError("User already banned")
    dbconnection.execute("INSERT INTO banned (user_id, reason) VALUES (user_id, '{}')".format(user_id, reason))
    cacher.drop_by_table_name('banned', 'user_id', user_id)