aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBobby <[email protected]>2024-12-15 17:39:07 -0500
committerBobby <[email protected]>2024-12-15 17:39:07 -0500
commit12c92bf4d74f3717b1eafe1737e671a2b8bda02e (patch)
tree3a8f0a2799e32a254c6f27514f586a0124ad7b2c
parent9f9025fe2f70ac500c01473a9659e2ecd1d11774 (diff)
downloadthatcomputerscientist-12c92bf4d74f3717b1eafe1737e671a2b8bda02e.tar.xz
thatcomputerscientist-12c92bf4d74f3717b1eafe1737e671a2b8bda02e.zip
post list on homepage
-rw-r--r--apps/administration/migrations/0006_alter_announcement_table.py16
-rw-r--r--apps/blog/migrations/0015_post_image_url.py17
-rw-r--r--apps/blog/migrations/0016_post_body_ja_post_title_ja.py22
-rw-r--r--apps/blog/migrations/0017_category_name_ja.py17
-rw-r--r--apps/blog/migrations/0018_tag_name_ja.py17
-rw-r--r--apps/blog/models.py42
-rw-r--r--apps/core/views.py7
-rw-r--r--internal/weblog_utilities.py31
-rw-r--r--static/css/core/post_list.css73
-rw-r--r--static/css/shared/core.css2
-rw-r--r--templates/en/core/home.html5
-rw-r--r--templates/ja/core/home.html4
-rw-r--r--templates/partials/weblog_list.html44
-rw-r--r--templates/shared/left_sidebar.html33
14 files changed, 289 insertions, 41 deletions
diff --git a/apps/administration/migrations/0006_alter_announcement_table.py b/apps/administration/migrations/0006_alter_announcement_table.py
new file mode 100644
index 00000000..638ae0e4
--- /dev/null
+++ b/apps/administration/migrations/0006_alter_announcement_table.py
@@ -0,0 +1,16 @@
+# Generated by Django 5.0.7 on 2024-12-15 19:57
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("administration", "0005_announcement_content_ja"),
+ ]
+
+ operations = [
+ migrations.AlterModelTable(
+ name="announcement",
+ table="announcements_announcement",
+ ),
+ ]
diff --git a/apps/blog/migrations/0015_post_image_url.py b/apps/blog/migrations/0015_post_image_url.py
new file mode 100644
index 00000000..dc5df5b3
--- /dev/null
+++ b/apps/blog/migrations/0015_post_image_url.py
@@ -0,0 +1,17 @@
+# Generated by Django 5.0.7 on 2024-12-15 19:54
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("blog", "0014_anonymouscommentuser_alter_comment_user_and_more"),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name="post",
+ name="image_url",
+ field=models.URLField(blank=True),
+ ),
+ ]
diff --git a/apps/blog/migrations/0016_post_body_ja_post_title_ja.py b/apps/blog/migrations/0016_post_body_ja_post_title_ja.py
new file mode 100644
index 00000000..ef42fbc1
--- /dev/null
+++ b/apps/blog/migrations/0016_post_body_ja_post_title_ja.py
@@ -0,0 +1,22 @@
+# Generated by Django 5.0.7 on 2024-12-15 20:47
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("blog", "0015_post_image_url"),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name="post",
+ name="body_ja",
+ field=models.TextField(blank=True),
+ ),
+ migrations.AddField(
+ model_name="post",
+ name="title_ja",
+ field=models.CharField(blank=True, max_length=100),
+ ),
+ ]
diff --git a/apps/blog/migrations/0017_category_name_ja.py b/apps/blog/migrations/0017_category_name_ja.py
new file mode 100644
index 00000000..e01cec5d
--- /dev/null
+++ b/apps/blog/migrations/0017_category_name_ja.py
@@ -0,0 +1,17 @@
+# Generated by Django 5.0.7 on 2024-12-15 22:20
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("blog", "0016_post_body_ja_post_title_ja"),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name="category",
+ name="name_ja",
+ field=models.CharField(blank=True, max_length=50),
+ ),
+ ]
diff --git a/apps/blog/migrations/0018_tag_name_ja.py b/apps/blog/migrations/0018_tag_name_ja.py
new file mode 100644
index 00000000..c9d3cc4c
--- /dev/null
+++ b/apps/blog/migrations/0018_tag_name_ja.py
@@ -0,0 +1,17 @@
+# Generated by Django 5.0.7 on 2024-12-15 22:22
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("blog", "0017_category_name_ja"),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name="tag",
+ name="name_ja",
+ field=models.CharField(blank=True, max_length=50),
+ ),
+ ]
diff --git a/apps/blog/models.py b/apps/blog/models.py
index f564cd75..b4d791e2 100644
--- a/apps/blog/models.py
+++ b/apps/blog/models.py
@@ -4,63 +4,74 @@ from django.conf import settings
from django.db import models
from django.utils.text import slugify
-UPLOAD_ROOT = 'images/'
+UPLOAD_ROOT = "images/"
+
# Create your models here.
class Category(models.Model):
name = models.CharField(max_length=50)
+ name_ja = models.CharField(max_length=50, blank=True)
slug = models.SlugField(unique=True)
description = models.TextField(blank=True)
created_at = models.DateTimeField(auto_now_add=True)
def save(self, *args, **kwargs):
- if not self.slug or self.slug == '':
+ if not self.slug or self.slug == "":
self.slug = slugify(self.name)
return super(Category, self).save(*args, **kwargs)
def __str__(self):
return self.name
+
class Tag(models.Model):
name = models.CharField(max_length=50)
+ name_ja = models.CharField(max_length=50, blank=True)
slug = models.SlugField(unique=True)
description = models.TextField(blank=True)
created_at = models.DateTimeField(auto_now_add=True)
def save(self, *args, **kwargs):
- if not self.slug or self.slug == '':
+ if not self.slug or self.slug == "":
self.slug = slugify(self.name)
return super(Tag, self).save(*args, **kwargs)
def __str__(self):
return self.name
+
class Post(models.Model):
title = models.CharField(max_length=100)
+ title_ja = models.CharField(max_length=100, blank=True)
slug = models.SlugField(max_length=100, unique=True)
body = models.TextField(blank=True)
+ body_ja = models.TextField(blank=True)
date = models.DateTimeField(auto_now_add=False)
- post_image = models.ImageField(upload_to="{}/cover_images".format(UPLOAD_ROOT), blank=True)
+ post_image = models.ImageField(
+ upload_to="{}/cover_images".format(UPLOAD_ROOT), blank=True
+ )
+ image_url = models.URLField(blank=True)
author = models.ForeignKey(
settings.AUTH_USER_MODEL,
on_delete=models.CASCADE,
)
category = models.ForeignKey(
- 'Category',
+ "Category",
on_delete=models.CASCADE,
)
- tags = models.ManyToManyField('Tag', blank=True)
+ tags = models.ManyToManyField("Tag", blank=True)
is_public = models.BooleanField(default=False)
views = models.IntegerField(default=0)
def save(self, *args, **kwargs):
- if not self.slug or self.slug == '':
+ if not self.slug or self.slug == "":
self.slug = slugify(self.title)
return super(Post, self).save(*args, **kwargs)
def __str__(self):
return str(self.title)
-
+
+
class AnonymousCommentUser(models.Model):
name = models.CharField(max_length=32)
email = models.CharField(max_length=32)
@@ -68,17 +79,18 @@ class AnonymousCommentUser(models.Model):
avatar = models.CharField(max_length=128, blank=True)
@classmethod
- def get_or_create(cls, email, token, avatar=''):
- email_hash = hashlib.md5(email.encode('utf-8')).hexdigest()
- token_hash = hashlib.sha256(token.encode('utf-8')).hexdigest()
+ def get_or_create(cls, email, token, avatar=""):
+ email_hash = hashlib.md5(email.encode("utf-8")).hexdigest()
+ token_hash = hashlib.sha256(token.encode("utf-8")).hexdigest()
return cls(email=email_hash, token=token_hash, avatar=avatar)
-
+
def __str__(self):
return self.name + "(" + self.email + ")"
+
class Comment(models.Model):
post = models.ForeignKey(
- 'Post',
+ "Post",
on_delete=models.CASCADE,
)
user = models.ForeignKey(
@@ -88,7 +100,7 @@ class Comment(models.Model):
null=True,
)
anonymous_user = models.ForeignKey(
- 'AnonymousCommentUser',
+ "AnonymousCommentUser",
on_delete=models.CASCADE,
blank=True,
null=True,
@@ -99,4 +111,4 @@ class Comment(models.Model):
edited_at = models.DateTimeField(blank=True, null=True)
def __str__(self):
- return self.body[:50] + '...' if len(self.body) > 50 else self.body
+ return self.body[:50] + "..." if len(self.body) > 50 else self.body
diff --git a/apps/core/views.py b/apps/core/views.py
index 880dd366..0e23722a 100644
--- a/apps/core/views.py
+++ b/apps/core/views.py
@@ -2,7 +2,7 @@ from django.shortcuts import render
from thatcomputerscientist.utils import i18npatterns
from apps.administration.models import Announcement
from internal.mal_wrapper import get_mal_recent_activity
-
+from internal.weblog_utilities import recent_weblogs
MAL_USERNAME = "crvs"
@@ -14,10 +14,9 @@ def home(request):
LANGUAGE_CODE = i18npatterns(request.LANGUAGE_CODE)
request.meta.update(META)
announcements = Announcement.objects.filter(is_public=True).order_by("-created_at")
- announcements = announcements if len(announcements) > 0 else None
- recent_mal_activity = get_mal_recent_activity(MAL_USERNAME)
context = {
"announcements": announcements,
- "recent_mal_activity": recent_mal_activity,
+ "recent_mal_activity": get_mal_recent_activity(MAL_USERNAME),
+ "recent_weblogs": recent_weblogs(lang=LANGUAGE_CODE),
}
return render(request, f"{LANGUAGE_CODE}/core/home.html", context)
diff --git a/internal/weblog_utilities.py b/internal/weblog_utilities.py
new file mode 100644
index 00000000..a6eede4b
--- /dev/null
+++ b/internal/weblog_utilities.py
@@ -0,0 +1,31 @@
+from apps.blog.models import Post, Comment
+from bs4 import BeautifulSoup
+
+
+def add_excerpt(post, lang="en"):
+ if lang == "ja":
+ soup = BeautifulSoup(post.body_ja, "html.parser")
+ else:
+ soup = BeautifulSoup(post.body, "html.parser")
+ excerpt = ""
+ for paragraph in soup.find_all("p"):
+ paragraph = "<p>" + str(paragraph.text) + "</p>"
+ excerpt += str(paragraph)
+
+ if len(excerpt) >= 1000:
+ break
+ print(excerpt)
+ return excerpt
+
+
+def add_num_comments(post):
+ num_comments = Comment.objects.filter(post=post).count()
+ return num_comments
+
+
+def recent_weblogs(lang="en"):
+ recent_posts = Post.objects.filter(is_public=True).order_by("-date")[:5]
+ for post in recent_posts:
+ post.excerpt = add_excerpt(post, lang)
+ post.num_comments = add_num_comments(post)
+ return recent_posts
diff --git a/static/css/core/post_list.css b/static/css/core/post_list.css
new file mode 100644
index 00000000..a84dc36e
--- /dev/null
+++ b/static/css/core/post_list.css
@@ -0,0 +1,73 @@
+.post {
+ margin: 16px 0px;
+}
+
+.author-info>* {
+ display: inline-block;
+ vertical-align: middle;
+}
+
+.author-info {
+ margin: 8px 0px;
+}
+
+.post-profile-image {
+ width: 16px;
+ height: 16px;
+}
+
+.post-body {
+ position: relative;
+}
+
+.post-image {
+ float: left;
+ shape-outside: margin-box;
+ margin-right: 12px;
+ width: 350px;
+ height: 230px;
+ border-radius: 8px;
+ overflow: hidden;
+}
+
+.post-image img {
+ width: 100%;
+ height: 100%;
+ object-fit: cover;
+ border-radius: 8px;
+ position: relative;
+ top: 8px;
+}
+
+.post-content {
+ overflow: visible;
+}
+
+.post-content p {
+ text-align: justify;
+ margin: 8px 0px;
+}
+
+.post-actions {
+ display: flex;
+ justify-content: space-between;
+ margin: 8px 0px;
+ align-items: center;
+}
+
+.post-tag {
+ display: inline-block;
+ margin: 5px 2px;
+ padding: 2px 10px;
+ font-size: 11px;
+ font-weight: normal;
+ text-transform: capitalize;
+ background-color: #311b4f;
+ color: #dddddd !important;
+ border-radius: 10px;
+}
+
+.post-tag:hover {
+ background-color: #311b4f;
+ color: #dddddd !important;
+} \ No newline at end of file
diff --git a/static/css/shared/core.css b/static/css/shared/core.css
index e2eafaaa..02d41657 100644
--- a/static/css/shared/core.css
+++ b/static/css/shared/core.css
@@ -101,7 +101,7 @@ img {
width: 100%;
height: 100%;
background-color: #000;
- opacity: 0.75;
+ opacity: 0.8;
z-index: -99;
}
diff --git a/templates/en/core/home.html b/templates/en/core/home.html
index 2cc7e75d..281560c2 100644
--- a/templates/en/core/home.html
+++ b/templates/en/core/home.html
@@ -46,7 +46,10 @@
{% endif %}
</div>
<div class="pamphlet pamphlet-banner"></div>
-
+<h1 class="section-title">Contemplations of Late</h1>
+<div class="recent-weblogs">
+ {% include 'partials/weblog_list.html' with posts=recent_weblogs %}
+</div>
<h1 class="section-title">Recent Weeb Degenerecy</h1>
<div class="recent-anime">
diff --git a/templates/ja/core/home.html b/templates/ja/core/home.html
index 1a8597bc..20d8747e 100644
--- a/templates/ja/core/home.html
+++ b/templates/ja/core/home.html
@@ -46,6 +46,10 @@
{% endif %}
</div>
<div class="pamphlet pamphlet-banner"></div>
+<h1 class="section-title">最近の考察</h1>
+<div class="recent-weblogs">
+ {% include 'partials/weblog_list.html' with posts=recent_weblogs %}
+</div>
<h1 class="section-title">最近のアニメ活動</h1>
<div class="recent-anime">
{% for anime in recent_mal_activity.anime %}
diff --git a/templates/partials/weblog_list.html b/templates/partials/weblog_list.html
new file mode 100644
index 00000000..f166610e
--- /dev/null
+++ b/templates/partials/weblog_list.html
@@ -0,0 +1,44 @@
+{% load tz %}
+{% load static %}
+<link rel="stylesheet" href="{% static 'css/core/post_list.css' %}">
+{% for post in posts %}
+ <div class="post">
+ <div class="post-body">
+ <div class="post-image">
+ <img src="{{ post.image_url }}" alt="{% if request.LANGUAGE_CODE == 'ja' %}{{ post.title_ja }}{% else %}{{ post.title }}{% endif %}">
+ </div>
+ <div class="post-content">
+ <h2>
+ <a href="#">{% if request.LANGUAGE_CODE == 'ja' %}{{ post.title_ja }}{% else %}{{ post.title }}{% endif %}</a>
+ </h2>
+ <div class="author-info">
+ {% with post.author.userprofile_set.first as authorprofile %}
+ <img src="{% static 'images/avatars/' %}{{ authorprofile.avatar_url }}.gif" class="post-profile-image" alt="{{ post.author.first_name }}'s Avatar">
+ {% endwith %}
+ <a href="#"> {{ post.author.first_name }} {{ post.author.last_name }}</a>
+ <span>{% if request.LANGUAGE_CODE == 'ja' %}投稿カテゴリー:{% else %}posted in{% endif %}</span>
+ <a href="#{{ post.category.slug }}">{% if request.LANGUAGE_CODE == 'ja' %}{{ post.category.name_ja }}{% else %}{{ post.category }}{% endif %}</a>
+ <span>{% if request.LANGUAGE_CODE == 'ja' %}投稿日:{% else %}on{% endif %}</span>
+ <span style="margin-left: 4px;">{% localtime on %}{{ post.date | date:"M d, Y" }}{% endlocaltime %}</span>
+ </div>
+ {{ post.excerpt | safe }}
+ </div>
+ </div>
+ <div class="post-actions">
+ <div class="post-links">
+ <a href="#">{% if request.LANGUAGE_CODE == 'ja' %}続きを読む{% else %}Continue Reading{% endif %}</a> |
+ <a href="##comments">{{ post.num_comments }}
+ {% if request.LANGUAGE_CODE == 'ja' %}
+ コメント
+ {% else %}
+ Comment{% if not post.num_comments == 1 %}s{% endif %}
+ {% endif %}</a>
+ </div>
+ <div class="post-tags">
+ {% for tag in post.tags.all %}
+ <a class="post-tag" href="#{{ tag.slug }}">{% if request.LANGUAGE_CODE == 'ja' %}{{ tag.name_ja }}{% else %}{{ tag.name }}{% endif %}</a>
+ {% endfor %}
+ </div>
+ </div>
+ </div>
+{% endfor %} \ No newline at end of file
diff --git a/templates/shared/left_sidebar.html b/templates/shared/left_sidebar.html
index 975ad9a3..78ec7e2c 100644
--- a/templates/shared/left_sidebar.html
+++ b/templates/shared/left_sidebar.html
@@ -28,27 +28,20 @@
<div class="user-item">
<img src="{% static 'images/core/icons/journals.png' %}" alt="Journals Icon" />
<a href="#journals">{% if request.LANGUAGE_CODE == 'ja' %}ジャーナル{% else %}Journals{% endif %}</a>
+ </div>
+ <div class="user-item">
+ <img src="{% static 'images/core/icons/pagodarealm.png' %}" alt="The Pagoda Realm Icon" />
+ <a href="#pagodarealm">{% if request.LANGUAGE_CODE == 'ja' %}パゴダレルム{% else %}The Pagoda Realm{% endif %}</a>
+ </div>
+ <div class="user-item">
+ <img src="{% static 'images/core/icons/mypage.png' %}" alt="My Page Icon" />
+ <a href="#mypage">{% if request.LANGUAGE_CODE == 'ja' %}マイページ{% else %}My Page{% endif %}</a>
+ </div>
+ <div class="user-item">
+ <img src="{% static 'images/core/icons/logout.png' %}" alt="Logout Icon" />
+ <a href="#logout">{% if request.LANGUAGE_CODE == 'ja' %}ログアウト{% else %}Logout{% endif %}</a>
+ </div>
</div>
- <div class="user-item">
- <img src="{% static 'images/core/icons/pagodarealm.png' %}" alt="The Pagoda Realm Icon" />
- <a href="#pagodarealm">{% if request.LANGUAGE_CODE == 'ja' %}パゴダレルム{% else %}The Pagoda Realm{% endif %}</a>
- </div>
- <div class="user-item">
- <img src="{% static 'images/core/icons/mypage.png' %}" alt="My Page Icon" />
- <a href="#mypage">{% if request.LANGUAGE_CODE == 'ja' %}マイページ{% else %}My Page{% endif %}</a>
- </div>
- <div class="user-item">
- <img src="{% static 'images/core/icons/logout.png' %}" alt="Logout Icon" />
- <a href="#logout">{% if request.LANGUAGE_CODE == 'ja' %}ログアウト{% else %}Logout{% endif %}</a>
- </div>
- </div>
-
- {% comment %} <div class="user-links">
- <a href="#journals">{% if request.LANGUAGE_CODE == 'ja' %}ジャーナル{% else %}Journals{% endif %}</a>
- <a href="#mymatrix">{% if request.LANGUAGE_CODE == 'ja' %}マトリックス{% else %}My Matrix{% endif %}</a>
- <a href="#mypage">{% if request.LANGUAGE_CODE == 'ja' %}マイページ{% else %}My Page{% endif %}</a>
- <a href="#logout">{% if request.LANGUAGE_CODE == 'ja' %}ログアウト{% else %}Logout{% endif %}</a>
- </div> {% endcomment %}
</div>
{% endif %}