[damned-lies] refactor: fix few linter issues in common
- From: Claude Paroz <claudep src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [damned-lies] refactor: fix few linter issues in common
- Date: Sun, 18 Apr 2021 19:07:43 +0000 (UTC)
commit 4c7719d4edac8d6d8d33ff71c8dfb32aba15c78e
Author: Guillaume Bernard <associations guillaume-bernard fr>
Date: Sat Apr 17 20:17:07 2021 +0200
refactor: fix few linter issues in common
common/fields.py | 10 ++++------
common/middleware.py | 1 -
common/templatetags/list_to_columns.py | 14 +++++++++-----
common/utils.py | 4 ++--
4 files changed, 15 insertions(+), 14 deletions(-)
---
diff --git a/common/fields.py b/common/fields.py
index 5158502d..ec1fd29c 100644
--- a/common/fields.py
+++ b/common/fields.py
@@ -19,9 +19,9 @@ class DictionaryField(models.Field):
def from_db_value(self, value, *args):
if value is None:
return None
- elif value == "":
+ if value == "":
return {}
- elif isinstance(value, str):
+ if isinstance(value, str):
try:
return dict(json.loads(value))
except (ValueError, TypeError):
@@ -29,16 +29,14 @@ class DictionaryField(models.Field):
if isinstance(value, dict):
return value
- else:
- return {}
+ return {}
def get_prep_value(self, value):
if not value:
return ""
if isinstance(value, str):
return value
- else:
- return json.dumps(value)
+ return json.dumps(value)
def value_to_string(self, obj):
value = self._get_val_from_obj(obj)
diff --git a/common/middleware.py b/common/middleware.py
index 6bf6811b..1708c067 100644
--- a/common/middleware.py
+++ b/common/middleware.py
@@ -12,4 +12,3 @@ class TokenAuthenticationMiddleware(MiddlewareMixin):
if user:
user.backend = self.backend_path
request.user = user
-
diff --git a/common/templatetags/list_to_columns.py b/common/templatetags/list_to_columns.py
index 252d33aa..85889f1c 100644
--- a/common/templatetags/list_to_columns.py
+++ b/common/templatetags/list_to_columns.py
@@ -4,23 +4,25 @@ from django import template
register = template.Library()
+
class SplitListNode(template.Node):
- def __init__(self, list, cols, new_list):
- self.list = list
+ def __init__(self, list_, cols, new_list):
+ self.list = list_
self.cols = cols
self.new_list = new_list
- def split_seq(self, list, cols=2):
+ def split_seq(self, list_, cols=2):
start = 0
for i in range(cols):
- stop = start + len(list[i::cols])
- yield list[start:stop]
+ stop = start + len(list_[i::cols])
+ yield list_[start:stop]
start = stop
def render(self, context):
context[self.new_list] = self.split_seq(context[self.list], int(self.cols))
return ''
+
def list_to_columns(parser, token):
"""Parse template tag: {% list_to_columns list as new_list 2 %}"""
bits = token.contents.split()
@@ -29,4 +31,6 @@ def list_to_columns(parser, token):
if bits[2] != 'as':
raise template.TemplateSyntaxError("second argument to the list_to_columns tag must be 'as'")
return SplitListNode(bits[1], bits[4], bits[3])
+
+
list_to_columns = register.tag(list_to_columns)
diff --git a/common/utils.py b/common/utils.py
index b3fb0668..d1c4bf3c 100644
--- a/common/utils.py
+++ b/common/utils.py
@@ -71,8 +71,8 @@ def lc_sorted(*args, **kwargs):
def trans_sort_object_list(lst, tr_field):
"""Sort an object list with translated_name"""
- for l in lst:
- l.translated_name = _(getattr(l, tr_field))
+ for item in lst:
+ item.translated_name = _(getattr(item, tr_field))
return lc_sorted(lst, key=lambda o: o.translated_name.lower())
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]