Browse Source

finished

2025
Cailean Finn 2 weeks ago
parent
commit
ce9c22d0b1
  1. 57
      ContentfulService.py
  2. BIN
      __pycache__/ContentfulService.cpython-310.pyc
  3. 36
      app.py
  4. 6
      templates/index.html
  5. 8
      templates/list-exhibitions.html
  6. 11
      templates/list.html

57
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

BIN
__pycache__/ContentfulService.cpython-310.pyc

Binary file not shown.

36
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/<ex_type>')
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')

6
templates/index.html

@ -40,7 +40,7 @@
<div id="index-support-prio-top">
{% for img in prio_img_top %}
<div class="index-prio-img">
<img src="{{ url_for('static', filename='images/support/' + img) }}">
<img src="{{ img }}">
</div>
{% endfor %}
</div>
@ -48,7 +48,7 @@
<div id="index-support-prio">
{% for img in prio_img %}
<div class="index-prio-img">
<img src="{{ url_for('static', filename='images/support/' + img) }}">
<img src="{{ img }}">
</div>
{% endfor %}
</div>
@ -56,7 +56,7 @@
<div id="index-support">
{% for img in sup_img_list %}
<div class="index-support-img">
<img src="{{ url_for('static', filename='images/support/' + img) }}">
<img src="{{ img }}">
</div>
{% endfor %}
</div>

8
templates/list-exhibitions.html

@ -7,9 +7,9 @@
{% include '_nav.html' %}
{% include '_list-header.html'%}
<div id="main-container">
{% if ex_type == "UTA" %}
{% if ex_type == "S4W2" %}
<div class="list-header">
Unsettling the Algorithm
STARTS4WaterII
</div>
{% endif %}
{% if ex_type == "LAN" %}
@ -27,8 +27,8 @@
{% for event in content %}
{% if event.exh_type == ex_type %}
{% if ex_type == "UTA"%}
<a href='/{{ title.lower() }}/unsettling-the-algorithm/{{ event.title }}'>
{% if ex_type == "S4W2"%}
<a href='/{{ title.lower() }}/starts4waterii/{{ event.title }}'>
{% endif %}
{% if ex_type == "LAN"%}
<a href='/{{ title.lower() }}/local-artists-network/{{event.title}}'>

11
templates/list.html

@ -18,7 +18,16 @@
{% endif %}
{% if title == 'Exhibitions' %}
{% include '_ex.html' %}
{% for ex in exhibition_info %}
<div class="exh-container">
<a href="exhibitions/{{ ex.url }}"><h1>{{ ex.title }}</h1></a>
{{ ex.description | safe }}
<div class="exh-info">
<p>Date: {{ ex.start_date }} -> {{ ex.end_date }}</p>
<p>Location: {{ ex.location }}</p>
</div>
</div>
{% endfor %}
{% endif %}
{% endif %}
</div>

Loading…
Cancel
Save