def _state_engine_process_pay(request, challenge, engine, state, template_data): template = challenge.template beneficiary = EntityController.GetWrappedEntityByTypeAndId( challenge.recipient_entity_type, challenge.recipient_entity_id, EntityBase.EntityWrapperByEntityType(challenge.recipient_entity_type)) participation = get_object_or_404( ChallengeParticipation, challenge=challenge, participating_entity_id=request.current_role.entity.id, participating_entity_type=request.current_role.entity_type) if beneficiary.entity_type != EntityController.ENTITY_CLUB or not beneficiary.entity.is_fully_activated( ): participation.state_engine_state = _StateEngineStates.PLEDGE_THANKS participation.state_engine = engine participation.save() response = redirect( '/challenges/%s/%s/%s' % (challenge.id, engine, _StateEngineStates.PLEDGE_THANKS)) return response, state if request.method == "POST": token = request.POST.get('stripeToken', None) if token is None: logging.error('Missing stripeToken in payment processing') return None, _StateEngineStates.PAY_FAILED stripe_controller = get_stripe_recipient_controller_for_club( beneficiary.entity) if stripe_controller is None: return None, _StateEngineStates.PAY_FAILED donation = int(participation.donation_amount) * 100 payment_status = stripe_controller.accept_payment( "Donation of $%s by %s to %s for %s" % (int(participation.donation_amount), request.user.email, beneficiary.name, challenge.name), token, donation) if not payment_status['success']: return None, _StateEngineStates.PAY_FAILED participation.state_engine_state = _StateEngineStates.PAY_THANKS participation.charge_id = payment_status['charge_id'] participation.save() response = redirect('/challenges/%s/%s' % (challenge.id, engine)) return response, state template_data = { 'challenge': challenge, 'participation': participation, 'template': template, 'beneficiary': beneficiary, 'errors': request.method == 'POST' } response = render( request, 'spudderspuds/challenges/pages_ajax/challenge_accept_pay.html', template_data) return response, state
def _state_engine_process_pledge(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, created = ChallengeParticipation.objects.get_or_create( challenge=challenge, participating_entity_id=request.current_role.entity.id, participating_entity_type=request.current_role.entity_type) participation.state_engine_state = _StateEngineStates.PLEDGE participation.save() form = AcceptChallengeForm( initial={'donation': int(challenge.proposed_donation_amount)}) if request.method == 'POST': form = AcceptChallengeForm(request.POST) if form.is_valid(): participation, created = ChallengeParticipation.objects.get_or_create( challenge=challenge, participating_entity_id=request.current_role.entity.id, participating_entity_type=request.current_role.entity_type) participation.donation_amount = form.cleaned_data.get( 'donation', 0) participation.state = ChallengeParticipation.DONATE_ONLY_STATE participation.state_engine_state = _StateEngineStates.PLEDGE_THANKS beneficiary_can_receive_donations = False if beneficiary.entity_type == EntityController.ENTITY_CLUB: if beneficiary.entity.is_fully_activated(): beneficiary_can_receive_donations = True if beneficiary_can_receive_donations and participation.donation_amount > 0: participation.state = ChallengeParticipation.AWAITING_PAYMENT participation.state_engine = engine participation.save() redirect_url = '/challenges/%s/%s/%s' % ( challenge.id, engine, _StateEngineStates.PLEDGE_THANKS) if participation.state == ChallengeParticipation.AWAITING_PAYMENT: redirect_url = '/challenges/%s/%s/%s' % ( challenge.id, engine, _StateEngineStates.PAY) participation.state_engine_state = _StateEngineStates.PAY participation.state_engine = engine participation.save() response = redirect(redirect_url) return response, state if request.is_ajax(): response = HttpResponse("%s|%s" % (request.path, '<br/>'.join( ['<br/>'.join([_e for _e in e]) for e in form.errors.values()]))) return response, state template_data = { 'challenge': challenge, 'template': template, 'beneficiary': beneficiary, 'form': form } response = render( request, 'spudderspuds/challenges/pages_ajax/challenge_accept_pledge.html', template_data) return response, state
def challenge_accept_beneficiary(request, participation_id, state): participation = get_object_or_404(ChallengeParticipation, id=participation_id) if 'video_id' in request.GET: participation.youtube_video_id = request.GET['video_id'] participation.state = ChallengeParticipation.ACCEPTED_STATE participation.save() challenge = participation.challenge template = challenge.template original_beneficiary = EntityController.GetWrappedEntityByTypeAndId( challenge.recipient_entity_type, challenge.recipient_entity_id, EntityBase.EntityWrapperByEntityType(challenge.recipient_entity_type)) clubs = _get_clubs_by_state(request, state) for club in clubs: club['is_original_beneficiary'] = ( club['id'] == original_beneficiary.entity.id) clubs = sorted(clubs, key=lambda x: x['is_original_beneficiary'], reverse=True) template_data = { 'challenge': challenge, 'template': template, 'participation': participation, 'state': state, 'clubs': clubs } return render( request, 'spudderspuds/challenges/pages/challenge_accept_beneficiary.html', template_data)
def _state_engine_process_pay_failed(request, challenge, engine, state, template_data): beneficiary = EntityController.GetWrappedEntityByTypeAndId( challenge.recipient_entity_type, challenge.recipient_entity_id, EntityBase.EntityWrapperByEntityType(challenge.recipient_entity_type)) template = challenge.template participation = get_object_or_404( ChallengeParticipation, challenge=challenge, participating_entity_id=request.current_role.entity.id, participating_entity_type=request.current_role.entity_type) participation.state_engine_state = _StateEngineStates.PAY_FAILED participation.save() if request.method == "POST": response = redirect('/challenges/%s/%s' % (challenge.id, engine)) else: template_data = { 'challenge': challenge, 'participation': participation, 'template': template, 'beneficiary': beneficiary } response = render( request, 'spudderspuds/challenges/pages_ajax/challenge_accept_pay_failed.html', template_data) return response, state
def dashboard_edit(request): club = request.current_role.entity.club club_entity = EntityController.GetWrappedEntityByTypeAndId( EntityController.ENTITY_CLUB, club.id, EntityBase.EntityWrapperByEntityType(EntityController.ENTITY_CLUB)) basic_details_form = ClubProfileBasicDetailsForm(club=club, initial=club.__dict__) if request.method == 'POST': if request.FILES: icon = UploadForm(request.POST, request.FILES).save() club.thumbnail = icon club.save() basic_details_form = ClubProfileBasicDetailsForm(club=club, data=request.POST) if basic_details_form.is_valid(): for attr in ('name', ): setattr(club, attr, basic_details_form.cleaned_data.get(attr)) club.save() messages.success(request, 'Team details updated.') return redirect('/club/dashboard/edit') template_data = { 'upload_url': blobstore.create_upload_url('/club/dashboard/edit'), 'club_entity': club_entity, 'basic_details_form': basic_details_form} return render(request, 'spudderspuds/clubs/pages/dashboard_edit.html', template_data)
def _state_engine_process_create_team(request, challenge, engine, state, template_data): response = None beneficiary = EntityController.GetWrappedEntityByTypeAndId( challenge.recipient_entity_type, challenge.recipient_entity_id, EntityBase.EntityWrapperByEntityType(challenge.recipient_entity_type)) template_data['beneficiary'] = beneficiary form = CreateTempClubForm() if request.POST: form = CreateTempClubForm(request.POST) if form.is_valid(): temp_club = _create_temp_club(form, request.current_role.state) challenge.recipient_entity_id = temp_club.id challenge.recipient_entity_type = EntityController.ENTITY_TEMP_CLUB challenge.save() state = _StateEngineStates.SHARE elif request.is_ajax(): response = HttpResponse("%s|%s" % (request.path, '<br/>'.join( ['<br/>'.join([_e for _e in e]) for e in form.errors.values()]))) if state == _StateEngineStates.CREATE_TEAM: template_data['form'] = form response = render( request, 'spudderspuds/challenges/pages_ajax/challenge_accept_beneficiary_create_club.html', template_data) return response, state
def get_club_and_club_entity(request): club = request.current_role.entity.club club_entity = EntityController.GetWrappedEntityByTypeAndId( EntityController.ENTITY_CLUB, club.id, EntityBase.EntityWrapperByEntityType(EntityController.ENTITY_CLUB)) return club, club_entity
def _format_challenge(type, c, extras=None): if type == 'created': club = EntityController.GetWrappedEntityByTypeAndId( c.recipient_entity_type, c.recipient_entity_id, EntityBase.EntityWrapperByEntityType(c.recipient_entity_type)) name = '%s for %s' % (c.name, club.name) return { 'name': name, 'link': '/challenges/%s' % c.id, } if type == 'waiting': club = EntityController.GetWrappedEntityByTypeAndId( c.challenge.recipient_entity_type, c.challenge.recipient_entity_id, EntityBase.EntityWrapperByEntityType( c.challenge.recipient_entity_type)) return { 'name': c.challenge.name, 'link': '/challenges/%s/accept/notice' % c.challenge.id } if type == 'done': return {'name': 'Test'} if type == 'dash participating': club = EntityController.GetWrappedEntityByTypeAndId( c.challenge.recipient_entity_type, c.challenge.recipient_entity_id, EntityBase.EntityWrapperByEntityType( c.challenge.recipient_entity_type)) created = c.challenge.creator_entity_id == extras[ 'id'] and c.challenge.creator_entity_type == extras['type'] return { 'name': "%s for %s" % (c.challenge.name, club.name), 'link': c.link(), 'state': _format_challenge_state_button(c.state), 'manage': _get_icons(c.challenge, created) } if type == 'dash created' and c.id not in extras: club = EntityController.GetWrappedEntityByTypeAndId( c.recipient_entity_type, c.recipient_entity_id, EntityBase.EntityWrapperByEntityType(c.recipient_entity_type)) return { 'name': "%s for %s" % (c.name, club.name), 'link': '/challenges/%s' % c.id, 'state': '', 'manage': _get_icons(c, True) }
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 _state_engine_process_share(request, challenge, engine, state, template_data): template = challenge.template beneficiary = EntityController.GetWrappedEntityByTypeAndId( challenge.recipient_entity_type, challenge.recipient_entity_id, EntityBase.EntityWrapperByEntityType(challenge.recipient_entity_type)) template_data['template'] = template template_data['beneficiary'] = beneficiary response = render( request, 'spudderspuds/challenges/pages_ajax/challenge_accept_share.html', template_data) return response, state
def challenge_accept_pay(request, challenge_id): if not request.current_role: return redirect('/challenges/create/register?next=%s' % request.path) challenge = get_object_or_404(Challenge, id=challenge_id) template = challenge.template beneficiary = EntityController.GetWrappedEntityByTypeAndId( challenge.recipient_entity_type, challenge.recipient_entity_id, EntityBase.EntityWrapperByEntityType(challenge.recipient_entity_type)) challenge_participation = get_object_or_404( ChallengeParticipation, challenge=challenge, participating_entity_id=request.current_role.entity.id, participating_entity_type=request.current_role.entity_type) if not beneficiary.entity_type == EntityController.ENTITY_CLUB or not beneficiary.entity.is_fully_activated( ): return redirect('/challenges/%s/accept/notice?just_pledged=True' % challenge.id) if request.method == "POST": token = request.POST.get('stripeToken', None) if token is not None: stripe_controller = get_stripe_recipient_controller_for_club( beneficiary.entity) if stripe_controller is not None: payment_status = stripe_controller.accept_payment( "Donation by %s to %s for %s" % (request.user.email, beneficiary.name, challenge.name), token, int(challenge_participation.donation_amount) * 100) if payment_status['success']: challenge_participation.charge_id = payment_status[ 'charge_id'] challenge_participation.save() return redirect( '/challenges/%s/accept/notice?just_donated=True' % challenge.id) template_data = { 'challenge': challenge, 'challenge_participation': challenge_participation, 'template': template, 'beneficiary': beneficiary, 'errors': request.method == 'POST' } return render(request, 'spudderspuds/challenges/pages/challenge_accept_pay.html', template_data)
def get_entity_base_instanse_by_id_and_type(entity_id, entity_type): from spudderaccounts.wrappers import RoleBase from spudderdomain.controllers import RoleController, EntityController from spudderdomain.wrappers import EntityBase if entity_type in RoleController.ENTITY_TYPES: entity = RoleController.GetRoleForEntityTypeAndID( entity_type, entity_id, RoleBase.RoleWrapperByEntityType(entity_type)) elif entity_type in EntityController.ENTITY_TYPES: entity = EntityController.GetWrappedEntityByTypeAndId( entity_type, entity_id, EntityBase.EntityWrapperByEntityType(entity_type)) else: raise NotImplementedError("Entity type %s is not supported" % entity_type) return entity
def _state_engine_process_pledge_thanks(request, challenge, engine, state, template_data): template = challenge.template beneficiary = EntityController.GetWrappedEntityByTypeAndId( challenge.recipient_entity_type, challenge.recipient_entity_id, EntityBase.EntityWrapperByEntityType(challenge.recipient_entity_type)) template_data = { 'challenge': challenge, 'template': template, 'beneficiary': beneficiary } response = render( request, 'spudderspuds/challenges/pages_ajax/challenge_accept_pledge_thanks.html', template_data) return response, state
def _state_engine_process_upload_thanks(request, challenge, engine, state, template_data): 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) if request.GET.get('video_id'): participation.youtube_video_id = request.GET['video_id'] participation.state_engine_state = state participation.state_engine = engine participation.save() challenge = Challenge( template=template, name=template.name, parent=challenge, description=challenge.description, creator_entity_id=request.current_role.entity.id, creator_entity_type=request.current_role.entity_type, recipient_entity_id=challenge.recipient_entity_id, recipient_entity_type=challenge.recipient_entity_type, proposed_donation_amount=challenge.proposed_donation_amount, proposed_donation_amount_decline=challenge. proposed_donation_amount_decline, creating_participant=participation, youtube_video_id=participation.youtube_video_id) challenge.save() template_data['challenge'] = challenge template_data['just_uploaded'] = True participation.state_engine_state = _StateEngineStates.PLEDGE participation.state_engine = engine participation.save() template_data['template'] = template template_data['beneficiary'] = beneficiary template_data['participation'] = participation response = render( request, 'spudderspuds/challenges/pages_ajax/challenge_accept_upload_thanks.html', template_data) return response, state
def challenge_accept_pledge(request, challenge_id): challenge = get_object_or_404(Challenge, id=challenge_id) template = challenge.template beneficiary = EntityController.GetWrappedEntityByTypeAndId( challenge.recipient_entity_type, challenge.recipient_entity_id, EntityBase.EntityWrapperByEntityType(challenge.recipient_entity_type)) beneficiary_can_receive_donations = False if beneficiary.entity_type == EntityController.ENTITY_CLUB: if beneficiary.entity.is_fully_activated(): beneficiary_can_receive_donations = True form = AcceptChallengeForm( initial={ 'donation': int(challenge.proposed_donation_amount), 'is_donation': beneficiary_can_receive_donations }) if request.method == 'POST': form = AcceptChallengeForm(request.POST) if form.is_valid(): participation, created = ChallengeParticipation.objects.get_or_create( challenge=challenge, participating_entity_id=request.current_role.entity.id, participating_entity_type=request.current_role.entity_type) participation.donation_amount = form.cleaned_data.get( 'donation', 0) participation.state = ChallengeParticipation.DONATE_ONLY_STATE if beneficiary_can_receive_donations and participation.donation_amount > 0: participation.state = ChallengeParticipation.AWAITING_PAYMENT participation.save() redirect_url = '/challenges/%s/accept/notice?just_pledged=True' % challenge.id if participation.state == ChallengeParticipation.AWAITING_PAYMENT: redirect_url = '/challenges/%s/accept/pay' % challenge.id return redirect(redirect_url) template_data = { 'challenge': challenge, 'template': template, 'beneficiary': beneficiary, 'beneficiary_can_receive_donations': beneficiary_can_receive_donations, 'form': form } return render( request, 'spudderspuds/challenges/pages/challenge_accept_pledge.html', template_data)
def recipient(self): attribute_key = '_recipient' try: recipient = getattr(self, attribute_key) if not recipient: raise AttributeError except AttributeError: from spudderdomain.controllers import EntityController from spudderdomain.wrappers import EntityBase recipient = None for entity_type in [ EntityController.ENTITY_TEMP_CLUB, EntityController.ENTITY_CLUB ]: if self.recipient_entity_type == entity_type: recipient = EntityController.GetWrappedEntityByTypeAndId( entity_type, self.recipient_entity_id, EntityBase.EntityWrapperByEntityType(entity_type)) setattr(self, attribute_key, recipient) return recipient
def challenge_accept_notice(request, challenge_id): challenge = get_object_or_404(Challenge, id=challenge_id) template = challenge.template beneficiary = EntityController.GetWrappedEntityByTypeAndId( challenge.recipient_entity_type, challenge.recipient_entity_id, EntityBase.EntityWrapperByEntityType(challenge.recipient_entity_type)) participation, created = ChallengeParticipation.objects.get_or_create( challenge=challenge, participating_entity_id=request.current_role.entity.id, participating_entity_type=request.current_role.entity_type) participation.state = ChallengeParticipation.PRE_ACCEPTED_STATE participation.save() template_data = { 'challenge': challenge, 'template': template, 'beneficiary': beneficiary, 'participation': participation } return render( request, 'spudderspuds/challenges/pages/challenge_accept_notice.html', template_data)
def revoke_fan_invitation(request, page_id, fan_id): entity_team = EntityController.GetWrappedEntityByTypeAndId( EntityController.ENTITY_TEAM, page_id, EntityBase.EntityWrapperByEntityType(EntityController.ENTITY_TEAM)) fan = get_object_or_404(FanPage, pk=fan_id) # check that fan is an admin if not entity_team.is_admin(fan.id, RoleController.ENTITY_FAN): return HttpResponseBadRequest() if request.method == 'GET': return render(request, 'spudderspuds/teams/pages/revoke_fan_invitation.html', { 'team_page': entity_team.entity, 'fan': fan }) if request.method == 'POST': InvitationController.RevokeEntityInvitation( fan.id, RoleController.ENTITY_FAN, Invitation.ADMINISTRATE_TEAM_INVITATION, entity_team.entity.id, entity_team.entity_type) return HttpResponseRedirect('/team/%s/admins' % page_id)
def _GetInvitationSubjectAndMessage(cls, invitation): invitation_type = invitation.invitation_type if invitation_type in Invitation.INVITATION_TYPES: wrapper = EntityBase.EntityWrapperByEntityType(invitation.target_entity_type) entity = EntityController.GetWrappedEntityByTypeAndId(invitation.target_entity_type, invitation.target_entity_id, wrapper) try: name = entity.name except NotImplementedError: name = "" if invitation_type == Invitation.REGISTER_AND_ADMINISTRATE_TEAM_INVITATION: subject = MESSAGES[invitation_type]['subject'] message = str(MESSAGES[invitation_type]['message']) % (name, invitation.link) else: try: subject = MESSAGES[invitation_type][invitation.status]['subject'] except: raise NotImplementedError("Messages for invitation type '%s' and status " "'%s' not implemented with " % ( invitation_type, invitation.status)) else: if invitation.status == Invitation.PENDING_STATUS: if invitation_type == Invitation.AFFILIATE_INVITE_CLUB_ADMINISTRATOR: # This case has extra values to unpack to %s escapes, will cause errors # if not handled correctly subject = subject % invitation.extras['affiliate_name'] message = str(MESSAGES[invitation_type][invitation.status]['message']) % ( invitation.extras['affiliate_name'], name, invitation.link) else: message = str(MESSAGES[invitation_type][invitation.status]) % (name, invitation.link) else: message = str(MESSAGES[invitation_type][invitation.status]) % name return subject, message else: raise NotImplementedError("Invitation type '%s' not supported" % invitation_type)
def challenge_challenge_thanks(request, participation_id): participation = get_object_or_404(ChallengeChallengeParticipation, id=participation_id) creator = RoleController.GetRoleForEntityTypeAndID( participation.participating_entity_type, participation.participating_entity_id, RoleBase.EntityWrapperByEntityType( participation.participating_entity_type)) beneficiary = EntityController.GetWrappedEntityByTypeAndId( participation.recipient_entity_type, participation.recipient_entity_id, EntityBase.EntityWrapperByEntityType( participation.recipient_entity_type)) template_data = { 'participation': participation, 'creator': creator, 'beneficiary': beneficiary, 'just_submitted': request.GET.get('just_submitted') } return render( request, 'spudderspuds/challenges/pages/challenge_challenge_thanks.html', template_data)
def _state_engine_process_pay_thanks(request, challenge, engine, state, template_data): beneficiary = EntityController.GetWrappedEntityByTypeAndId( challenge.recipient_entity_type, challenge.recipient_entity_id, EntityBase.EntityWrapperByEntityType(challenge.recipient_entity_type)) template = challenge.template participation = get_object_or_404( ChallengeParticipation, challenge=challenge, participating_entity_id=request.current_role.entity.id, participating_entity_type=request.current_role.entity_type) template_data = { 'challenge': challenge, 'participation': participation, 'template': template, 'beneficiary': beneficiary } response = render( request, 'spudderspuds/challenges/pages_ajax/challenge_accept_pay_thanks.html', template_data) return response, state
def _state_engine_process_notice(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, created = ChallengeParticipation.objects.get_or_create( challenge=challenge, participating_entity_id=request.current_role.entity.id, participating_entity_type=request.current_role.entity_type) participation.state = ChallengeParticipation.PRE_ACCEPTED_STATE participation.state_engine = engine participation.state_engine_state = state participation.save() template_data['template'] = template template_data['beneficiary'] = beneficiary template_data['participation'] = participation response = render( request, 'spudderspuds/challenges/pages_ajax/challenge_accept_notice.html', template_data) return response, state
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)
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