31 Commits

Author SHA1 Message Date
Swen Kooij
476a20ba88 Merge pull request #61 from SectorLabs/bump-version
Bump version number to 5.0a8
2019-02-21 12:47:15 +02:00
Swen Kooij
ad99b77bcd Bump version number to 5.0a8 2019-02-21 12:34:22 +02:00
Swen Kooij
151250505d Merge pull request #60 from AdrianMuntean/error_on_empty_localized_integer_field
Return empty string in case the LocalizedIntegerField is null
2019-02-21 12:31:50 +02:00
Adrian Muntean
d8b872758c Return empty string in case of None 2019-02-20 12:26:04 +02:00
Adrian Muntean
a0ca977cab Set None in case the LocalizedIntegerField is null
In case the LocalizedIntegerField is null in the DB then it must explicitly be set to None,
otherwise it will yield TypeError: __str__ returned non-string
2019-02-14 14:48:38 +02:00
Swen Kooij
eb2cb6b244 Bump version number to 5.0a7 2019-01-14 11:00:20 +02:00
Swen Kooij
ed15fb0079 Upgrade django-postgres-extra>=1.21a15 2019-01-14 11:00:12 +02:00
Swen Kooij
f59904f8ea Bump version number to 5.0a6 2019-01-11 15:03:19 +02:00
Swen Kooij
f20966d6d2 Fix tests not passing for Django 2.X 2019-01-11 15:02:22 +02:00
Swen Kooij
25417b5815 Merge pull request #56 from sliverc/user_defined_pk_descriptor
Avoid DoesNotExist error when creating model with user defined pk
2019-01-11 14:47:33 +02:00
Swen Kooij
abd1587ca0 Merge pull request #54 from sliverc/query_by_active_lang
Add support for localized query lookups
2019-01-11 14:47:18 +02:00
Swen Kooij
60fc79e9ff Merge pull request #57 from velrest/master
Fix typo in documentation for clean
2019-01-11 14:46:21 +02:00
Swen Kooij
ca470fc577 Merge pull request #49 from MELScience/admin-fix
Add tests for LocalizedFieldsAdminMixin
2019-01-11 14:46:10 +02:00
Swen Kooij
fac1a595aa Merge pull request #55 from sliverc/hstore_extension
Enable HStore extension for localized fields to work
2019-01-11 14:44:05 +02:00
Swen Kooij
d66f5085a8 Merge branch 'master' into hstore_extension 2019-01-11 14:40:38 +02:00
Swen Kooij
c6e8321ae7 Add CircleCI badge to README 2019-01-11 14:40:27 +02:00
Swen Kooij
b2f50ec82b Convert to use CircleCI and run tests against Django 2.1/Python 3.7 2019-01-11 14:37:03 +02:00
Oliver Sauder
ff836836bf Add support for localized query look ups 2018-12-03 09:45:08 +01:00
Swen Kooij
acf8867974 Merge pull request #52 from SectorLabs/localized-integer-field-widget
Add LocalizedIntegerFieldWidget
2018-09-24 15:16:55 +03:00
Cristi Ingineru
4922a1b93f self.translate() 2018-09-24 12:57:46 +03:00
Jonas Cosandey
d308e773cf fix typo 2018-09-12 14:27:44 +02:00
Oliver Sauder
b3b88d6d28 Avoid does not exist error when creating model with user defined pk 2018-09-10 12:05:46 +02:00
Oliver Sauder
6c902229ce Enable HStore extension for localized fields to work 2018-08-27 15:07:41 +02:00
Cristi Ingineru
4f83cbf4ed Add LocalizedIntegerFieldWidget 2018-08-16 14:27:38 +03:00
Swen Kooij
88e2d29596 Bump version number to 5.0a3 2018-06-28 12:39:25 +03:00
Swen Kooij
588f32086b Merge pull request #51 from SectorLabs/multiwidget
Copy the widget for each language
2018-06-28 12:39:02 +03:00
Cristi Ingineru
13e2666a51 Copy the widget for each language 2018-06-28 12:33:44 +03:00
Swen Kooij
2393539b44 Bump version number to 5.0a2 2018-06-19 12:30:04 +03:00
Swen Kooij
e322b3d63b Upgrade django-postgres-extra to 1.21a11 2018-06-19 12:29:55 +03:00
seroy
8ba0540237 Fix using LocalizedFieldsAdminMixin with inlines 2018-04-20 02:33:15 +03:00
seroy
b3624916b2 Add tests for LocalizedFieldsAdminMixin 2018-04-20 02:27:57 +03:00
31 changed files with 455 additions and 72 deletions

