-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #732 from ocf/add-quotas
Added print quota
- Loading branch information
Showing
2 changed files
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from django.http import HttpRequest | ||
from django.http import HttpResponse | ||
from django.http import HttpResponseBadRequest | ||
from django.http import JsonResponse | ||
from django.views.decorators.http import require_POST | ||
from ocflib.printing.quota import get_connection | ||
from ocflib.printing.quota import get_quota | ||
|
||
from ocfweb.auth import login_required | ||
from ocfweb.component.session import logged_in_user | ||
|
||
|
||
@require_POST | ||
@login_required | ||
def paper_quota(request: HttpRequest) -> HttpResponse: | ||
try: | ||
user = logged_in_user(request) | ||
|
||
with get_connection() as c: | ||
quota = get_quota(c, user) | ||
return JsonResponse({ | ||
'user': quota.user, | ||
'daily': quota.daily, | ||
'semesterly': quota.semesterly, | ||
}) | ||
|
||
except (KeyError, ValueError) as e: | ||
return HttpResponseBadRequest(e) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters