Skip to content

Commit 31a837d

Browse files
committed
Merge branch 'dev' into Draft_api
2 parents 4783222 + c630b09 commit 31a837d

12 files changed

Lines changed: 163 additions & 25 deletions

File tree

.git-blame-ignore-revs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Autoformat: black
2+
2ee4a7853e7eb55e47653d5f69f271f858a6d3a8

.github/renovate.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
3+
"extends": [
4+
"github>EventAccess/renovate-config"
5+
]
6+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
name: Python
2+
on:
3+
pull_request:
4+
push:
5+
branches:
6+
- dev
7+
jobs:
8+
python-mypy:
9+
name: Mypy
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: read
13+
pull-requests: write
14+
15+
steps:
16+
- uses: actions/checkout@v4.2.2
17+
18+
- name: Set up Python
19+
uses: actions/setup-python@v5.4.0
20+
with:
21+
python-version: 3.12
22+
cache: 'pip'
23+
cache-dependency-path: |
24+
**/requirements.txt
25+
**/requirements-*.txt
26+
27+
- name: Install reviewdog
28+
uses: reviewdog/action-setup@v1.3.0
29+
with:
30+
reviewdog_version: latest
31+
32+
- name: Install dependencies
33+
run: pip install -r requirements-dev.txt
34+
35+
- name: Run MyPy
36+
run: |
37+
mypy --output=json \
38+
| jq -Mac '{"message":(.message+"\n"+.hint),"location":{"path":.file,"range":{"start":{"line":.line,"column":.column}}},"severity":.severity|ascii_upcase,"code":{"url":"https://mypy.readthedocs.io/en/stable/error_code_list.html","value":.code}}' \
39+
| reviewdog -f=rdjsonl -reporter=github-check -name mypy -fail-level warning -filter-mode nofilter
40+
env:
41+
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
42+
43+
python-black:
44+
name: Black
45+
runs-on: ubuntu-latest
46+
permissions:
47+
contents: read
48+
pull-requests: write
49+
50+
steps:
51+
- uses: actions/checkout@v4.2.2
52+
53+
- name: Set up Python
54+
uses: actions/setup-python@v5.4.0
55+
with:
56+
python-version: 3.12
57+
cache: 'pip'
58+
cache-dependency-path: |
59+
**/requirements.txt
60+
**/requirements-*.txt
61+
62+
- name: Install reviewdog
63+
uses: reviewdog/action-setup@v1.3.0
64+
with:
65+
reviewdog_version: v0.20.1
66+
67+
- name: Install dependencies
68+
run: pip install -r requirements-dev.txt
69+
70+
- name: Run Black
71+
if: github.event_name == 'pull_request'
72+
uses: reviewdog/action-black@v3.22.2
73+
with:
74+
reporter: github-pr-review
75+
tool_name: black
76+
level: warning
77+
fail_on_error: true
78+
filter_mode: nofilter
79+
80+
- name: Run Black
81+
if: github.event_name == 'push'
82+
uses: reviewdog/action-black@v3.22.2
83+
with:
84+
reporter: github-check
85+
tool_name: black
86+
level: warning
87+
fail_on_error: true
88+
filter_mode: nofilter

.gitignore

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
*.py[ocd]
2-
**/.env
3-
*.sqlite3
1+
*.py[ocd]
2+
**/.env
3+
*.sqlite3
4+
venv

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM python:3.12.7 AS base
1+
FROM python:3.13.1 AS base
22

33
WORKDIR /app
44

@@ -21,7 +21,7 @@ COPY . .
2121
RUN DJANGO_STATIC_ROOT=/static python manage.py collectstatic --no-input
2222
RUN find /static -ls
2323

24-
FROM ghcr.io/static-web-server/static-web-server:2.33.1 AS static-server
24+
FROM ghcr.io/static-web-server/static-web-server:2.35.0 AS static-server
2525
WORKDIR /srv/http
2626
ENV SERVER_ROOT=/srv/http
2727

