From 63a0363124db49fa9a6159cee735d1121f9d8c30 Mon Sep 17 00:00:00 2001
From: Furkan
Date: Mon, 29 May 2023 14:17:04 +0300
Subject: [PATCH] Display entry favorite count, refactored entry templates
---
ozgursozluk/api.py | 4 +++-
ozgursozluk/configs.py | 2 ++
ozgursozluk/models.py | 8 ++-----
ozgursozluk/templates/entry.html | 18 +++------------
ozgursozluk/templates/entry_macro.html | 31 ++++++++++++++++++++++++++
ozgursozluk/templates/topic.html | 21 ++---------------
6 files changed, 43 insertions(+), 41 deletions(-)
create mode 100644 ozgursozluk/templates/entry_macro.html
diff --git a/ozgursozluk/api.py b/ozgursozluk/api.py
index 953c5bc..86f4656 100644
--- a/ozgursozluk/api.py
+++ b/ozgursozluk/api.py
@@ -44,6 +44,7 @@ class EksiSozluk:
entry.find("div", class_="content"),
entry.find("a", class_="entry-author").text,
entry.find("a", class_="entry-date permalink", href=True).text,
+ int(entry.attrs["data-favorite-count"])
)
def search_topic(self, query: str) -> Topic:
@@ -94,9 +95,10 @@ class EksiSozluk:
entry.find("div", class_="content"),
entry.find("a", class_="entry-author").text,
entry.find("a", class_="entry-date permalink", href=True).text,
+ int(entry.attrs["data-favorite-count"]),
int(h1.attrs["data-id"]),
h1.attrs["data-title"],
- h1.find("a")["href"][1:],
+ h1.find("a")["href"][1:]
)
def get_author(self, nickname: str) -> Author:
diff --git a/ozgursozluk/configs.py b/ozgursozluk/configs.py
index 8487e10..30a0d8a 100644
--- a/ozgursozluk/configs.py
+++ b/ozgursozluk/configs.py
@@ -7,12 +7,14 @@ SECRET_KEY: Final = environ.get("OZGURSOZLUK_SECRET_KEY", "Some secret string")
DEFAULT_THEME: Final = "light"
DEFAULT_DISPLAY_PINNED_TOPICS: Final = "true"
DEFAULT_DISPLAY_AUTHOR_NICKNAMES: Final = "false"
+DEFAULT_DISPLAY_ENTRY_FAVORITE_COUNT: Final = "false"
DEFAULT_EKSI_SOZLUK_BASE_URL: Final = "https://eksisozluk.com"
DEFAULT_COOKIES: Final = {
"theme": DEFAULT_THEME,
"display_pinned_topics": DEFAULT_DISPLAY_PINNED_TOPICS,
"display_author_nicknames": DEFAULT_DISPLAY_AUTHOR_NICKNAMES,
+ "display_entry_favorite_count": DEFAULT_DISPLAY_ENTRY_FAVORITE_COUNT,
"eksi_sozluk_base_url": DEFAULT_EKSI_SOZLUK_BASE_URL
}
diff --git a/ozgursozluk/models.py b/ozgursozluk/models.py
index 682694e..728c8ab 100644
--- a/ozgursozluk/models.py
+++ b/ozgursozluk/models.py
@@ -9,15 +9,11 @@ class Entry:
content_html: str
author: str
datetime: str
+ favorite_count: int
@dataclass
-class EntryTopic:
- id: int
- content: str
- content_html: str
- author: str
- datetime: str
+class EntryTopic(Entry):
topic_id: int
topic_title: str
topic_path: str
diff --git a/ozgursozluk/templates/entry.html b/ozgursozluk/templates/entry.html
index cb79265..92e0bca 100644
--- a/ozgursozluk/templates/entry.html
+++ b/ozgursozluk/templates/entry.html
@@ -17,20 +17,8 @@
-
- {{ entry.content_html|safe }}
-
-
- {% if request.cookies.get('display_author_nicknames') == 'true' %}
-
-
- {{ entry.author }}
-
-
- -
- {% endif %}
-
{{ entry.datetime }}
-
-
+ {% from "entry_macro.html" import render_entry %}
+ {{ render_entry(entry, False) }}
{% endblock %}
+
diff --git a/ozgursozluk/templates/entry_macro.html b/ozgursozluk/templates/entry_macro.html
new file mode 100644
index 0000000..96cca49
--- /dev/null
+++ b/ozgursozluk/templates/entry_macro.html
@@ -0,0 +1,31 @@
+{% macro render_entry(entry, clickable_date) %}
+
+ {{ entry.content_html|safe }}
+
+
+ {% if request.cookies.get('display_entry_favorite_count') == 'true' %}
+
+ {{ entry.favorite_count }} favorites
+
+ -
+ {% endif %}
+ {% if request.cookies.get('display_author_nicknames') == 'true' %}
+
+
+ {{ entry.author }}
+
+
+ -
+ {% endif %}
+
+ {% if clickable_date %}
+
+ {{ entry.datetime }}
+
+ {% else %}
+ {{ entry.datetime }}
+ {% endif %}
+
+
+
+{% endmacro %}
\ No newline at end of file
diff --git a/ozgursozluk/templates/topic.html b/ozgursozluk/templates/topic.html
index c79b4e6..28aeec3 100644
--- a/ozgursozluk/templates/topic.html
+++ b/ozgursozluk/templates/topic.html
@@ -23,25 +23,8 @@
{% include "paginate.html" %}
{% for entry in topic.entrys %}
-
- {{ entry.content_html|safe }}
-
-
-
+ {% from "entry_macro.html" import render_entry %}
+ {{ render_entry(entry, True) }}
{% endfor %}