diff --git a/boofilsic/urls.py b/boofilsic/urls.py index 551bcc44..a324914f 100644 --- a/boofilsic/urls.py +++ b/boofilsic/urls.py @@ -22,7 +22,7 @@ from users.views import login urlpatterns = [ - path("api/", api.urls), # type: ignore + path("api/", api.urls), path("login/", login), path("markdownx/", include("markdownx.urls")), path("account/", include("users.urls")), diff --git a/catalog/common/downloaders.py b/catalog/common/downloaders.py index 0ecbb208..12323716 100644 --- a/catalog/common/downloaders.py +++ b/catalog/common/downloaders.py @@ -151,7 +151,7 @@ def validate_response(self, response): else: return RESPONSE_INVALID_CONTENT - def _download(self, url) -> Tuple[DownloaderResponse | MockResponse, int]: + def _download(self, url) -> Tuple[DownloaderResponse | MockResponse | None, int]: try: if not _mock_mode: resp = requests.get( @@ -179,7 +179,7 @@ def _download(self, url) -> Tuple[DownloaderResponse | MockResponse, int]: self.logs.append( {"response_type": RESPONSE_NETWORK_ERROR, "url": url, "exception": e} ) - return None, RESPONSE_NETWORK_ERROR # type: ignore + return None, RESPONSE_NETWORK_ERROR def download(self): resp, self.response_type = self._download(self.url) @@ -237,7 +237,7 @@ def download(self): while retries: retries -= 1 resp, self.response_type = self._download(self.url) - if self.response_type == RESPONSE_OK: + if self.response_type == RESPONSE_OK and resp: return resp elif self.response_type != RESPONSE_NETWORK_ERROR and retries == 0: raise DownloadError(self) diff --git a/journal/models/collection.py b/journal/models/collection.py index 27a386cc..9e209c3b 100644 --- a/journal/models/collection.py +++ b/journal/models/collection.py @@ -90,7 +90,7 @@ def save(self, *args, **kwargs): ): self.catalog_item.title = self.title self.catalog_item.brief = self.brief - self.catalog_item.cover = self.cover # type: ignore + self.catalog_item.cover = self.cover self.catalog_item.save() super().save(*args, **kwargs) Takahe.post_collection(self) diff --git a/journal/models/mixins.py b/journal/models/mixins.py index ac3f836b..e319b66c 100644 --- a/journal/models/mixins.py +++ b/journal/models/mixins.py @@ -3,6 +3,8 @@ from users.models import APIdentity, User if TYPE_CHECKING: + from django.db.models import ForeignKey + from .common import Piece @@ -15,8 +17,9 @@ class UserOwnedObjectMixin: visibility = models.PositiveSmallIntegerField(default=0) """ - owner: APIdentity - visibility: int + if TYPE_CHECKING: + owner: ForeignKey[APIdentity, Piece] + visibility: int def is_visible_to(self: "Piece | Self", viewing_user: User) -> bool: # type: ignore owner = self.owner @@ -26,7 +29,7 @@ def is_visible_to(self: "Piece | Self", viewing_user: User) -> bool: # type: ig return True if not viewing_user.is_authenticated: return self.visibility == 0 - viewer = viewing_user.identity # type: ignore[assignment] + viewer = viewing_user.identity if not viewer: return False if self.visibility == 2: diff --git a/journal/views/mark.py b/journal/views/mark.py index 3bd35c43..9f38428a 100644 --- a/journal/views/mark.py +++ b/journal/views/mark.py @@ -127,7 +127,7 @@ def mark(request: AuthedHttpRequest, item_uuid): visibility = int(request.POST.get("visibility", default=0)) rating_grade = request.POST.get("rating_grade", default=0) rating_grade = int(rating_grade) if rating_grade else None - status = ShelfType(request.POST.get("status")) + status = ShelfType(request.POST.get("status", "wishlist")) text = request.POST.get("text") tags = request.POST.get("tags") tags = tags.split(",") if tags else [] diff --git a/social/models.py b/social/models.py index c89197e8..617bb599 100644 --- a/social/models.py +++ b/social/models.py @@ -42,7 +42,7 @@ class ActivityTemplate(models.TextChoices): class LocalActivity(models.Model, UserOwnedObjectMixin): - owner = models.ForeignKey(APIdentity, on_delete=models.CASCADE) # type: ignore + owner = models.ForeignKey(APIdentity, on_delete=models.CASCADE) visibility = models.PositiveSmallIntegerField(default=0) # type: ignore template = models.CharField( blank=False, choices=ActivityTemplate.choices, max_length=50 diff --git a/takahe/models.py b/takahe/models.py index 6cd6f02d..2c678666 100644 --- a/takahe/models.py +++ b/takahe/models.py @@ -30,8 +30,7 @@ from .uris import * if TYPE_CHECKING: - from django.db.models.manager import RelatedManager - + from django_stubs_ext.db.models.manager import RelatedManager _migration_mode = False @@ -201,7 +200,8 @@ def valid(self): class User(AbstractBaseUser): - identities: "RelatedManager[Identity]" + if TYPE_CHECKING: + identities: RelatedManager["Identity"] class Meta: # managed = False @@ -1493,18 +1493,6 @@ def usage_days(self, num: int = 7) -> dict[date, int]: results[date(year, month, day)] = val return dict(sorted(results.items(), reverse=True)[:num]) - def to_mastodon_json(self, following: bool | None = None): - value = { - "name": self.hashtag, - "url": self.urls.view.full(), # type: ignore - "history": [], - } - - if following is not None: - value["following"] = following - - return value - class PostInteraction(models.Model): """ diff --git a/users/account.py b/users/account.py index bcafd770..41baeb1d 100644 --- a/users/account.py +++ b/users/account.py @@ -173,8 +173,8 @@ def OAuth2_login(request): user: User = authenticate(request, token=token, site=site) # type: ignore if user: # existing user - user.mastodon_token = token # type: ignore - user.mastodon_refresh_token = refresh_token # type: ignore + user.mastodon_token = token + user.mastodon_refresh_token = refresh_token user.save(update_fields=["mastodon_token", "mastodon_refresh_token"]) return login_existing_user(request, user) else: # newly registered user @@ -284,7 +284,7 @@ def clean_email(self): def send_verification_link(user_id, action, email): s = {"i": user_id, "e": email, "a": action} - v = TimestampSigner().sign_object(s) # type: ignore + v = TimestampSigner().sign_object(s) if action == "verify": subject = f'{settings.SITE_INFO["site_name"]} - {_("验证电子邮件地址")}' url = settings.SITE_INFO["site_url"] + "/account/verify_email?c=" + v @@ -321,7 +321,7 @@ def send_verification_link(user_id, action, email): def verify_email(request): error = "" try: - s = TimestampSigner().unsign_object(request.GET.get("c"), max_age=60 * 15) # type: ignore + s = TimestampSigner().unsign_object(request.GET.get("c"), max_age=60 * 15) except Exception as e: logger.error(e) error = _("链接无效或已过期") diff --git a/users/views.py b/users/views.py index 65151bfa..5902339b 100644 --- a/users/views.py +++ b/users/views.py @@ -193,7 +193,7 @@ def reject_follow_request(request: AuthedHttpRequest, user_name): @login_required def set_layout(request: AuthedHttpRequest): if request.method == "POST": - layout = json.loads(request.POST.get("layout", {})) # type: ignore + layout = json.loads(request.POST.get("layout", "{}")) if request.POST.get("name") == "profile": request.user.preference.profile_layout = layout request.user.preference.save(update_fields=["profile_layout"]) @@ -229,7 +229,7 @@ def report(request: AuthedHttpRequest): form.save() dw = settings.DISCORD_WEBHOOKS.get("user-report") if dw: - webhook = SyncWebhook.from_url(dw) # type: ignore + webhook = SyncWebhook.from_url(dw) webhook.send( f"New report from {request.user} about {form.instance.reported_user} : {form.instance.message}" )