Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add blog to Jandig #562

Merged
merged 25 commits into from
Jun 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
d0db52e
Update URL order in configs for better debugging routes
pablodiegoss May 26, 2024
2cf2909
Create app Blog
pablodiegoss May 26, 2024
60e9ca4
Create models Post, Category and PostStatus
pablodiegoss May 26, 2024
a4abd1f
Update ProfileAdmin
pablodiegoss May 26, 2024
c23d5ec
Add admin for Posts and Categories
pablodiegoss May 26, 2024
e29f5c6
Create views for Blog index, categories and post details
pablodiegoss May 26, 2024
c721e43
Add blog URLs
pablodiegoss May 26, 2024
4276c2a
Add jinja templates for blog
pablodiegoss May 26, 2024
6a3979e
Update Profile and User admin pages
pablodiegoss Jun 5, 2024
aad40f6
Update detail page for posts
pablodiegoss Jun 5, 2024
f18ea52
Update index page for blog
pablodiegoss Jun 5, 2024
93b5a16
Update configs to add a blog.css file
pablodiegoss Jun 5, 2024
f7cacc5
Show only published posts
pablodiegoss Jun 5, 2024
2651cd4
Add back button
pablodiegoss Jun 22, 2024
5a8885d
Update css
pablodiegoss Jun 22, 2024
78b4b1f
Update blog model fields
pablodiegoss Jun 22, 2024
b44ddec
Add pagination to blog index
pablodiegoss Jun 22, 2024
9e805e4
Remove warning from nullable manytomany field
pablodiegoss Jun 22, 2024
71b8849
Add pagination to categories page
pablodiegoss Jun 22, 2024
f0e0836
Add images to posts
pablodiegoss Jun 23, 2024
2b894d6
Add categories header to blog
pablodiegoss Jun 23, 2024
b29b034
Apply black and isort to blog code
pablodiegoss Jun 23, 2024
48e3be9
Create Clipping page, model, view and templates
pablodiegoss Jun 23, 2024
74137f6
Add project migrations
pablodiegoss Jun 23, 2024
709c629
Add django htmx to dependencies
pablodiegoss Jun 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: '3.8'

services:
django:
build:
Expand Down
17 changes: 16 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ django-storages = "^1.12.3"
sentry-sdk = "^1.7.0"
djangorestframework = "^3.13.1"
drf-nested-routers = "^0.93.4"
django-htmx = "^1.18.0"

[tool.poetry.dev-dependencies]
playwright = "^1.41.2"
Expand Down
Empty file added src/blog/__init__.py
Empty file.
15 changes: 15 additions & 0 deletions src/blog/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
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)
class PostAdmin(admin.ModelAdmin):
list_display = ("title", "status", "created", "updated")
raw_id_fields = ("author",)

def get_queryset(self, request):
return super().get_queryset(request).select_related("author")
6 changes: 6 additions & 0 deletions src/blog/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class BlogConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "blog"
10 changes: 10 additions & 0 deletions src/blog/jinja2/blog/category.jinja2
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{% extends "blog/index.jinja2" %}

{% block page_title %}
<h2>{{ category }}</h2>
{% endblock page_title %}

{%block button%}
<a id="back-button" href="{{ url('blog_index') }}">{{ _('< Back to Blog') }}</a>
<br />
{%endblock%}
26 changes: 26 additions & 0 deletions src/blog/jinja2/blog/clipping.jinja2
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{% extends '/core/home.jinja2' %}

{% block extra_css %}
<link rel="stylesheet" href="{{ static('css/blog.css') }}">
{% endblock %}

{% block content %}
<div id="blog-area">
{% block button %}
{% endblock %}
{% block page_title %}
<h2>{{ _("Clippings") }}</h2>
{% endblock page_title %}
{% for clipping in clippings %}
<div class="post">
<h3>{{ clipping.title }}</h3>
<p>{{ clipping.created.date() }} </p>
<p>{{ clipping.description }}</p>
<a href="{{ clipping.link }}">{{ clipping.link }}</a>
<br />
<br />
<a href="{{ clipping.file.url }}">{{ _("Download File")}}</a>
</div>
{% endfor %}
</div>
{% endblock %}
37 changes: 37 additions & 0 deletions src/blog/jinja2/blog/detail.jinja2
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{% extends "blog/index.jinja2" %}

