From 48e3be91d3723c353ffbc37e0a263bf12165c9ab Mon Sep 17 00:00:00 2001 From: Pablo Silva Date: Sun, 23 Jun 2024 22:48:11 +0100 Subject: [PATCH] Create Clipping page, model, view and templates --- src/blog/admin.py | 3 ++- src/blog/jinja2/blog/clipping.jinja2 | 26 ++++++++++++++++++++++++ src/blog/jinja2/blog/post_preview.jinja2 | 1 - src/blog/models.py | 13 ++++++++++++ src/blog/urls.py | 1 + src/blog/views.py | 8 +++++++- src/core/jinja2/core/useful_links.jinja2 | 3 +++ 7 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 src/blog/jinja2/blog/clipping.jinja2 diff --git a/src/blog/admin.py b/src/blog/admin.py index 471d17bf..cb2d3a08 100644 --- a/src/blog/admin.py +++ b/src/blog/admin.py @@ -1,8 +1,9 @@ -from blog.models import Category, Post, PostImage +from blog.models import Category, Clipping, Post, PostImage from django.contrib import admin admin.site.register(Category) admin.site.register(PostImage) +admin.site.register(Clipping) @admin.register(Post) diff --git a/src/blog/jinja2/blog/clipping.jinja2 b/src/blog/jinja2/blog/clipping.jinja2 new file mode 100644 index 00000000..390b78e7 --- /dev/null +++ b/src/blog/jinja2/blog/clipping.jinja2 @@ -0,0 +1,26 @@ +{% extends '/core/home.jinja2' %} + +{% block extra_css %} + +{% endblock %} + +{% block content %} +
+ {% block button %} + {% endblock %} + {% block page_title %} +

{{ _("Clippings") }}

+ {% endblock page_title %} + {% for clipping in clippings %} +
+

{{ clipping.title }}

+

{{ clipping.created.date() }}

+

{{ clipping.description }}

+ {{ clipping.link }} +
+
+ {{ _("Download File")}} +
+ {% endfor %} +
+{% endblock %} \ No newline at end of file diff --git a/src/blog/jinja2/blog/post_preview.jinja2 b/src/blog/jinja2/blog/post_preview.jinja2 index 82637970..c6cde1dd 100644 --- a/src/blog/jinja2/blog/post_preview.jinja2 +++ b/src/blog/jinja2/blog/post_preview.jinja2 @@ -1,4 +1,3 @@ -{% set count = 1 %} {% for post in posts %}

{{ post.title }}

diff --git a/src/blog/models.py b/src/blog/models.py index c9830610..570943e5 100644 --- a/src/blog/models.py +++ b/src/blog/models.py @@ -28,6 +28,19 @@ def __str__(self): return self.file.name.lstrip(IMAGE_BASE_PATH) +class Clipping(models.Model): + id = models.BigAutoField(primary_key=True) + title = models.CharField(max_length=200) + description = models.CharField(max_length=500) + link = models.URLField() + file = models.FileField(upload_to="clipping_files/") + created = models.DateTimeField(auto_now_add=True, editable=True) + updated = models.DateTimeField(auto_now=True, editable=True) + + def __str__(self): + return self.title + + class Post(models.Model): id = models.BigAutoField(primary_key=True) title = models.CharField(max_length=200) diff --git a/src/blog/urls.py b/src/blog/urls.py index c4d7cd1b..c48125c2 100644 --- a/src/blog/urls.py +++ b/src/blog/urls.py @@ -6,5 +6,6 @@ urlpatterns = [ path("", views.blog_index, name="blog_index"), path("post//", views.blog_detail, name="blog_detail"), + path("clippings/", views.clipping, name="clippings"), path("category//", views.blog_category, name="blog_category"), ] diff --git a/src/blog/views.py b/src/blog/views.py index 48f07919..b9eaf918 100644 --- a/src/blog/views.py +++ b/src/blog/views.py @@ -1,4 +1,4 @@ -from blog.models import Category, Post, PostStatus +from blog.models import Category, Clipping, Post, PostStatus from django.shortcuts import render PREVIEW_SIZE = 300 @@ -62,3 +62,9 @@ def blog_detail(request, pk): context = {"post": post, "images": post.images.all()} return render(request, "blog/detail.jinja2", context) + + +def clipping(request): + clippings = Clipping.objects.all().order_by("-created") + context = {"clippings": clippings} + return render(request, "blog/clipping.jinja2", context) diff --git a/src/core/jinja2/core/useful_links.jinja2 b/src/core/jinja2/core/useful_links.jinja2 index f6796c01..b2d56f36 100644 --- a/src/core/jinja2/core/useful_links.jinja2 +++ b/src/core/jinja2/core/useful_links.jinja2 @@ -11,6 +11,9 @@
{{ _('Blog') }}
+
+ {{ _('Clippings') }} +
{{ _('My Stuff') }}