Skip to content

Commit d66f508

Browse files
authored
Merge branch 'master' into hstore_extension
2 parents 6c90222 + c6e8321 commit d66f508

File tree

18 files changed

+167
-57
lines changed

18 files changed

+167
-57
lines changed

.circleci/config.yml

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
version: 2
2+
jobs:
3+
test-python35:
4+
docker:
5+
- image: python:3.5-alpine
6+
- image: postgres:11.0
7+
environment:
8+
POSTGRES_DB: 'localizedfields'
9+
POSTGRES_USER: 'localizedfields'
10+
POSTGRES_PASSWORD: 'localizedfields'
11+
steps:
12+
- checkout
13+
- run:
14+
name: Install packages
15+
command: apk add postgresql-libs gcc musl-dev postgresql-dev git
16+
- run:
17+
name: Install Python packages
18+
command: pip install -r requirements/test.txt
19+
- run:
20+
name: Run tests
21+
command: tox -e 'py35-dj{111,20,21}'
22+
environment:
23+
DATABASE_URL: 'postgres://localizedfields:localizedfields@localhost:5432/localizedfields'
24+
25+
test-python36:
26+
docker:
27+
- image: python:3.6-alpine
28+
- image: postgres:11.0
29+
environment:
30+
POSTGRES_DB: 'localizedfields'
31+
POSTGRES_USER: 'localizedfields'
32+
POSTGRES_PASSWORD: 'localizedfields'
33+
steps:
34+
- checkout
35+
- run:
36+
name: Install packages
37+
command: apk add postgresql-libs gcc musl-dev postgresql-dev git
38+
- run:
39+
name: Install Python packages
40+
command: pip install -r requirements/test.txt
41+
- run:
42+
name: Run tests
43+
command: tox -e 'py36-dj{111,20,21}'
44+
environment:
45+
DATABASE_URL: 'postgres://localizedfields:localizedfields@localhost:5432/localizedfields'
46+
47+
test-python37:
48+
docker:
49+
- image: python:3.7-alpine
50+
- image: postgres:11.0
51+
environment:
52+
POSTGRES_DB: 'localizedfields'
53+
POSTGRES_USER: 'localizedfields'
54+
POSTGRES_PASSWORD: 'localizedfields'
55+
steps:
56+
- checkout
57+
- run:
58+
name: Install packages
59+
command: apk add postgresql-libs gcc musl-dev postgresql-dev git
60+
- run:
61+
name: Install Python packages
62+
command: pip install -r requirements/test.txt
63+
- run:
64+
name: Run tests
65+
command: tox -e 'py37-dj{111,20,21}'
66+
environment:
67+
DATABASE_URL: 'postgres://localizedfields:localizedfields@localhost:5432/localizedfields'
68+
69+
lint:
70+
docker:
71+
- image: python:3.5-alpine
72+
steps:
73+
- checkout
74+
- run:
75+
name: Install packages
76+
command: apk add postgresql-libs gcc musl-dev postgresql-dev git
77+
- run:
78+
name: Install Python packages
79+
command: pip install -r requirements/test.txt
80+
- run:
81+
name: Lint code
82+
command: python setup.py lint
83+
84+
85+
workflows:
86+
version: 2
87+
build:
88+
jobs:
89+
- test-python35
90+
- test-python36
91+
- test-python37
92+
- lint

