Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Support for ticket prices in multiple currencies

  • Loading branch information...
commit 0d78a4ef4f142593c6438dea3419ce274db0b927 1 parent 1d1da8c
Russ Garrett russss authored
Showing with 48 additions and 19 deletions.
  1. +30 −9 models/ticket.py
  2. +18 −10 utils.py
39 models/ticket.py
View
@@ -20,26 +20,25 @@ class TicketType(db.Model):
notice = db.Column(db.String)
capacity = db.Column(db.Integer, nullable=False)
limit = db.Column(db.Integer, nullable=False)
- cost_pence = db.Column(db.Integer, nullable=False)
tickets = db.relationship("Ticket", backref="type")
- def __init__(self, name, capacity, limit, cost, notice=None):
+ def __init__(self, name, capacity, limit, notice=None):
self.name = name
self.capacity = capacity
self.limit = limit
- self.cost = cost
self.notice = notice
def __repr__(self):
return "<TicketType: %s>" % (self.name)
+ def get_price(self, currency):
+ for price in self.prices:
+ if price.currency == currency:
+ return price.value
+
@property
def cost(self):
- return Decimal(self.cost_pence) / 100
-
- @cost.setter
- def cost(self, val):
- self.cost_pence = int(val * 100)
+ return self.get_price('GBP')
def user_limit(self, user):
if user.is_authenticated():
@@ -62,6 +61,28 @@ def user_limit(self, user):
Under18 = ConstTicketType('Under-18 Camp Ticket')
+class TicketPrice(db.Model):
+ __tablename__ = 'ticket_price'
+ id = db.Column(db.Integer, primary_key=True)
+ ticket_type_id = db.Column(db.Integer, db.ForeignKey('ticket_type.id'), nullable=False)
+ currency = db.Column(db.String, nullable=False)
+ ticket_type = db.relationship(TicketType, backref="prices")
+ price_value = db.Column(db.Integer, nullable=False)
+
+ def __init__(self, ticket_type, currency, price):
+ self.ticket_type = ticket_type
+ self.currency = currency
+ self.value = price
+
+ @property
+ def value(self):
+ return Decimal(self.price_value) / 100
+
+ @value.setter
+ def value(self, val):
+ self.price_value = int(val * 100)
+
+
class Ticket(db.Model):
__tablename__ = 'ticket'
id = db.Column(db.Integer, primary_key=True)
@@ -88,7 +109,7 @@ def expired(self):
if self.paid:
return False
return self.expires < datetime.utcnow()
-
+
def __repr__(self):
return "<Ticket: %s, type: %s, paid? %s, expired: %s>" % (self.id, self.type_id, self.paid, str(self.expired()))
28 utils.py
View
@@ -17,7 +17,7 @@
from datetime import datetime
from main import app, mail
-from models import User, TicketType, Ticket
+from models import User, TicketType, Ticket, TicketPrice
from models.payment import Payment, BankPayment, GoCardlessPayment, safechars
#app = Flask(__name__)
@@ -266,22 +266,30 @@ def run(self):
#
# if you change these, change ticket_forms in views/tickets.py as well.
#
- types = [
- TicketType('Prepay Camp Ticket', 250, 4, 30.00),
- TicketType('Full Camp Ticket (prepay)', 250, 4, 95.00 - 30.00 - 5.00),
- TicketType('Full Camp Ticket', 499 - 20, 4, 95.00),
+
+ data = [
+ #(name, capacity, max per person, GBP, EUR, Description)
+ ('Prepay Camp Ticket', 250, 4, 30.00, 40.00, None),
+ ('Full Camp Ticket (prepay)', 250, 4, 60.00, 75.00, None),
+ ('Full Camp Ticket', 499 - 20, 4, 95.00, 120.00, None),
# XXX the number of Camp Tickets (of the different types) shoudnt excede 499 - 20 ( issue #85, sort of. )
-# TicketType('Full Camp Ticket (latecomer)', 499 - 20, 4, 100.00),
- TicketType('Under-18 Camp Ticket', 30, 4, 45.00,
+# ('Full Camp Ticket (latecomer)', 499 - 20, 4, 100.00),
+ ('Under-18 Camp Ticket', 30, 4, 47.50, 60.00,
"All children must be accompanied by an adult."),
-# TicketType('Parking Ticket', 25, 4, 10.00,
+# ('Parking Ticket', 25, 4, 10.00,
# "We're trying to keep cars on-site to a minimum. "
# "Please use the nearby carpark or find someone to share with if possible."),
- TicketType('Campervan Ticket', 5, 1, 30.00,
+ ('Campervan Ticket', 5, 1, 30.00, 40.00,
"Space for campervans is extremely limited. We'll email you for details of your requirements."),
- #TicketType('Donation'),
+ #('Donation'),
]
+ types = []
+ for row in data:
+ tt = TicketType(*row[0:3], notice=row[5])
+ tt.prices = [TicketPrice(tt, 'GBP', row[3]), TicketPrice(tt, 'EUR', row[4])]
+ types.append(tt)
+
for tt in types:
try:
TicketType.query.filter_by(name=tt.name).one()
Please sign in to comment.
Something went wrong with that request. Please try again.