Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Help a cause by building a donation system
Search
Dražen Lučanin
April 29, 2017
Programming
0
74
Help a cause by building a donation system
DjangoGirls Vienna April 2017 lightning talk
Dražen Lučanin
April 29, 2017
Tweet
Share
More Decks by Dražen Lučanin
See All by Dražen Lučanin
Digitalisation for Citizen Empowerment
metakermit
0
33
Crowdfunding Python (& other IT) projects
metakermit
0
77
Pokreni posao: Freelancing
metakermit
1
180
Efficiently deploying Django
metakermit
1
140
Home office on a budget
metakermit
0
93
How to start freelancing
metakermit
0
210
From freelancing to incorporating
metakermit
0
200
Running a company as an e-Resident in Croatia
metakermit
0
650
CSS Animations
metakermit
0
310
Other Decks in Programming
See All in Programming
Random\Randomizer クラスで日常のあれこれを解決しよう! / Random\Randomizer class solves familiar trouble
cocoeyes02
0
170
ゆるい個人開発のススメ
kuroppe1819
10
980
Semantic search with Django and pgvector
pauloxnet
0
240
Ruby Pattern Matching
bkuhlmann
0
920
educure_カリキュラム生操作マニュアル.pdf
linew_official
0
670
R言語の環境構築と基礎 Tokyo.R 112
bob3bob3
0
260
"config" ってなんだ? / What is "config"?
okashoi
0
240
AWS Application Composerで始める、 サーバーレスなデータ基盤構築 / 20240406-jawsug-hokuriku-shinkansen
kasacchiful
1
260
コーンフレークから始める モデリング会話入門
ogurotakayuki
0
350
Tailwind CSSを本気でカスタマイズする方法
fsubal
13
5.1k
冗長なエラーログを削減し、スタックトレースを手に入れる / Reducing Verbose Error Logs and Obtaining Stack Traces
upamune
0
250
Changed Rules: Architectures with Lightweight Stores
manfredsteyer
PRO
0
240
Featured
See All Featured
Producing Creativity
orderedlist
PRO
337
39k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
7
990
The Art of Programming - Codeland 2020
erikaheidi
42
12k
Code Review Best Practice
trishagee
55
15k
Rails Girls Zürich Keynote
gr2m
91
13k
Clear Off the Table
cherdarchuk
84
310k
Adopting Sorbet at Scale
ufuk
68
8.6k
Mobile First: as difficult as doing things right
swwweet
216
8.6k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
155
14k
The Pragmatic Product Professional
lauravandoore
25
5.8k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
17
1.4k
Building Applications with DynamoDB
mza
88
5.6k
Transcript
Help a cause by building a donation system Dražen Lučanin
@metakermit
• Helping a young green party run for local elections
in Zagreb • Inspiration for applying your Django skills :) Background
Functionality • Donation form with field validation • Talking to
an external API to generate a scannable 2D barcode • Email the payment information • Admin interface ◦ confirming payments ◦ exporting reports
Model class Donation(models.Model): uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) submitted_time =
models.DateTimeField(auto_now_add=True) OIB = models.CharField(max_length=11, validators=[oib_validator]) name = models.CharField(max_length=30, validators=[utf8_30_validator]) email = models.EmailField() street = models.CharField(max_length=27, validators=[utf8_27_validator]) place = models.CharField(max_length=27, validators=[utf8_27_validator]) phone = models.CharField(max_length=30, blank=True) # optional physical_person = models.BooleanField(default=True) amount = models.PositiveIntegerField() paid = models.BooleanField(default=False) barcode = models.ImageField(blank=True, upload_to='barcodes/%Y/%m/%d') invoice_image = models.ImageField(blank=True, upload_to='invoices/%Y/%m/%d')
None
Talking to an external API – requests hub3_args = {
"renderer": "image", "data": { "amount": self.amount, "sender": { "name": self.name, }, "receiver": { "iban": settings.DONATIONS_RECIPIENT_IBAN, } } } response = requests.post( 'https://hub3.bigfish.software/api/v1/barcode', json=hub3_args )
We even got a bit fancy using PIL… img =
Image.open(blank_invoice_path) draw = ImageDraw.Draw(img) draw.text((749, 132), settings.DONATIONS_RECIPIENT_IBAN, text_color, font=font)
Popular payment services • Stripe • BrainTree
Email the payment info – django-anymail + Mailgun msg =
EmailMultiAlternatives( subject="Uplatnica za donaciju", body=text_content, to=[f"{donation.name} <{donation.email}>"] ) msg.attach('uplatnica.jpg', invoice_file.getvalue(), 'image/jpeg') msg.attach('barcode.png', barcode_file.getvalue(), 'image/png') # Send it: msg.send()
And it works… • http://www.zagrebjenas.hr/doniraj/
Thanks! • Now go build your own project :)