.coveragerc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
[run]
22
include = localized_fields/*
33
omit = *migrations*, *tests*
4-
plugins =
5-
django_coverage_plugin

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Ignore virtual environments
22
env/
3+
.env/
34

45
# Ignore Python byte code cache
56
*.pyc

.scrutinizer.yml

Lines changed: 0 additions & 34 deletions
This file was deleted.

README.rst

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
django-localized-fields
22
=======================
33

4-
.. image:: https://scrutinizer-ci.com/g/SectorLabs/django-localized-fields/badges/quality-score.png
5-
:target: https://scrutinizer-ci.com/g/SectorLabs/django-localized-fields/
6-
7-
.. image:: https://scrutinizer-ci.com/g/SectorLabs/django-localized-fields/badges/coverage.png
8-
:target: https://scrutinizer-ci.com/g/SectorLabs/django-localized-fields/
4+
.. image:: https://circleci.com/gh/SectorLabs/django-localized-fields.svg?style=svg
5+
:target: https://circleci.com/gh/SectorLabs/django-localized-fields
96

107
.. image:: https://img.shields.io/github/license/SectorLabs/django-localized-fields.svg
118
:target: https://github.com/SectorLabs/django-localized-fields/blob/master/LICENSE.md

localized_fields/fields/integer_field.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from .field import LocalizedField
77
from ..value import LocalizedValue, LocalizedIntegerValue
8+
from ..forms import LocalizedIntegerFieldForm
89

910

1011
class LocalizedIntegerField(LocalizedField):
@@ -63,6 +64,15 @@ def get_prep_value(self, value: LocalizedIntegerValue) -> dict:
6364

6465
return prepped_value
6566

67+
def formfield(self, **kwargs):
68+
"""Gets the form field associated with this field."""
69+
defaults = {
70+
'form_class': LocalizedIntegerFieldForm
71+
}
72+
73+
defaults.update(kwargs)
74+
return super().formfield(**defaults)
75+
6676
@staticmethod
6777
def _convert_localized_value(value: LocalizedValue) -> LocalizedIntegerValue:
6878
"""Converts from :see:LocalizedValue to :see:LocalizedIntegerValue."""

localized_fields/forms.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
from django.forms.widgets import FILE_INPUT_CONTRADICTION
77

88
from .value import LocalizedValue, LocalizedStringValue, \
9-
LocalizedFileValue
9+
LocalizedFileValue, LocalizedIntegerValue
1010
from .widgets import LocalizedFieldWidget, LocalizedCharFieldWidget, \
11-
LocalizedFileWidget
11+
LocalizedFileWidget, AdminLocalizedIntegerFieldWidget
1212

1313

1414
class LocalizedFieldForm(forms.MultiValueField):
@@ -79,6 +79,14 @@ class LocalizedTextFieldForm(LocalizedFieldForm):
7979
value_class = LocalizedStringValue
8080

8181

82+
class LocalizedIntegerFieldForm(LocalizedFieldForm):
83+
"""Form for a localized integer field, allows editing
84+
the field in multiple languages."""
85+
86+
widget = AdminLocalizedIntegerFieldWidget
87+
value_class = LocalizedIntegerValue
88+
89+
8290
class LocalizedFileFieldForm(LocalizedFieldForm, forms.FileField):
8391
"""Form for a localized file field, allows editing
8492
the field in multiple languages."""

localized_fields/value.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,3 +228,9 @@ def __int__(self):
228228
return self.default_value
229229

230230
return int(value)
231+
232+
def __str__(self) -> str:
233+
"""Returns string representation of value"""
234+
235+
value = self.translate()
236+
return str(value) if value is not None else None

localized_fields/widgets.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,7 @@ class AdminLocalizedCharFieldWidget(AdminLocalizedFieldWidget):
120120

121121
class AdminLocalizedFileFieldWidget(AdminLocalizedFieldWidget):
122122
widget = widgets.AdminFileWidget
123+
124+
125+
class AdminLocalizedIntegerFieldWidget(AdminLocalizedFieldWidget):
126+
widget = widgets.AdminIntegerFieldWidget

requirements/test.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@
22

33
django-autoslug==1.9.3
44
django-bleach==0.3.0
5-
django-coverage-plugin==1.3.1
65
psycopg2==2.7.3.2
76
pylint==1.8.1
87
pylint-common==0.2.5
98
pylint-django==0.8.0
109
pylint-plugin-utils==0.2.6
1110
coverage==4.4.2
12-
django-coverage-plugin==1.3.1
13-
flake8==3.5.0
11+
flake8==3.6.0
1412
pep8==1.7.1
1513
dj-database-url==0.4.2
1614
tox==2.9.1

0 commit comments

Comments
 (0)