Ejemplo n.º 1
0
def addClub(request):
    args = {};

    # if it's a POST, add the club
    if request.POST:
        # get post data
        form = AddClubForm(request.user, request.POST);

        # check if form is valid
        if form.is_valid():
            # add the club
            org = form.save();

            # get club creator
            user = User.objects.get(id=request.user.id);

            # add club creator to club as admin
            uto = UserToOrganization(user=user, organization=org, admin=True);
            uto.save();

            # go to directory
            return redirect('/clubs');
        
        # if form is invalid, return it to the user
        else:
            return render(request, 'addClub.html', {'form': form});

    # else, show a new addClub form
    else:
        args.update(csrf(request));
        args['form'] = AddClubForm(request.user);
        return render(request, 'addClub.html', args);
Ejemplo n.º 2
0
def profile(request, user_id):
    args = {};

    try:
        user = User.objects.get(id=user_id);
    except ObjectDoesNotExist:
        user = request.user;

    if user.first_name:
        user.name = user.first_name;
        if user.last_name: 
            user.name += " " + user.last_name;
    else:
        user.name = user.username;

    user.clubs = UserToOrganization.getOrganizationsForUser(user);

    club_events = list()
    for org in user.clubs:
        events_for_org = Organization.getEventsForOrganization(org)
        club_events.extend(events_for_org)

    for event in UserToEvent.getEventsForUser(user):
        # only add individual event if not suscribed to club that is hosting the event
        if event not in club_events:
            club_events.append(event)

    user.events = club_events

    args['user'] = user;

    return render(request, "userProfile.html", args);
Ejemplo n.º 3
0
def joinClub(request):
    if request.user.is_authenticated() and request.POST and 'join-club-button' in request.POST:
        organization_id = int(request.POST.get('organization_id','-1'));

        org = Organization.objects.get(id=organization_id);
        user = User.objects.get(id=request.user.id);

        uto = UserToOrganization(user=user, organization=org);

        uto.save();

        return redirect("/clubs/"+str(organization_id));

    elif request.user.is_authenticated() and request.POST and 'leave-club-button' in request.POST:
        organization_id = int(request.POST.get('organization_id','-1'));

        org = Organization.objects.get(id=organization_id);
        user = User.objects.get(id=request.user.id);

        uto = UserToOrganization.objects.get(user=user, organization=org);

        uto.delete();

        return redirect("/clubs/"+str(organization_id));
Ejemplo n.º 4
0
def dashboard(request):
    args = {};
    args['user'] = request.user;

    clubs = UserToOrganization.getOrganizationsForUser(request.user);
    club_events = list()
    for org in clubs:
        events_for_org = Organization.getEventsForOrganization(org)
        club_events.extend(events_for_org)

    for event in UserToEvent.getEventsForUser(request.user):
        # only add individual event if not suscribed to club that is hosting the event
        if event not in club_events:
            club_events.append(event)

    args['events'] = club_events

    return render(request, "dashboard.html", args);