Consistent use of languages settings, and Django 1.10 fixes. 0.8.5
authorRadek Czajka <rczajka@rczajka.pl>
Fri, 15 Feb 2019 13:07:03 +0000 (14:07 +0100)
committerRadek Czajka <rczajka@rczajka.pl>
Fri, 15 Feb 2019 13:09:36 +0000 (14:09 +0100)
migdal/__init__.py
migdal/admin.py
migdal/models.py
migdal/sitemap.py
migdal/urls.py
setup.py

index e785125..b3e09da 100644 (file)
@@ -45,9 +45,16 @@ class Settings(AppSettings):
     OBLIGATORY_LANGUAGES = None
 
     def _more_OPTIONAL_LANGUAGES(self, value):
     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
 
     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')
     PUBLISH_DATE_EDITABLE = False
 
 app_settings = Settings('MIGDAL')
index ed829e6..2a674b1 100644 (file)
@@ -42,7 +42,7 @@ def filtered_entry_admin(typ):
             return field
 
         date_hierarchy = 'date'
             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 ()
         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,))
             )
         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',) + \
             ]) 
 
         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(('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')
             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):
     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,))
         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)
             ]) 
     admin.site.register(Category, CategoryAdmin)
index 3890f94..7cef388 100644 (file)
@@ -33,7 +33,7 @@ class Category(models.Model):
         return 'migdal_category', [self.slug]
 
 
         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),
 })
     '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
 
     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()
             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):
             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(
             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 <a href="https://txstyle.org/article/44/an-overview-of-the-textile-syntax">Textile</a> syntax.')
 
 
 TEXTILE_HELP = _('Use <a href="https://txstyle.org/article/44/an-overview-of-the-textile-syntax">Textile</a> 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(
     'slug': SlugNullField(unique=True, db_index=True, null=True, blank=True),
     'title': models.CharField(_('title'), max_length=255, null=True, blank=True),
     'lead': TextileField(
index a8ef28c..049d7e1 100755 (executable)
@@ -4,8 +4,8 @@
 #
 from django.contrib.sitemaps import Sitemap
 from django.utils.translation import override
 #
 from django.contrib.sitemaps import Sitemap
 from django.utils.translation import override
+from . import app_settings
 from .models import Entry
 from .models import Entry
-from django.conf import settings
 
 
 class MigdalSitemap(Sitemap):
 
 
 class MigdalSitemap(Sitemap):
@@ -27,5 +27,5 @@ class MigdalSitemap(Sitemap):
 
 
 sitemaps = {}
 
 
 sitemaps = {}
-for lc, ln in settings.LANGUAGES:
+for lc, ln in app_settings.LANGUAGES:
     sitemaps['entry_%s' % lc] = MigdalSitemap(lc)
     sitemaps['entry_%s' % lc] = MigdalSitemap(lc)
index e651a97..3fd9e0e 100644 (file)
@@ -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 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 = []
 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'/$'),
     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<slug>[^/]+)/$'),
             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<slug>[^/]+)/$'),
-            'migdal.views.entry', {'type_db': t.db},
+            views.entry, {'type_db': t.db},
             name='migdal_entry_%s' % t.db),
     ]
 
 
 urlpatterns = i18n_patterns(
     # main page
             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(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<category_slug>[^/]*)/$'),
         name='migdal_submit_thanks'),
     # category
     url(string_concat(r'^', _('categories'), r'/(?P<category_slug>[^/]*)/$'),
-        'migdal.views.entry_list', name='migdal_category'),
+        views.entry_list, name='migdal_category'),
     url(string_concat(r'^', _('categories'), r'/(?P<category_slug>[^/]*)/rss.xml$'),
         feeds.EntriesFeed(), name='migdal_category_feed'),
     url(string_concat(r'^', _('categories'), r'/(?P<category_slug>[^/]*)/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
 )
     # type-specific views
     *pats
 )
index 5f52c53..07fb7f1 100755 (executable)
--- a/setup.py
+++ b/setup.py
@@ -23,7 +23,7 @@ def whole_trees(package_dir, paths):
 
 setup(
     name='django-migdal',
 
 setup(
     name='django-migdal',
-    version='0.8.4',
+    version='0.8.5',
     author='Radek Czajka',
     author_email='radoslaw.czajka@nowoczesnapolska.org.pl',
     url='',
     author='Radek Czajka',
     author_email='radoslaw.czajka@nowoczesnapolska.org.pl',
     url='',