diff --git a/ContentfulService.py b/ContentfulService.py index c9fdef2..9088fba 100644 --- a/ContentfulService.py +++ b/ContentfulService.py @@ -1,6 +1,7 @@ import contentful import markdown import os +import re class ContentfulService: def __init__(self, space_id, access_token): @@ -44,4 +45,60 @@ class ContentfulService: } location_list.append(content) return location_list + + def get_exhibition_list_info(self): + entries = self.client.entries({'content_type': 'exhibitionList'}) + exhibition_list = [] + for e in entries: + title = getattr(e, 'title') + + description = getattr(e, 'description') + description = markdown.markdown(description) + + start_date = getattr(e, 'start_date') + start_date = start_date.strftime('%#d %b %Y') if start_date else None + + end_date = getattr(e, 'end_date') + end_date = end_date.strftime('%#d %b %Y') if end_date else None + + location = getattr(e, 'location') + + slug = title.lower() # Convert to lowercase + slug = re.sub(r'[^a-z0-9\s-]', '', slug) # Remove non-alphanumeric characters + slug = re.sub(r'[\s-]+', '-', slug).strip('-') # Replace spaces and repeated hyphens + url = slug + + content = { + 'title': title, + 'location': location, + 'description': description, + 'start_date': start_date, + 'end_date': end_date, + 'url': url + } + + exhibition_list.append(content) + return exhibition_list + + def get_sponser_logos(self): + entries = self.client.entries({'content_type': 'sponser'}) + supp_img = [] + prio_img = [] + top_img = [] + for e in entries: + src = getattr(e, 'logo') + idx = getattr(e, 'type') + + content = 'https:{0}'.format(src.url()) + + + if idx == '1': + top_img.append(content) + elif idx == '2': + prio_img.append(content) + else: + supp_img.append(content) + + + return supp_img, prio_img, top_img \ No newline at end of file diff --git a/__pycache__/ContentfulService.cpython-310.pyc b/__pycache__/ContentfulService.cpython-310.pyc index 9f0f05b..430c93f 100644 Binary files a/__pycache__/ContentfulService.cpython-310.pyc and b/__pycache__/ContentfulService.cpython-310.pyc differ diff --git a/app.py b/app.py index e773902..e48c3a2 100644 --- a/app.py +++ b/app.py @@ -29,7 +29,7 @@ def inject_general_info(): @app.route('/') def index(): - sup_img, prio_img, prio_img_top = get_support_images() + sup_img, prio_img, prio_img_top = contentful_service.get_sponser_logos() return render_template('index.html', title='', sup_img_list=sup_img, prio_img=prio_img, prio_img_top=prio_img_top) @app.route('/grph') @@ -43,7 +43,9 @@ def events(): @app.route('/exhibitions') def exhibitions(): - return render_template('list.html', title='Exhibitions') + exhibition_info = contentful_service.get_exhibition_list_info() + print(exhibition_info) + return render_template('list.html', title='Exhibitions', exhibition_info=exhibition_info) @app.route('/exhibitions/') def exhibition_type(ex_type): @@ -53,6 +55,8 @@ def exhibition_type(ex_type): ex_type = "UTA" elif ex_type == "ethics-studio": ex_type = "ES" + elif ex_type == "starts4waterii": + ex_type = "S4W2" exhibitions = get_all_content('exhibition') return render_template('list-exhibitions.html', title="Exhibitions", content=exhibitions, ex_type=ex_type) @@ -148,33 +152,7 @@ def process_content(entries, type): # Sort the content list by the 'title' key alphabetically content_list.sort(key=lambda x: x['title'].lower()) - return content_list - -def get_support_images(): - # Specify the folder where images are stored - image_folder = os.path.join(app.static_folder, 'images/support') - - # Define a list of supported image file extensions - valid_extensions = ['.jpg', '.jpeg', '.png', '.gif', '.bmp'] - - # List to hold the image file names - image_files = [] - prio_image_files = [] - prio_image_top_files = [] - - # Loop through files in the directory - for filename in os.listdir(image_folder): - # Check if the file is an image (by extension) - if os.path.splitext(filename)[1].lower() in valid_extensions: - if os.path.splitext(filename)[0].lower() == "dg" or os.path.splitext(filename)[0].lower() == "sw": - prio_image_top_files.append(filename) - elif os.path.splitext(filename)[0].lower() == "french-emb" or os.path.splitext(filename)[0].lower() == "nn" or os.path.splitext(filename)[0].lower() == "if": - prio_image_files.append(filename) - else: - image_files.append(filename) - - return image_files, prio_image_files, prio_image_top_files - + return content_list def format_datetime(dt): date_str = dt.strftime('%d.%m.%y') diff --git a/templates/index.html b/templates/index.html index f4e3551..483a81a 100644 --- a/templates/index.html +++ b/templates/index.html @@ -40,7 +40,7 @@
{% for img in prio_img_top %}
- +
{% endfor %}
@@ -48,7 +48,7 @@
{% for img in prio_img %}
- +
{% endfor %}
@@ -56,7 +56,7 @@
{% for img in sup_img_list %}
- +
{% endfor %}
diff --git a/templates/list-exhibitions.html b/templates/list-exhibitions.html index 3261a4f..6838803 100644 --- a/templates/list-exhibitions.html +++ b/templates/list-exhibitions.html @@ -7,9 +7,9 @@ {% include '_nav.html' %} {% include '_list-header.html'%}
- {% if ex_type == "UTA" %} + {% if ex_type == "S4W2" %}
- Unsettling the Algorithm ↑ + STARTS4WaterII ↑
{% endif %} {% if ex_type == "LAN" %} @@ -27,8 +27,8 @@ {% for event in content %} {% if event.exh_type == ex_type %} - {% if ex_type == "UTA"%} - + {% if ex_type == "S4W2"%} + {% endif %} {% if ex_type == "LAN"%} diff --git a/templates/list.html b/templates/list.html index 89d92d5..1007ecf 100644 --- a/templates/list.html +++ b/templates/list.html @@ -18,7 +18,16 @@ {% endif %} {% if title == 'Exhibitions' %} - {% include '_ex.html' %} + {% for ex in exhibition_info %} +
+

{{ ex.title }}

+ {{ ex.description | safe }} +
+

Date: {{ ex.start_date }} -> {{ ex.end_date }}

+

Location: {{ ex.location }}

+
+
+ {% endfor %} {% endif %} {% endif %}