Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added print quota #732

Merged
merged 3 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions ocfweb/api/paper.py
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)
2 changes: 2 additions & 0 deletions ocfweb/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from ocfweb.api import announce
from ocfweb.api import hours
from ocfweb.api import lab
from ocfweb.api import paper
from ocfweb.api import session_tracking
from ocfweb.api import shorturls
from ocfweb.api import staff_hours
Expand All @@ -18,4 +19,5 @@
path('lab/staff', stats.get_staff_in_lab, name='get_staff_in_lab'),
path('session/log', session_tracking.log_session, name='log_session'),
path('shorturl/<path:slug>', shorturls.bounce_shorturl, name='bounce_shorturl'),
path('quotas/paper', paper.paper_quota, name='paper_quota'),
]