Exemplo n.º 1
0
def landing_page(request):
    template_data = {
        'find_teams': TeamPage.objects.all()[:10],
        'find_fans': FanPage.objects.all()[:10],
        'find_venues': Venue.objects.all()[:10]}
    if is_fan(request.current_role):
        spud_stream = SpudsController(request.current_role).get_spud_stream()
        fan_spuds = SpudsController.GetSpudsForFan(request.current_role.entity)
        stream = SpudsController.MergeSpudLists(spud_stream, fan_spuds)
        template_data['spuds'] = stream

        entity = {
            'id': request.current_role.entity.id,
            'type': request.current_role.entity_type
        }

        participating_challenges = ChallengeParticipation.objects.filter(
            participating_entity_id=entity['id'],
            participating_entity_type=entity['type'])
        template_data['challenge_participations'] = participating_challenges
        template_data['state_engine_states'] = _StateEngineStates
        template_data['my_challenges'] = Challenge.objects.filter(
            creator_entity_id=request.current_role.entity.id,
            creator_entity_type=request.current_role.entity_type)

        # participating_ids = [c.challenge.id for c in participating_challenges]
        #
        # template_data['challenges'] = [_format_challenge('dash participating', c, entity)
        #                                for c in participating_challenges] + \
        #                               [_format_challenge('dash created', c, participating_ids)
        #                                for c in Challenge.objects.filter(creator_entity_id=entity['id'],
        #                                                                  creator_entity_type=entity['type'])]
        #
        template_data['fan_nav_active'] = "explore"
    return render(request, 'spudderspuds/pages/landing_page.html', template_data)
Exemplo n.º 2
0
def test_spuds(request):
    template_data = {}
    if is_fan(request.current_role):
        stream = SpudsController(request.current_role).get_spud_stream() + SpudsController.GetSpudsForFan(
            request.current_role.entity)
        # shuffle(stream)
        template_data['spuds'] = stream
        return render(request, 'spudderspuds/pages/test_spuds.html', template_data)
Exemplo n.º 3
0
def test_spuds(request):
    template_data = {}
    if is_fan(request.current_role):
        stream = SpudsController(request.current_role).get_spud_stream(
        ) + SpudsController.GetSpudsForFan(request.current_role.entity)
        # shuffle(stream)
        template_data['spuds'] = stream
        return render(request, 'spudderspuds/pages/test_spuds.html',
                      template_data)
Exemplo n.º 4
0
def should_current_role_be_here(request):
    if request.current_role and request.current_role.entity_type == RoleController.ENTITY_FAN:
        return False, redirect('/spuds')
    if request.current_role and not is_fan(request.current_role) and not user_has_fan_role(request):
        if request.GET.get('twitter', None) and request.GET.get('spud_id', None):
            return False, redirect(
                '/spuds/register_add_fan_role?twitter=%s&spud_id=%s' %
                (request.GET['twitter'], request.GET['spud_id']))
        else:
            return False, redirect('/spuds/register_add_fan_role')
    return True, None
Exemplo n.º 5
0
def should_current_role_be_here(request):
    if request.current_role and request.current_role.entity_type == RoleController.ENTITY_FAN:
        return False, redirect('/spuds')
    if request.current_role and not is_fan(
            request.current_role) and not user_has_fan_role(request):
        if request.GET.get('twitter', None) and request.GET.get(
                'spud_id', None):
            return False, redirect(
                '/spuds/register_add_fan_role?twitter=%s&spud_id=%s' %
                (request.GET['twitter'], request.GET['spud_id']))
        else:
            return False, redirect('/spuds/register_add_fan_role')
    return True, None
