Esempio n. 1
0
def home(_: Request):
    user_id = 1
    user = repository.get_user_by_id(user_id)

    return {
        'user': user,
    }
Esempio n. 2
0
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)
Esempio n. 4
0
    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
Esempio n. 5
0
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}
Esempio n. 6
0
    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)
Esempio n. 7
0
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))
Esempio n. 8
0
    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
Esempio n. 9
0
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}')
Esempio n. 10
0
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