Revised the code as suggested by PyCharm.

This commit is contained in:
依瑪貓 2020-08-13 10:17:52 +08:00
parent 1be05c2252
commit e06821194c
8 changed files with 17 additions and 19 deletions

View File

@ -30,9 +30,6 @@
.date-account-line { .date-account-line {
font-size: 0.833em; font-size: 0.833em;
} }
.negative {
color: red;
}
.journal-credit { .journal-credit {
padding-left: 1em; padding-left: 1em;
} }

View File

@ -24,7 +24,7 @@
/** /**
* Returns the regular payment data. * Returns the regular payment data.
* *
* @returns {{debits: [], credits: []}} * @returns {{debit: [], credit: []}}
*/ */
function getRegularPayments() { function getRegularPayments() {
const today = new Date($("#txn-date").get(0).value); const today = new Date($("#txn-date").get(0).value);

View File

@ -142,7 +142,7 @@ function loadSummaryCategoryData() {
*/ */
function startSummaryHelper(summary) { function startSummaryHelper(summary) {
// Replaced common substitution character "*" with "×" // Replaced common substitution character "*" with "×"
summary_content = summary.val(); let summary_content = summary.val();
summary_content = summary_content.replace(/\*(\d+)$/, "×$1"); summary_content = summary_content.replace(/\*(\d+)$/, "×$1");
const type = summary.data("type"); const type = summary.data("type");
const no = summary.data("no"); const no = summary.data("no");
@ -331,7 +331,7 @@ function switchSummaryTab(tab) {
/** /**
* Sets the known general category buttons. * Sets the known general category buttons.
* *
* @param {string} category the general category * @param {string|null} category the general category
*/ */
function setSummaryGeneralCategoryButtons(category) { function setSummaryGeneralCategoryButtons(category) {
$(".btn-summary-general-category").each(function () { $(".btn-summary-general-category").each(function () {
@ -480,7 +480,7 @@ function setSummaryRegularPaymentButtons(category) {
* *
* @param {string} format the category format, either "general", * @param {string} format the category format, either "general",
* "travel", or "bus". * "travel", or "bus".
* @param {string} category the category * @param {string|null} category the category
*/ */
function setSummaryAccount(format, category) { function setSummaryAccount(format, category) {
const recordId = $("#summary-record").get(0).value; const recordId = $("#summary-record").get(0).value;

View File

@ -43,7 +43,7 @@ def accounting_amount(value: Union[str, int]) -> str:
break break
s = m.group(1) + "," + m.group(2) s = m.group(1) + "," + m.group(2)
if value < 0: if value < 0:
s = "(%s)" % (s) s = "(%s)" % s
return s return s

View File

@ -56,10 +56,10 @@ class AccountBackend:
"""Returns the user by her log in user name. """Returns the user by her log in user name.
Args: Args:
username (str): The log in user name. username: The log in user name.
Return: Return:
User: The user, or None if the user does not eixst. The user, or None if the user does not exist.
""" """
return User.objects.filter(login_id=username).first() return User.objects.filter(login_id=username).first()
@ -133,7 +133,9 @@ def _get_host(ip: str) -> Optional[str]:
""" """
try: try:
return socket.gethostbyaddr(ip)[0] return socket.gethostbyaddr(ip)[0]
except Exception: except socket.herror:
return None
except socket.gaierror:
return None return None

View File

@ -146,7 +146,7 @@ class UserForm(forms.Form):
raise error raise error
def _validate_passwords_equal(self) -> None: def _validate_passwords_equal(self) -> None:
"""Validates whether the two passwords are equa. """Validates whether the two passwords are equal.
Raises: Raises:
forms.ValidationError: When the validation fails. forms.ValidationError: When the validation fails.

View File

@ -20,8 +20,7 @@
""" """
import datetime import datetime
import re import re
from datetime import date from typing import Optional, List
from typing import Optional, List, Any, Union
from django.core.serializers.json import DjangoJSONEncoder from django.core.serializers.json import DjangoJSONEncoder
from django.template import defaultfilters from django.template import defaultfilters
@ -461,7 +460,7 @@ class Period:
self.start = datetime.date(year, month, 1) self.start = datetime.date(year, month, 1)
self.end = self._month_last_day(timezone.localdate()) self.end = self._month_last_day(timezone.localdate())
self.description = gettext("Since %s")\ self.description = gettext("Since %s")\
% self._month_text(year, month) % self._month_text(year, month)
self.prep_desc = self.description self.prep_desc = self.description
return return
# Until a specific month # Until a specific month
@ -474,7 +473,7 @@ class Period:
self.start = Period.Parser.VERY_START self.start = Period.Parser.VERY_START
self.end = self._month_last_day(until_month) self.end = self._month_last_day(until_month)
self.description = gettext("Until %s")\ self.description = gettext("Until %s")\
% self._month_text(year, month) % self._month_text(year, month)
self.prep_desc = self.description self.prep_desc = self.description
return return
# A specific year # A specific year
@ -495,7 +494,7 @@ class Period:
self.end = datetime.date(year, 12, 31) self.end = datetime.date(year, 12, 31)
self.start = Period.Parser.VERY_START self.start = Period.Parser.VERY_START
self.description = gettext("Until %s")\ self.description = gettext("Until %s")\
% self._year_text(year) % self._year_text(year)
self.prep_desc = self.description self.prep_desc = self.description
return return
# All time # All time
@ -574,7 +573,7 @@ class Period:
int(m.group(3))) int(m.group(3)))
self.start = Period.Parser.VERY_START self.start = Period.Parser.VERY_START
self.description = gettext("Until %s")\ self.description = gettext("Until %s")\
% self._date_text(self.end) % self._date_text(self.end)
self.prep_desc = self.description self.prep_desc = self.description
return return
# Wrong period format # Wrong period format

View File

@ -211,4 +211,4 @@ def is_in_section(request: HttpRequest, section_name: str) -> bool:
return False return False
view_name = request.resolver_match.view_name view_name = request.resolver_match.view_name
return view_name == section_name\ return view_name == section_name\
or view_name.startswith(section_name + ".") or view_name.startswith(section_name + ".")