Ejemplo n.º 1
0
def editBasicInfo(request, pk):

    PlayerHasTeam = None
    saved = None
    if request.method == "POST":

        form = addTeamForm(data=request.POST, files=request.FILES)

        if form.is_valid() and form.is_bound == True:

            name = form.cleaned_data["name"]
            description = form.cleaned_data["description"]
            team_logo = form.cleaned_data["team_logo"]
            big_logo = form.cleaned_data["big_logo"]

            try:
                player = request.user.get_profile()
            except player.DoesNotExist:
                player = player(user=request.user)
            editTeam = Team.objects.filter(leader=player.pk)[0]

            editTeam.name = name
            editTeam.description = description
            editTeam.team_logo = team_logo
            editTeam.big_logo = big_logo

            editTeam.save()
            saved = True

            return render_to_response(
                "teams/addTeamForm.html",
                {"form": form, "saved": saved, "leader": True, "edit": True, "pk": pk},
                context_instance=RequestContext(request),
            )
        else:
            return render_to_response(
                "teams/addTeamForm.html",
                {"form": form, "fail": True, "edit": True, "pk": pk},
                context_instance=RequestContext(request),
            )

    try:
        player = request.user.get_profile()
    except player.DoesNotExist:
        player = player(user=request.user)
    editTeam = Team.objects.filter(leader=player.pk)[0]
    form = addTeamForm(
        initial={
            "name": editTeam.name,
            "description": editTeam.description,
            "team_logo": editTeam.team_logo,
            "big_logo": editTeam.big_logo,
            "last_name": editTeam.name,
        }
    )
    # if len(Team.objects.filter(leader=player))> 0 or len(UserInTeamNtoN.objects.filter(user_id=player)) > 0 :

    # admin
    if len(Team.objects.filter(leader=player)) > 0:
        return render_to_response(
            "teams/addTeamForm.html",
            {"form": form, "leader": True, "PlayerHasTeam": PlayerHasTeam, "edit": True, "pk": pk},
            context_instance=RequestContext(request),
        )
    # member
    if len(UserInTeamNtoN.objects.filter(user_id=player, accepted=True)) > 0:
        return render_to_response(
            "teams/addTeamForm.html",
            {"form": form, "member": True, "PlayerHasTeam": PlayerHasTeam, "pk": pk},
            context_instance=RequestContext(request),
        )
    elif len(UserInTeamNtoN.objects.filter(user_id=player)) > 0:
        return render_to_response(
            "teams/addTeamForm.html",
            {"form": form, "no_team": True, "PlayerHasTeam": PlayerHasTeam, "pk": pk},
            context_instance=RequestContext(request),
        )
    else:
        return render_to_response(
            "teams/addTeamForm.html",
            {"form": form, "PlayerHasTeam": PlayerHasTeam, "pk": pk},
            context_instance=RequestContext(request),
        )
Ejemplo n.º 2
0
def addTeam(request):

    PlayerHasTeam = None
    saved = None
    if request.method == "POST":

        form = addTeamForm(data=request.POST, files=request.FILES)

        if form.is_valid() and form.is_bound == True:

            name = form.cleaned_data["name"]
            description = form.cleaned_data["description"]
            team_logo = form.cleaned_data["team_logo"]
            big_logo = form.cleaned_data["big_logo"]

            try:
                player = request.user.get_profile()
            except player.DoesNotExist:
                player = player(user=request.user)

            new_team = Team(
                name=name,
                description=description,
                team_logo=team_logo,
                big_logo=big_logo,
                counts_of_players=1,
                reg_date=datetime.datetime.now(),
                leader=player,
            )

            new_team.save()
            saved = True

            return render_to_response(
                "teams/addTeamForm.html",
                {"form": form, "saved": saved, "new": True},
                context_instance=RequestContext(request),
            )
        else:
            return render_to_response(
                "teams/addTeamForm.html",
                {"form": form, "fail": True, "new": True},
                context_instance=RequestContext(request),
            )

    try:
        player = request.user.get_profile()
    except player.DoesNotExist:
        player = player(user=request.user)
    form = addTeamForm({})
    # if len(Team.objects.filter(leader=player))> 0 or len(UserInTeamNtoN.objects.filter(user_id=player)) > 0 :

    # admin
    if len(Team.objects.filter(leader=player)) > 0:
        return render_to_response(
            "teams/addTeamForm.html",
            {"form": form, "leader": True, "PlayerHasTeam": PlayerHasTeam},
            context_instance=RequestContext(request),
        )
    # member
    if len(UserInTeamNtoN.objects.filter(user_id=player, accepted=True)) > 0:
        return render_to_response(
            "teams/addTeamForm.html",
            {"form": form, "member": True, "PlayerHasTeam": PlayerHasTeam},
            context_instance=RequestContext(request),
        )
    elif len(UserInTeamNtoN.objects.filter(user_id=player)) > 0:
        return render_to_response(
            "teams/addTeamForm.html",
            {"form": form, "no_team": True, "PlayerHasTeam": PlayerHasTeam},
            context_instance=RequestContext(request),
        )
    else:
        return render_to_response(
            "teams/addTeamForm.html",
            {"form": form, "PlayerHasTeam": PlayerHasTeam},
            context_instance=RequestContext(request),
        )