Exemplo n.º 6
0
def affiliate_splash(request, affiliate_url_name):
    """
    Gives affiliate splash page
    :param request: any request
    :param affiliate_url_name: any string without the \ character,
        formatted to lowercase for URL matching
    :return: an affiliate's splash page, or a 404 error if not a valid
        affiliate URL
    """
    if affiliate_url_name:
        affiliate_url_name = affiliate_url_name.lower()
    if affiliate_url_name and affiliate_url_name == 'nays' and feature_is_enabled('nays_survey'):
        return _nays_survey(request)

    try:
        aff = Affiliate.objects.get(url_name=affiliate_url_name)
    except Affiliate.DoesNotExist:
        raise Http404
    else:
        template_data = {
            'find_teams': TeamPage.objects.filter(affiliate=aff)[:10],
            'find_fans': FanPage.objects.filter(affiliate=aff)[:10],
            'find_clubs': Club.objects.filter(affiliate=aff)[:10],
            'affiliate': aff
        }
        if is_fan(request.current_role):
            spud_stream = SpudsController(request.current_role).get_spud_stream()
            fan_spuds = SpudsController.GetSpudsForFan(request.current_role.entity)
            stream = SpudsController.MergeSpudLists(spud_stream, fan_spuds)
            template_data['spuds'] = stream
            krowdio_response = get_following(request.current_role)
            template_data['teams'] = krowdio_users_to_links(
                request.can_edit,
                request.current_role,
                krowdio_response['data'],
                EntityController.ENTITY_TEAM)
            template_data['fans'] = krowdio_users_to_links(
                request.can_edit,
                request.current_role,
                krowdio_response['data'],
                RoleController.ENTITY_FAN)
            template_data['fan_nav_active'] = "explore"
        return render(request,
                      'spudderaffiliates/pages/landing_page.html',
                      template_data)
Exemplo n.º 7
0
def affiliate_splash(request, affiliate_url_name):
    """
    Gives affiliate splash page
    :param request: any request
    :param affiliate_url_name: any string without the \ character,
        formatted to lowercase for URL matching
    :return: an affiliate's splash page, or a 404 error if not a valid
        affiliate URL
    """
    if affiliate_url_name:
        affiliate_url_name = affiliate_url_name.lower()
    if affiliate_url_name and affiliate_url_name == 'nays' and feature_is_enabled(
            'nays_survey'):
        return _nays_survey(request)

    try:
        aff = Affiliate.objects.get(url_name=affiliate_url_name)
    except Affiliate.DoesNotExist:
        raise Http404
    else:
        template_data = {
            'find_teams': TeamPage.objects.filter(affiliate=aff)[:10],
            'find_fans': FanPage.objects.filter(affiliate=aff)[:10],
            'find_clubs': Club.objects.filter(affiliate=aff)[:10],
            'affiliate': aff
        }
        if is_fan(request.current_role):
            spud_stream = SpudsController(
                request.current_role).get_spud_stream()
            fan_spuds = SpudsController.GetSpudsForFan(
                request.current_role.entity)
            stream = SpudsController.MergeSpudLists(spud_stream, fan_spuds)
            template_data['spuds'] = stream
            krowdio_response = get_following(request.current_role)
            template_data['teams'] = krowdio_users_to_links(
                request.can_edit, request.current_role,
                krowdio_response['data'], EntityController.ENTITY_TEAM)
            template_data['fans'] = krowdio_users_to_links(
                request.can_edit, request.current_role,
                krowdio_response['data'], RoleController.ENTITY_FAN)
            template_data['fan_nav_active'] = "explore"
        return render(request, 'spudderaffiliates/pages/landing_page.html',
                      template_data)
