예제 #1
0
def accept_fan_invitation(request, page_id, invitation_id):
    entity_team = EntityController.GetWrappedEntityByTypeAndId(
        EntityController.ENTITY_TEAM, page_id,
        EntityBase.EntityWrapperByEntityType(EntityController.ENTITY_TEAM))
    invitation = get_object_or_404(Invitation, pk=invitation_id)
    fan = get_object_or_404(FanPage, pk=invitation.invitee_entity_id)
    if request.user != fan.fan:
        return HttpResponseBadRequest()

    # check that fan is not an admin already
    if entity_team.is_admin(fan.id, RoleController.ENTITY_FAN):
        return HttpResponseBadRequest()

    if request.method == 'GET':
        return render(request, 'spudderspuds/teams/pages/accept_fan_invitation.html', {
            'team_page': entity_team.entity,
            'fan': fan,
            'invitation': invitation,
            'is_invitation_active': invitation.status == invitation.PENDING_STATUS
        })
    if request.method == 'POST':
        invitation.status = Invitation.ACCEPTED_STATUS
        invitation.save()
        team_admin = TeamAdministrator(
            entity_type=RoleController.ENTITY_FAN,
            entity_id=fan.id,
            team_page=entity_team.entity
        )
        team_admin.save()
        if SocialController.IsFanFollowsTheTeam(fan, entity_team.entity):
            return HttpResponseRedirect('/team/%s/admins' % page_id)
        else:
            redirect_url = "/fan/follow?origin=/team/%s/admins" % entity_team.entity.id
            return HttpResponseRedirect(redirect_url)
예제 #2
0
def register_club(request):
    initial_data = dict(request.GET.iteritems())
    if request.current_role.entity_type == RoleController.ENTITY_FAN:
        initial_data['state'] = request.current_role.entity.state
    form = RegisterCreateClubForm(initial=initial_data)
    if request.method == 'POST':
        form = RegisterCreateClubForm(data=request.POST)
        if form.is_valid():
            data = form.cleaned_data
            name = data.get('name')
            at_name = data.get('at_name')
            sport = data.get('sport')
            description = data.get('description')
            state = data.get('state')
            address = data.get('address')
            club = Club(name=name,
                        address=address,
                        description=description,
                        state=state)
            club.save()
            club_admin = ClubAdministrator(club=club, admin=request.user)
            club_admin.save()
            change_current_role(request, RoleController.ENTITY_CLUB_ADMIN,
                                club_admin.id)
            team = TeamPage(name=name,
                            at_name=at_name,
                            free_text=description,
                            state=state,
                            sport=sport)
            team.save()
            team_admin = TeamAdministrator(
                entity_type=request.current_role.entity_type,
                entity_id=request.current_role.entity.id,
                team_page=team)
            team_admin.save()
            tca = TeamClubAssociation(team_page=team, club=club)
            tca.save()
            following_tag = FanFollowingEntityTag(
                fan=request.current_role.entity,
                tag=at_name,
                entity_id=team.id,
                entity_type=EntityController.ENTITY_TEAM)
            following_tag.save()
            start_following(request.current_role, EntityController.ENTITY_TEAM,
                            team.id)
            return redirect('/club/dashboard?message=just_registered')
    return render(request,
                  'spudderspuds/challenges/pages/register_create_club.html',
                  {'form': form})
예제 #3
0
def register_club(request):
    initial_data = dict(request.GET.iteritems())
    if request.current_role.entity_type == RoleController.ENTITY_FAN:
        initial_data['state'] = request.current_role.entity.state
    form = RegisterCreateClubForm(initial=initial_data)
    if request.method == 'POST':
        form = RegisterCreateClubForm(data=request.POST)
        if form.is_valid():
            data = form.cleaned_data
            name = data.get('name')
            at_name = data.get('at_name')
            sport = data.get('sport')
            description = data.get('description')
            state = data.get('state')
            address = data.get('address')
            club = Club(name=name, address=address, description=description, state=state)
            club.save()
            club_admin = ClubAdministrator(club=club, admin=request.user)
            club_admin.save()
            change_current_role(request, RoleController.ENTITY_CLUB_ADMIN, club_admin.id)
            team = TeamPage(name=name, at_name=at_name, free_text=description, state=state, sport=sport)
            team.save()
            team_admin = TeamAdministrator(
                entity_type=request.current_role.entity_type,
                entity_id=request.current_role.entity.id,
                team_page=team)
            team_admin.save()
            tca = TeamClubAssociation(team_page=team, club=club)
            tca.save()
            following_tag = FanFollowingEntityTag(
                fan=request.current_role.entity,
                tag=at_name,
                entity_id=team.id,
                entity_type=EntityController.ENTITY_TEAM)
            following_tag.save()
            start_following(request.current_role, EntityController.ENTITY_TEAM, team.id)
            return redirect('/club/dashboard?message=just_registered')
    return render(
        request,
        'spudderspuds/challenges/pages/register_create_club.html',
        {'form': form})
