X-Git-Url: https://git.frykholm.com/tranquillity.git/blobdiff_plain/93be18536faaa33c9c2d3a4e5625fa7bfca8eb20..HEAD:/customerportal/views.py diff --git a/customerportal/views.py b/customerportal/views.py index 3578d6a..182086e 100644 --- a/customerportal/views.py +++ b/customerportal/views.py @@ -1,9 +1,24 @@ from django.shortcuts import render from django.http import HttpResponse from django.contrib.auth.decorators import login_required +from django.conf import settings +try: + import requests +except ModuleNotFoundError as e: + pass + @login_required def index(request): - - return render(request, 'customerportal/landing.html') + headers = {"Access-Token":settings.FORTNOX_ACCESS_TOKEN, + "Client-Secret":settings.FORTNOX_CLIENT_SECRET, + "Content-Type":"application/json", + "Accept":"application/json" } + res = requests.get("https://api.fortnox.se/3/contracts/", headers=headers) + contracts=res.json() + contracts = [contract for contract in contracts['Contracts'] if int(contract['CustomerNumber']) == request.user.fortnox_external_id] + res = requests.get("https://api.fortnox.se/3/invoices/", headers=headers) + invoices = res.json() + invoices = [invoice for invoice in invoices['Invoices'] if int(invoice['CustomerNumber']) == request.user.fortnox_external_id] + return render(request, 'customerportal/landing.html',context={'contracts':contracts, 'invoices':invoices})