27 lines
673 B
Python
27 lines
673 B
Python
from rowers.models import Rower
|
|
|
|
class InsufficientCreditError(Exception):
|
|
"""Raised when trying to subtract more than available"""
|
|
pass
|
|
|
|
def upgrade(amount, rower):
|
|
if rower.eurocredits > amount:
|
|
return rower.eurocredits
|
|
else:
|
|
rower.eurocredits = amount
|
|
rower.save()
|
|
return rower.eurocredits
|
|
return rower.eurocredits
|
|
|
|
def withdraw(amount, rower):
|
|
if rower.eurocredits < amount:
|
|
rower.eurocredits = 0
|
|
rower.save()
|
|
raise InsufficientCreditError
|
|
else:
|
|
rower.eurocredits = rower.eurocredits - amount
|
|
rower.save()
|
|
return rower.eurocredits
|
|
|
|
return rower.eurocredits
|