예제 #4
0
def accept_fan_invitation(request, page_id, invitation_id):
    entity_team = EntityController.GetWrappedEntityByTypeAndId(
        EntityController.ENTITY_TEAM, page_id,
        EntityBase.EntityWrapperByEntityType(EntityController.ENTITY_TEAM))
    invitation = get_object_or_404(Invitation, pk=invitation_id)
    fan = get_object_or_404(FanPage, pk=invitation.invitee_entity_id)
    if request.user != fan.fan:
        return HttpResponseBadRequest()

    # check that fan is not an admin already
    if entity_team.is_admin(fan.id, RoleController.ENTITY_FAN):
        return HttpResponseBadRequest()

    if request.method == 'GET':
        return render(
            request, 'spudderspuds/teams/pages/accept_fan_invitation.html', {
                'team_page':
                entity_team.entity,
                'fan':
                fan,
                'invitation':
                invitation,
                'is_invitation_active':
                invitation.status == invitation.PENDING_STATUS
            })
    if request.method == 'POST':
        invitation.status = Invitation.ACCEPTED_STATUS
        invitation.save()
        team_admin = TeamAdministrator(entity_type=RoleController.ENTITY_FAN,
                                       entity_id=fan.id,
                                       team_page=entity_team.entity)
        team_admin.save()
        if SocialController.IsFanFollowsTheTeam(fan, entity_team.entity):
            return HttpResponseRedirect('/team/%s/admins' % page_id)
        else:
            redirect_url = "/fan/follow?origin=/team/%s/admins" % entity_team.entity.id
            return HttpResponseRedirect(redirect_url)
예제 #5
0
def fan_register(request):
    # Should the current_role be here?
    should_be_here, response = should_current_role_be_here(request)
    if not should_be_here:
        return response

    # Extract an invitation if there is one
    invitation = extract_invitation_from_request(request)

    template_data = {'tab': request.GET.get('tab', 'fan')}
    form = FanRegisterForm(initial=request.GET)
    club_form = RegisterClubWithFanForm()


    if request.method == "POST":
        is_valid = True
        tab = request.POST.get('tab')
        template_data['tab'] = tab

        if tab == 'org':
            club_form = RegisterClubWithFanForm(request.POST)
            is_valid = club_form.is_valid()

        form = FanRegisterForm(request.POST)
        if is_valid and form.is_valid():
            # Get the form data
            username = form.cleaned_data.get('email_address')
            password = form.cleaned_data.get('password')
            state = form.cleaned_data.get('state')
            # Create the auth.User
            user = User.objects.create_user(username, username, password)
            user.save()
            user.spudder_user.mark_password_as_done()
            # Create the Fan
            fan_role = create_and_activate_fan_role(request, user)
            request.current_role = fan_role
            fan_page = fan_role.entity
            fan_page.state = state
            at_name = create_at_name_from_email_address(username)
            fan_page.username = at_name
            fan_page.save()
            # Login the user
            login(request, authenticate(username=username, password=password))
            is_signin_claiming_spud(
                request,
                fan_role.entity,
                form.cleaned_data.get('twitter', None),
                form.cleaned_data.get('spud_id', None))
            if invitation:
                if invitation.invitation_type == Invitation.REGISTER_AND_ADMINISTRATE_TEAM_INVITATION:
                    team_admin = TeamAdministrator(entity_type=fan_role.entity_type, entity_id=fan_role.entity.id)
                    team_admin.team_page_id = invitation.target_entity_id
                    team_admin.save()
                    invitation.status = Invitation.ACCEPTED_STATUS
                    invitation.save()
                elif invitation.invitation_type == Invitation.AFFILIATE_INVITE_CLUB_ADMINISTRATOR:
                    fan_role.entity.affiliate = Affiliate.objects.get(name=invitation.extras['affiliate_name'])
                    return HttpResponseRedirect('/spudderaffiliates/invitation/%s/create_club' % invitation.id)
                return redirect('/fan/follow?origin=invitation')
            if tab == 'org':
                # Get the form data
                club_name = club_form.cleaned_data.get('name')
                # Create the club
                club = Club(name=club_name, state=state)
                club.save()
                # Create the club admin
                club_admin = ClubAdministrator(club=club, admin=user)
                club_admin.save()
                club_admin_role = change_current_role(request, RoleController.ENTITY_CLUB_ADMIN, club_admin.id)
                request.current_role = club_admin_role
                EventController.RegisterEvent(request, EventController.CLUB_REGISTERED)
            return redirect(request.current_role.home_page_path)

    template_data["form"] = form
    template_data['club_form'] = club_form
    return render(request, 'spudderspuds/pages/user_register.html', template_data)
 def CreateTeam(cls, role, **kwargs):
     team = TeamPage(**kwargs)
     team.save()
     team_admin = TeamAdministrator(entity_type=role.entity_type, entity_id=role.entity.id, team_page=team)
     team_admin.save()
     return team
