def home(_: Request): user_id = 1 user = repository.get_user_by_id(user_id) return { 'user': user, }
def home(_: Request): user_id = 1 # probably get from a cookie? user = repository.get_user_by_id(user_id) return { 'user': user, }
def __init__(self, request: Request, user_id: int): super().__init__(request) self.user_id = user_id self.user = repository.get_user_by_id(user_id) if not self.user: self.error = "No user with ID {}.".format(user_id)
def __init__(self, request: Request, user_id: int): super().__init__(request) self.bill_id = int(request.matchdict.get('bill_id')) self.bill = repository.get_bill_by_id(self.bill_id) self.user_id = user_id self.user = repository.get_user_by_id(user_id) self.amount = None
def details_get(request: Request): bill_id = int(request.matchdict.get('bill_id')) bill = repository.get_bill_by_id(bill_id) if not bill: return Response(status=404) user_id = 1 # probably get from a cookie? user = repository.get_user_by_id(user_id) return {'user': user, 'bill': bill, 'error': None}
def test_sitemap(self): # Update the way we find the bills for this user. # Turns out the ID varies depending on how you populate # the DB. urls = [ '/' ] user = repository.get_user_by_id(1) bills: List[Bill] = user.bills for b in bills: urls.append('/bill/{}'.format(b.id)) for url in urls: self.app.get(url, status=200)
def details_post(request: Request): bill_id = int(request.matchdict.get('bill_id')) bill = repository.get_bill_by_id(bill_id) if not bill: return Response(status=404) user_id = 1 # probably get from a cookie? user = repository.get_user_by_id(user_id) amount = int(request.POST.get('amount', -1)) if amount < 0 or amount > bill.total - bill.paid: error = 'Your amount must be more the zero and less than what you owe.' return {'user': user, 'bill': bill, 'error': error, 'amount': amount} repository.add_payment(amount, bill_id) return HTTPFound(location='/bill/{}'.format(bill_id))
def __init__(self, request: Request, user_id: int): super().__init__(request) self.bill_id = int(request.matchdict.get('bill_id', -1)) self.bill = repository.get_bill_by_id(self.bill_id) self.user_id = user_id self.user = repository.get_user_by_id(user_id) self.amount = None if not self.user: self.error = "No user with ID {}".format(user_id) elif not self.bill: self.error = "The bill with ID {} was not found".format( self.bill_id) elif self.user.id != self.bill.user_id: self.error = "The bill does not belong to user" self.bill = None
def details_post(request: Request): user_id = 1 user = repository.get_user_by_id(user_id) bill_id = int(request.matchdict.get('bill_id')) bill = repository.get_bill_by_id(bill_id) if not bill: return Response(status=404) amount = int(request.POST.get('amount', -1)) if amount < 0 or amount > bill.total - bill.paid: error = 'Your amount must be more than zero and less than what you owe.' return { 'user': user, 'bill': bill, 'error': error, 'amount': amount, } repository.add_payment(amount, bill_id) raise HTTPFound(location=f'/bill/{bill_id}')
def get_user(request): """Return User object from database with given id.""" user_id = request.unauthenticated_userid if user_id is not None: user = repository.get_user_by_id(user_id) return user