fix some type hints

This commit is contained in:
Your Name 2023-08-10 17:15:00 -04:00 committed by Henri Dickson
parent a69fc2ac4b
commit 7d1388df30
12 changed files with 36 additions and 48 deletions

View file

@ -237,7 +237,7 @@ SITE_INFO = {
"sentry_dsn": None, "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 # if you are creating new site, use
# REDIRECT_URIS = SITE_INFO["site_url"] + "/account/login/oauth" # REDIRECT_URIS = SITE_INFO["site_url"] + "/account/login/oauth"
@ -386,11 +386,11 @@ SEARCH_INDEX_NEW_ONLY = False
# MEILISEARCH_KEY = 'deadbeef' # MEILISEARCH_KEY = 'deadbeef'
# SEARCH_BACKEND = "TYPESENSE" # SEARCH_BACKEND = "TYPESENSE"
# TYPESENSE_CONNECTION = { TYPESENSE_CONNECTION = {
# "api_key": "xyz", "api_key": "xyz",
# "nodes": [{"host": "localhost", "port": "8108", "protocol": "http"}], "nodes": [{"host": "localhost", "port": "8108", "protocol": "http"}],
# "connection_timeout_seconds": 2, "connection_timeout_seconds": 2,
# } }
SEARCH_BACKEND = None 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_MAX_RESPONSE_BODY_SIZE = 1024 # If response body>1024 bytes, ignore
# SILKY_INTERCEPT_PERCENT = 10 # SILKY_INTERCEPT_PERCENT = 10
DISCORD_WEBHOOKS = {} DISCORD_WEBHOOKS = {"user-report": None}
NINJA_PAGINATION_PER_PAGE = 20 NINJA_PAGINATION_PER_PAGE = 20
OAUTH2_PROVIDER = { OAUTH2_PROVIDER = {

View file

@ -22,7 +22,7 @@ from common.api import api
from users.views import login from users.views import login
urlpatterns = [ urlpatterns = [
# path("api/", api.urls), # type: ignore path("api/", api.urls), # type: ignore
path("login/", login), path("login/", login),
path("markdownx/", include("markdownx.urls")), path("markdownx/", include("markdownx.urls")),
path("account/", include("users.urls")), path("account/", include("users.urls")),

View file

@ -205,7 +205,7 @@ def search_item_legacy(
query = query.strip() query = query.strip()
if not query: if not query:
return 400, {"message": "Invalid 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} return 200, {"items": result.items}

View file

@ -246,8 +246,8 @@ class Item(SoftDeleteMixin, PolymorphicModel):
url_path = "item" # subclass must specify this url_path = "item" # subclass must specify this
type = None # subclass must specify this type = None # subclass must specify this
parent_class = None # subclass may specify this to allow create child item parent_class = None # subclass may specify this to allow create child item
category = None # subclass must specify this category: ItemCategory | None = None # subclass must specify this
demonstrative = None # subclass must specify this demonstrative: str | None = None # subclass must specify this
uid = models.UUIDField(default=uuid.uuid4, editable=False, db_index=True) uid = models.UUIDField(default=uuid.uuid4, editable=False, db_index=True)
title = models.CharField(_("标题"), max_length=1000, default="") title = models.CharField(_("标题"), max_length=1000, default="")
brief = models.TextField(_("简介"), blank=True, default="") brief = models.TextField(_("简介"), blank=True, default="")

View file

@ -10,11 +10,11 @@ import json
import logging import logging
import re import re
from dataclasses import dataclass, field from dataclasses import dataclass, field
from typing import Callable from typing import Callable, Type
import django_rq import django_rq
from .models import ExternalResource, IdealIdTypes, IdType, Item from .models import ExternalResource, IdealIdTypes, IdType, Item, SiteName
_logger = logging.getLogger(__name__) _logger = logging.getLogger(__name__)
@ -38,10 +38,10 @@ class AbstractSite:
Abstract class to represent a site Abstract class to represent a site
""" """
SITE_NAME = None SITE_NAME: SiteName | None = None
ID_TYPE = None ID_TYPE: IdType | None = None
WIKI_PROPERTY_ID = "P0undefined0" WIKI_PROPERTY_ID: str | None = "P0undefined0"
DEFAULT_MODEL = None DEFAULT_MODEL: Type[Item] | None = None
URL_PATTERNS = [r"\w+://undefined/(\d+)"] URL_PATTERNS = [r"\w+://undefined/(\d+)"]
@classmethod @classmethod
@ -57,7 +57,7 @@ class AbstractSite:
return False return False
@classmethod @classmethod
def id_to_url(cls, id_value): def id_to_url(cls, id_value: str):
return "https://undefined/" + id_value return "https://undefined/" + id_value
@classmethod @classmethod

View file

@ -7,7 +7,7 @@ from django.utils import timezone
from loguru import logger from loguru import logger
from catalog.models import * 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 MAX_ITEMS_PER_PERIOD = 12
MIN_MARKS = 2 MIN_MARKS = 2

View file

@ -69,7 +69,7 @@ class PageNumberPagination(NinjaPageNumberPagination):
api = NinjaAPI( api = NinjaAPI(
auth=OAuthAccessTokenAuth(), auth=OAuthAccessTokenAuth(),
title=settings.SITE_INFO["site_name"] + " API", title=f'{settings.SITE_INFO["site_name"]} API',
version="1.0.0", version="1.0.0",
description=f"{settings.SITE_INFO['site_name']} API <hr/><a href='{settings.SITE_INFO['site_url']}'>Learn more</a>", description=f"{settings.SITE_INFO['site_name']} API <hr/><a href='{settings.SITE_INFO['site_url']}'>Learn more</a>",
) )

View file

@ -1,5 +1,5 @@
from django import template from django import template
from django.shortcuts import reverse from django.urls import reverse
from journal.models import Collection, Like from journal.models import Collection, Like

View file

@ -1,7 +1,7 @@
import re import re
from django.db import models from django.db import models
from django.shortcuts import reverse from django.urls import reverse
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from markdown import markdown from markdown import markdown
from markdownx.models import MarkdownxField from markdownx.models import MarkdownxField

View file

@ -1,24 +0,0 @@
from django.conf import settings
from django.core.management.base import BaseCommand
from mastodon.api import get_instance_info
from mastodon.models import MastodonApplication
from users.models import User
class Command(BaseCommand):
help = "Find wrong sites"
def handle(self, *args, **options):
for site in MastodonApplication.objects.all():
d = site.domain_name
login_domain = (
d.strip().lower().split("//")[-1].split("/")[0].split("@")[-1]
)
domain, version = get_instance_info(login_domain)
if d != domain:
print(f"{d} should be {domain}")
for u in User.objects.filter(mastodon_site=d, is_active=True):
u.mastodon_site = domain
print(f"fixing {u}")
u.save()

View file

@ -7,3 +7,13 @@ indent=2
[tool.isort] [tool.isort]
profile = "black" profile = "black"
[tool.mypy]
exclude = [
'^neodb/',
'^legacy/',
]
plugins = ["mypy_django_plugin.main"]
[tool.django-stubs]
django_settings_module = "boofilsic.settings"

View file

@ -8,6 +8,7 @@ ActivityManager generates chronological view for user and, in future, ActivitySt
import logging import logging
from functools import cached_property from functools import cached_property
from typing import Type
from django.conf import settings from django.conf import settings
from django.db import models from django.db import models
@ -125,8 +126,8 @@ class DataSignalManager:
class DefaultActivityProcessor: class DefaultActivityProcessor:
model = None model: Type[Piece]
template = None template: ActivityTemplate
def __init__(self, action_object): def __init__(self, action_object):
self.action_object = action_object self.action_object = action_object