Commit a489bf1d authored by Sébastiaan Versteeg's avatar Sébastiaan Versteeg
Browse files

- Make description translatable

- Use fields instead of fieldset in admin
- Preserve i18n fields from base in ModelTranslateMeta
- Re-enable usage of name for boards
parent ae817a24
from django.contrib import admin
from utils.translation import TranslatedModelAdmin
from django.conf import settings
from . import models
......@@ -8,14 +9,8 @@ from . import models
class CommitteeAdmin(TranslatedModelAdmin):
list_filter = ('until',)
fieldsets = (
(None, {
'fields': (
'name', 'description', 'photo', 'permissions',
'since', 'until'
)
}),
)
fields = ('name', 'description', 'photo', 'permissions',
'since', 'until',)
def get_queryset(self, request):
qs = super().get_queryset(request)
......@@ -26,14 +21,8 @@ class CommitteeAdmin(TranslatedModelAdmin):
class BoardAdmin(TranslatedModelAdmin):
exclude = ('is_board',)
fieldsets = (
(None, {
'fields': (
'description', 'photo', 'permissions',
'since', 'until'
)
}),
)
fields = ('name', 'description', 'photo', 'permissions',
'since', 'until',)
@admin.register(models.CommitteeMembership)
......
......@@ -3,8 +3,10 @@
"model": "activemembers.committee",
"pk": 1,
"fields": {
"name": "testcie1",
"description": "Test",
"name_nl": "testcie1",
"name_en": "testcie1",
"description_nl": "Test",
"description_en": "Test",
"photo": "Thom_Wiggers.jpg",
"permissions": [
25,
......@@ -17,8 +19,10 @@
"model": "activemembers.committee",
"pk": 2,
"fields": {
"name": "testcie2",
"description": "testdesc2",
"name_nl": "testcie2",
"name_en": "testcie2",
"description_nl": "testdesc2",
"description_en": "testdesc2",
"photo": "Thom_Wiggers_4YRoxV3.jpg",
"permissions": []
}
......
......@@ -15,6 +15,7 @@ class Migration(migrations.Migration):
db_alias = schema_editor.connection.alias
for committee in Committee.unfiltered_objects.using(db_alias).all():
committee.name_en = committee.name_nl
committee.description_en = committee.description_nl
committee.save()
def reverse_func(apps, schema_editor):
......@@ -22,6 +23,7 @@ class Migration(migrations.Migration):
operations = [
migrations.RenameField('committee', 'name', 'name_nl'),
migrations.RenameField('committee', 'description', 'description_nl'),
migrations.AddField(
model_name='committee',
name='name_en',
......@@ -36,5 +38,19 @@ class Migration(migrations.Migration):
verbose_name='Committee name (NL)'),
preserve_default=True,
),
migrations.AddField(
model_name='committee',
name='description_en',
field=models.CharField(default='', max_length=40, unique=True,
verbose_name='Description (EN)'),
preserve_default=False,
),
migrations.AlterField(
model_name='committee',
name='description_nl',
field=models.CharField(max_length=40, unique=True,
verbose_name='Description (NL)'),
preserve_default=True,
),
migrations.RunPython(forwards_func, reverse_func),
]
import datetime
import logging
from django.core.exceptions import ValidationError, NON_FIELD_ERRORS
from django.contrib.auth.models import Permission
from django.conf import settings
from django.core.exceptions import ValidationError, NON_FIELD_ERRORS
from django.db import models
from django.urls import reverse
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _
from utils.translation import MultilingualField, ModelTranslateMeta
from members.models import Member
from utils.translation import MultilingualField, ModelTranslateMeta
logger = logging.getLogger(__name__)
......@@ -45,7 +42,8 @@ class Committee(models.Model, metaclass=ModelTranslateMeta):
unique=True,
)
description = models.TextField(
description = MultilingualField(
models.TextField,
verbose_name=_('Description'),
)
......@@ -105,12 +103,6 @@ class Board(Committee):
default=True,
)
def clean(self):
for lang in settings.LANGUAGES:
field_name = '{}_{}'.format('name', lang[0])
setattr(self, field_name, '{} {} - {}'
.format('Board', self.since, self.until))
def get_absolute_url(self):
return reverse('committees:board', args=[str(self.pk)])
......
......@@ -62,6 +62,14 @@ class ModelTranslateMeta(models.base.ModelBase):
def __new__(cls, name, bases, dct):
field_i18n = {'default': {}, 'fields': {}}
try:
# Inherit i18n fields from superclass
field_i18n = bases[0]._meta._field_i18n
except IndexError:
pass
except AttributeError:
pass
for attr, field in list(dct.items()):
if not isinstance(field, MultilingualField):
continue
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment