Skip to content
This repository has been archived by the owner on Jun 27, 2024. It is now read-only.

Commit

Permalink
new: decorator for mmdb promotion
Browse files Browse the repository at this point in the history
  • Loading branch information
EdwinRodger committed Dec 14, 2023
1 parent 1aba8fc commit 8003bd2
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 3 deletions.
11 changes: 11 additions & 0 deletions src/anime/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
remove_cover,
save_picture,
)
from src.home.utils import mmdb_promotion
from src.models import Anime

today_date = datetime.date(datetime.today())
Expand Down Expand Up @@ -310,3 +311,13 @@ def search_anime():
sort_function="All",
truncate_title=truncate_title,
)


from src.anime.routes import anime


@anime.before_request
def before_request():
endpoint = request.endpoint
if endpoint == "anime.anime_list":
mmdb_promotion(anime_list)()
16 changes: 14 additions & 2 deletions src/home/routes.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from flask import Blueprint, render_template
from flask import Blueprint, render_template, request

from src.home.utils import anime_overview_data, check_for_update, manga_overview_data
from src.home.utils import anime_overview_data, check_for_update, manga_overview_data, mmdb_promotion

home = Blueprint("home", __name__)

Expand Down Expand Up @@ -29,3 +29,15 @@ def more():
@home.route("/credits")
def credits():
return render_template("credits.html", title="Credits", current_section="More")


@home.before_request
def before_request():
endpoint = request.endpoint
action = {
"home.homepage": homepage,
"home.more": more,
"home.credits": credits,
}.get(endpoint, homepage)

mmdb_promotion(action)()
25 changes: 25 additions & 0 deletions src/home/utils.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import hashlib
import json
import os
import random
import statistics
from collections import Counter

import requests
from flask import flash

from src.models import Anime, Manga

Expand Down Expand Up @@ -172,3 +174,26 @@ def check_for_update():

# An update is available
return True


def mmdb_promotion(func):
def wrapper(*args, **kwargs):
with open("json/settings.json", "r") as f:
json_settings = json.load(f)

if json_settings["mmdb_promotion"] == "Yes":
num = random.randint(1, 25)
if num == 1:
flash(
'Star MyMangaDataBase on <a href="https://github.com/EdwinRodger/MyMangaDataBase/blob/main/docs/help.md" target="_blank">GitHub</a>!',
"info",
)
if num == 2:
flash(
'Like MyMangaDataBase on <a href="https://alternativeto.net/software/mymangadatabase/" target="_blank">AlternativeTo</a>!',
"info",
)

return func(*args, **kwargs)

return wrapper
8 changes: 8 additions & 0 deletions src/manga/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from sqlalchemy import delete

from src import db
from src.home.utils import mmdb_promotion
from src.manga.backup import (
export_mmdb_backup,
import_mmdb_backup,
Expand Down Expand Up @@ -371,3 +372,10 @@ def search_manga():
sort_function="All",
truncate_title=truncate_title,
)


@manga.before_request
def before_request():
endpoint = request.endpoint
if endpoint == "manga.manga_list":
mmdb_promotion(manga_list)()
2 changes: 1 addition & 1 deletion src/templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
{% if messages %}
{% for category, messages in messages %}
<div class="alert alert-{{ category }} text-center rounded-0">
{{ messages }}
{{ messages | safe }}
</div>
{% endfor %}
{% endif %}
Expand Down

0 comments on commit 8003bd2

Please # to comment.