File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11* .py [ocd ]
22** /.env
3+ * .sqlite3
Original file line number Diff line number Diff line change 1+ from base64 import b16decode , b16encode
2+
3+
4+ class BinaryHexConverter :
5+ regex = "(?:[0-9a-fA-F]{2})+"
6+
7+ def to_python (self , value : str ) -> bytes :
8+ return b16decode (value , casefold = True )
9+
10+ def to_url (self , value : bytes ) -> str :
11+ return b16encode (value ).decode ()
Original file line number Diff line number Diff line change 1+ from django .urls import path , register_converter
2+
3+ from . import views , converters
4+
5+ register_converter (converters .BinaryHexConverter , "hex" )
6+
7+ urlpatterns = [
8+ path ("nfctag/<hex:tag>" , views .scanned ),
9+ ]
Original file line number Diff line number Diff line change 11from django .shortcuts import render
2+ from django .views .decorators .http import require_POST
3+ from django .views .decorators .cache import never_cache
4+ from django .http import JsonResponse
25
3- # Create your views here.
6+ from database .models import Attendant
7+
8+
9+ @require_POST
10+ @never_cache
11+ def scanned (request , tag : bytes ):
12+ try :
13+ attendant = Attendant .objects .get (tag = tag )
14+ # TODO: Queue event
15+ return JsonResponse ({"valid" : attendant .is_valid }, status = 202 )
16+
17+ except Attendant .DoesNotExist :
18+ return JsonResponse ({"error" : "No such tag" }, status = 404 )
Original file line number Diff line number Diff line change 3737 "django.contrib.sessions" ,
3838 "django.contrib.messages" ,
3939 "django.contrib.staticfiles" ,
40+ # ---
41+ "database" ,
42+ "backendapi" ,
4043]
4144
4245MIDDLEWARE = [
Original file line number Diff line number Diff line change 1616"""
1717
1818from django .contrib import admin
19- from django .urls import path
19+ from django .urls import include , path
20+
21+ import backendapi .urls
2022
2123urlpatterns = [
2224 path ("admin/" , admin .site .urls ),
25+ path ("api/" , include (backendapi .urls )),
2326]
Original file line number Diff line number Diff line change 1+ [pytest]
2+ DJANGO_SETTINGS_MODULE = config.settings
3+ python_files = tests.py test_*.py *_tests.py
You can’t perform that action at this time.
0 commit comments