diff --git a/boofilsic/settings.py b/boofilsic/settings.py index 4b1cd920..08ddd03a 100644 --- a/boofilsic/settings.py +++ b/boofilsic/settings.py @@ -237,7 +237,7 @@ SITE_INFO = { "sentry_dsn": None, } -REDIRECT_URIS = SITE_INFO["site_url"] + "/users/OAuth2_login/" +REDIRECT_URIS = f'{SITE_INFO["site_url"]}/users/OAuth2_login/' # if you are creating new site, use # REDIRECT_URIS = SITE_INFO["site_url"] + "/account/login/oauth" @@ -386,11 +386,11 @@ SEARCH_INDEX_NEW_ONLY = False # MEILISEARCH_KEY = 'deadbeef' # SEARCH_BACKEND = "TYPESENSE" -# TYPESENSE_CONNECTION = { -# "api_key": "xyz", -# "nodes": [{"host": "localhost", "port": "8108", "protocol": "http"}], -# "connection_timeout_seconds": 2, -# } +TYPESENSE_CONNECTION = { + "api_key": "xyz", + "nodes": [{"host": "localhost", "port": "8108", "protocol": "http"}], + "connection_timeout_seconds": 2, +} SEARCH_BACKEND = None @@ -410,7 +410,8 @@ DISABLE_MODEL_SIGNAL = False # disable index and social feeds during importing/ # SILKY_MAX_RESPONSE_BODY_SIZE = 1024 # If response body>1024 bytes, ignore # SILKY_INTERCEPT_PERCENT = 10 -DISCORD_WEBHOOKS = {} +DISCORD_WEBHOOKS = {"user-report": None} + NINJA_PAGINATION_PER_PAGE = 20 OAUTH2_PROVIDER = { diff --git a/boofilsic/urls.py b/boofilsic/urls.py index ebecef4b..ad023bf1 100644 --- a/boofilsic/urls.py +++ b/boofilsic/urls.py @@ -22,7 +22,7 @@ from common.api import api from users.views import login urlpatterns = [ - # path("api/", api.urls), # type: ignore + path("api/", api.urls), # type: ignore path("login/", login), path("markdownx/", include("markdownx.urls")), path("account/", include("users.urls")), diff --git a/catalog/api.py b/catalog/api.py index 0cf231f2..eb307efb 100644 --- a/catalog/api.py +++ b/catalog/api.py @@ -205,7 +205,7 @@ def search_item_legacy( query = query.strip() if not query: return 400, {"message": "Invalid query"} - result = Indexer.search(query, page=1, category=category) + result = Indexer.search(query, page=1, categories=[category]) return 200, {"items": result.items} diff --git a/catalog/common/models.py b/catalog/common/models.py index 001fd52d..7186ec76 100644 --- a/catalog/common/models.py +++ b/catalog/common/models.py @@ -246,8 +246,8 @@ class Item(SoftDeleteMixin, PolymorphicModel): url_path = "item" # subclass must specify this type = None # subclass must specify this parent_class = None # subclass may specify this to allow create child item - category = None # subclass must specify this - demonstrative = None # subclass must specify this + category: ItemCategory | None = None # subclass must specify this + demonstrative: str | None = None # subclass must specify this uid = models.UUIDField(default=uuid.uuid4, editable=False, db_index=True) title = models.CharField(_("标题"), max_length=1000, default="") brief = models.TextField(_("简介"), blank=True, default="") diff --git a/catalog/common/sites.py b/catalog/common/sites.py index c4f696b3..ee4be7b1 100644 --- a/catalog/common/sites.py +++ b/catalog/common/sites.py @@ -10,11 +10,11 @@ import json import logging import re from dataclasses import dataclass, field -from typing import Callable +from typing import Callable, Type import django_rq -from .models import ExternalResource, IdealIdTypes, IdType, Item +from .models import ExternalResource, IdealIdTypes, IdType, Item, SiteName _logger = logging.getLogger(__name__) @@ -38,10 +38,10 @@ class AbstractSite: Abstract class to represent a site """ - SITE_NAME = None - ID_TYPE = None - WIKI_PROPERTY_ID = "P0undefined0" - DEFAULT_MODEL = None + SITE_NAME: SiteName | None = None + ID_TYPE: IdType | None = None + WIKI_PROPERTY_ID: str | None = "P0undefined0" + DEFAULT_MODEL: Type[Item] | None = None URL_PATTERNS = [r"\w+://undefined/(\d+)"] @classmethod @@ -57,7 +57,7 @@ class AbstractSite: return False @classmethod - def id_to_url(cls, id_value): + def id_to_url(cls, id_value: str): return "https://undefined/" + id_value @classmethod diff --git a/catalog/management/commands/discover.py b/catalog/management/commands/discover.py index 7332d737..32e316ba 100644 --- a/catalog/management/commands/discover.py +++ b/catalog/management/commands/discover.py @@ -7,7 +7,7 @@ from django.utils import timezone from loguru import logger from catalog.models import * -from journal.models import Comment, ItemCategory, ShelfMember, query_item_category +from journal.models import Comment, ShelfMember, query_item_category MAX_ITEMS_PER_PERIOD = 12 MIN_MARKS = 2 diff --git a/common/api.py b/common/api.py index 41db7e76..901e7912 100644 --- a/common/api.py +++ b/common/api.py @@ -69,7 +69,7 @@ class PageNumberPagination(NinjaPageNumberPagination): api = NinjaAPI( auth=OAuthAccessTokenAuth(), - title=settings.SITE_INFO["site_name"] + " API", + title=f'{settings.SITE_INFO["site_name"]} API', version="1.0.0", description=f"{settings.SITE_INFO['site_name']} API