def register(request): form = ChallengesRegisterForm( initial=request.GET, enable_register_club=feature_is_enabled('challenge_register_club')) if request.method == "POST": form = ChallengesRegisterForm(request.POST, enable_register_club=feature_is_enabled('challenge_register_club')) if form.is_valid(): username = form.cleaned_data.get('email_address') password = form.cleaned_data.get('password') user = User.objects.create_user(username, username, password) user.save() user.spudder_user.mark_password_as_done() fan_entity = create_and_activate_fan_role(request, user) fan_page = fan_entity.entity fan_page.username = form.cleaned_data.get('username') fan_page.state = str(request.META.get('HTTP_X_APPENGINE_REGION')).upper() fan_page.save() login(request, authenticate(username=username, password=password)) if feature_is_enabled('tracking_pixels'): EventController.RegisterEvent(request, EventController.CHALLENGER_USER_REGISTERER) if form.cleaned_data.get('account_type') == EntityController.ENTITY_CLUB: return redirect('/challenges/register/team?next=%s' % form.cleaned_data.get('next', '/')) return redirect(form.cleaned_data.get('next', '/')) return render( request, 'spudderspuds/challenges/pages/register.html', {'form': form})
def register(request): form = ChallengesRegisterForm( initial=request.GET, enable_register_club=feature_is_enabled('challenge_register_club')) if request.method == "POST": form = ChallengesRegisterForm( request.POST, enable_register_club=feature_is_enabled('challenge_register_club')) if form.is_valid(): username = form.cleaned_data.get('email_address') password = form.cleaned_data.get('password') user = User.objects.create_user(username, username, password) user.save() user.spudder_user.mark_password_as_done() fan_entity = create_and_activate_fan_role(request, user) fan_page = fan_entity.entity fan_page.username = form.cleaned_data.get('username') fan_page.state = str( request.META.get('HTTP_X_APPENGINE_REGION')).upper() fan_page.save() login(request, authenticate(username=username, password=password)) if feature_is_enabled('tracking_pixels'): EventController.RegisterEvent( request, EventController.CHALLENGER_USER_REGISTERER) if form.cleaned_data.get( 'account_type') == EntityController.ENTITY_CLUB: return redirect('/challenges/register/team?next=%s' % form.cleaned_data.get('next', '/')) return redirect(form.cleaned_data.get('next', '/')) return render(request, 'spudderspuds/challenges/pages/register.html', {'form': form})
def get_affiliate_club_and_challenge(affiliate_key): challenge_id = None if affiliate_key == "dreamsforkids-piechallenge": if not feature_is_enabled('challenge_dreamsforkids_piechallenge'): raise Http404 club_name = 'Dreams for Kids' challenge_template_slug = "piechallenge" challenge_you_tube_video_id = "vqgpHZ09St8" elif affiliate_key == "dreamsforkids-payitforward": if not feature_is_enabled('challenge_dreamsforkids_payitforward'): raise Http404 club_name = "Dreams for Kids" challenge_template_slug = "payitforward" challenge_you_tube_video_id = "R_EkUOThl7w" elif affiliate_key == "bpt_memorial_field_fund_rak": if not feature_is_enabled('challenge_bpt_memorial_field_fund_rak'): raise Http404 club_name = "Brendan P. Tevlin FUND" challenge_template_slug = "bptrak" challenge_you_tube_video_id = "R2yX64Gh2iI" if settings.ENVIRONMENT == Environments.LIVE: challenge_id = '5184724934852608' else: return None, None try: club = Club.objects.get(name=club_name) except Club.DoesNotExist: raise NotImplementedError('A club with the name %s does not exists.' % club_name) try: template = ChallengeTemplate.objects.get(slug=challenge_template_slug) except ChallengeTemplate.DoesNotExist: raise NotImplementedError("A challenge template with the slug %s does not exists, do you need to ensure " "challenge template in the admin console?" % challenge_template_slug) club_entity = EntityController.GetWrappedEntityByTypeAndId( EntityController.ENTITY_CLUB, club.id, EntityBase.EntityWrapperByEntityType(EntityController.ENTITY_CLUB)) if challenge_id: try: challenge = Challenge.objects.get(id=challenge_id) except Challenge.DoesNotExist: raise NotImplementedError("A challenge with the id %s does not exist for the club %s" % ( challenge_id, club_name)) else: challenge, created = Challenge.objects.get_or_create( parent=None, template=template, name=template.name, creator_entity_id=club.id, creator_entity_type=EntityController.ENTITY_CLUB, recipient_entity_id=club.id, recipient_entity_type=EntityController.ENTITY_CLUB, proposed_donation_amount=10, proposed_donation_amount_decline=20) challenge.description = template.description challenge.youtube_video_id = challenge_you_tube_video_id challenge.save() return club_entity, challenge
def challenges_splash(request): template_data = {'challenges': []} if feature_is_enabled('challenge_bpt_memorial_field_fund_rak'): template_data['challenges'].append(rak_challenge) if feature_is_enabled('challenge_dreamsforkids_piechallenge'): template_data['challenges'].append(pie_challenge) if feature_is_enabled('challenge_dreamsforkids_payitforward'): template_data['challenges'].append(pif_challenge) return render(request, 'spudderspuds/challenges/pages/challenges.html', template_data)
def challenges_splash(request): template_data = {'challenges': []} if feature_is_enabled('challenge_bpt_memorial_field_fund_rak'): template_data['challenges'].append(rak_challenge) if feature_is_enabled('challenge_dreamsforkids_piechallenge'): template_data['challenges'].append(pie_challenge) if feature_is_enabled('challenge_dreamsforkids_payitforward'): template_data['challenges'].append(pif_challenge) return render(request, 'spudderspuds/challenges/pages/challenges.html', template_data)
def _state_engine_process_register(request, challenge, engine, state, template_data): response = None next_state = _StateEngineStates.NOTICE if engine == "pledge-only": next_state = _StateEngineStates.PLEDGE if request.current_role: state = next_state else: form = FanRegisterForm() if request.method == "POST": form = FanRegisterForm(request.POST) if form.is_valid(): username = form.cleaned_data.get('email_address') password = form.cleaned_data.get('password') user = User.objects.create_user(username, username, password) user.save() user.spudder_user.mark_password_as_done() fan_entity = create_and_activate_fan_role(request, user) request.current_role = fan_entity fan_page = fan_entity.entity fan_page.username = create_at_name_from_email_address(username) fan_page.state = form.cleaned_data.get('state') fan_page.save() user = authenticate(username=username, password=password) login(request, user) if feature_is_enabled('tracking_pixels'): EventController.RegisterEvent(request, EventController.CHALLENGER_USER_REGISTERER) state = next_state response = redirect('/challenges/%s/%s/%s' % (challenge.id, engine, state)) if state == _StateEngineStates.REGISTER: template_data['form'] = form response = render(request, 'spudderspuds/challenges/pages_ajax/register.html', template_data) return response, state
def affiliate_dashboard(request): """ Displays the affiliate dashboard :param request: any request :return: a simple dashboard with affiliate data overview """ if feature_is_enabled('affiliate_login'): return render(request, 'spudderaffiliates/pages/dashboard.html') else: raise Http404
def affiliate_dashboard(request): """ Displays the affiliate dashboard :param request: any request :return: a simple dashboard with affiliate data overview """ if feature_is_enabled('affiliate_login'): return render(request, 'spudderaffiliates/pages/dashboard.html') else: raise Http404
def _state_engine_process_upload(request, challenge, engine, state, template_data): response = None template = challenge.template beneficiary = EntityController.GetWrappedEntityByTypeAndId( challenge.recipient_entity_type, challenge.recipient_entity_id, EntityBase.EntityWrapperByEntityType(challenge.recipient_entity_type)) participation = ChallengeParticipation.objects.get( challenge=challenge, participating_entity_id=request.current_role.entity.id, participating_entity_type=request.current_role.entity_type) redirect_url = '/challenges/%s/%s/4?just_pledged=True' % (challenge.id, engine) action_upload_image = 'upload_image' image_form = UploadImageForm(initial={'action': action_upload_image}) upload_url = '/challenges/%s/accept' % challenge.id if request.method == 'POST': action = request.POST.get('action') if action == action_upload_image: if request.FILES: upload_form = UploadForm(request.POST, request.FILES) file = upload_form.save() participation.image = file participation.state = ChallengeParticipation.ACCEPTED_STATE participation.state_engine = engine participation.save() if feature_is_enabled('tracking_pixels'): EventController.RegisterEvent( request, EventController.CHALLENGE_ACCEPTED) if request.is_ajax(): response = HttpResponse(redirect_url) return response, state response = redirect(redirect_url) return response, state if request.is_ajax(): response = HttpResponse( "%s|%s" % (blobstore.create_upload_url(upload_url), '<br/>'.join([ '<br/>'.join([_e for _e in e]) for e in image_form.errors.values() ]))) return response, state template_data['template'] = template template_data['beneficiary'] = beneficiary template_data['participation'] = participation template_data['redirect_url'] = redirect_url template_data['upload_url'] = blobstore.create_upload_url(upload_url) response = render( request, 'spudderspuds/challenges/pages_ajax/challenge_accept_upload.html', template_data) return response, state
def challenge_challenge_accept_notice(request, state=None, club_entity_type=None, club_id=None, participation_id=None): if state and club_entity_type and club_id: ccp = ChallengeChallengeParticipation( participating_entity_id=request.current_role.entity.id, participating_entity_type=request.current_role.entity_type, recipient_entity_id=club_id, recipient_entity_type=club_entity_type) ccp.save() return redirect('/challenges/challenge_challenge/%s/upload' % ccp.id) participation = get_object_or_404(ChallengeChallengeParticipation, id=participation_id) form = ChallengeChallengeParticipationForm() upload_url = '/challenges/challenge_challenge/%s/upload' % participation_id if request.method == 'POST': form = ChallengeChallengeParticipationForm(request.POST) if form.is_valid(): participation.youtube_video_id = form.cleaned_data.get( 'youtube_video_id') participation.name = form.cleaned_data.get('challenge_name') participation.description = form.cleaned_data.get( 'challenge_description') participation.state = ChallengeChallengeParticipation.STATE_COMPLETE if request.FILES: file = UploadForm(request.POST, request.FILES).save() participation.image = file participation.save() redirect_url = '/challenges/challenge_challenge/%s/thanks?just_submitted=True' % participation_id if feature_is_enabled('tracking_pixels'): EventController.RegisterEvent( request, EventController.CHALLENGE_ACCEPTED) if request.is_ajax(): return HttpResponse(redirect_url) return redirect(redirect_url) if request.is_ajax(): return HttpResponse( "%s|%s" % (blobstore.create_upload_url(upload_url), '<br/>'.join([ '<br/>'.join([_e for _e in e]) for e in form.errors.values() ]))) template_data = { 'form': form, 'upload_url': blobstore.create_upload_url(upload_url) } return render( request, 'spudderspuds/challenges/pages/challenge_challenge_accept_upload.html', template_data)
def student_challenges(request): """ Displays a list of challenges for students to get engaged with :param request: any request :return: a page like the challenges splash, but with limited challenges """ template_data = {'challenges': []} if feature_is_enabled('challenge_bpt_memorial_field_fund_rak'): template_data['challenges'].append(rak_challenge) return render(request, 'spudderspuds/challenges/pages/student_challenges.html', template_data)
def student_challenges(request): """ Displays a list of challenges for students to get engaged with :param request: any request :return: a page like the challenges splash, but with limited challenges """ template_data = {'challenges': []} if feature_is_enabled('challenge_bpt_memorial_field_fund_rak'): template_data['challenges'].append(rak_challenge) return render(request, 'spudderspuds/challenges/pages/student_challenges.html', template_data)
def temp_redirect_view(request): """ Redirects the root to info.spudder.com and handles any funky sub-domains This is a temp solution to this problem and should be replaced with A and C name changes at the DNS level, but ... it will do for now :) MG 20140618 :param request: the request object :return: HttpResponseRedirect object """ redirect_url = None if hasattr(request, 'META'): try: url_parts = request.META['HTTP_HOST'].split('.') if len(url_parts) > 1: if url_parts[0] == "cern": redirect_url = "http://www.spudder.com/cern/" if url_parts[0] == "spudder" and url_parts[1] == "com": redirect_url = "http://www." + ",".join(url_parts) if redirect_url: return HttpResponseRedirect(redirect_url) except KeyError: pass # request META dict doesn't have HTTP_HOST key (f.i. in tests) # Deal with current role if one exists if request.current_role: return redirect(request.current_role.home_page_path) # challenges_only_override - launch with only challenges Sep 2014 if feature_is_enabled('challenges_only_override'): from spudderspuds.challenges.views import challenges_splash return challenges_splash(request) top_teams = TeamsController.GetTopTeamEntities() top_team = ([t for t in top_teams if t.jumbotron] or [None])[0] top_venues = VenuesController.GetTopVenueEntities() top_venue = ([t for t in top_venues if t.jumbotron] or [None])[0] top_fans = FansController.GetTopFanEntities() top_fan = ([t for t in top_fans if t.jumbotron] or [None])[0] template_data = { 'signin_form': FanSigninForm(), 'top_teams': [e for e in top_teams if e != top_team][:5], 'top_team': top_team, 'top_venues': [e for e in top_venues if e != top_venue][:5], 'top_venue': top_venue, 'top_fans': [e for e in top_fans if e != top_fan][:5], 'top_fan': top_fan, } return render(request, 'main_splash.html', template_data)
def tracking_pixel_code_context(request): """ Looks for a TRACKING_PIXEL_CONF dict in the events file and if the event (dict key) has a list of template names then these are added to the context as {{ tracking_pixel_code }} """ tracking_pixel_code = "" if feature_is_enabled('tracking_pixels'): for event in TRACKING_PIXEL_CONF.keys(): if EventController.PopEvent(request, event): templates = TRACKING_PIXEL_CONF.get(event, []) for template in templates: tracking_pixel_code += render_to_string(template) return {'tracking_pixel_code': tracking_pixel_code}
def temp_redirect_view(request): """ Redirects the root to info.spudder.com and handles any funky sub-domains This is a temp solution to this problem and should be replaced with A and C name changes at the DNS level, but ... it will do for now :) MG 20140618 :param request: the request object :return: HttpResponseRedirect object """ redirect_url = None if hasattr(request, 'META'): try: url_parts = request.META['HTTP_HOST'].split('.') if len(url_parts) > 1: if url_parts[0] == "cern": redirect_url = "http://www.spudder.com/cern/" if url_parts[0] == "spudder" and url_parts[1] == "com": redirect_url = "http://www." + ",".join(url_parts) if redirect_url: return HttpResponseRedirect(redirect_url) except KeyError: pass # request META dict doesn't have HTTP_HOST key (f.i. in tests) # Deal with current role if one exists if request.current_role: return redirect(request.current_role.home_page_path) # challenges_only_override - launch with only challenges Sep 2014 if feature_is_enabled('challenges_only_override'): from spudderspuds.challenges.views import challenges_splash return challenges_splash(request) top_teams = TeamsController.GetTopTeamEntities() top_team = ([t for t in top_teams if t.jumbotron] or [None])[0] top_venues = VenuesController.GetTopVenueEntities() top_venue = ([t for t in top_venues if t.jumbotron] or [None])[0] top_fans = FansController.GetTopFanEntities() top_fan = ([t for t in top_fans if t.jumbotron] or [None])[0] template_data = { 'signin_form': FanSigninForm(), 'top_teams': [e for e in top_teams if e != top_team][:5], 'top_team': top_team, 'top_venues': [e for e in top_venues if e != top_venue][:5], 'top_venue': top_venue, 'top_fans': [e for e in top_fans if e != top_fan][:5], 'top_fan': top_fan, } return render(request, 'main_splash.html', template_data)
def create_invited_club(request, invitation_id): """ Gives basic instruction on how to create club :param request: any request :return: a simple page with instructions """ if feature_is_enabled('invite_clubs'): request.session['invitation_id'] = invitation_id inv = Invitation.objects.get(id=invitation_id) name = TempClub.objects.get(id=inv.target_entity_id).name return render(request, 'spudderaffiliates/pages/create_club_instructions.html', {'club_name': name}) else: raise Http404
def create_team(request, invitation_id): """ Prompts user to create a team for recently-created club :param request: any request :param invitation_id: a valid ID of an Invitation object with type AFFILIATE_INVITE_CLUB_ADMINISTRATOR :return: a page with basic instructions explaining is optional to create the team tho recommended """ if feature_is_enabled('invite_clubs'): inv = Invitation.objects.get(id=invitation_id) name = TempClub.objects.get(id=inv.target_entity_id).name return render(request, 'spudderaffiliates/pages/create_team_instructions.html', {'club_name': name})
def incorrect_name(request, invitation_id): """ Simple error page telling user Amazon username was wrong :param request: any request :param invitation_id: a valid ID of an Invitation object with type AFFILIATE_INVITE_CLUB_ADMINISTRATOR :return: a simple page explaining why we need username to match """ if feature_is_enabled('invite_clubs'): inv = Invitation.objects.get(id=invitation_id) return render(request, 'spudderaffiliates/pages/name_failed.html',{ 'club_name': TempClub.objects.get(id=inv.target_entity_id).name, }) else: raise Http404
def create_invited_club(request, invitation_id): """ Gives basic instruction on how to create club :param request: any request :return: a simple page with instructions """ if feature_is_enabled('invite_clubs'): request.session['invitation_id'] = invitation_id inv = Invitation.objects.get(id=invitation_id) name = TempClub.objects.get(id=inv.target_entity_id).name return render(request, 'spudderaffiliates/pages/create_club_instructions.html', { 'club_name': name }) else: raise Http404
def redirect_to_registration(request, invitation_id): """ Redirects a user without a Fan account to a registration page :param request: any request :param invitation_id: a valid ID of an Invitation object with type AFFILIATE_INVITE_CLUB_ADMINISTRATOR :return: a redirect to the Fan registration page, with the invitation supplied in session info """ if feature_is_enabled('invite_clubs'): inv = Invitation.objects.get(id=invitation_id) email = TempClub.objects.get(id=inv.target_entity_id).email request.session['invitation_id'] = invitation_id return HttpResponseRedirect('/spuds/register?email_address=%s' % email) else: raise Http404
def incorrect_name(request, invitation_id): """ Simple error page telling user Amazon username was wrong :param request: any request :param invitation_id: a valid ID of an Invitation object with type AFFILIATE_INVITE_CLUB_ADMINISTRATOR :return: a simple page explaining why we need username to match """ if feature_is_enabled('invite_clubs'): inv = Invitation.objects.get(id=invitation_id) return render(request, 'spudderaffiliates/pages/name_failed.html', { 'club_name': TempClub.objects.get(id=inv.target_entity_id).name, }) else: raise Http404
def redirect_to_registration(request, invitation_id): """ Redirects a user without a Fan account to a registration page :param request: any request :param invitation_id: a valid ID of an Invitation object with type AFFILIATE_INVITE_CLUB_ADMINISTRATOR :return: a redirect to the Fan registration page, with the invitation supplied in session info """ if feature_is_enabled('invite_clubs'): inv = Invitation.objects.get(id=invitation_id) email = TempClub.objects.get(id=inv.target_entity_id).email request.session['invitation_id'] = invitation_id return HttpResponseRedirect('/spuds/register?email_address=%s' % email) else: raise Http404
def invite_club_manager(request): """ Invites users to create a club :param request: any request :return: a simple form to add a club administrator from email """ if feature_is_enabled('invite_clubs'): if request.method == 'POST': form = ClubAdministratorForm(request.POST) if form.is_valid(): email = form.cleaned_data.get('email') name = form.cleaned_data.get('club_name') state = form.cleaned_data.get('state') fan = InvitationController.CheckFanWithEmailExists(email) club = TempClub(email=email, name=name, state=state, affiliate=request.session['affiliate']) club.save() aff = request.session['affiliate'] if fan: InvitationController.InviteEntity( fan.id, RoleController.ENTITY_FAN, Invitation.AFFILIATE_INVITE_CLUB_ADMINISTRATOR, club.id, EntityController.ENTITY_TEMP_CLUB, extras={'affiliate_name': aff.name}) else: InvitationController.InviteNonUser( email, Invitation.AFFILIATE_INVITE_CLUB_ADMINISTRATOR, club.id, EntityController.ENTITY_TEMP_CLUB, extras={'affiliate_name': aff.name}) messages.success( request, "%s invited to administer club \"%s\"" % (email, name)) form = ClubAdministratorForm() else: form = ClubAdministratorForm() return render(request, 'spudderaffiliates/pages/invite_club.html', {'form': form}) else: raise Http404
def create_team(request, invitation_id): """ Prompts user to create a team for recently-created club :param request: any request :param invitation_id: a valid ID of an Invitation object with type AFFILIATE_INVITE_CLUB_ADMINISTRATOR :return: a page with basic instructions explaining is optional to create the team tho recommended """ if feature_is_enabled('invite_clubs'): inv = Invitation.objects.get(id=invitation_id) name = TempClub.objects.get(id=inv.target_entity_id).name return render(request, 'spudderaffiliates/pages/create_team_instructions.html', { 'club_name': name })
def invitation(request, invitation_id): """ Acceptance page for invitation. :param request: any request :return: a place to register if not a user and to create a club associated with affiliate if are a user """ if feature_is_enabled('invite_clubs'): inv = Invitation.objects.get(id=invitation_id) if request.method == 'POST' and request.current_role: fan = request.current_role.entity fan.affiliate = Affiliate.objects.get( name=inv.extras['affiliate_name']) fan.save() request.session['invitation_id'] = invitation_id return HttpResponseRedirect( '/spudderaffiliates/invitation/%s/create_club' % inv.id) else: if request.current_role: if request.current_role.entity_type == RoleController.ENTITY_FAN: fan = request.current_role.entity if fan.affiliate == Affiliate.objects.get( name=inv.extras['affiliate_name']): return HttpResponseRedirect( '/spudderaffiliates/invitation/%s/create_club' % inv.id) return render_to_response( 'spudderaffiliates/pages/accept_invitation.html', { 'club_name': TempClub.objects.get(id=inv.target_entity_id).name, 'affiliate_name': inv.extras['affiliate_name'] }, context_instance=RequestContext(request)) else: return render_to_response( 'spudderaffiliates/pages/accept_invitation_fan_role_not_active.html', context_instance=RequestContext(request)) else: email = TempClub.objects.get(id=inv.target_entity_id).email request.session['invitation_id'] = invitation_id return HttpResponseRedirect( '/spuds/register?email_address=%s' % email) else: raise Http404
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)
def _state_engine_process_upload(request, challenge, engine, state, template_data): response = None template = challenge.template beneficiary = EntityController.GetWrappedEntityByTypeAndId( challenge.recipient_entity_type, challenge.recipient_entity_id, EntityBase.EntityWrapperByEntityType(challenge.recipient_entity_type)) participation = ChallengeParticipation.objects.get( challenge=challenge, participating_entity_id=request.current_role.entity.id, participating_entity_type=request.current_role.entity_type) redirect_url = '/challenges/%s/%s/4?just_pledged=True' % (challenge.id, engine) action_upload_image = 'upload_image' image_form = UploadImageForm(initial={'action': action_upload_image}) upload_url = '/challenges/%s/accept' % challenge.id if request.method == 'POST': action = request.POST.get('action') if action == action_upload_image: if request.FILES: upload_form = UploadForm(request.POST, request.FILES) file = upload_form.save() participation.image = file participation.state = ChallengeParticipation.ACCEPTED_STATE participation.state_engine = engine participation.save() if feature_is_enabled('tracking_pixels'): EventController.RegisterEvent(request, EventController.CHALLENGE_ACCEPTED) if request.is_ajax(): response = HttpResponse(redirect_url) return response, state response = redirect(redirect_url) return response, state if request.is_ajax(): response = HttpResponse("%s|%s" % (blobstore.create_upload_url(upload_url), '<br/>'.join( ['<br/>'.join([_e for _e in e]) for e in image_form.errors.values()]))) return response, state template_data['template'] = template template_data['beneficiary'] = beneficiary template_data['participation'] = participation template_data['redirect_url'] = redirect_url template_data['upload_url'] = blobstore.create_upload_url(upload_url) response = render(request, 'spudderspuds/challenges/pages_ajax/challenge_accept_upload.html', template_data) return response, state
def affiliate_login(request): if feature_is_enabled('affiliate_login'): error = False if request.method == 'POST': username = request.POST.get('username', None) password = request.POST.get('password', None) try: aff = Affiliate.objects.get(username=username, password=password) except Affiliate.DoesNotExist: error = True else: request.session['affiliate'] = aff return redirect(affiliate_dashboard) return render_to_response( 'spudderaffiliates/pages/login.html', {'error': error}, context_instance=RequestContext(request)) else: raise Http404
def invite_club_manager(request): """ Invites users to create a club :param request: any request :return: a simple form to add a club administrator from email """ if feature_is_enabled('invite_clubs'): if request.method == 'POST': form = ClubAdministratorForm(request.POST) if form.is_valid(): email = form.cleaned_data.get('email') name = form.cleaned_data.get('club_name') state = form.cleaned_data.get('state') fan = InvitationController.CheckFanWithEmailExists(email) club = TempClub(email=email, name=name, state=state, affiliate=request.session['affiliate']) club.save() aff = request.session['affiliate'] if fan: InvitationController.InviteEntity(fan.id, RoleController.ENTITY_FAN, Invitation.AFFILIATE_INVITE_CLUB_ADMINISTRATOR, club.id, EntityController.ENTITY_TEMP_CLUB, extras={'affiliate_name': aff.name}) else: InvitationController.InviteNonUser(email, Invitation.AFFILIATE_INVITE_CLUB_ADMINISTRATOR, club.id, EntityController.ENTITY_TEMP_CLUB, extras={'affiliate_name': aff.name}) messages.success(request, "%s invited to administer club \"%s\"" % (email, name)) form = ClubAdministratorForm() else: form = ClubAdministratorForm() return render(request, 'spudderaffiliates/pages/invite_club.html', { 'form': form }) else: raise Http404
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)
def affiliate_login(request): if feature_is_enabled('affiliate_login'): error = False if request.method == 'POST': username = request.POST.get('username', None) password = request.POST.get('password', None) try: aff = Affiliate.objects.get(username=username, password=password) except Affiliate.DoesNotExist: error = True else: request.session['affiliate'] = aff return redirect(affiliate_dashboard) return render_to_response('spudderaffiliates/pages/login.html', {'error': error}, context_instance=RequestContext(request)) else: raise Http404
def _state_engine_process_register(request, challenge, engine, state, template_data): response = None next_state = _StateEngineStates.NOTICE if engine == "pledge-only": next_state = _StateEngineStates.PLEDGE if request.current_role: state = next_state else: form = FanRegisterForm() if request.method == "POST": form = FanRegisterForm(request.POST) if form.is_valid(): username = form.cleaned_data.get('email_address') password = form.cleaned_data.get('password') user = User.objects.create_user(username, username, password) user.save() user.spudder_user.mark_password_as_done() fan_entity = create_and_activate_fan_role(request, user) request.current_role = fan_entity fan_page = fan_entity.entity fan_page.username = create_at_name_from_email_address(username) fan_page.state = form.cleaned_data.get('state') fan_page.save() user = authenticate(username=username, password=password) login(request, user) if feature_is_enabled('tracking_pixels'): EventController.RegisterEvent( request, EventController.CHALLENGER_USER_REGISTERER) state = next_state response = redirect('/challenges/%s/%s/%s' % (challenge.id, engine, state)) if state == _StateEngineStates.REGISTER: template_data['form'] = form response = render( request, 'spudderspuds/challenges/pages_ajax/register.html', template_data) return response, state
def create_and_activate_fan_role(request, user): # get or create fan role fan, created = FanPage.objects.get_or_create(fan=user) fan.save() # set new users to follow [email protected] fan if feature_is_enabled('all_fans_auto_follow_main_spudder_fan') and created: main_account = User.objects.get( email=settings.MAIN_SPUDDER_FAN_ACCOUNT_EMAIL) main_fan = FanPage.objects.get(fan=main_account) current_entity = RoleController.GetRoleForEntityTypeAndID( RoleController.ENTITY_FAN, fan.id, RoleBase.RoleWrapperByEntityType(RoleController.ENTITY_FAN)) start_following(current_entity, RoleController.ENTITY_FAN, main_fan.id) # activate role role_controller = RoleController(user) role_controller.role_by_entity_type_and_entity_id( RoleController.ENTITY_FAN, fan.id, RoleBase.RoleWrapperByEntityType(RoleController.ENTITY_FAN)) change_current_role(request, RoleController.ENTITY_FAN, fan.id) return RoleFan(fan)
def challenge_challenge_accept_notice(request, state=None, club_entity_type=None, club_id=None, participation_id=None): if state and club_entity_type and club_id: ccp = ChallengeChallengeParticipation( participating_entity_id=request.current_role.entity.id, participating_entity_type=request.current_role.entity_type, recipient_entity_id=club_id, recipient_entity_type=club_entity_type) ccp.save() return redirect('/challenges/challenge_challenge/%s/upload' % ccp.id) participation = get_object_or_404(ChallengeChallengeParticipation, id=participation_id) form = ChallengeChallengeParticipationForm() upload_url = '/challenges/challenge_challenge/%s/upload' % participation_id if request.method == 'POST': form = ChallengeChallengeParticipationForm(request.POST) if form.is_valid(): participation.youtube_video_id = form.cleaned_data.get('youtube_video_id') participation.name = form.cleaned_data.get('challenge_name') participation.description = form.cleaned_data.get('challenge_description') participation.state = ChallengeChallengeParticipation.STATE_COMPLETE if request.FILES: file = UploadForm(request.POST, request.FILES).save() participation.image = file participation.save() redirect_url = '/challenges/challenge_challenge/%s/thanks?just_submitted=True' % participation_id if feature_is_enabled('tracking_pixels'): EventController.RegisterEvent(request, EventController.CHALLENGE_ACCEPTED) if request.is_ajax(): return HttpResponse(redirect_url) return redirect(redirect_url) if request.is_ajax(): return HttpResponse("%s|%s" % ( blobstore.create_upload_url(upload_url), '<br/>'.join(['<br/>'.join([_e for _e in e]) for e in form.errors.values()]))) template_data = { 'form': form, 'upload_url': blobstore.create_upload_url(upload_url)} return render(request, 'spudderspuds/challenges/pages/challenge_challenge_accept_upload.html', template_data)
def invitation(request, invitation_id): """ Acceptance page for invitation. :param request: any request :return: a place to register if not a user and to create a club associated with affiliate if are a user """ if feature_is_enabled('invite_clubs'): inv = Invitation.objects.get(id=invitation_id) if request.method == 'POST' and request.current_role: fan = request.current_role.entity fan.affiliate = Affiliate.objects.get(name=inv.extras['affiliate_name']) fan.save() request.session['invitation_id'] = invitation_id return HttpResponseRedirect('/spudderaffiliates/invitation/%s/create_club' % inv.id) else: if request.current_role: if request.current_role.entity_type == RoleController.ENTITY_FAN: fan = request.current_role.entity if fan.affiliate == Affiliate.objects.get(name=inv.extras['affiliate_name']): return HttpResponseRedirect('/spudderaffiliates/invitation/%s/create_club' % inv.id) return render_to_response('spudderaffiliates/pages/accept_invitation.html', { 'club_name': TempClub.objects.get(id=inv.target_entity_id).name, 'affiliate_name': inv.extras['affiliate_name'] }, context_instance=RequestContext(request)) else: return render_to_response('spudderaffiliates/pages/accept_invitation_fan_role_not_active.html', context_instance=RequestContext(request)) else: email = TempClub.objects.get(id=inv.target_entity_id).email request.session['invitation_id'] = invitation_id return HttpResponseRedirect('/spuds/register?email_address=%s' % email) else: raise Http404
def create_and_activate_fan_role(request, user): # get or create fan role fan, created = FanPage.objects.get_or_create(fan=user) fan.save() # set new users to follow [email protected] fan if feature_is_enabled('all_fans_auto_follow_main_spudder_fan') and created: main_account = User.objects.get(email=settings.MAIN_SPUDDER_FAN_ACCOUNT_EMAIL) main_fan = FanPage.objects.get(fan=main_account) current_entity = RoleController.GetRoleForEntityTypeAndID( RoleController.ENTITY_FAN, fan.id, RoleBase.RoleWrapperByEntityType(RoleController.ENTITY_FAN)) start_following(current_entity, RoleController.ENTITY_FAN, main_fan.id) # activate role role_controller = RoleController(user) role_controller.role_by_entity_type_and_entity_id( RoleController.ENTITY_FAN, fan.id, RoleBase.RoleWrapperByEntityType(RoleController.ENTITY_FAN)) change_current_role(request, RoleController.ENTITY_FAN, fan.id) return RoleFan(fan)
# Configuration shared across all applications AWS_ACCESS_KEY_ID = 'AKIAIEUN2XKQF4ZU7UDA' AWS_SECRET_KEY_ID = 'CIwpNtDm6OBGUiOGxjZ+XqdOjMPhhaFgTi7c1Ah/' GOOGLE_PLACES_API_KEY = 'AIzaSyBY2lT_31eUX7yTH90gyPXxcJvM4pqSycs' KROWDIO_GLOBAL_PASSWORD = '******' LOGIN_URL = '/users/account/signin' BOOTSTRAP3 = { 'field_renderers': { 'default': 'bootstrap3.renderers.SpudderFieldRenderer', 'inline': 'bootstrap3.renderers.InlineFieldRenderer', }, } from features import * if feature_is_enabled('email_error_logs'): from spudmart.utils.log import register_logger ADMINS = { '*****@*****.**': logging.ERROR, '*****@*****.**': logging.ERROR, } register_logger(ADMINS) if feature_is_enabled('tracking_pixels'): from events import * MAIN_SPUDDER_FAN_ACCOUNT_EMAIL = "*****@*****.**"
# Configuration shared across all applications AWS_ACCESS_KEY_ID = "AKIAIEUN2XKQF4ZU7UDA" AWS_SECRET_KEY_ID = "CIwpNtDm6OBGUiOGxjZ+XqdOjMPhhaFgTi7c1Ah/" GOOGLE_PLACES_API_KEY = "AIzaSyBY2lT_31eUX7yTH90gyPXxcJvM4pqSycs" KROWDIO_GLOBAL_PASSWORD = "******" LOGIN_URL = "/users/account/signin" BOOTSTRAP3 = { "field_renderers": { "default": "bootstrap3.renderers.SpudderFieldRenderer", "inline": "bootstrap3.renderers.InlineFieldRenderer", } } from features import * if feature_is_enabled("email_error_logs"): from spudmart.utils.log import register_logger ADMINS = {"*****@*****.**": logging.ERROR, "*****@*****.**": logging.ERROR} register_logger(ADMINS) if feature_is_enabled("tracking_pixels"): from events import * MAIN_SPUDDER_FAN_ACCOUNT_EMAIL = "*****@*****.**"
def get_affiliate_club_and_challenge(affiliate_key): challenge_id = None if affiliate_key == "dreamsforkids-piechallenge": if not feature_is_enabled('challenge_dreamsforkids_piechallenge'): raise Http404 club_name = 'Dreams for Kids' challenge_template_slug = "piechallenge" challenge_you_tube_video_id = "vqgpHZ09St8" elif affiliate_key == "dreamsforkids-payitforward": if not feature_is_enabled('challenge_dreamsforkids_payitforward'): raise Http404 club_name = "Dreams for Kids" challenge_template_slug = "payitforward" challenge_you_tube_video_id = "R_EkUOThl7w" elif affiliate_key == "bpt_memorial_field_fund_rak": if not feature_is_enabled('challenge_bpt_memorial_field_fund_rak'): raise Http404 club_name = "Brendan P. Tevlin FUND" challenge_template_slug = "bptrak" challenge_you_tube_video_id = "R2yX64Gh2iI" if settings.ENVIRONMENT == Environments.LIVE: challenge_id = '5184724934852608' else: return None, None try: club = Club.objects.get(name=club_name) except Club.DoesNotExist: raise NotImplementedError('A club with the name %s does not exists.' % club_name) try: template = ChallengeTemplate.objects.get(slug=challenge_template_slug) except ChallengeTemplate.DoesNotExist: raise NotImplementedError( "A challenge template with the slug %s does not exists, do you need to ensure " "challenge template in the admin console?" % challenge_template_slug) club_entity = EntityController.GetWrappedEntityByTypeAndId( EntityController.ENTITY_CLUB, club.id, EntityBase.EntityWrapperByEntityType(EntityController.ENTITY_CLUB)) if challenge_id: try: challenge = Challenge.objects.get(id=challenge_id) except Challenge.DoesNotExist: raise NotImplementedError( "A challenge with the id %s does not exist for the club %s" % (challenge_id, club_name)) else: challenge, created = Challenge.objects.get_or_create( parent=None, template=template, name=template.name, creator_entity_id=club.id, creator_entity_type=EntityController.ENTITY_CLUB, recipient_entity_id=club.id, recipient_entity_type=EntityController.ENTITY_CLUB, proposed_donation_amount=10, proposed_donation_amount_decline=20) challenge.description = template.description challenge.youtube_video_id = challenge_you_tube_video_id challenge.save() return club_entity, challenge