From: Radek Czajka Date: Fri, 15 Feb 2019 13:07:03 +0000 (+0100) Subject: Consistent use of languages settings, and Django 1.10 fixes. X-Git-Tag: 0.8.5 X-Git-Url: https://git.mdrn.pl/django-migdal.git/commitdiff_plain/263bed72cd989b0ae9ba4a19825e3c0109a66407?ds=inline Consistent use of languages settings, and Django 1.10 fixes. --- diff --git a/migdal/__init__.py b/migdal/__init__.py index e785125..b3e09da 100644 --- a/migdal/__init__.py +++ b/migdal/__init__.py @@ -45,9 +45,16 @@ class Settings(AppSettings): OBLIGATORY_LANGUAGES = None def _more_OPTIONAL_LANGUAGES(self, value): - return tuple(lang for lang in settings.LANGUAGES if lang not in self.OBLIGATORY_LANGUAGES) + if value is None: + return tuple(lang for lang in settings.LANGUAGES if lang not in self.OBLIGATORY_LANGUAGES) + else: + return value OPTIONAL_LANGUAGES = None + def _more_LANGUAGES(self, value): + return self.OBLIGATORY_LANGUAGES + self.OPTIONAL_LANGUAGES + LANGUAGES = None + PUBLISH_DATE_EDITABLE = False app_settings = Settings('MIGDAL') diff --git a/migdal/admin.py b/migdal/admin.py index ed829e6..2a674b1 100644 --- a/migdal/admin.py +++ b/migdal/admin.py @@ -42,7 +42,7 @@ def filtered_entry_admin(typ): return field date_hierarchy = 'date' - readonly_fields = ('date', 'changed_at') + translated_fields(('published_at',)) + readonly_fields = ('date', 'changed_at') + translated_fields(('published_at',), app_settings.LANGUAGES) if app_settings.PUBLISH_DATE_EDITABLE: readonly_fields += ('first_published_at',) _promo_if_necessary = ('promo',) if typ.promotable else () @@ -85,17 +85,17 @@ def filtered_entry_admin(typ): ) prepopulated_fields = dict([ ("slug_%s" % lang_code, ("title_%s" % lang_code,)) - for lang_code, lang_name in settings.LANGUAGES + for lang_code, lang_name in app_settings.LANGUAGES ]) list_display = translated_fields(('title',), app_settings.OBLIGATORY_LANGUAGES) + \ ('date', 'author') + \ _promo_if_necessary + \ ('in_stream', 'first_published_at',) + \ - translated_fields(('published_at',)) + \ + translated_fields(('published_at',), app_settings.LANGUAGES) + \ translated_fields(('needed',), app_settings.OPTIONAL_LANGUAGES) list_filter = _promo_if_necessary + \ - translated_fields(('published',)) + \ + translated_fields(('published',), app_settings.LANGUAGES) + \ translated_fields(('needed',), app_settings.OPTIONAL_LANGUAGES) inlines = (PhotoInline, AttachmentInline) search_fields = ('title_pl', 'title_en') @@ -111,9 +111,9 @@ if app_settings.TAXONOMIES: from migdal.models import Category class CategoryAdmin(admin.ModelAdmin): - list_display = translated_fields(('title', 'slug')) + ('taxonomy',) + list_display = translated_fields(('title', 'slug'), app_settings.LANGUAGES) + ('taxonomy',) prepopulated_fields = dict([ ("slug_%s" % lang_code, ("title_%s" % lang_code,)) - for lang_code, lang_name in settings.LANGUAGES + for lang_code, lang_name in app_settings.LANGUAGES ]) admin.site.register(Category, CategoryAdmin) diff --git a/migdal/models.py b/migdal/models.py index 3890f94..7cef388 100644 --- a/migdal/models.py +++ b/migdal/models.py @@ -33,7 +33,7 @@ class Category(models.Model): return 'migdal_category', [self.slug] -add_translatable(Category, { +add_translatable(Category, languages=app_settings.LANGUAGES, fields={ 'title': models.CharField(max_length=64, unique=True, db_index=True), 'slug': models.SlugField(unique=True, db_index=True), }) @@ -77,7 +77,7 @@ class Entry(models.Model): def save(self, *args, **kwargs): published_now = False - for lc, ln in settings.LANGUAGES: + for lc, ln in app_settings.LANGUAGES: if (getattr(self, "published_%s" % lc) and getattr(self, "published_at_%s" % lc) is None): now = datetime.now() @@ -90,7 +90,7 @@ class Entry(models.Model): self.notify_author_published() def clean(self): - for lc, ln in settings.LANGUAGES: + for lc, ln in app_settings.LANGUAGES: if (getattr(self, "published_%s" % lc) and not getattr(self, "slug_%s" % lc)): raise ValidationError( @@ -132,7 +132,7 @@ add_translatable(Entry, languages=app_settings.OPTIONAL_LANGUAGES, fields={ TEXTILE_HELP = _('Use Textile syntax.') -add_translatable(Entry, { +add_translatable(Entry, languages=app_settings.LANGUAGES, fields={ 'slug': SlugNullField(unique=True, db_index=True, null=True, blank=True), 'title': models.CharField(_('title'), max_length=255, null=True, blank=True), 'lead': TextileField( diff --git a/migdal/sitemap.py b/migdal/sitemap.py index a8ef28c..049d7e1 100755 --- a/migdal/sitemap.py +++ b/migdal/sitemap.py @@ -4,8 +4,8 @@ # from django.contrib.sitemaps import Sitemap from django.utils.translation import override +from . import app_settings from .models import Entry -from django.conf import settings class MigdalSitemap(Sitemap): @@ -27,5 +27,5 @@ class MigdalSitemap(Sitemap): sitemaps = {} -for lc, ln in settings.LANGUAGES: +for lc, ln in app_settings.LANGUAGES: sitemaps['entry_%s' % lc] = MigdalSitemap(lc) diff --git a/migdal/urls.py b/migdal/urls.py index e651a97..3fd9e0e 100644 --- a/migdal/urls.py +++ b/migdal/urls.py @@ -7,7 +7,7 @@ from django.conf.urls import url from django.utils.translation import ugettext_lazy as _ from django.utils.translation import string_concat from migdal import feeds, app_settings -from migdal.views import SearchPublishedView +from migdal import views from fnpdjango.utils.urls import i18n_patterns pats = [] @@ -15,32 +15,32 @@ for t in app_settings.TYPES: pats += [ # entry list url(string_concat(r'^', t.slug, r'/$'), - 'migdal.views.entry_list', {'type_db': t.db}, + views.entry_list, {'type_db': t.db}, name='migdal_entry_list_%s' % t.db), url(string_concat(r'^', t.slug, r'/rss.xml$'), feeds.EntriesFeed(), {'type_db': t.db}, name='migdal_entry_list_%s_feed' % t.db), # single entry url(string_concat(r'^', t.slug, r'/(?P[^/]+)/$'), - 'migdal.views.entry', {'type_db': t.db}, + views.entry, {'type_db': t.db}, name='migdal_entry_%s' % t.db), ] urlpatterns = i18n_patterns( # main page - url(r'^$', 'migdal.views.main', name='migdal_main'), + url(r'^$', views.main, name='migdal_main'), url(r'^rss.xml$', feeds.EntriesFeed(), name='migdal_main_feed'), # submit new entry - url(string_concat(r'^', _('submit'), r'/$'), 'migdal.views.submit', name='migdal_submit'), - url(string_concat(r'^', _('submit'), r'/', _('thanks'), r'$'), 'migdal.views.submit_thanks', + url(string_concat(r'^', _('submit'), r'/$'), views.submit, name='migdal_submit'), + url(string_concat(r'^', _('submit'), r'/', _('thanks'), r'$'), views.submit_thanks, name='migdal_submit_thanks'), # category url(string_concat(r'^', _('categories'), r'/(?P[^/]*)/$'), - 'migdal.views.entry_list', name='migdal_category'), + views.entry_list, name='migdal_category'), url(string_concat(r'^', _('categories'), r'/(?P[^/]*)/rss.xml$'), feeds.EntriesFeed(), name='migdal_category_feed'), - url(string_concat(r'^', _('search')), SearchPublishedView(), name='search'), + url(string_concat(r'^', _('search')), views.SearchPublishedView(), name='search'), # type-specific views *pats ) diff --git a/setup.py b/setup.py index 5f52c53..07fb7f1 100755 --- a/setup.py +++ b/setup.py @@ -23,7 +23,7 @@ def whole_trees(package_dir, paths): setup( name='django-migdal', - version='0.8.4', + version='0.8.5', author='Radek Czajka', author_email='radoslaw.czajka@nowoczesnapolska.org.pl', url='',