Python models 模块,Team() 实例源码

我们从Python开源项目中,提取了以下6个代码示例,用于说明如何使用models.Team()

项目:get5-web    作者:splewis    | 项目源码 | 文件源码
def add_teams(self, user):
        if self.team1_id.choices is None:
            self.team1_id.choices = []

        if self.team2_id.choices is None:
            self.team2_id.choices = []

        team_ids = [team.id for team in user.teams]
        for team in Team.query.filter_by(public_team=True):
            if team.id not in team_ids:
                team_ids.append(team.id)

        team_tuples = []
        for teamid in team_ids:
            team_tuples.append((teamid, Team.query.get(teamid).name))

        self.team1_id.choices += team_tuples
        self.team2_id.choices += team_tuples
项目:get5-web    作者:splewis    | 项目源码 | 文件源码
def match(matchid):
    match = Match.query.get_or_404(matchid)
    team1 = Team.query.get_or_404(match.team1_id)
    team2 = Team.query.get_or_404(match.team2_id)
    map_stat_list = match.map_stats.all()

    is_owner = False
    has_admin_access = False

    if g.user:
        is_owner = (g.user.id == match.user_id)
        has_admin_access = is_owner or (config_setting(
            'ADMINS_ACCESS_ALL_MATCHES') and g.user.admin)

    return render_template(
        'match.html', user=g.user, admin_access=has_admin_access,
                           match=match, team1=team1, team2=team2,
                           map_stat_list=map_stat_list)
项目:bbgo    作者:genonfire    | 项目源码 | 文件源码
def show_recruitment(request, id):
    """Show recruitment"""
    article = get_object_or_404(Team, pk=id)
    article.view_count += 1
    article.save()

    table = article.table
    team_table = TeamTable()
    table_name = team_table.get_table_name(table)
    table_desc = team_table.get_table_desc(table)

    if article.status != '1normal':
        status_text = article.get_status_text()
    else:
        status_text = ''

    return render(
        request,
        "teams/show_recruitment.html",
        {
            'article': article,
            'table': table,
            'table_name': table_name,
            'table_desc': table_desc,
            'status_text': status_text,
        }
    )
项目:bbgo    作者:genonfire    | 项目源码 | 文件源码
def edit_recruitment(request, id):
    """Edit recruitment"""
    article = get_object_or_404(Team, pk=id)

    if request.method == "POST":
        editform = TeamEditForm(request.POST, instance=article)
        if editform.is_valid():
            article = editform.save(commit=False)
            article.modified_at = timezone.now()
            article.save()

            request.user.profile.last_article_at = timezone.now()
            request.user.profile.save()

            return redirect(article.get_article_url())
    elif request.method == "GET":
        team_table = TeamTable()
        if article.table >= team_table.get_table_len():
            return error_page(request)

        table_name = team_table.get_table_name(article.table)
        if table_name == '':
            return error_page(request)

        table_desc = team_table.get_table_desc(article.table)
        category_choices = team_table.get_category(article.table)

        editform = TeamEditForm(instance=article)

    return render(
        request,
        'teams/edit_recruitment.html',
        {
            'form': editform,
            'edit_type': 'edit',
            'table_name': table_name,
            'table_desc': table_desc,
            'category_choices': category_choices,
            'category': article.category,
        }
    )
项目:bbgo    作者:genonfire    | 项目源码 | 文件源码
def change_status(request, id, status):
    """Change status"""
    article = get_object_or_404(Team, pk=id)

    if request.user == article.user or request.user.is_staff:
        if article.status != status:
            if status == '1normal':
                article.status = status
                article.save()
            elif status == '7canceled' or status == '8full':
                article.status = status
                article.save()

                slot_users = article.slot_users.all()
                for slot_user in slot_users:
                    if slot_user.profile.alarm_full:
                        if slot_user.profile.alarm_list != '':
                            slot_user.profile.alarm_list += ','
                        if status == '8full':
                            alarm_text = 'f:%d' % article.id
                        else:
                            alarm_text = 'c:%d' % article.id
                        slot_user.profile.alarm_list += alarm_text
                        slot_user.profile.alarm = True
                        slot_user.save()
        return redirect(article.get_article_url())
    else:
        return error_page(request)
项目:bbgo    作者:genonfire    | 项目源码 | 文件源码
def recruitment(request, table=0, page=0):
    """Recruitment"""
    team_table = TeamTable()
    if int(table) >= team_table.get_table_len():
        return error_page(request)

    table_name = team_table.get_table_name(table)
    if table_name == '':
        return error_page(request)

    if int(page) < 1:
        return redirect('teams:recruitment', table=table, page=1)

    table_desc = team_table.get_table_desc(table)
    list_count = team_table.get_list_count()

    current_page = int(page) - 1
    start_at = current_page * list_count
    end_at = start_at + list_count

    q = Q(status='1normal') | Q(status='7canceled') | Q(status='8full') | Q(status='5hidden')

    total = Team.objects.filter(table=table).filter(q).count()
    lists = Team.objects.filter(table=table).filter(q).order_by('-id')[start_at:end_at]

    index_total = int(ceil(float(total) / list_count))
    index_begin = (current_page / 10) * 10 + 1
    index_end = mindex_end = index_total
    if index_end - index_begin >= 10:
        index_end = index_begin + 9
    mindex_begin = (current_page / 5) * 5 + 1
    if mindex_end - mindex_begin >= 5:
        mindex_end = mindex_begin + 4

    if request.user.is_authenticated():
        writable = True
    else:
        writable = False

    return render(
        request,
        "teams/recruitment.html",
        {
            'lists': lists,
            'total': total,
            'table': table,
            'table_name': table_name,
            'table_desc': table_desc,
            'page': current_page + 1,
            'index_begin': index_begin,
            'index_end': index_end + 1,
            'mindex_begin': mindex_begin,
            'mindex_end': mindex_end + 1,
            'index_total': index_total,
            'writable': writable,
        }
    )