Example #1
0
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
Example #2
0
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
Example #3
0
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)
Example #4
0
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)