diff --git a/alkatorapi/models.py b/alkatorapi/models.py index aaa7e2d..ae2811f 100644 --- a/alkatorapi/models.py +++ b/alkatorapi/models.py @@ -8,8 +8,8 @@ ALKATOR_CHOICES = ( ) ALKATOR_CLASSES = ( - (2, "Podzim 2024"), - (1, "Jaro 2024"), + (1, "Jaro 2024 Sobkovice"), + (2, "Podzim 2024 Studené"), ) ALKATOR_CHOICES_DICT = { diff --git a/alkatorapi/views.py b/alkatorapi/views.py index f22795c..2dab8ec 100644 --- a/alkatorapi/views.py +++ b/alkatorapi/views.py @@ -11,6 +11,7 @@ import json import glob import PIL.Image import random +from collections import OrderedDict from .models import User, ALKATOR_CHOICES_DICT, ALKATOR_CLASSES from alkator.settings import COMGATE_MERCHANT, COMGATE_SECRET, COMGATE_TEST @@ -194,16 +195,22 @@ def results(request): def photos(request): rtn = [] for (i, name) in ALKATOR_CLASSES: + photos = {} + rtn.append(photos) + photos['name'] = name + photos['index'] = i + photos['photos'] = [] files = glob.glob(f"photos/{i}/*.jpg") random.shuffle(files) for file in files: img = PIL.Image.open(file) - rtn.append({ + photos['photos'].append({ 'original': '/' + file.replace(".jpg", ".webp"), 'thumbnail': '/' + file.replace(f'photos/{i}/', f'photos/{i}/thumbnail/').replace(".jpg", ".webp"), 'original_width': img.width, 'original_height': img.height, }) + return HttpResponse(json.dumps(rtn), content_type='application/json') diff --git a/frontend/src/scripts/index.js b/frontend/src/scripts/index.js index cbeb250..0732610 100644 --- a/frontend/src/scripts/index.js +++ b/frontend/src/scripts/index.js @@ -21,6 +21,7 @@ class Main extends Component { status: "", faq: false, results: [], + gallery_open: undefined, page: window.location.hash, photos: [], photoIsOpen: false, @@ -46,6 +47,9 @@ class Main extends Component { } window.addEventListener("hashchange", (e) => {this.onHashChange(e)}) } + openGallery = (i) => { + this.setState({gallery_open: i}) + } closePhoto = () => { this.setState(state => ({ photoIsOpen: false })) } @@ -56,7 +60,7 @@ class Main extends Component { }) } onHashChange(event){ - this.setState({page: window.location.hash}) + this.setState({page: window.location.hash, gallery_open: undefined}) } handleChangeFiles(event) { this.setState({files: [...event.target.files]}) @@ -105,17 +109,19 @@ class Main extends Component { } render(){ let photos_gallery = []; - let photos_carousel = [] - for (const photo of this.state.photos){ - photos_gallery.push({ - src: photo.thumbnail, - width: photo.original_width, - height: photo.original_height, - }) - photos_carousel.push({ - original: photo.original - }) - }; + let photos_carousel = []; + if(this.state.gallery_open !== undefined){ + for (const photo of this.state.photos[this.state.gallery_open].photos){ + photos_gallery.push({ + src: photo.thumbnail, + width: photo.original_width, + height: photo.original_height, + }) + photos_carousel.push({ + original: photo.original + }) + }; + } return (