generated from hjess/PythonTemplateProject
cache fix og title
All checks were successful
Build, Push, and Deploy to Nomad / docker-nomad (push) Successful in 41s
All checks were successful
Build, Push, and Deploy to Nomad / docker-nomad (push) Successful in 41s
This commit is contained in:
@@ -4,7 +4,7 @@ from fastapi import APIRouter, Request
|
||||
from fastapi.responses import HTMLResponse
|
||||
from fastapi.templating import Jinja2Templates
|
||||
from fastapi.responses import JSONResponse
|
||||
|
||||
import time
|
||||
|
||||
class CategoryController:
|
||||
def __init__(self,data_file="generated_data.json"):
|
||||
@@ -33,15 +33,51 @@ class CategoryController:
|
||||
return json.load(file)
|
||||
|
||||
async def get_index(self, request: Request):
|
||||
"""Index route."""
|
||||
"""
|
||||
Handle requests for the index (home) page.
|
||||
|
||||
This function is executed every time the root route (index page) is accessed.
|
||||
It renders the 'index.html' template and populates it with dynamic data, such as:
|
||||
- 'page_title': A static title for the home page ("Forside").
|
||||
- 'author': The author's name ("Henrik").
|
||||
- 'data': General data accessible to the template.
|
||||
|
||||
Args:
|
||||
request (Request): The HTTP request object.
|
||||
|
||||
Returns:
|
||||
TemplateResponse: A rendered HTML page for the index (home) route.
|
||||
"""
|
||||
return self.templates.TemplateResponse(
|
||||
"index.html",
|
||||
{"request": request, "data": self.data, "page_title": "Forside", "author": "Henrik"},
|
||||
)
|
||||
|
||||
async def get_category(self, request: Request, category_name: str):
|
||||
"""Category route."""
|
||||
"""
|
||||
Handle requests for specific category pages.
|
||||
|
||||
This function is executed every time a category route is accessed.
|
||||
It dynamically retrieves and serves content for the requested category.
|
||||
- Searches for the requested category in 'self.data["categories"]' based on the provided category name.
|
||||
- Reads the 'index.html' file located under 'data/{category_name}/' if it exists.
|
||||
- Returns the rendered 'category.html' template with the following dynamic data:
|
||||
- 'page_title': The name of the category.
|
||||
- 'author': The author of the category.
|
||||
- 'content': The content of the 'index.html' file.
|
||||
- 'timestamp': The current Unix time when the request is processed.
|
||||
- Returns a 404 HTML response if the category is not found or the file does not exist.
|
||||
|
||||
Args:
|
||||
request (Request): The HTTP request object.
|
||||
category_name (str): The name of the category being accessed.
|
||||
|
||||
Returns:
|
||||
TemplateResponse: A rendered HTML page with dynamic category content.
|
||||
HTMLResponse: A 404 response if the category does not exist.
|
||||
"""
|
||||
category = next((cat for cat in self.data["categories"] if cat["path"] == category_name), None)
|
||||
unix_time_now = int( time.time() )
|
||||
if category:
|
||||
category_file = f"data/{category_name}/index.html"
|
||||
if os.path.exists(category_file):
|
||||
@@ -55,6 +91,7 @@ class CategoryController:
|
||||
"page_title": category["name"],
|
||||
"author": category["author"],
|
||||
"content": category_content,
|
||||
"timestamp": unix_time_now
|
||||
},
|
||||
)
|
||||
return HTMLResponse("Kategori ikke fundet", status_code=404)
|
||||
|
||||
@@ -54,29 +54,29 @@
|
||||
<li><strong>UCI El Corte Inglés</strong>: Den moderne biografoplevelse med de nyeste blockbusters. Sammenligneligt med Palads i København, men med en lidt mere luksuriøs oplevelse i selve komplekset.</li>
|
||||
</ul>
|
||||
<p><div class="button-stack">
|
||||
<button onclick="openModal('modal6E3E27_0')" class="stacked-button"> <img src="https://lifecooler.com/files/registos/imagens/404151/158177.jpg" class="thumbnail"></button>
|
||||
<div class="modal" id="modal6E3E27_0"> <div class="modal-content">
|
||||
<button onclick="openModal('modal3A7677_0')" class="stacked-button"> <img src="https://lifecooler.com/files/registos/imagens/404151/158177.jpg" class="thumbnail"></button>
|
||||
<div class="modal" id="modal3A7677_0"> <div class="modal-content">
|
||||
<h2>Modal 0</h2>
|
||||
<img src="https://lifecooler.com/files/registos/imagens/404151/158177.jpg">
|
||||
<div class="modal-buttons">
|
||||
<button onclick="closeModal('modal6E3E27_0')">Close</button>
|
||||
<button class="next-btn" onclick="nextModal('modal6E3E27_0', 'modal6E3E27_0_1')">Next</button>
|
||||
<button onclick="closeModal('modal3A7677_0')">Close</button>
|
||||
<button class="next-btn" onclick="nextModal('modal3A7677_0', 'modal3A7677_0_1')">Next</button>
|
||||
</div> </div></div>
|
||||
<button onclick="openModal('modal6E3E27_0_1')" class="stacked-button"> <img src="https://lifecooler.com/files/registos/imagens/404151/158170.jpg" class="thumbnail" ></button>
|
||||
<div class="modal" id="modal6E3E27_0_1"> <div class="modal-content">
|
||||
<button onclick="openModal('modal3A7677_0_1')" class="stacked-button"> <img src="https://lifecooler.com/files/registos/imagens/404151/158170.jpg" class="thumbnail" ></button>
|
||||
<div class="modal" id="modal3A7677_0_1"> <div class="modal-content">
|
||||
<h2>Modal 1</h2>
|
||||
<img src="https://lifecooler.com/files/registos/imagens/404151/158170.jpg">
|
||||
<div class="modal-buttons">
|
||||
<button onclick="closeModal('modal6E3E27_0_1')">Close</button>
|
||||
<button class="next-btn" onclick="nextModal('modal6E3E27_0_1', 'modal6E3E27_0_1_2')">Next</button>
|
||||
<button onclick="closeModal('modal3A7677_0_1')">Close</button>
|
||||
<button class="next-btn" onclick="nextModal('modal3A7677_0_1', 'modal3A7677_0_1_2')">Next</button>
|
||||
</div> </div></div>
|
||||
<button onclick="openModal('modal6E3E27_0_1_2')" class="stacked-button"> <img src="https://upload.wikimedia.org/wikipedia/commons/8/88/Fachada_S%C3%A3oJorge.jpg" class="thumbnail"></button>
|
||||
<div class="modal" id="modal6E3E27_0_1_2"> <div class="modal-content">
|
||||
<button onclick="openModal('modal3A7677_0_1_2')" class="stacked-button"> <img src="https://upload.wikimedia.org/wikipedia/commons/8/88/Fachada_S%C3%A3oJorge.jpg" class="thumbnail"></button>
|
||||
<div class="modal" id="modal3A7677_0_1_2"> <div class="modal-content">
|
||||
<h2>Modal 2</h2>
|
||||
<img src="https://upload.wikimedia.org/wikipedia/commons/8/88/Fachada_S%C3%A3oJorge.jpg">
|
||||
<div class="modal-buttons">
|
||||
<button onclick="closeModal('modal6E3E27_0_1_2')">Close</button>
|
||||
<button class="next-btn" onclick="nextModal('modal6E3E27_0_1_2', 'modal6E3E27_0_1_2_0')">Next</button>
|
||||
<button onclick="closeModal('modal3A7677_0_1_2')">Close</button>
|
||||
<button class="next-btn" onclick="nextModal('modal3A7677_0_1_2', 'modal3A7677_0_1_2_0')">Next</button>
|
||||
</div> </div></div>
|
||||
</div></p>
|
||||
<p>Biografbesøg i Lissabon er en afslappet måde at tilbringe tid med familien. Jeg nyder selv at tage afsted med Erika for at dele både film og hygge.</p>
|
||||
@@ -104,37 +104,37 @@
|
||||
<p>Samtidig er mange oplevelser billigere end i København, og her er en atmosfære, der er svær at finde nordpå: Lissabon har en unik blanding af tradition og modernitet, som gør den til en by, der bliver ved med at fascinere.</p>
|
||||
<h3>Lidt billeder</h3>
|
||||
<p><div class="button-stack">
|
||||
<button onclick="openModal('modal28D1BC_0')" class="stacked-button"> <img src="https://picsum.photos/id/34/500/375" class="thumbnail"></button>
|
||||
<div class="modal" id="modal28D1BC_0"> <div class="modal-content">
|
||||
<button onclick="openModal('modal6C80E1_0')" class="stacked-button"> <img src="https://picsum.photos/id/34/500/375" class="thumbnail"></button>
|
||||
<div class="modal" id="modal6C80E1_0"> <div class="modal-content">
|
||||
<h2>Modal 0</h2>
|
||||
<img src="https://picsum.photos/id/34/500/375">
|
||||
<div class="modal-buttons">
|
||||
<button onclick="closeModal('modal28D1BC_0')">Close</button>
|
||||
<button class="next-btn" onclick="nextModal('modal28D1BC_0', 'modal28D1BC_0_1')">Next</button>
|
||||
<button onclick="closeModal('modal6C80E1_0')">Close</button>
|
||||
<button class="next-btn" onclick="nextModal('modal6C80E1_0', 'modal6C80E1_0_1')">Next</button>
|
||||
</div> </div></div>
|
||||
<button onclick="openModal('modal28D1BC_0_1')" class="stacked-button"> <img src="https://picsum.photos/id/42/500/375" class="thumbnail" ></button>
|
||||
<div class="modal" id="modal28D1BC_0_1"> <div class="modal-content">
|
||||
<button onclick="openModal('modal6C80E1_0_1')" class="stacked-button"> <img src="https://picsum.photos/id/42/500/375" class="thumbnail" ></button>
|
||||
<div class="modal" id="modal6C80E1_0_1"> <div class="modal-content">
|
||||
<h2>Modal 1</h2>
|
||||
<img src="https://picsum.photos/id/42/500/375">
|
||||
<div class="modal-buttons">
|
||||
<button onclick="closeModal('modal28D1BC_0_1')">Close</button>
|
||||
<button class="next-btn" onclick="nextModal('modal28D1BC_0_1', 'modal28D1BC_0_1_2')">Next</button>
|
||||
<button onclick="closeModal('modal6C80E1_0_1')">Close</button>
|
||||
<button class="next-btn" onclick="nextModal('modal6C80E1_0_1', 'modal6C80E1_0_1_2')">Next</button>
|
||||
</div> </div></div>
|
||||
<button onclick="openModal('modal28D1BC_0_1_2')" class="stacked-button"> <img src="https://picsum.photos/id/72/500/375" class="thumbnail"></button>
|
||||
<div class="modal" id="modal28D1BC_0_1_2"> <div class="modal-content">
|
||||
<button onclick="openModal('modal6C80E1_0_1_2')" class="stacked-button"> <img src="https://picsum.photos/id/72/500/375" class="thumbnail"></button>
|
||||
<div class="modal" id="modal6C80E1_0_1_2"> <div class="modal-content">
|
||||
<h2>Modal 2</h2>
|
||||
<img src="https://picsum.photos/id/72/500/375">
|
||||
<div class="modal-buttons">
|
||||
<button onclick="closeModal('modal28D1BC_0_1_2')">Close</button>
|
||||
<button class="next-btn" onclick="nextModal('modal28D1BC_0_1_2', 'modal28D1BC_0_1_2_3')">Next</button>
|
||||
<button onclick="closeModal('modal6C80E1_0_1_2')">Close</button>
|
||||
<button class="next-btn" onclick="nextModal('modal6C80E1_0_1_2', 'modal6C80E1_0_1_2_3')">Next</button>
|
||||
</div> </div></div>
|
||||
<button onclick="openModal('modal28D1BC_0_1_2_3')" class="stacked-button"> <img src="https://picsum.photos/id/94/500/375" class="thumbnail" ></button>
|
||||
<div class="modal" id="modal28D1BC_0_1_2_3"> <div class="modal-content">
|
||||
<button onclick="openModal('modal6C80E1_0_1_2_3')" class="stacked-button"> <img src="https://picsum.photos/id/94/500/375" class="thumbnail" ></button>
|
||||
<div class="modal" id="modal6C80E1_0_1_2_3"> <div class="modal-content">
|
||||
<h2>Modal 3</h2>
|
||||
<img src="https://picsum.photos/id/94/500/375">
|
||||
<div class="modal-buttons">
|
||||
<button onclick="closeModal('modal28D1BC_0_1_2_3')">Close</button>
|
||||
<button class="next-btn" onclick="nextModal('modal28D1BC_0_1_2_3', 'modal28D1BC_0_1_2_3_0')">Next</button>
|
||||
<button onclick="closeModal('modal6C80E1_0_1_2_3')">Close</button>
|
||||
<button class="next-btn" onclick="nextModal('modal6C80E1_0_1_2_3', 'modal6C80E1_0_1_2_3_0')">Next</button>
|
||||
</div> </div></div>
|
||||
</div></p>
|
||||
</div>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<title>{% block title %}PortugalFAQ{% endblock %}</title>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=yes" />
|
||||
<link rel="stylesheet" href="/static/css/main.css?v={{ current_time }}">
|
||||
<link rel="stylesheet" href="/static/css/main.css?v={{ timestamp }}">
|
||||
</head>
|
||||
<body class="is-preload">
|
||||
<!-- Wrapper -->
|
||||
@@ -32,6 +32,7 @@
|
||||
{% else %}
|
||||
<p>Ingen næste kategori.</p>
|
||||
{% endif %}
|
||||
|
||||
</footer>
|
||||
</div>
|
||||
</div>
|
||||
@@ -57,7 +58,7 @@
|
||||
<script src="/static/js/breakpoints.min.js"></script>
|
||||
<script src="/static/js/util.js"></script>
|
||||
<script src="/static/js/main.js"></script>
|
||||
<script src="/static/js/modal_handler.js?v={{ current_time }}"></script>
|
||||
<script src="/static/js/modal_handler.js?v={{ timestamp }}"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,6 +1,6 @@
|
||||
{% extends "base_template.html" %}
|
||||
|
||||
{% block title %}{{ category_name }} - PortugalFAQ{% endblock %}
|
||||
{% block title %}{{ page_title }} - PortugalFAQ{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<header class="main">
|
||||
|
||||
Reference in New Issue
Block a user