92
.circleci/config.yml Normal file
View File

@@ -0,0 +1,92 @@
version: 2
jobs:
test-python35:
docker:
- image: python:3.5-alpine
- image: postgres:11.0
environment:
POSTGRES_DB: 'localizedfields'
POSTGRES_USER: 'localizedfields'
POSTGRES_PASSWORD: 'localizedfields'
steps:
- checkout
- run:
name: Install packages
command: apk add postgresql-libs gcc musl-dev postgresql-dev git
- run:
name: Install Python packages
command: pip install -r requirements/test.txt
- run:
name: Run tests
command: tox -e 'py35-dj{111,20,21}'
environment:
DATABASE_URL: 'postgres://localizedfields:localizedfields@localhost:5432/localizedfields'
test-python36:
docker:
- image: python:3.6-alpine
- image: postgres:11.0
environment:
POSTGRES_DB: 'localizedfields'
POSTGRES_USER: 'localizedfields'
POSTGRES_PASSWORD: 'localizedfields'
steps:
- checkout
- run:
name: Install packages
command: apk add postgresql-libs gcc musl-dev postgresql-dev git
- run:
name: Install Python packages
command: pip install -r requirements/test.txt
- run:
name: Run tests
command: tox -e 'py36-dj{111,20,21}'
environment:
DATABASE_URL: 'postgres://localizedfields:localizedfields@localhost:5432/localizedfields'
test-python37:
docker:
- image: python:3.7-alpine
- image: postgres:11.0
environment:
POSTGRES_DB: 'localizedfields'
POSTGRES_USER: 'localizedfields'
POSTGRES_PASSWORD: 'localizedfields'
steps:
- checkout
- run:
name: Install packages
command: apk add postgresql-libs gcc musl-dev postgresql-dev git
- run:
name: Install Python packages
command: pip install -r requirements/test.txt
- run:
name: Run tests
command: tox -e 'py37-dj{111,20,21}'
environment:
DATABASE_URL: 'postgres://localizedfields:localizedfields@localhost:5432/localizedfields'
lint:
docker:
- image: python:3.5-alpine
steps:
- checkout
- run:
name: Install packages
command: apk add postgresql-libs gcc musl-dev postgresql-dev git
- run:
name: Install Python packages
command: pip install -r requirements/test.txt
- run:
name: Lint code
command: python setup.py lint
workflows:
version: 2
build:
jobs:
- test-python35
- test-python36
- test-python37
- lint

View File

