Skip to content

Commit

Permalink
Merge pull request #562 from memeLab/add_blog
Browse files Browse the repository at this point in the history
Add blog to Jandig
  • Loading branch information
pablodiegoss authored Jun 23, 2024
2 parents 3412e25 + 709c629 commit b05f10f
Show file tree
Hide file tree
Showing 29 changed files with 1,611 additions and 9 deletions.
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

0 comments on commit b05f10f

Please sign in to comment.