def campaign_edit(request, key): """ Edit a campaign, basically delivers the angular app that changes the values via the REST backend. """ campaign = get_campaign_or_404(request, key) rest_url = request.build_absolute_uri("/yeah/rest/campaigns/{}".format(campaign.key)) methods = get_payment_methods() currencies = [{"id": x[0], "display_name": x[1]} for x in Campaign.CURRENCIES] campaign_ser = CampaignSerializer(campaign) initial_data = JSONRenderer().render(campaign_ser.data, accepted_media_type="application/json; indent=4") perk_ser = PerkSerializer(campaign.perks.all(), many=True) initial_perks = JSONRenderer().render(perk_ser.data, accepted_media_type="application/json; indent=4") context = { "rest_url": rest_url, "campaign": campaign, "methods": methods, "initial_data": initial_data, "initial_perks": initial_perks, "currencies": currencies, } return render(request, "campaigns/campaign_edit.html", context)
def campaign_edit(request, key): """ Edit a campaign, basically delivers the angular app that changes the values via the REST backend. """ campaign = get_campaign_or_404(request, key) methods = get_payment_methods() currencies = [{'id': x[0], 'display_name': x[1]} for x in Campaign.CURRENCIES] campaign_ser = CampaignSerializer(campaign) initial_data = JSONRenderer().render(campaign_ser.data, accepted_media_type='application/json; indent=4') perk_ser = PerkSerializer(campaign.perks.all(), many=True) initial_perks = JSONRenderer().render(perk_ser.data, accepted_media_type='application/json; indent=4') context = { 'campaign': campaign, 'methods': methods, 'initial_data': initial_data, 'initial_perks': initial_perks, 'currencies': currencies, } return render(request, 'campaigns/campaign_edit.html', context)
def campaign_edit(request, key): """ Edit a campaign, basically delivers the angular app that changes the values via the REST backend. """ campaign = get_campaign_or_404(request, key) rest_url = request.build_absolute_uri('/yeah/rest/campaigns/{}'.format(campaign.key)) methods = get_payment_methods() currencies = [{'id': x[0], 'display_name': x[1]} for x in Campaign.CURRENCIES] campaign_ser = CampaignSerializer(campaign) initial_data = JSONRenderer().render(campaign_ser.data, accepted_media_type='application/json; indent=4') perk_ser = PerkSerializer(campaign.perks.all(), many=True) initial_perks = JSONRenderer().render(perk_ser.data, accepted_media_type='application/json; indent=4') context = { 'rest_url': rest_url, 'campaign': campaign, 'methods': methods, 'initial_data': initial_data, 'initial_perks': initial_perks, 'currencies': currencies, } return render(request, 'campaigns/campaign_edit.html', context)
def campaign_details(request, key): """ View that shows a single activity. """ logger.debug("campaign details") campaign = get_campaign_or_404(request, key) template_name = 'campaigns/campaign_details.html' if request.method == 'GET': if request.GET.get('embedded', None) is not None: template_name = 'campaigns/campaign_details_embedded.html' methods = get_payment_methods() supporters = Transaction.objects.filter(campaign=campaign, show_name=True) context = { 'campaign': campaign, 'methods': methods, 'supporters': supporters } try: if settings.YLDT_PLEDGE_BUTTON_TEXT: context['pledge_button_text'] = settings.YLDT_PLEDGE_BUTTON_TEXT except AttributeError: pass return render(request, template_name, context)
def campaign_show_transactions(request, key): """ Show all the transactions of one campaign. """ campaign = get_campaign_or_404(request, key) transactions = Transaction.objects.filter(campaign=campaign).order_by("started") context = {"campaign": campaign, "transactions": transactions} return render(request, "campaigns/campaign_show_transactions.html", context)
def campaign_show_transactions(request, key): """ Show all the transactions of one campaign. """ campaign = get_campaign_or_404(request, key) transactions = Transaction.objects.filter( campaign=campaign).order_by('started') context = {'campaign': campaign, 'transactions': transactions} return render(request, 'campaigns/campaign_show_transactions.html', context)
def campaign_show_transactions(request, key): """ Show all the transactions of one campaign. """ campaign = get_campaign_or_404(request, key) transactions = Transaction.objects.filter(campaign=campaign).order_by('started') context = { 'campaign': campaign, 'transactions': transactions } return render(request, 'campaigns/campaign_show_transactions.html', context)
def select_payment(request, key): """ The user has clicked the "Pledge now" button. Let's show him the list of available Payment methods """ campaign = get_campaign_or_404(request, key) perk_id = request.GET.get('perk', None) pledge_value = Decimal('0.0') perk = None if perk_id != None: perk = get_object_or_404(Perk, pk=int(perk_id)) pledge_value = perk.amount methods = get_payment_methods() context = { 'campaign': campaign, 'selected_perk': perk, 'methods': methods, 'pledge_value': pledge_value, } if request.method == 'POST': form = forms.SelectPaymentForm(campaign, perk, request.POST) if form.is_valid(): amount = form.cleaned_data.get('amount') payment_method_name= form.cleaned_data.get('payment_method') method = get_method_by_name(payment_method_name) email = form.cleaned_data.get('email1') name = form.cleaned_data.get('name') show_name = not form.cleaned_data['hide_name'] # Create a new payment transaction with a random ID. transaction_id = str(uuid.uuid4()) perk_id = None if perk != None: perk_id = perk.id PledgePaymentCommand(transaction_id, campaign.key, amount, email, perk_id, name, show_name) UnverifyPaymentCommand(transaction_id, payment_method_name) # Delegate the payment transaction to the pay() method of the selected # payment method. The method will then redirect the user to the page it needs # to complete the payment. return method.pay(request, campaign, transaction_id) else: return render(request, 'campaigns/select_payment.html', dict(context, form=form)) else: return render(request, 'campaigns/select_payment.html', context)
def select_payment(request, key): """ The user has clicked the "Pledge now" button. Let's show him the list of available Payment methods """ campaign = get_campaign_or_404(request, key) perk_id = request.GET.get("perk", None) pledge_value = Decimal("0.0") perk = None if perk_id != None: perk = get_object_or_404(Perk, pk=int(perk_id)) pledge_value = perk.amount methods = get_payment_methods() context = {"campaign": campaign, "selected_perk": perk, "methods": methods, "pledge_value": pledge_value} if request.method == "POST": form = forms.SelectPaymentForm(campaign, perk, request.POST) if form.is_valid(): amount = form.cleaned_data.get("amount") payment_method_name = form.cleaned_data.get("payment_method") method = get_method_by_name(payment_method_name) email = form.cleaned_data.get("email1") name = form.cleaned_data.get("name") show_name = not form.cleaned_data["hide_name"] # Create a new payment transaction with a random ID. transaction_id = str(uuid.uuid4()) perk_id = None if perk != None: perk_id = perk.id BeginPayment(transaction_id, campaign.key, amount, email, perk_id, name, show_name, payment_method_name) # Delegate the payment transaction to the pay() method of the selected # payment method. The method will then redirect the user to the page it needs # to complete the payment. return method.pay(request, campaign, transaction_id) else: return render(request, "campaigns/select_payment.html", dict(context, form=form)) else: return render(request, "campaigns/select_payment.html", context)
def campaign_details(request, key): """ View that shows a single activity. """ logger.debug("campaign details") campaign = get_campaign_or_404(request, key) template_name = "campaigns/campaign_details.html" if request.method == "GET": if request.GET.get("embedded", None) is not None: template_name = "campaigns/campaign_details_embedded.html" methods = get_payment_methods() supporters = Transaction.objects.filter(campaign=campaign, show_name=True) context = {"campaign": campaign, "methods": methods, "supporters": supporters} try: if settings.YLDT_PLEDGE_BUTTON_TEXT: context["pledge_button_text"] = settings.YLDT_PLEDGE_BUTTON_TEXT except AttributeError: pass return render(request, template_name, context)
def campaign_details(request, key): """ View that shows a single campaign. """ logger.debug("campaign details") campaign = get_campaign_or_404(request, key) template_name = 'campaigns/campaign_details.html' if request.method == 'GET': if request.GET.get('embedded', None) is not None: template_name = 'campaigns/campaign_details_embedded.html' methods = get_payment_methods() supporters = Transaction.objects.filter(campaign=campaign, show_name=True) context = {'campaign': campaign, 'methods': methods, 'supporters': supporters} try: if settings.YLDT_PLEDGE_BUTTON_TEXT: context['pledge_button_text'] = settings.YLDT_PLEDGE_BUTTON_TEXT except AttributeError: pass return render(request, template_name, context)