{% block content %}
<div id="post-area">
<a id="back-button" href="{{ url('blog_index') }}">{{ _('< Back to Blog') }}</a>
<br />
{% block page_title %}
<h2>{{ post.title }}</h2>
{% endblock page_title %}
<small>
{{ post.created.date() }}
{% if post.categories.count() > 0 %}
| {{ _("Categories:") }}
{% for category in post.categories.all() %}
<a href="{{ url('blog_category',args=[category.name])}}">
{{ category.name }}
</a>
{% endfor %}
{% endif%}
</small>
<div id=post>
<p>{{ post.body |safe }}</p>
{% for image in images %}
<div class="post-image">
<img class="post-image" src="{{ image.file.url }}" />
{% if image.description %}
<h5>{{ image.description }}</h5>
{% endif %}
</div>
{% endfor %}
</div>

</div>
<br />
<a href="#" id="back-to-top"> {{_("Back to Top")}}</a>

{% endblock %}
28 changes: 28 additions & 0 deletions src/blog/jinja2/blog/index.jinja2
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{% extends '/core/home.jinja2' %}

{% block extra_css %}
<link rel="stylesheet" href="{{ static('css/blog.css') }}">
{% endblock %}

{% block content %}
<div id="blog-area">
{% block button %}
{% endblock %}
{% block page_title %}
<h2>{{ _("Blog Posts") }}</h2>
{% endblock page_title %}
<div id="category-header">
<small>
{{_("Categories:")}}
{% for category in blog_categories %}
<a href="{{ url('blog_category',args=[category.name])}}">
{{ category.name }}
</a>
{% endfor %}
</small>
</div>
<div id="posts-area">
{% include "/blog/post_preview.jinja2" %}
</div>
</div>
{% endblock %}
20 changes: 20 additions & 0 deletions src/blog/jinja2/blog/post_preview.jinja2
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{% for post in posts %}
<div class="post">
<h3><a href="{{ url('blog_detail', args=[post.pk])}}">{{ post.title }}</a></h3>
<small>
{{ post.created.date() }}
{% if post.categories.count() > 0 %}
| {{ _("Categories:") }}
{% for category in post.categories.all() %}
<a href="{{ url('blog_category', args=[category.name])}}">
{{ category.name }}
</a>
{% endfor %}
{% endif%}
</small>
<p>{{ post.body[:PREVIEW_SIZE] | safe }}... <a href="{{ url('blog_detail', args=[post.pk])}}">{{ _("Read More") }}</a></p>
</div>
{% endfor %}
{% if posts.count() == page_size %}
<button hx-get="{{ page_url }}?page={{ next_page_number }}" hx-trigger="click" hx-swap="outerHTML"> {{_("See more")}}</button>
{% endif %}
93 changes: 93 additions & 0 deletions src/blog/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# Generated by Django 4.1.5 on 2024-06-23 17:41

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

initial = True

dependencies = [
("users", "0009_alter_profile_id"),
]

operations = [
migrations.CreateModel(
name="Category",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("name", models.CharField(max_length=100)),
],
options={
"verbose_name_plural": "categories",
},
),
migrations.CreateModel(
name="PostImage",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("file", models.FileField()),
(
"description",
models.CharField(blank=True, max_length=500, null=True),
),
],
),
migrations.CreateModel(
name="Post",
fields=[
("id", models.BigAutoField(primary_key=True, serialize=False)),
("title", models.CharField(max_length=200)),
(
"status",
models.CharField(
choices=[("draft", "Draft"), ("published", "Published")],
default="draft",
max_length=20,
),
),
("body", models.TextField()),
("created", models.DateTimeField()),
("updated", models.DateTimeField(auto_now=True)),
(
"author",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.DO_NOTHING,
related_name="posts",
to="users.profile",
),
),
(
"categories",
models.ManyToManyField(
blank=True, related_name="posts", to="blog.category"
),
),
(
"images",
models.ManyToManyField(
blank=True, related_name="posts", to="blog.postimage"
),
),
],
),
]
Loading
Loading