Exemplo n.º 8
0
def create_team(request):
    form = CreateTeamForm(initial={'next_url': request.GET.get('next_url')})
    social_media_form = LinkedInSocialMediaForm()
    template_data = {'SPORTS': SPORTS}
    if request.method == "POST":
        form = CreateTeamForm(request.POST)
        social_media_form = LinkedInSocialMediaForm(request.POST)

        if form.is_valid() and social_media_form.is_valid():
            team = TeamsController.CreateTeam(
                request.current_role,
                name=form.cleaned_data.get('name'),
                contact_details=form.cleaned_data.get('contact_details'),
                free_text=form.cleaned_data.get('free_text'),
                sport=dict(form.fields['sport'].choices)[form.cleaned_data.get(
                    'sport')],
                state=form.cleaned_data.get('state'),
                at_name=form.cleaned_data.get('at_name'),
            )

            location_info = request.POST.get('location_info', None)
            team.update_location(location_info)

            set_social_media(team, social_media_form)

            team.save()
            if is_fan(request.current_role):
                redirect_url = "/fan/follow?origin=/team/create&team_id=%s" % team.id
            else:
                if is_cern_student(request.current_role):
                    created_team(request.current_role.entity)
                redirect_url = "/team/%s" % team.id

            return redirect(redirect_url)

    template_data['form'] = form
    template_data['social_media'] = social_media_form
    return render(request, 'spudderspuds/teams/pages/create_team.html',
                  template_data)
Exemplo n.º 9
0
def create_team(request):
    form = CreateTeamForm(initial={'next_url': request.GET.get('next_url')})
    social_media_form = LinkedInSocialMediaForm()
    template_data = {'SPORTS': SPORTS}
    if request.method == "POST":
        form = CreateTeamForm(request.POST)
        social_media_form = LinkedInSocialMediaForm(request.POST)

        if form.is_valid() and social_media_form.is_valid():
            team = TeamsController.CreateTeam(
                request.current_role,
                name=form.cleaned_data.get('name'),
                contact_details=form.cleaned_data.get('contact_details'),
                free_text=form.cleaned_data.get('free_text'),
                sport=dict(form.fields['sport'].choices)[form.cleaned_data.get('sport')],
                state=form.cleaned_data.get('state'),
                at_name=form.cleaned_data.get('at_name'),
            )

            location_info = request.POST.get('location_info', None)
            team.update_location(location_info)

            set_social_media(team, social_media_form)

            team.save()
            if is_fan(request.current_role):
                redirect_url = "/fan/follow?origin=/team/create&team_id=%s" % team.id
            else:
                if is_cern_student(request.current_role):
                    created_team(request.current_role.entity)
                redirect_url = "/team/%s" % team.id

            return redirect(redirect_url)

    template_data['form'] = form
    template_data['social_media'] = social_media_form
    return render(request, 'spudderspuds/teams/pages/create_team.html', template_data)
Exemplo n.º 10
0
def landing_page(request):
    template_data = {
        'find_teams': TeamPage.objects.all()[:10],
        'find_fans': FanPage.objects.all()[:10],
        'find_venues': Venue.objects.all()[:10]
    }
    if is_fan(request.current_role):
        spud_stream = SpudsController(request.current_role).get_spud_stream()
        fan_spuds = SpudsController.GetSpudsForFan(request.current_role.entity)
        stream = SpudsController.MergeSpudLists(spud_stream, fan_spuds)
        template_data['spuds'] = stream

        entity = {
            'id': request.current_role.entity.id,
            'type': request.current_role.entity_type
        }

        participating_challenges = ChallengeParticipation.objects.filter(
            participating_entity_id=entity['id'],
            participating_entity_type=entity['type'])
        template_data['challenge_participations'] = participating_challenges
        template_data['state_engine_states'] = _StateEngineStates
        template_data['my_challenges'] = Challenge.objects.filter(
            creator_entity_id=request.current_role.entity.id,
            creator_entity_type=request.current_role.entity_type)

        # participating_ids = [c.challenge.id for c in participating_challenges]
        #
        # template_data['challenges'] = [_format_challenge('dash participating', c, entity)
        #                                for c in participating_challenges] + \
        #                               [_format_challenge('dash created', c, participating_ids)
        #                                for c in Challenge.objects.filter(creator_entity_id=entity['id'],
        #                                                                  creator_entity_type=entity['type'])]
        #
        template_data['fan_nav_active'] = "explore"
    return render(request, 'spudderspuds/pages/landing_page.html',
                  template_data)