Skip to content

Commit

Permalink
mypy: fix mypy errors in wladmin module. Rel: #3703
Browse files Browse the repository at this point in the history
  • Loading branch information
SukiCZ committed Oct 5, 2024
1 parent d31f719 commit 1492e68
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion weblate/billing/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ class Billing(models.Model):
# with payment processor
payment = models.JSONField(editable=False, default=dict, encoder=DjangoJSONEncoder)

objects = BillingManager.from_queryset(BillingQuerySet)()
objects: BillingQuerySet = BillingManager.from_queryset(BillingQuerySet)()

Check failure on line 196 in weblate/billing/models.py

View workflow job for this annotation

GitHub Actions / mypy

Incompatible types in assignment (expression has type "BillingManager", variable has type "BillingQuerySet")

class Meta:
verbose_name = "Customer billing"
Expand Down
4 changes: 2 additions & 2 deletions weblate/wladmin/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,12 +328,12 @@ class SupportStatusDict(TypedDict):

def get_support_status(request: AuthenticatedHttpRequest) -> SupportStatusDict:
if hasattr(request, "weblate_support_status"):
support_status = request.weblate_support_status
support_status: SupportStatusDict = request.weblate_support_status

Check warning on line 331 in weblate/wladmin/models.py

View check run for this annotation

Codecov / codecov/patch

weblate/wladmin/models.py#L331

Added line #L331 was not covered by tests
else:
support_status = cache.get(SUPPORT_STATUS_CACHE_KEY)
if support_status is None:
support_status_instance = SupportStatus.objects.get_current()
support_status: SupportStatusDict = {
support_status = {
"has_support": support_status_instance.name != "community",
"in_limits": support_status_instance.in_limits,
}
Expand Down
4 changes: 2 additions & 2 deletions weblate/wladmin/sites.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from django.utils.translation import gettext, gettext_lazy

if TYPE_CHECKING:
from weblate.auth.models import AuthenticatedHttpRequest
from django.http import HttpRequest


class WeblateAdminSite(AdminSite):
Expand All @@ -38,7 +38,7 @@ def site_url(self):
return settings.URL_PREFIX
return "/"

def each_context(self, request: AuthenticatedHttpRequest):
def each_context(self, request: HttpRequest):
from weblate.wladmin.models import ConfigurationError

result = super().each_context(request)
Expand Down
17 changes: 9 additions & 8 deletions weblate/wladmin/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
from weblate.utils.version import GIT_LINK, GIT_REVISION
from weblate.utils.views import show_form_errors
from weblate.vcs.ssh import (
KeyType,
add_host_key,
can_generate_key,
generate_ssh_key,
Expand Down Expand Up @@ -322,9 +323,8 @@ def performance(request: AuthenticatedHttpRequest) -> HttpResponse:

@management_access
def ssh_key(request: AuthenticatedHttpRequest) -> HttpResponse:
filename, data = get_key_data_raw(
key_type=request.GET.get("type", "rsa"), kind="private"
)
key_type = cast(KeyType, request.GET.get("type", "rsa"))
filename, data = get_key_data_raw(key_type=key_type, kind="private")
if data is None:
raise Http404

Expand All @@ -345,7 +345,8 @@ def ssh(request: AuthenticatedHttpRequest) -> HttpResponse:

# Generate key if it does not exist yet
if can_generate and action == "generate":
generate_ssh_key(request, key_type=request.POST.get("type", "rsa"))
key_type = cast(KeyType, request.POST.get("type", "rsa"))
generate_ssh_key(request, key_type=key_type)
return redirect("manage-ssh")

# Read key data if it exists
Expand Down Expand Up @@ -429,14 +430,14 @@ def users_check(request: AuthenticatedHttpRequest) -> HttpResponse:
# Legacy links for care.weblate.org integration
if "email" in data and "q" not in data:
data = data.copy()
data["q"] = data["email"]
data.setlist("q", data.getlist("email"))
form = AdminUserSearchForm(data)

user_list = None
if form.is_valid():
user_list = User.objects.search(
form.cleaned_data.get("q", ""), parser=form.fields["q"].parser
)[:2]
parser = getattr(form.fields["q"], "parser", "unit")
query = form.cleaned_data.get("q", "")
user_list = User.objects.search(query, parser=parser)[:2]
if user_list.count() != 1:
return redirect_param(
"manage-users", "?q={}".format(quote(form.cleaned_data["q"]))
Expand Down

0 comments on commit 1492e68

Please sign in to comment.