Пример #1
0
def public_user_register_contest(account_num, contest):
    # can not register started contest
    if has_started(contest):
        return False

    account_num = public_user.check_account_num_valid(account_num)
    # if invalid
    if account_num == -1:
        return False
    public_contestants = public_user.get_public_contestant(contest)
    need = account_num - len(public_contestants)
    # public contestant attend more than needed, kick some out
    if need < 0:
        public_user.delete_public_contestants(
            public_contestants[account_num:len(public_contestants)])
        return account_num
    # public contestant is not enough
    available_users = public_user.get_available_public_users()
    lack = need - len(available_users)
    # available public user is enough
    if lack <= 0:
        add_contestants_and_activate(available_users[0:need], contest)
    # available public user not enough, then create some
    else:
        new_users = public_user.create_public_users(lack)
        add_contestants_and_activate(new_users, contest)
        add_contestants_and_activate(available_users, contest)
    return account_num
Пример #2
0
def public_user_register_contest(account_num, contest):
    # can not register started contest
    if has_started(contest):
        return False

    account_num = public_user.check_account_num_valid(account_num)
    # if invalid
    if account_num == -1:
        return False
    public_contestants = public_user.get_public_contestant(contest)
    need = account_num - len(public_contestants)
    # public contestant attend more than needed, kick some out
    if need < 0:
        public_user.delete_public_contestants(\
            public_contestants[account_num:len(public_contestants)])
        return account_num
    #public contestant is not enough
    available_users = public_user.get_available_public_users()
    lack = need - len(available_users)
    # available public user is enough
    if lack <=0:
        add_contestants_and_activate(available_users[0:need], contest)
    # available public user not enough, then create some
    else:
        new_users = public_user.create_public_users(lack)
        add_contestants_and_activate(new_users, contest)
        add_contestants_and_activate(available_users, contest)
    return account_num
Пример #3
0
def group_register_contest(group, contest):
    if has_started(contest):
        return False
    for user in group.member.all():
        if user_can_register_contest(user, contest):
            add_contestant(user, contest)
    return True
Пример #4
0
def group_register_contest(group, contest):
    if has_started(contest):
        return False
    for user in group.member.all():
        if user_can_register_contest(user, contest):
            add_contestant(user, contest)
    return True
Пример #5
0
def show_register_btn(user, contest):
    if not user.is_authenticated():
        return False
    has_not_started = not contest_info.has_started(contest)
    own_contest = user_info.has_contest_ownership(user, contest)
    is_not_public_user = not is_public_user(user)
    user_is_admin = user.has_admin_auth()
    return has_not_started and (own_contest or is_not_public_user or user_is_admin)