예제 #7
0
def fan_register(request):
    # Should the current_role be here?
    should_be_here, response = should_current_role_be_here(request)
    if not should_be_here:
        return response

    # Extract an invitation if there is one
    invitation = extract_invitation_from_request(request)

    template_data = {'tab': request.GET.get('tab', 'fan')}
    form = FanRegisterForm(initial=request.GET)
    club_form = RegisterClubWithFanForm()

    if request.method == "POST":
        is_valid = True
        tab = request.POST.get('tab')
        template_data['tab'] = tab

        if tab == 'org':
            club_form = RegisterClubWithFanForm(request.POST)
            is_valid = club_form.is_valid()

        form = FanRegisterForm(request.POST)
        if is_valid and form.is_valid():
            # Get the form data
            username = form.cleaned_data.get('email_address')
            password = form.cleaned_data.get('password')
            state = form.cleaned_data.get('state')
            # Create the auth.User
            user = User.objects.create_user(username, username, password)
            user.save()
            user.spudder_user.mark_password_as_done()
            # Create the Fan
            fan_role = create_and_activate_fan_role(request, user)
            request.current_role = fan_role
            fan_page = fan_role.entity
            fan_page.state = state
            at_name = create_at_name_from_email_address(username)
            fan_page.username = at_name
            fan_page.save()
            # Login the user
            login(request, authenticate(username=username, password=password))
            is_signin_claiming_spud(request, fan_role.entity,
                                    form.cleaned_data.get('twitter', None),
                                    form.cleaned_data.get('spud_id', None))
            if invitation:
                if invitation.invitation_type == Invitation.REGISTER_AND_ADMINISTRATE_TEAM_INVITATION:
                    team_admin = TeamAdministrator(
                        entity_type=fan_role.entity_type,
                        entity_id=fan_role.entity.id)
                    team_admin.team_page_id = invitation.target_entity_id
                    team_admin.save()
                    invitation.status = Invitation.ACCEPTED_STATUS
                    invitation.save()
                elif invitation.invitation_type == Invitation.AFFILIATE_INVITE_CLUB_ADMINISTRATOR:
                    fan_role.entity.affiliate = Affiliate.objects.get(
                        name=invitation.extras['affiliate_name'])
                    return HttpResponseRedirect(
                        '/spudderaffiliates/invitation/%s/create_club' %
                        invitation.id)
                return redirect('/fan/follow?origin=invitation')
            if tab == 'org':
                # Get the form data
                club_name = club_form.cleaned_data.get('name')
                # Create the club
                club = Club(name=club_name, state=state)
                club.save()
                # Create the club admin
                club_admin = ClubAdministrator(club=club, admin=user)
                club_admin.save()
                club_admin_role = change_current_role(
                    request, RoleController.ENTITY_CLUB_ADMIN, club_admin.id)
                request.current_role = club_admin_role
                EventController.RegisterEvent(request,
                                              EventController.CLUB_REGISTERED)
            return redirect(request.current_role.home_page_path)

    template_data["form"] = form
    template_data['club_form'] = club_form
    return render(request, 'spudderspuds/pages/user_register.html',
                  template_data)