diff --git a/alkator/urls.py b/alkator/urls.py index 4f1c9ea..ad6f677 100644 --- a/alkator/urls.py +++ b/alkator/urls.py @@ -16,7 +16,7 @@ Including another URLconf """ from django.contrib import admin from django.urls import path -from alkatorapi.views import register, results, photos, payment_result, payment_state, invoice +from alkatorapi.views import register, results, photos, payment_result, payment_state, invoice, upload_files urlpatterns = [ path('admin/', admin.site.urls), @@ -26,4 +26,5 @@ urlpatterns = [ path('api/payment_result', payment_result), path('api/payment_state', payment_state), path('api/invoice', invoice), + path('api/upload_files', upload_files) ] diff --git a/alkatorapi/views.py b/alkatorapi/views.py index db12ebc..af9c21e 100644 --- a/alkatorapi/views.py +++ b/alkatorapi/views.py @@ -207,6 +207,18 @@ def photos(request): return HttpResponse(json.dumps(rtn), content_type='application/json') +@csrf_exempt +def upload_files(request): + for name, file in request.FILES.items(): + print(name) + rand = random.randint(0, 99999) + random_name = f'photos/uploads/{rand}_{file.name}' + with open(random_name, "wb+") as destination: + for chunk in file.chunks(): + destination.write(chunk) + return HttpResponse('{"success":"Úspěšně nahráno! Počkejte až dojde ke schválení nahraných souborů."}', content_type='application/json') + + @staff_member_required def invoice(request): user = User.objects.get(invoice_id=request.GET['invoice_id']) diff --git a/frontend/src/scripts/index.js b/frontend/src/scripts/index.js index 4de552a..87f4a9d 100644 --- a/frontend/src/scripts/index.js +++ b/frontend/src/scripts/index.js @@ -15,6 +15,7 @@ class Main extends Component { constructor(props) { super(props); this.state = { + files: [], text: "", status: "", faq: false, @@ -55,15 +56,19 @@ class Main extends Component { onHashChange(event){ this.setState({page: window.location.hash}) } + handleChangeFiles(event) { + this.setState({files: [...event.target.files]}) + } onSubmit(event){ event.preventDefault(); let form = document.getElementById("form"); + let api_endpoint = form.action; let formData = new FormData(form); if(this.state.progress){ return; } this.setState({progress: true}) - fetch(addr_prefix + "/api/register", { + fetch(addr_prefix + api_endpoint, { method:"POST", body: formData, }).then(resp => resp.json()).then(json => { @@ -78,7 +83,9 @@ class Main extends Component { text: json.success, status: "success", }) - window.open(json.redirect ,"_self") + if (json.redirect){ + window.open(json.redirect ,"_self") + } } }); } @@ -128,12 +135,30 @@ class Main extends Component { + + {this.state.status == "success" && +
+ {this.state.text} +
} + {this.state.status == "failed" && +
+ {this.state.text} +
} + {this.state.page == "#upload_files" && +
+
this.onSubmit(e)}> + + +
+
} {this.state.page == "#payment" &&
Platební bránu poskytuje firma Comgate, a.s. Platit je možné pomocí platební karty nebo bankovním převodem. Podrobnosti a přesný postup platby včetně animací najdete v odkazech.
@@ -150,14 +175,6 @@ class Main extends Component { } {this.state.page == "" &&
- {this.state.status == "success" && -
- {this.state.text} -
} - {this.state.status == "failed" && -
- {this.state.text} -
} {this.state.faq &&
} {this.state.faq && @@ -261,7 +278,7 @@ class Main extends Component {

Sportem ku chlastu!

-

Výsledky 2. ročníku (Podzim 2024)

+

Výsledky 1. ročníku

{this.state.results && @@ -296,7 +313,7 @@ class Main extends Component {

Kapacita je aktuálně naplněna, budem se těšit u dalšího ročníku.

{/* - this.onSubmit(e)}> + this.onSubmit(e)}>

Registrace

diff --git a/photos/.gitkeep b/photos/1/.gitkeep old mode 100644 new mode 100755 similarity index 100% rename from photos/.gitkeep rename to photos/1/.gitkeep diff --git a/photos/2/.gitkeep b/photos/2/.gitkeep new file mode 100755 index 0000000..e69de29 diff --git a/photos/uploads/.gitkeep b/photos/uploads/.gitkeep new file mode 100755 index 0000000..e69de29 diff --git a/resize_photos.py b/resize_photos.py index ed1c20a..dd76887 100644 --- a/resize_photos.py +++ b/resize_photos.py @@ -1,7 +1,7 @@ import glob import PIL.Image -photos = glob.glob('photos/*.jpg') +photos = glob.glob('photos/2/*.jpg') for image in photos: print(image)