Пример #1
0
def sendRequestForMembership(request):
    try:
        selectedPLayer = request.user.get_profile()
    except player.DoesNotExist:
        selectedPLayer = player(user=request.user)
    addInvitation = formularis.addRequestToTeam(request.POST)
    if addInvitation.is_valid():
        id = int(addInvitation.cleaned_data["team_id"])
        UserInTeamNtoNObject = UserInTeamNtoN(
            user_id=selectedPLayer, team_id=Team.objects.get(pk=id), invitation=True, dateOfAdd=datetime.datetime.now()
        )
        UserInTeamNtoNObject.save()
        return render_to_response(
            "teams/messagePage.html",
            {"saved": True, "id_team": addInvitation.cleaned_data["team_id"]},
            context_instance=RequestContext(request),
        )
    else:
        return render_to_response(
            "teams/messagePage.html",
            {"id_team": addInvitation.cleaned_data["team_id"]},
            context_instance=RequestContext(request),
        )
Пример #2
0
def teamDetail(request, pk):

    generalyTeamAdmin = None
    haveRequest = None
    haveRequetInThisTeam = None
    playerRequest = None
    team = None
    a = []
    PK = int(pk)

    # for e in UserInTeamNtoN.objects.filter(team_id=self.kwargs.get('pk', None)):
    #    a.append(player.objects.filter(pk=e.user_id.user_id)[0])
    # context['players'] = a

    # addInvitation = formularis.addRequestToTeam(request.POST)
    # delInvitation = formularis.deleteRequestToTeam(request.POST)

    # if addInvitation.is_valid():
    #    print addInvitation.cleaned_data['team_id']
    # if delInvitation.is_valid():
    #    print delInvitation.cleaned_data['team_id']
    # print 'Tu je add' , addInvitation
    # print 'Tu je del' , delInvitation
    # return render_to_response('teams/messagePage.html',None, context_instance=RequestContext(request))

    if request.method == "GET":
        team = Team.objects.get(pk=PK)
        if request.user.is_authenticated():
            try:
                selectedPLayer = request.user.get_profile()
            except player.DoesNotExist:
                selectedPLayer = player(user=request.user)
            member = UserInTeamNtoN.objects.filter(user_id=selectedPLayer)
            teamadmin = Team.objects.filter(leader=selectedPLayer)

            if len(teamadmin) > 0:
                generalyTeamAdmin = True
                if teamadmin[0].pk == PK:
                    # je administratorom timu
                    return redirect("/teams/myTeam/")

            if len(member) > 0:
                haveRequest = True
                if member[0].team_id.pk == PK:
                    if member[0].accepted == True:
                        # je clen timu
                        return redirect("/teams/myTeam/")
                    elif member[0].invitation == True and member[0].accepted == False:
                        # Poziadavka bola odmietnuta
                        playerRequest = False
                        haveRequetInThisTeam = True
                    else:
                        # Poziadavka od hraca este nebola spracovana
                        playerRequest = True
                        haveRequetInThisTeam = True

        for e in UserInTeamNtoN.objects.filter(team_id=PK, accepted=True):
            a.append(player.objects.get(pk=e.user_id.pk))
        a.append(player.objects.get(pk=team.leader.pk))

        # try:
        #    context['players'] = player(pk=UserInTeamNtoN(team_id=self.model.pk).user_id).objects.all()
        # except ValueError:
        #    print 'Error(Weak) - teams.views.DetailView - v danom time je len osoba ktora ho vytvorila'
        #    context['players'] = None

        # context['new_feeds'] = NewsFeeds(team_id=self.model.pk).objects.order_by('-publish_date')
        new_feeds = NewsFeeds.objects.filter(team_id=PK).order_by("publish_date").reverse()
        GalleryTeam = Gallery.objects.filter(team_id=PK).order_by("date_of_add")[:3].reverse()
        Events = Event.objects.filter(users__in=a).distinct()
        # context['path'] = PROJECT_PATH.strip("\HrajAirsoft").replace('\\', '/') + "/"
        lastEvents = Events.filter(startOfAction__lte=datetime.datetime.now()).order_by("startOfAction").reverse()
        futureEvents = Events.filter(startOfAction__gt=datetime.datetime.now()).order_by("startOfAction")
        a.pop()
        players = a
        addRequestToTeam = formularis.addRequestToTeam(initial={"team_id": PK})

        deleteRequestToTeam = formularis.deleteRequestToTeam(initial={"team_id": PK})
        team_data = {
            "team": team,
            "new_feeds": new_feeds,
            "GalleryTeam": GalleryTeam,
            "playerRequest": playerRequest,
            "players": players,
            "teamadmin": generalyTeamAdmin,
            "addRequestToTeam": addRequestToTeam,
            "deleteRequestToTeam": deleteRequestToTeam,
            "haveRequest": haveRequest,
            "haveRequetInThisTeam": haveRequetInThisTeam,
            "lastEvents": lastEvents,
            "futureEvents": futureEvents,
        }

        return render_to_response("teams/detail.html", team_data, context_instance=RequestContext(request))