From 288759146cf8c82bba7bfe277d4e5a5f8151a8cf Mon Sep 17 00:00:00 2001 From: jmsgrogan Date: Sun, 18 Feb 2024 10:51:57 +0000 Subject: [PATCH] Clean images and case insensitive nav. --- .../primary/migrations/0010_page_prority.py | 18 ++++++++++++++++++ .../0011_rename_prority_page_priority.py | 18 ++++++++++++++++++ wedding_site/primary/models.py | 1 + wedding_site/primary/static/primary/style.css | 7 +++++-- wedding_site/primary/views.py | 15 ++++++++++++++- wedding_site/wedding_site/settings.py | 2 +- wedding_site/wedding_site/urls.py | 2 ++ 7 files changed, 59 insertions(+), 4 deletions(-) create mode 100644 wedding_site/primary/migrations/0010_page_prority.py create mode 100644 wedding_site/primary/migrations/0011_rename_prority_page_priority.py diff --git a/wedding_site/primary/migrations/0010_page_prority.py b/wedding_site/primary/migrations/0010_page_prority.py new file mode 100644 index 0000000..01223ed --- /dev/null +++ b/wedding_site/primary/migrations/0010_page_prority.py @@ -0,0 +1,18 @@ +# Generated by Django 5.0.2 on 2024-02-18 09:58 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('primary', '0009_page_pretty_name'), + ] + + operations = [ + migrations.AddField( + model_name='page', + name='prority', + field=models.IntegerField(default=0), + ), + ] diff --git a/wedding_site/primary/migrations/0011_rename_prority_page_priority.py b/wedding_site/primary/migrations/0011_rename_prority_page_priority.py new file mode 100644 index 0000000..42ac5dd --- /dev/null +++ b/wedding_site/primary/migrations/0011_rename_prority_page_priority.py @@ -0,0 +1,18 @@ +# Generated by Django 5.0.2 on 2024-02-18 10:02 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('primary', '0010_page_prority'), + ] + + operations = [ + migrations.RenameField( + model_name='page', + old_name='prority', + new_name='priority', + ), + ] diff --git a/wedding_site/primary/models.py b/wedding_site/primary/models.py index a73c009..ac7603e 100644 --- a/wedding_site/primary/models.py +++ b/wedding_site/primary/models.py @@ -18,6 +18,7 @@ class Page(models.Model): pretty_name = models.CharField(max_length=200, default="") published = models.BooleanField(default=False) navigable = models.BooleanField(default=False) + priority = models.IntegerField(default=0) def __str__(self): return self.name diff --git a/wedding_site/primary/static/primary/style.css b/wedding_site/primary/static/primary/style.css index 8384158..bbd73c0 100755 --- a/wedding_site/primary/static/primary/style.css +++ b/wedding_site/primary/static/primary/style.css @@ -33,10 +33,9 @@ body { img { margin:0 auto; - width: 100%; display: flex; justify-content: center; - max-height:300px; + max-width:800px; border-radius: 8px; box-shadow: 0 4px 8px 0; } @@ -107,6 +106,10 @@ ul { list-style-position: inside; } +ul li { + padding: 5px 0px; +} + .login-input{ margin-top: 30px; text-align: center; diff --git a/wedding_site/primary/views.py b/wedding_site/primary/views.py index f9295ff..6a90d8f 100644 --- a/wedding_site/primary/views.py +++ b/wedding_site/primary/views.py @@ -6,6 +6,8 @@ from django.template import Context from django.contrib.auth import authenticate, login from django.contrib.auth.decorators import login_required +from django.views.defaults import page_not_found + import markdown from bs4 import BeautifulSoup @@ -24,6 +26,17 @@ _TEMPLATE = """ """ +def handler404(request, exception, template_name="404.html"): + page_names = ["home", "schedule", "thingstodo"] + working_path = request.path.lower() + if working_path and working_path[0] == "/": + working_path = working_path[1:] + if working_path and working_path[-1] == "/": + working_path = working_path[:-1] + if working_path in page_names: + return redirect(working_path) + return page_not_found(request, exception, template_name) + def get_site_header(site): template = Template(site.header) context = Context({"site": site}) @@ -60,7 +73,7 @@ def home(request): def get_page_header(site: Site): - pages = site.page_set.filter(navigable=True) + pages = site.page_set.order_by("priority").filter(navigable=True) template = Template(site.page_header) context = Context({"pages" : pages}) return template.render(context) diff --git a/wedding_site/wedding_site/settings.py b/wedding_site/wedding_site/settings.py index c43b4ba..d97a4d7 100644 --- a/wedding_site/wedding_site/settings.py +++ b/wedding_site/wedding_site/settings.py @@ -25,7 +25,7 @@ SECRET_KEY = 'django-insecure-bj9fez3qztt5e2lrzpgh%%nat@w^kn!k@l92l=+#%wm)4)p^5m # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True -ALLOWED_HOSTS = [] +ALLOWED_HOSTS = ["localhost"] # Application definition diff --git a/wedding_site/wedding_site/urls.py b/wedding_site/wedding_site/urls.py index 6528297..539927f 100644 --- a/wedding_site/wedding_site/urls.py +++ b/wedding_site/wedding_site/urls.py @@ -23,3 +23,5 @@ urlpatterns = [ path("", include('primary.urls')), path('admin/', admin.site.urls), ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) + +handler404 = 'primary.views.handler404'