@@ -1,5 +1,3 @@
[run]
include = localized_fields/*
omit = *migrations*, *tests*
plugins =
django_coverage_plugin

1
.gitignore vendored
View File

@@ -1,5 +1,6 @@
# Ignore virtual environments
env/
.env/
# Ignore Python byte code cache
*.pyc

View File

@@ -1,34 +0,0 @@
checks:
python:
code_rating: true
duplicate_code: true
tools:
pylint:
python_version: '3'
config_file: .pylintrc
filter:
excluded_paths:
- '*/tests/*'
- '*/migrations/*'
build:
environment:
python: '3.5.0'
variables:
DJANGO_SETTINGS_MODULES: settings
DATABASE_URL: postgres://scrutinizer:scrutinizer@localhost:5434/localized_fields
postgresql: true
dependencies:
override:
- 'pip install -r requirements/test.txt'
tests:
override:
-
command: pep8 ./localized_fields/
-
command: flake8 ./localized_fields/
-
command: tox
coverage:
file: '.coverage'
format: 'py-cc'

View File

@@ -1,11 +1,8 @@
django-localized-fields
=======================
.. image:: https://scrutinizer-ci.com/g/SectorLabs/django-localized-fields/badges/quality-score.png
:target: https://scrutinizer-ci.com/g/SectorLabs/django-localized-fields/
.. image:: https://scrutinizer-ci.com/g/SectorLabs/django-localized-fields/badges/coverage.png
:target: https://scrutinizer-ci.com/g/SectorLabs/django-localized-fields/
.. image:: https://circleci.com/gh/SectorLabs/django-localized-fields.svg?style=svg
:target: https://circleci.com/gh/SectorLabs/django-localized-fields
.. image:: https://img.shields.io/github/license/SectorLabs/django-localized-fields.svg
:target: https://github.com/SectorLabs/django-localized-fields/blob/master/LICENSE.md
@@ -282,7 +279,7 @@ Besides ``LocalizedField``, there's also:
Allows storing integers in multiple languages. This works exactly like ``LocalizedField`` except that
all values must be integers. Do note that values are stored as strings in your database because
the backing field type is ``hstore``, which only allows storing integers. The ``LocalizedIntegerField``
the backing field type is ``hstore``, which only allows storing strings. The ``LocalizedIntegerField``
takes care of ensuring that all values are integers and converts the stored strings back to integers
when retrieving them from the database. Do not expect to be able to do queries such as:
@@ -348,6 +345,7 @@ Experimental feature
^^^^^^^^^^^^^^^^^^^^
Enables the following experimental features:
* ``LocalizedField`` will return ``None`` instead of an empty ``LocalizedValue`` if there is no database value.
* ``LocalizedField`` lookups will lookup by currently active language instead of HStoreField
.. code-block:: python

View File

@@ -0,0 +1 @@
default_app_config = 'localized_fields.apps.LocalizedFieldsConfig'

View File

@@ -1,5 +1,3 @@
from django.contrib.admin import ModelAdmin
from . import widgets
from .fields import LocalizedField, LocalizedCharField, LocalizedTextField, \
LocalizedFileField
@@ -13,7 +11,7 @@ FORMFIELD_FOR_LOCALIZED_FIELDS_DEFAULTS = {
}
class LocalizedFieldsAdminMixin(ModelAdmin):
class LocalizedFieldsAdminMixin:
"""Mixin for making the fancy widgets work in Django Admin."""
class Media:

View File

@@ -1,5 +1,21 @@
import inspect
from django.apps import AppConfig
from django.conf import settings
from . import lookups
from .fields import LocalizedField
from .lookups import LocalizedLookupMixin
class LocalizedFieldsConfig(AppConfig):
name = 'localized_fields'
def ready(self):
if getattr(settings, 'LOCALIZED_FIELDS_EXPERIMENTAL', False):
for _, clazz in inspect.getmembers(lookups):
if not inspect.isclass(clazz) or clazz is LocalizedLookupMixin:
continue
if issubclass(clazz, LocalizedLookupMixin):
LocalizedField.register_lookup(clazz)

View File

@@ -41,7 +41,7 @@ class LocalizedValueDescriptor:
if self.field.name in instance.__dict__:
value = instance.__dict__[self.field.name]
elif instance.pk is not None:
elif not instance._state.adding:
instance.refresh_from_db(fields=[self.field.name])
value = getattr(instance, self.field.name)
else:

View File

@@ -165,7 +165,7 @@ class LocalizedField(HStoreField):
can store in the database.
For example, when all the language fields are
left empty, and the field is allows to be null,
left empty, and the field is allowed to be null,
we will store None instead of empty keys.
Arguments:

View File

@@ -5,6 +5,7 @@ from django.db.utils import IntegrityError
from .field import LocalizedField
from ..value import LocalizedValue, LocalizedIntegerValue
from ..forms import LocalizedIntegerFieldForm
class LocalizedIntegerField(LocalizedField):
@@ -63,6 +64,15 @@ class LocalizedIntegerField(LocalizedField):
return prepped_value
def formfield(self, **kwargs):
"""Gets the form field associated with this field."""
defaults = {
'form_class': LocalizedIntegerFieldForm
}
defaults.update(kwargs)
return super().formfield(**defaults)
@staticmethod
def _convert_localized_value(value: LocalizedValue) -> LocalizedIntegerValue:
"""Converts from :see:LocalizedValue to :see:LocalizedIntegerValue."""

View File

@@ -6,9 +6,9 @@ from django.core.exceptions import ValidationError
from django.forms.widgets import FILE_INPUT_CONTRADICTION
from .value import LocalizedValue, LocalizedStringValue, \
LocalizedFileValue
LocalizedFileValue, LocalizedIntegerValue
from .widgets import LocalizedFieldWidget, LocalizedCharFieldWidget, \
LocalizedFileWidget
LocalizedFileWidget, AdminLocalizedIntegerFieldWidget
class LocalizedFieldForm(forms.MultiValueField):
@@ -79,6 +79,14 @@ class LocalizedTextFieldForm(LocalizedFieldForm):
value_class = LocalizedStringValue
class LocalizedIntegerFieldForm(LocalizedFieldForm):
"""Form for a localized integer field, allows editing
the field in multiple languages."""
widget = AdminLocalizedIntegerFieldWidget
value_class = LocalizedIntegerValue
class LocalizedFileFieldForm(LocalizedFieldForm, forms.FileField):
"""Form for a localized file field, allows editing
the field in multiple languages."""

View File

@@ -0,0 +1,80 @@
from django.conf import settings
from django.contrib.postgres.fields.hstore import KeyTransform
from django.contrib.postgres.lookups import (SearchLookup, TrigramSimilar,
Unaccent)
from django.db.models.expressions import Col
from django.db.models.lookups import (Contains, EndsWith, Exact, IContains,
IEndsWith, IExact, In, IRegex, IsNull,
IStartsWith, Regex, StartsWith)
from django.utils import translation
class LocalizedLookupMixin():
def process_lhs(self, qn, connection):
if isinstance(self.lhs, Col):
language = translation.get_language() or settings.LANGUAGE_CODE
self.lhs = KeyTransform(language, self.lhs)
return super().process_lhs(qn, connection)
def get_prep_lookup(self):
return str(self.rhs)
class LocalizedSearchLookup(LocalizedLookupMixin, SearchLookup):
pass
class LocalizedUnaccent(LocalizedLookupMixin, Unaccent):
pass
class LocalizedTrigramSimilair(LocalizedLookupMixin, TrigramSimilar):
pass
class LocalizedExact(LocalizedLookupMixin, Exact):
pass
class LocalizedIExact(LocalizedLookupMixin, IExact):
pass
class LocalizedIn(LocalizedLookupMixin, In):
pass
class LocalizedContains(LocalizedLookupMixin, Contains):
pass
class LocalizedIContains(LocalizedLookupMixin, IContains):
pass
class LocalizedStartsWith(LocalizedLookupMixin, StartsWith):
pass
class LocalizedIStartsWith(LocalizedLookupMixin, IStartsWith):
pass
class LocalizedEndsWith(LocalizedLookupMixin, EndsWith):
pass
class LocalizedIEndsWith(LocalizedLookupMixin, IEndsWith):
pass
class LocalizedIsNullWith(LocalizedLookupMixin, IsNull):
pass
class LocalizedRegexWith(LocalizedLookupMixin, Regex):
pass
class LocalizedIRegexWith(LocalizedLookupMixin, IRegex):
pass

View File

@@ -0,0 +1,14 @@
# Generated by Django 2.1 on 2018-08-27 08:05
from django.contrib.postgres.operations import HStoreExtension
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
]
operations = [
HStoreExtension(),
]

View File

View File

@@ -1,4 +1,16 @@
{% for widget in widget.subwidgets %}
<label for="{{ widget.attrs.id }}">{{ widget.lang_name }}</label>
{% include widget.template_name %}
{% endfor %}
{% with widget_id=widget.attrs.id %}
<div class="localized-fields-widget" role="tabs" data-synctabs="translation">
<ul class="localized-fields-widget tabs">
{% for widget in widget.subwidgets %}
<li class="localized-fields-widget tab">
<label for="{{ widget_id }}_{{ widget.lang_code }}">{{ widget.lang_name|capfirst }}</label>
</li>
{% endfor %}
</ul>
{% for widget in widget.subwidgets %}
<div role="tabpanel" id="{{ widget_id }}_{{ widget.lang_code }}">
{% include widget.template_name %}
</div>
{% endfor %}
</div>
{% endwith %}

View File

@@ -228,3 +228,9 @@ class LocalizedIntegerValue(LocalizedValue):
return self.default_value
return int(value)
def __str__(self) -> str:
"""Returns string representation of value"""
value = self.translate()
return str(value) if value is not None else ''

View File

@@ -1,3 +1,5 @@
import copy
from typing import List
from django.conf import settings
@@ -16,7 +18,7 @@ class LocalizedFieldWidget(forms.MultiWidget):
"""Initializes a new instance of :see:LocalizedFieldWidget."""
initial_widgets = [
self.widget
copy.copy(self.widget)
for _ in settings.LANGUAGES
]
@@ -118,3 +120,7 @@ class AdminLocalizedCharFieldWidget(AdminLocalizedFieldWidget):
class AdminLocalizedFileFieldWidget(AdminLocalizedFieldWidget):
widget = widgets.AdminFileWidget
class AdminLocalizedIntegerFieldWidget(AdminLocalizedFieldWidget):
widget = widgets.AdminIntegerFieldWidget

View File

@@ -2,15 +2,9 @@
django-autoslug==1.9.3
django-bleach==0.3.0
django-coverage-plugin==1.3.1
psycopg2==2.7.3.2
pylint==1.8.1
pylint-common==0.2.5
pylint-django==0.8.0
pylint-plugin-utils==0.2.6
coverage==4.4.2
django-coverage-plugin==1.3.1
flake8==3.5.0
flake8==3.6.0
pep8==1.7.1
dj-database-url==0.4.2
tox==2.9.1

View File

@@ -21,6 +21,9 @@ LANGUAGES = (
)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.admin',
'localized_fields',
'tests',
)

View File

@@ -1,5 +1,6 @@
[flake8]
max-line-length = 120
ignore = E252, W605
exclude = env,.tox,.git,config/settings,*/migrations/*,*/static/CACHE/*,docs,node_modules
[pep8]

View File

@@ -1,13 +1,39 @@
import os
import distutils.cmd
import subprocess
from setuptools import find_packages, setup
class BaseCommand(distutils.cmd.Command):
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def create_command(text, commands):
"""Creates a custom setup.py command."""
class CustomCommand(BaseCommand):
description = text
def run(self):
for cmd in commands:
subprocess.check_call(cmd)
return CustomCommand
with open(os.path.join(os.path.dirname(__file__), 'README.rst'), encoding='utf-8') as readme:
README = readme.read()
setup(
name='django-localized-fields',
version='5.0a1',
version='5.0a8',
packages=find_packages(exclude=['tests']),
include_package_data=True,
license='MIT License',
@@ -18,7 +44,7 @@ setup(
author_email='open-source@sectorlabs.ro',
keywords=['django', 'localized', 'language', 'models', 'fields'],
install_requires=[
'django-postgres-extra>=1.21a',
'django-postgres-extra>=1.21a15',
'Django>=1.11',
'deprecation==2.0.3'
],
@@ -32,5 +58,11 @@ setup(
'Programming Language :: Python :: 3.5',
'Topic :: Internet :: WWW/HTTP',
'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
]
],
cmdclass={
'lint': create_command(
'Lints the code',
[['flake8', 'setup.py', 'localized_fields', 'tests']],
),
},
)

87
tests/test_admin.py Normal file
View File

@@ -0,0 +1,87 @@
from django.apps import apps
from django.contrib import admin
from django.contrib.admin.checks import check_admin_app
from django.db import models
from django.test import TestCase
from localized_fields.fields import LocalizedField
from localized_fields.admin import LocalizedFieldsAdminMixin
from tests.fake_model import get_fake_model
class LocalizedFieldsAdminMixinTestCase(TestCase):
"""Tests the :see:LocalizedFieldsAdminMixin class."""
TestModel = None
TestRelModel = None
@classmethod
def setUpClass(cls):
"""Creates the test model in the database."""
super(LocalizedFieldsAdminMixinTestCase, cls).setUpClass()
cls.TestRelModel = get_fake_model(
{
'description': LocalizedField()
}
)
cls.TestModel = get_fake_model(
{
'title': LocalizedField(),
'rel': models.ForeignKey(cls.TestRelModel,
on_delete=models.CASCADE)
}
)
def tearDown(self):
if admin.site.is_registered(self.TestModel):
admin.site.unregister(self.TestModel)
if admin.site.is_registered(self.TestRelModel):
admin.site.unregister(self.TestRelModel)
@classmethod
def test_model_admin(cls):
"""Tests whether :see:LocalizedFieldsAdminMixin
mixin are works with admin.ModelAdmin"""
@admin.register(cls.TestModel)
class TestModelAdmin(LocalizedFieldsAdminMixin, admin.ModelAdmin):
pass
assert len(check_admin_app(apps.get_app_configs())) == 0
@classmethod
def test_stackedmodel_admin(cls):
"""Tests whether :see:LocalizedFieldsAdminMixin mixin are works
with admin.StackedInline"""
class TestModelStackedInline(LocalizedFieldsAdminMixin,
admin.StackedInline):
model = cls.TestModel
@admin.register(cls.TestRelModel)
class TestRelModelAdmin(admin.ModelAdmin):
inlines = [
TestModelStackedInline,
]
assert len(check_admin_app(apps.get_app_configs())) == 0
@classmethod
def test_tabularmodel_admin(cls):
"""Tests whether :see:LocalizedFieldsAdminMixin mixin are works
with admin.TabularInline"""
class TestModelTabularInline(LocalizedFieldsAdminMixin,
admin.TabularInline):
model = cls.TestModel
@admin.register(cls.TestRelModel)
class TestRelModelAdmin(admin.ModelAdmin):
inlines = [
TestModelTabularInline,
]
assert len(check_admin_app(apps.get_app_configs())) == 0

View File

@@ -1,6 +1,7 @@
import json
from django.conf import settings
from django.db import models
from django.db.utils import IntegrityError
from django.test import TestCase
@@ -33,7 +34,6 @@ class LocalizedFieldTestCase(TestCase):
field = LocalizedField(required=False)
assert field.required == []
@staticmethod
def test_from_db_value():
"""Tests whether the :see:from_db_value function
@@ -205,6 +205,16 @@ class LocalizedFieldTestCase(TestCase):
for field in field.formfield().fields:
assert field.required
def test_descriptor_user_defined_primary_key(self):
"""Tests that descriptor works even when primary key is user defined."""
model = get_fake_model(dict(
slug=models.SlugField(primary_key=True),
title=LocalizedField()
))
obj = model.objects.create(slug='test', title='test')
assert obj.title == 'test'
def test_required_all(self):
"""Tests whether passing required=True properly validates
that all languages are filled in."""

View File

@@ -40,7 +40,6 @@ class LocalizedFieldFormTestCase(TestCase):
for field in form.fields:
assert not field.required
@staticmethod
def test_compress():
"""Tests whether the :see:compress function

View File

@@ -148,7 +148,7 @@ class LocalizedIntegerFieldTestCase(TestCase):
with connection.cursor() as cursor:
table_name = self.TestModel._meta.db_table
cursor.execute("update %s set score = 'en=>haha'" % table_name);
cursor.execute("update %s set score = 'en=>haha'" % table_name)
obj.refresh_from_db()
assert obj.score.get(settings.LANGUAGE_CODE) is None

51
tests/test_lookups.py Normal file
View File

@@ -0,0 +1,51 @@
from django.apps import apps
from django.conf import settings
from django.test import TestCase, override_settings
from django.utils import translation
from localized_fields.fields import LocalizedField
from localized_fields.value import LocalizedValue
from .fake_model import get_fake_model
@override_settings(LOCALIZED_FIELDS_EXPERIMENTAL=True)
class LocalizedLookupsTestCase(TestCase):
"""Tests whether localized lookups properly work with."""
TestModel1 = None
@classmethod
def setUpClass(cls):
"""Creates the test model in the database."""
super(LocalizedLookupsTestCase, cls).setUpClass()
# reload app as setting has changed
config = apps.get_app_config('localized_fields')
config.ready()
cls.TestModel = get_fake_model(
{
'text': LocalizedField(),
}
)
def test_localized_lookup(self):
"""Tests whether localized lookup properly works."""
self.TestModel.objects.create(
text=LocalizedValue(dict(en='text_en', ro='text_ro', nl='text_nl')),
)
# assert that it properly lookups the currently active language
for lang_code, _ in settings.LANGUAGES:
translation.activate(lang_code)
assert self.TestModel.objects.filter(text='text_' + lang_code).exists()
# ensure that the default language is used in case no
# language is active at all
translation.deactivate_all()
assert self.TestModel.objects.filter(text='text_en').exists()
# ensure that hstore lookups still work
assert self.TestModel.objects.filter(text__ro='text_ro').exists()

View File

@@ -1,6 +1,4 @@
from django.conf import settings
from django.test import TestCase
from django.utils import translation
from localized_fields.fields import LocalizedField

View File

@@ -152,7 +152,7 @@ class LocalizedValueTestCase(TestCase):
# with no value, we always expect it to return None
localized_value = LocalizedValue()
assert localized_value.translate() == None
assert localized_value.translate() is None
assert str(localized_value) == ''
# with no value for the default language, the default
@@ -164,7 +164,7 @@ class LocalizedValueTestCase(TestCase):
})
translation.activate(settings.LANGUAGE_CODE)
assert localized_value.translate() == None
assert localized_value.translate() is None
assert str(localized_value) == ''
@staticmethod

View File

@@ -16,6 +16,7 @@ class LocalizedFieldWidgetTestCase(TestCase):
widget = LocalizedFieldWidget()
assert len(widget.widgets) == len(settings.LANGUAGES)
assert len(set(widget.widgets)) == len(widget.widgets)
@staticmethod
def test_decompress():

View File

@@ -1,10 +1,11 @@
[tox]
envlist = py35-dj{111,20}
envlist = py35-dj{111,20,21}, py36-dj{111,20,21}, py37-dj{111,20,21}
[testenv]
deps =
dj111: Django>=1.11,<1.12
dj20: Django>=2.0,<2.1
dj21: Django>=2.1,<2.2
-rrequirements/test.txt
setenv =
DJANGO_SETTINGS_MODULE=settings