From ef70e5f9c6174ecdddeec574e118dda5a23391f3 Mon Sep 17 00:00:00 2001 From: doubaniux Date: Fri, 11 Nov 2022 18:40:02 +0100 Subject: [PATCH] generalize instance related code --- .github/workflows/codeql-analysis.yml | 4 +- .github/workflows/pysa.yml | 4 +- .gitignore | 3 ++ Dockerfile | 2 +- boofilsic/settings.py | 46 +++++++++--------- books/models.py | 2 +- books/templates/books/create_update.html | 2 +- .../templates/books/create_update_review.html | 2 +- books/templates/books/delete.html | 2 +- books/templates/books/delete_review.html | 2 +- books/templates/books/mark_list.html | 2 +- books/templates/books/review_detail.html | 4 +- books/templates/books/review_list.html | 2 +- books/templates/books/scrape.html | 2 +- collection/models.py | 2 +- collection/templates/create_update.html | 2 +- collection/templates/delete.html | 4 +- collection/templates/entity_list.html | 2 +- collection/templates/list.html | 2 +- common/models.py | 4 +- common/static/css/boofilsic.css | 13 +++++ common/static/css/boofilsic.min.css | 2 +- common/static/js/home.js | 18 +++++++ common/static/js/mastodon.js | 1 + .../lib/css/{neo.css => collection.css} | 17 ------- common/static/lib/js/hyperscript-0.9.5.min.js | 2 - common/static/lib/js/hyperscript-0.9.7.min.js | 1 + common/static/sass/_Vendor.sass | 15 ++++++ common/templates/common/error.html | 2 +- common/templates/common/search_result.html | 6 +-- common/templates/partial/_common_libs.html | 14 +++--- common/templates/partial/_sidebar.html | 2 +- common/templates/partial/list_item_book.html | 2 +- common/templates/partial/list_item_game.html | 2 +- common/templates/partial/list_item_movie.html | 2 +- common/templates/partial/list_item_music.html | 2 +- common/templatetags/mastodon.py | 14 ++++++ common/templatetags/neo.py | 48 ------------------- common/templatetags/prettydate.py | 22 +++++++++ common/templatetags/user_item.py | 19 ++++++++ docker-compose.yml | 2 +- games/models.py | 2 +- games/templates/games/create_update.html | 2 +- .../templates/games/create_update_review.html | 2 +- games/templates/games/delete.html | 2 +- games/templates/games/delete_review.html | 2 +- games/templates/games/mark_list.html | 2 +- games/templates/games/review_detail.html | 4 +- games/templates/games/review_list.html | 2 +- games/templates/games/scrape.html | 2 +- management/templates/management/detail.html | 2 +- management/templates/management/list.html | 2 +- movies/models.py | 2 +- movies/templates/movies/create_update.html | 2 +- .../movies/create_update_review.html | 2 +- movies/templates/movies/delete.html | 2 +- movies/templates/movies/delete_review.html | 2 +- movies/templates/movies/mark_list.html | 2 +- movies/templates/movies/review_detail.html | 4 +- movies/templates/movies/review_list.html | 2 +- movies/templates/movies/scrape.html | 2 +- music/models.py | 4 +- music/templates/music/album_mark_list.html | 2 +- .../templates/music/album_review_detail.html | 4 +- music/templates/music/album_review_list.html | 2 +- .../templates/music/create_update_album.html | 2 +- .../music/create_update_album_review.html | 2 +- music/templates/music/create_update_song.html | 2 +- .../music/create_update_song_review.html | 2 +- music/templates/music/delete_album.html | 2 +- .../templates/music/delete_album_review.html | 2 +- music/templates/music/delete_song.html | 2 +- music/templates/music/delete_song_review.html | 2 +- music/templates/music/scrape_album.html | 2 +- music/templates/music/scrape_song.html | 2 +- music/templates/music/song_mark_list.html | 2 +- music/templates/music/song_review_detail.html | 4 +- music/templates/music/song_review_list.html | 2 +- requirements.txt | 5 -- timeline/templates/timeline_data.html | 2 +- users/templates/users/home.html | 6 +-- users/templates/users/item_list.html | 6 +-- users/templates/users/login.html | 5 +- users/templates/users/manage_report.html | 2 +- users/templates/users/register.html | 2 +- users/templates/users/report.html | 2 +- users/templates/users/tags.html | 2 +- 87 files changed, 224 insertions(+), 193 deletions(-) rename common/static/lib/css/{neo.css => collection.css} (91%) delete mode 100644 common/static/lib/js/hyperscript-0.9.5.min.js create mode 100644 common/static/lib/js/hyperscript-0.9.7.min.js delete mode 100644 common/templatetags/neo.py create mode 100644 common/templatetags/prettydate.py create mode 100644 common/templatetags/user_item.py diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 514df728..429d462e 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -13,10 +13,10 @@ name: "CodeQL" on: push: - branches: [ "neo" ] + branches: [ "master" ] pull_request: # The branches below must be a subset of the branches above - branches: [ "neo" ] + branches: [ "master" ] schedule: - cron: '35 0 * * 0' diff --git a/.github/workflows/pysa.yml b/.github/workflows/pysa.yml index e4e20af3..50e8865b 100644 --- a/.github/workflows/pysa.yml +++ b/.github/workflows/pysa.yml @@ -17,9 +17,9 @@ name: Pysa on: workflow_dispatch: push: - branches: [ "neo" ] + branches: [ "master" ] pull_request: - branches: [ "neo" ] + branches: [ "master" ] schedule: - cron: '45 12 * * 4' diff --git a/.gitignore b/.gitignore index d1edae82..4d9446ad 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,6 @@ log # conf folder for neodb /neodb + +# typesense folder +/typesense-data diff --git a/Dockerfile b/Dockerfile index cc9bf6e8..5115d87f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,7 +11,7 @@ RUN pip install --no-cache-dir -r /tmp/requirements.txt \ && useradd -U app_user \ && install -d -m 0755 -o app_user -g app_user /app/static -ENV DJANGO_SETTINGS_MODULE=neodb.dev +ENV DJANGO_SETTINGS_MODULE=yoursettings.dev WORKDIR /app USER app_user:app_user COPY --chown=app_user:app_user . . diff --git a/boofilsic/settings.py b/boofilsic/settings.py index 6393f4a0..bab03dbf 100644 --- a/boofilsic/settings.py +++ b/boofilsic/settings.py @@ -12,7 +12,6 @@ https://docs.djangoproject.com/en/3.0/ref/settings/ import os import psycopg2.extensions -from git import Repo # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) @@ -67,7 +66,6 @@ INSTALLED_APPS = [ 'timeline.apps.TimelineConfig', 'easy_thumbnails', 'user_messages', - 'django_slack', ] MIDDLEWARE = [ @@ -113,9 +111,9 @@ if DEBUG: 'default': { 'ENGINE': 'django.db.backends.postgresql', 'NAME': os.environ.get('DB_NAME', 'test'), - 'USER': os.environ.get('DB_USER', 'donotban'), - 'PASSWORD': os.environ.get('DB_PASSWORD', 'donotbansilvousplait'), - 'HOST': os.environ.get('DB_HOST', '172.18.116.29'), + 'USER': os.environ.get('DB_USER', 'postgres'), + 'PASSWORD': os.environ.get('DB_PASSWORD', 'admin123'), + 'HOST': os.environ.get('DB_HOST', '127.0.0.1'), 'OPTIONS': { 'client_encoding': 'UTF8', # 'isolation_level': psycopg2.extensions.ISOLATION_LEVEL_DEFAULT, @@ -280,26 +278,27 @@ LUMINATI_PASSWORD = 'nsb7te9bw0ney' SCRAPING_TIMEOUT = 90 # ScraperAPI api key -SCRAPERAPI_KEY = 'wnb3794v675b8w475h0e8hr7tyge' +SCRAPERAPI_KEY = '***REMOVED***' PROXYCRAWL_KEY = None SCRAPESTACK_KEY = None # Spotify credentials -SPOTIFY_CREDENTIAL = "NzYzNkYTE6MGQ0ODY0NTY2Y2b3n645sdfgAyY2I1ljYjg3Nzc0MjIwODQ0ZWE=" +SPOTIFY_CREDENTIAL = "***REMOVED***" # IMDb API service https://imdb-api.com/ -IMDB_API_KEY = "k23fwewff23" +IMDB_API_KEY = "***REMOVED***" # The Movie Database (TMDB) API Keys -TMDB_API3_KEY = "deadbeef" -TMDB_API4_KEY = "deadbeef.deadbeef.deadbeef" +TMDB_API3_KEY = "***REMOVED***" +# TMDB_API4_KEY = "deadbeef.deadbeef.deadbeef" # Google Books API Key -GOOGLE_API_KEY = 'deadbeef-deadbeef-deadbeef' +GOOGLE_API_KEY = '***REMOVED***' # IGDB -IGDB_CLIENT_ID = 'deadbeef' -IGDB_ACCESS_TOKEN = 'deadbeef' +IGDB_CLIENT_ID = '***REMOVED***' +IGDB_SECRET = "***REMOVED***" +IGDB_ACCESS_TOKEN = '***REMOVED***' # Thumbnail setting # It is possible to optimize the image size even more: https://easy-thumbnails.readthedocs.io/en/latest/ref/optimize/ @@ -346,19 +345,18 @@ RQ_SHOW_ADMIN_LINK = True SEARCH_INDEX_NEW_ONLY = False -SEARCH_BACKEND = None # SEARCH_BACKEND = 'MEILISEARCH' # MEILISEARCH_SERVER = 'http://127.0.0.1:7700' # MEILISEARCH_KEY = 'deadbeef' -# SEARCH_BACKEND = 'TYPESENSE' -# TYPESENSE_CONNECTION = { -# 'api_key': 'deadbeef', -# 'nodes': [{ -# 'host': 'localhost', -# 'port': '8108', -# 'protocol': 'http' -# }], -# 'connection_timeout_seconds': 2 -# } +SEARCH_BACKEND = 'TYPESENSE' +TYPESENSE_CONNECTION = { + 'api_key': 'xyz', + 'nodes': [{ + 'host': 'localhost', + 'port': '8108', + 'protocol': 'http' + }], + 'connection_timeout_seconds': 2 +} diff --git a/books/models.py b/books/models.py index 8b23e9a6..2b1caeaf 100644 --- a/books/models.py +++ b/books/models.py @@ -160,7 +160,7 @@ class BookReview(Review): @property def url(self): - return settings.APP_WEBSITE + reverse("books:retrieve_review", args=[self.id]) + return reverse("books:retrieve_review", args=[self.id]) @property def item(self): diff --git a/books/templates/books/create_update.html b/books/templates/books/create_update.html index de4b8ca7..f48cd4b9 100644 --- a/books/templates/books/create_update.html +++ b/books/templates/books/create_update.html @@ -11,7 +11,7 @@ {{ site_name }} - {{ title }} - + diff --git a/books/templates/books/create_update_review.html b/books/templates/books/create_update_review.html index 04cc0c3b..d440b96f 100644 --- a/books/templates/books/create_update_review.html +++ b/books/templates/books/create_update_review.html @@ -13,7 +13,7 @@ {{ site_name }} - {{ title }} - + diff --git a/books/templates/books/delete.html b/books/templates/books/delete.html index 82d2fd7a..c1792a20 100644 --- a/books/templates/books/delete.html +++ b/books/templates/books/delete.html @@ -12,7 +12,7 @@ {{ site_name }} - {% trans '删除图书' %} - + diff --git a/books/templates/books/delete_review.html b/books/templates/books/delete_review.html index 7a0fad5c..77c88340 100644 --- a/books/templates/books/delete_review.html +++ b/books/templates/books/delete_review.html @@ -11,7 +11,7 @@ {{ site_name }} - {% trans '删除评论' %} - + diff --git a/books/templates/books/mark_list.html b/books/templates/books/mark_list.html index fe96c4ad..bd81a459 100644 --- a/books/templates/books/mark_list.html +++ b/books/templates/books/mark_list.html @@ -13,7 +13,7 @@ {{ site_name }} - {{ book.title }}{% trans '的标记' %} - + diff --git a/books/templates/books/review_detail.html b/books/templates/books/review_detail.html index b4046532..a08d868e 100644 --- a/books/templates/books/review_detail.html +++ b/books/templates/books/review_detail.html @@ -17,12 +17,12 @@ {{ site_name }}{% trans '书评' %} - {{ review.title }} - + - + diff --git a/books/templates/books/review_list.html b/books/templates/books/review_list.html index a7682b0b..77f2db7e 100644 --- a/books/templates/books/review_list.html +++ b/books/templates/books/review_list.html @@ -13,7 +13,7 @@ {{ site_name }} - {{ book.title }}{% trans '的评论' %} - + diff --git a/books/templates/books/scrape.html b/books/templates/books/scrape.html index 4f0adcea..81fa6a99 100644 --- a/books/templates/books/scrape.html +++ b/books/templates/books/scrape.html @@ -11,7 +11,7 @@ {{ site_name }} - {% trans '从豆瓣获取数据' %} - + diff --git a/collection/models.py b/collection/models.py index d079ec60..dda20130 100644 --- a/collection/models.py +++ b/collection/models.py @@ -64,7 +64,7 @@ class Collection(UserOwnedEntity): @property def url(self): - return settings.APP_WEBSITE + reverse("collection:retrieve", args=[self.id]) + return reverse("collection:retrieve", args=[self.id]) @property def wish_url(self): diff --git a/collection/templates/create_update.html b/collection/templates/create_update.html index 43e82dcb..4f7cd5ca 100644 --- a/collection/templates/create_update.html +++ b/collection/templates/create_update.html @@ -11,7 +11,7 @@ {{ site_name }} - {{ title }} - +