def donation(request): context_dict = {} if request.POST: try: if Donation.objects.filter(): donation = Donation.objects.filter()[0] else: donation = Donation() donation.name = "Corona virus fundraising" donation.save() donor = Donor() donor.full_name = request.POST['firstname'] + " " + request.POST[ 'lastname'] donor.amount = request.POST['amount'] donor.email = request.POST['email'] donor.phone_number = request.POST['phonenumber'] donor.save() donorDonation = DonorDonation() donorDonation.donation = donation donorDonation.donor = donor return redirect('/') except: render(request, 'app/donate.html', context_dict) else: return render(request, 'app/donate.html', context_dict)
def form_valid(self, form): data = form.cleaned_data requeriment = Requirement.objects.get(id=self.kwargs['requeriment_id']) requeriment.name = data['name_item'] requeriment.description = data['description'] common_user = self.object.commonuser common_user.cpf = data['cpf'] common_user.phone = data['phone'] common_user.anonymous = data['anonymous'] common_user.save() new_item = Item(owner=self.request.user, description=requeriment.description, name_item=requeriment.name) new_item.save() new_object = Object(item=new_item, type=requeriment.type) new_object.save() messages.success(self.request, "Novo Objeto cadastrado com sucesso!") match = Match(requirement=requeriment, item=new_item) match.save() notification = Notification(user=requeriment.owner, match=match) notification.save() donation = Donation( donator=self.request.user, institute=requeriment.owner, item=new_item, data=datetime.datetime.today().strftime('%Y-%m-%d'), is_completed=False) donation.save() messages.success(self.request, 'Muito Obrigado pela sua Doação!') return super(DonatorRequerimentView, self).form_valid(form)
def donate_stripe(): """ Charge a stripe token """ if app.debug is True: stripe.api_key = app.config['STRIPE_DEBUG_SECRET_KEY'] else: stripe.api_key = app.config['STRIPE_PROD_SECRET_KEY'] # Get the stripe token from the form submission token = request.form.get('stripeDonationToken') normalized_amount = request.form.get('stripeDonationAmountNormalized') email = request.form.get('stripeDonationEmail') currency = request.form.get('stripeDonationCurrency') # Create the charge on Stripe's servers - this will charge the user's card try: charge = stripe.Charge.create( amount=normalized_amount, # amount in cents, again currency=currency, card=token, description="Donation", receipt_email=email) # Store a log of this charge in database donation = Donation(current_user.get_id(), charge.amount, charge.currency, charge) db.session.add(donation) db.session.commit() flash("Thank you for your donation!", "success") except (stripe.CardError, stripe.InvalidRequestError), e: # The card has been declined flash( "Sorry, there was an error with your donation! Your card has not been charged.", "danger") pass
def donate(scholarship_id=None): scholarship = Scholarship.get_scholarship(scholarship_id) if not scholarship: flash( 'Error finding donation page. Please make sure the scholarship ID is correct.' ) return redirect(url_for('donor.browse')) form = DonationForm(request.form, obj=donor) if form.validate_on_submit(): amount = form.amount.data or form.other_amount.data donation = Donation( donor_id=Donor.get_donor(user_id=current_user.id).donor_id, scholarship_id=scholarship_id, message=form.message.data, amount=amount, cleared=False) db.session.add(donation) db.session.commit() form.populate_obj(donor) return render_template( 'donor/donate.html', scholarship=scholarship, donation=donation, key=current_app.config['STRIPE_CREDENTIALS']['publishable_key'], form=form) return render_template('donor/donate.html', form=form, scholarship=scholarship)
def recognize_donations(): date_format = '%Y-%m-%d %H:%M:%S' recognizer = DonationRecognizer() last_donation = Donation.last_donation() vods = recognizer.vods_with_donations() for vod in vods: try: if last_donation and dt.datetime.strptime( vod.published, date_format) < last_donation.vod_published_at: continue stream = vod.allstreams[-1] video = cv.VideoCapture(stream.url) if last_donation: frame_start = last_donation.donated_at else: frame_start = 0 recognizer.recognize(video=video, vod=vod, frame_start=frame_start, break_after_recognition=False, callback=lambda x: recognizer.save(x)) except OSError: pass
def test_model_creation(self): u1 = User() l1 = Lead() c1 = Call() d1 = Donation() p1 = Pass() cb1 = Callback() self.assertTrue(True)
def form_valid(self, form): data = form.cleaned_data user_data = {} common_data = {} user_data['last_name'] = data['last_name'] user_data['first_name'] = data['first_name'] user_data['email'] = data['email'] user_data['username'] = data['username'] user_data['password'] = data['password'] common_data['cpf'] = data['cpf'] common_data['phone'] = data['phone'] if data['username'] and data['password']: new_user = User.objects.create_user(**user_data) new_common_user = CommonUser(user=new_user, **common_data) new_common_user.save() messages.success(self.request, 'Novo usuário cadastrado com sucesso.') else: return self.form_invalid(form) requeriment = Requirement.objects.get(id=self.kwargs['requeriment_id']) requeriment.name = data['name_item'] requeriment.description = data['description'] new_item = Item(owner=new_user, description=requeriment.description, name_item=requeriment.name) new_item.save() new_object = Object(item=new_item, type=requeriment.type) new_object.save() messages.success(self.request, "Novo Objeto cadastrado com sucesso!") match = Match(requirement=requeriment, item=new_item) match.save() notification = Notification(user=requeriment.owner, match=match) notification.save() donation = Donation( donator=new_user, institute=requeriment.owner, item=new_item, data=datetime.datetime.today().strftime('%Y-%m-%d'), is_completed=False) donation.save() messages.success(self.request, 'Muito Obrigado pela sua Doação!') return super(DonatorRequerimentViewAnonymous, self).form_valid(form)
def form_valid(self, form): data = form.cleaned_data item = Item.objects.get(id=self.kwargs['item_id']) item.name_item = data['name'] item.description = data['description'] object = Object.objects.get(item=item) object.type = data['type'] requeriment = Requirement(name=item.name_item, type=object.type, status=True, owner=self.request.user, description=item.description) requeriment.save() match = Match(requirement=requeriment, item=item) match.save() donation = Donation(donator=item.owner, institute=requeriment.owner, item=item, data=datetime.datetime.today().strftime('%Y-%m-%d'), is_completed=False) donation.save() notification = Notification(user=requeriment.owner, match=match) notification.save() notification = Notification(user=item.owner, match=match) notification.save() messages.success(self.request, "Nova Necessidade cadastrada com sucesso!") return super(NewItemRequerimentView, self).form_valid(form)
def save(self, data): donation = Donation( raw_donation=data.get('raw_donation'), author=data.get('author'), amount=data.get('amount'), currency=data.get('currency'), donated_at=data.get('donated_at'), donation_image=memoryview(data.get('donation_image')), vod_youtube_id=self.vod.videoid, vod_published_at=self.vod.published ) db.session.add(donation) db.session.commit()
def donation(campaign_id): form = DonationForm() campaign = Campaign.query.get_or_404(campaign_id) if form.validate_on_submit(): donation = Donation(title=form.title.data, campaign=campaign, user_id=current_user.username, amount=form.amount.data) db.session.add(donation) db.session.commit() flash('Your Donation has been added!', 'success') return redirect(url_for('home')) return render_template('donation.html', title='New Donation', form=form, legend='New Donation')
def success(): donation_id = request.form.get('donation_id') if not donation_id: flash('There was an error - redirecting you to homepage') return redirect(url_for('home.index')) donation = Donation.get_donation(donation_id) scholarship = Scholarship.get_scholarship(donation.scholarship_id) amount = int(donation.amount * 100) customer = stripe.Customer.create(email=current_user.email, card=request.form['stripeToken']) charge = stripe.Charge.create(customer=customer.id, amount=amount, currency='usd', description='Crowdscholar donation') scholarship.amount_funded += donation.amount if scholarship.amount_funded >= scholarship.amount_target: scholarship.status = 1 donation.cleared = True db.session.commit() flash('Thank you for your donation, {}!'.format(current_user.first_name)) return render_template('donor/success.html', scholarship=scholarship, donation=donation)
def generate_context(self, d: Donation): total_qty, total_value = d.total_quantity_and_value() today_date = tz.localdate().strftime('%b %d, %Y') number_of_padding_needed = max(10 - d.item_set.count(), 0) return { 'reboot_stat': self.get_full_year_stat(d.donate_date.year), 'donor_stat': self.reboot_yearly_stat(d.donate_date.year, d.donor), 'logo_path': self.static_file_path('img/reboot-round.png'), 'sign_path': self.static_file_path('img/colin-webster.png'), 'footer_path': self.static_file_path('img/reboot-footer.png'), 'slogan_path': self.static_file_path('img/reboot-slogan.png'), 'css_path': self.static_file_path('css/receipt.css'), 'generated_date': today_date, 'date': d.donate_date, 'donor': d.donor, 'tax_receipt_no': d.pk, 'list_of_items': d.item_set.all(), 'total_value': format(total_value, '.2f'), 'total_qty': total_qty, 'pick_up': d.pick_up, 'empty_rows': [i for i in range(number_of_padding_needed)] }