Skip to content

Commit

Permalink
Merge pull request #6 from furkansm/main
Browse files Browse the repository at this point in the history
Entry favorite count & more
  • Loading branch information
beucismis authored May 31, 2023
2 parents 444a5b3 + b7bcddd commit 5a2d21a
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 79 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,5 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

Pipfile*
2 changes: 1 addition & 1 deletion ozgursozluk/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from flask import Flask


__version__ = "0.6.3"
__version__ = "0.7.0"
__author__ = "beucismis"
__source__ = "https://github.com/beucismis/ozgursozluk"
__description__ = "a free and open source alternative ekşi sözlük front-end"
Expand Down
4 changes: 3 additions & 1 deletion ozgursozluk/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def entrys(self, response: BeautifulSoup) -> Iterator[Entry]:
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:
Expand Down Expand Up @@ -94,9 +95,10 @@ def get_entry(self, id: int) -> EntryTopic:
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:
Expand Down
9 changes: 9 additions & 0 deletions ozgursozluk/configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,17 @@
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
}

themes: Final = [
"light",
"dark",
Expand Down
8 changes: 2 additions & 6 deletions ozgursozluk/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 3 additions & 15 deletions ozgursozluk/templates/entry.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,8 @@
</p>
</div>
</div>
<div class="entry">
{{ entry.content_html|safe }}
</br>
<div style="text-align: right;">
{% if request.cookies.get('display_author_nicknames') == 'true' %}
<small>
<a href="{{ url_for('author', nickname=entry.author) }}">
{{ entry.author }}
</a>
</small>
-
{% endif %}
<small>{{ entry.datetime }}</small>
</div>
</div>
{% from "entry_macro.html" import render_entry %}
{{ render_entry(entry, False) }}
</div>
{% endblock %}

31 changes: 31 additions & 0 deletions ozgursozluk/templates/entry_macro.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{% macro render_entry(entry, clickable_date) %}
<div class="entry">
{{ entry.content_html|safe }}
</br>
<div style="text-align: right;">
{% if request.cookies.get('display_entry_favorite_count') == 'true' %}
<small>
{{ entry.favorite_count }} favorites
</small>
-
{% endif %}
{% if request.cookies.get('display_author_nicknames') == 'true' %}
<small>
<a href="{{ url_for('author', nickname=entry.author) }}">
{{ entry.author }}
</a>
</small>
-
{% endif %}
<small>
{% if clickable_date %}
<a href="{{ url_for('entry', id=entry.id) }}">
{{ entry.datetime }}
</a>
{% else %}
{{ entry.datetime }}
{% endif %}
</small>
</div>
</div>
{% endmacro %}
2 changes: 1 addition & 1 deletion ozgursozluk/templates/paginate.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div>
{% if a %}
{% if not a %}
{% if p > 1 %}
<a href="{{ url_for('topic', path=topic.path, p=p-1) }}">previous</a>
{% if p < topic.page_count %}/{% endif %}
Expand Down
11 changes: 11 additions & 0 deletions ozgursozluk/templates/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@
{% endfor %}
</select>
</div>
<div class="settings-group">
display entry favorite count:
<select name="display_entry_favorite_count">
{% for status in ['true', 'false'] %}
<option value="{{ status }}"
{% if default_display_entry_favorite_count == status %}selected{% endif %}>
{{ status }}
</option>
{% endfor %}
</select>
</div>
<div class="settings-group">
ekşi sözlük base url:
<select name="eksi_sozluk_base_url">
Expand Down
21 changes: 2 additions & 19 deletions ozgursozluk/templates/topic.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,8 @@
{% include "paginate.html" %}
</div>
{% for entry in topic.entrys %}
<div class="entry">
{{ entry.content_html|safe }}
</br>
<div style="text-align: right;">
{% if request.cookies.get('display_author_nicknames') == 'true' %}
<small>
<a href="{{ url_for('author', nickname=entry.author) }}">
{{ entry.author }}
</a>
</small>
-
{% endif %}
<small>
<a href="{{ url_for('entry', id=entry.id) }}">
{{ entry.datetime }}
</a>
</small>
</div>
</div>
{% from "entry_macro.html" import render_entry %}
{{ render_entry(entry, True) }}
{% endfor %}
<div class="info" style="padding-top: 0;">
<div></div>
Expand Down
47 changes: 11 additions & 36 deletions ozgursozluk/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
from ozgursozluk.configs import (
themes,
eksi_sozluk_base_urls,
DEFAULT_THEME,
DEFAULT_DISPLAY_PINNED_TOPICS,
DEFAULT_DISPLAY_AUTHOR_NICKNAMES,
DEFAULT_EKSI_SOZLUK_BASE_URL,
DEFAULT_COOKIES,
DEFAULT_EKSI_SOZLUK_BASE_URL
)


Expand Down Expand Up @@ -103,43 +101,20 @@ def settings():

if request.method == "POST":
response = redirect(url_for("settings"))
response.set_cookie(
"theme",
request.form["theme"],
expires=expires(),
)
response.set_cookie(
"display_pinned_topics",
request.form["display_pinned_topics"],
expires=expires(),
)
response.set_cookie(
"display_author_nicknames",
request.form["display_author_nicknames"],
expires=expires(),
)
response.set_cookie(
"eksi_sozluk_base_url",
request.form["eksi_sozluk_base_url"],
expires=expires(),
)
for cookie in DEFAULT_COOKIES:
response.set_cookie(
cookie,
request.form[cookie],
expires=expires()
)

return response

return render_template(
"settings.html",
default_theme=request.cookies.get(
"theme", DEFAULT_THEME,
),
default_display_pinned_topics=request.cookies.get(
"display_pinned_topics", DEFAULT_DISPLAY_PINNED_TOPICS,
),
default_display_author_nicknames=request.cookies.get(
"display_author_nicknames", DEFAULT_DISPLAY_AUTHOR_NICKNAMES,
),
default_eksi_sozluk_base_url=request.cookies.get(
"eksi_sozluk_base_url", DEFAULT_EKSI_SOZLUK_BASE_URL,
),
# Unpack DEFAULT_COOKIES variable to the template
**{f"default_{cookie}": request.cookies.get(cookie, DEFAULT_COOKIES[cookie])
for cookie in DEFAULT_COOKIES}
)


Expand Down

0 comments on commit 5a2d21a

Please sign in to comment.