示例#1
0
def create_team(request):
    if request.method != 'POST':
        return render(request, 'team/create_team.html',
                      {'form': TeamCreationForm()})

    # Stop if a person tries to create more than the allowed ammount of teams.
    if Team.objects.filter(leader=request.user).count() >= settings.MAX_TEAMS:
        messages.error(
            request,
            _(u'You can\'t be the leader of more than {max} teams.').format(
                max=settings.MAX_TEAMS))
        return redirect('teams')

    form = TeamCreationForm(request.POST)
    if form.is_valid():
        cleaned = form.cleaned_data
        team = Team(
            leader=request.user,
            title=cleaned['title'],
            tag=cleaned['tag'],
        )
        team.save()
        messages.success(request,
                         _(u'Team {team} has been created.').format(team=team))
        return redirect(team)
    else:
        # Return with errors
        form = TeamCreationForm(request.POST,
                                auto_id=True,
                                error_class=InlineSpanErrorList)
        return render(request, 'team/create_team.html', {'form': form})
示例#2
0
def create(account, name, country, logo, application):
    team = None
    with transaction.commit_on_success():
        team = Team()
        team.name = name
        team.link = uslugify(name)
        team.country = country
        team.logo = logo
        team.application = application
        team.created_by = account
        team.updated_by = account
        team.save()
        team.members.add(account)
    signals.team_created.send(sender=create, team=team, creator=account)
    return team