Fix various pep8/flake8/pylint errors

This commit is contained in:
Swen Kooij
2017-05-25 19:40:03 +03:00
parent 5a4f449363
commit 92a53bc3d7
11 changed files with 39 additions and 166 deletions

View File

@@ -1,4 +1,4 @@
from typing import Callable
from typing import Callable, Tuple
from datetime import datetime
from django import forms
@@ -69,13 +69,7 @@ class LocalizedAutoSlugField(LocalizedField):
slugs = LocalizedValue()
for lang_code, _ in settings.LANGUAGES:
value = self._get_populate_from_value(
instance,
self.populate_from,
lang_code
)
for lang_code, value in self._get_populate_values(instance):
if not value:
continue
@@ -128,6 +122,30 @@ class LocalizedAutoSlugField(LocalizedField):
return unique_slug
def _get_populate_values(self, instance) -> Tuple[str, str]:
"""Gets all values (for each language) from the
specified's instance's `populate_from` field.
Arguments:
instance:
The instance to get the values from.
Returns:
A list of (lang_code, value) tuples.
"""
return [
(
lang_code,
self._get_populate_from_value(
instance,
self.populate_from,
lang_code
),
)
for lang_code, _ in settings.LANGUAGES
]
@staticmethod
def _get_populate_from_value(instance, field_name: str, language: str):
"""Gets the value to create a slug from in the specified language.

View File

@@ -1,6 +1,5 @@
from datetime import datetime
from django.conf import settings
from django.utils.text import slugify
from django.core.exceptions import ImproperlyConfigured
@@ -73,13 +72,7 @@ class LocalizedUniqueSlugField(LocalizedAutoSlugField):
slugs = LocalizedValue()
for lang_code, _ in settings.LANGUAGES:
value = self._get_populate_from_value(
instance,
self.populate_from,
lang_code
)
for lang_code, value in self._get_populate_values(instance):
if not value:
continue