backendapi/admin.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,11 @@
1-
from django.contrib import admin
1+
from django.contrib import admin
2+
from database.models import Attendant
3+
from base64 import b16encode
4+
5+
6+
@admin.register(Attendant)
7+
class AttendantAdmin(admin.ModelAdmin):
8+
list_display = ("ticket_id", "nfc_id_decoded", "discord", "is_crew", "is_valid")
9+
10+
def nfc_id_decoded(self, obj):
11+
return b16encode(obj.nfc_id).decode()

backendapi/urls.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@
66
urlpatterns = [
77
path("nfctag/<hex:tag>", views.scanned),
88
path("test", views.api_get, name="api_get"),
9+
path("tickets/verify/<slug:ticket>", views.verify_ticket, name="verify_ticket"),
10+
path("attendants", views.create_attendant, name="create_attendant"),
911
]

backendapi/views.py

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
from django.views.decorators.http import require_POST
44
from django.views.decorators.cache import never_cache
55
from django.http import JsonResponse
6+
from rest_framework.decorators import api_view
7+
from rest_framework.response import Response
8+
from rest_framework import status
9+
from base64 import b16decode, b16encode
610

711
from rest_framework.decorators import api_view
812
from rest_framework.response import Response
@@ -100,14 +104,6 @@ def api_get(request, pk=None):
100104
)
101105

102106

103-
"""
104-
def api_get(request):
105-
if request.method == "GET":
106-
return Response({"message": "GET request received"}, status=202)
107-
elif request.method == "POST":
108-
return Response({"message": "POST request received"}, status=405) """
109-
110-
111107
def base_view(request): # basic frontend registration view.
112108
return render(request, "base.html")
113109

@@ -132,3 +128,38 @@ def registration_view(request):
132128
"success": success,
133129
}
134130
return render(request, "registration.html", context)
131+
132+
133+
@api_view(["GET"])
134+
def verify_ticket(request, ticket):
135+
# TODO: Implement ticket check
136+
if ticket == "test123":
137+
return Response(
138+
{"is_valid": True},
139+
status=status.HTTP_200_OK,
140+
)
141+
return Response(
142+
{"is_valid": False},
143+
status=status.HTTP_400_BAD_REQUEST,
144+
)
145+
146+
147+
@api_view(["POST"])
148+
def create_attendant(request):
149+
ticket_id = request.data.get("ticket_id")
150+
nfc_id = b16decode(request.data.get("nfc_id"), casefold=True)
151+
152+
if not ticket_id or not nfc_id:
153+
return Response(
154+
{"error": "ticket_id and nfc_id are required."},
155+
status=status.HTTP_400_BAD_REQUEST,
156+
)
157+
158+
attendant = Attendant.objects.create(ticket_id=ticket_id, nfc_id=nfc_id)
159+
160+
return Response(
161+
{
162+
"message": "Attendant created successfully.",
163+
"id": attendant.id,
164+
}
165+
)

config/settings.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@
2222
# See https://docs.djangoproject.com/en/5.0/howto/deployment/checklist/
2323

2424
# SECURITY WARNING: keep the secret key used in production secret!
25-
SECRET_KEY = os.getenv(
26-
"DJANGO_SECRET_KEY",
27-
"django-insecure-w^mv=r_(x-se8p#@i*dxfu1^*8$fci+116it+fkj*nx!o2h*r1",
28-
)
25+
SECRET_KEY = os.getenv("DJANGO_SECRET_KEY")
26+
assert SECRET_KEY, "DJANGO_SECRET_KEY env variable is required"
2927
# SECURITY WARNING: don't run with debug turned on in production!
3028
DEBUG = os.getenv("DJANGO_DEBUG", "False").lower() == "true"
3129

3230
ALLOWED_HOSTS = os.getenv("DJANGO_HOSTS", "*").split(",")
31+
if ALLOWED_HOSTS[0] != "*":
32+
CSRF_TRUSTED_ORIGINS = [f"https://{host}" for host in ALLOWED_HOSTS]
3333

3434

3535
# Application definition

0 commit comments

Comments
 (0)