Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions localized_fields/fields/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,26 @@ class LocalizedField(HStoreField):
descriptor_class = LocalizedValueDescriptor

def __init__(
self, *args, required: Union[bool, List[str]] = None, **kwargs
self,
*args,
required: Optional[Union[bool, List[str]]] = None,
blank: bool = False,
**kwargs
):
"""Initializes a new instance of :see:LocalizedField."""

super(LocalizedField, self).__init__(*args, required=required, **kwargs)

if (self.required is None and self.blank) or self.required is False:
if (required is None and blank) or required is False:
self.required = []
elif self.required is None and not self.blank:
elif required is None and not blank:
self.required = [settings.LANGUAGE_CODE]
elif self.required is True:
elif required is True:
self.required = [lang_code for lang_code, _ in settings.LANGUAGES]
else:
self.required = required

super(LocalizedField, self).__init__(
*args, required=self.required, blank=blank, **kwargs
)

def contribute_to_class(self, model, name, **kwargs):
"""Adds this field to the specifed model.
Expand Down
2 changes: 2 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ DJANGO_SETTINGS_MODULE=settings
testpaths=tests
addopts=-m "not benchmark"
junit_family=legacy
filterwarnings=
ignore::DeprecationWarning:localized_fields.fields.autoslug_field
7 changes: 7 additions & 0 deletions settings.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import django
import dj_database_url

DEBUG = True
Expand Down Expand Up @@ -51,6 +52,12 @@
'django.contrib.auth.middleware.AuthenticationMiddleware',
]

# See: https://github.com/psycopg/psycopg2/issues/1293
if django.VERSION >= (3, 1):
USE_TZ = True
USE_I18N = True
TIME_ZONE = 'UTC'

# set to a lower number than the default, since
# we want the tests to be fast, default is 100
LOCALIZED_FIELDS_MAX_RETRIES = 3
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ def run(self):
"autopep8==1.4.4",
"isort==4.3.20",
"sl-docformatter==1.4",
"click==8.0.2",
],
},
cmdclass={
Expand Down