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})
Exemple #2
0
def save_club_from_program_json_data(json_data):
    try:
        Club.objects.get(original_domain_name='leagueathletics',
                         original_domain_id=json_data['id'])
    except Club.DoesNotExist:
        name = json_data['orgName']
        if not name:
            return False

        Club(name=name,
             website=json_data['url'],
             address=json_data['location'] + ', ' + json_data['zip'],
             original_domain_name='leagueathletics',
             original_domain_id=json_data['id']).save()
        return True
    except MultipleObjectsReturned:
        # There are situations, where API returns multiple programs for same organisation (with same ID)
        # An example is zip code 01450 - it returns two programs for "LS Baseball" organisation (with ID = 1398).
        # In our case we just need to remove the duplicates
        # Locally it can occur because of eventual consistency in HRD (write occurs to close to next read)

        logging.info('#' * 60)
        logging.info('Removing duplicates for "%s" (ID: %s, zip: %s)' %
                     (json_data['orgName'], json_data['id'], json_data['zip']))
        logging.info('#' * 60)

        clubs = list(
            Club.objects.filter(original_domain_name='leagueathletics',
                                original_domain_id=json_data['id']))
        for club in clubs[1:]:
            club.delete()
    except KeyError, e:
        logging.info('Key error for "%s" (ID: %s, zip: %s)' %
                     (json_data['orgName'], json_data['id'], json_data['zip']))
        logging.info(e)
Exemple #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})
Exemple #4
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)
Exemple #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)