From: Radek Czajka Date: Fri, 5 Oct 2012 07:25:05 +0000 (+0200) Subject: making migdal more universal X-Git-Url: https://git.mdrn.pl/prawokultury.git/commitdiff_plain/5af5cc14f6b2ecddcad714053e048e39d52ca02d making migdal more universal --- diff --git a/migdal/__init__.py b/migdal/__init__.py index 05322b4..0a04b06 100644 --- a/migdal/__init__.py +++ b/migdal/__init__.py @@ -14,9 +14,9 @@ class Settings(AppSettings): # Types of entries: # (slug, commentable, on main) TYPES = ( - EntryType('news', _('news'), commentable=True, on_main=True), - EntryType('publications', _('publications'), commentable=False, on_main=False), - EntryType('info', _('info'), commentable=False, on_main=False), + EntryType('news', _('news'), commentable=True, on_main=True, promotable=True), + EntryType('publications', _('publications')), + EntryType('info', _('info')), ) TYPE_SUBMIT = 'news' TAXONOMIES = ( @@ -25,6 +25,8 @@ class Settings(AppSettings): ) LAST_COMMENTS = 5 + MENU = [] + TYPES_DICT = None def _more_TYPES_DICT(self, value): return dict((t.db, t) for t in self.TYPES) @@ -33,6 +35,10 @@ class Settings(AppSettings): def _more_TYPES_ON_MAIN(self, value): return tuple(t.db for t in self.TYPES if t.on_main) + TYPES_PROMOTABLE = None + def _more_TYPES_PROMOTABLE(self, value): + return tuple(t.db for t in self.TYPES if t.promotable) + OBLIGATORY_LANGUAGES = None def _more_OBLIGATORY_LANGUAGES(self, value): return value or tuple(lang for lang in settings.LANGUAGES diff --git a/migdal/admin.py b/migdal/admin.py index d93a782..4043921 100644 --- a/migdal/admin.py +++ b/migdal/admin.py @@ -5,9 +5,10 @@ from django.conf import settings from django.contrib import admin from django.utils.translation import ugettext_lazy as _ -from migdal.models import Category, Entry, Attachment +from migdal.models import Entry, Attachment from migdal import app_settings from migdal.helpers import translated_fields +from prawokultury.model_helpers import filtered_model class AttachmentInline(admin.TabularInline): @@ -15,55 +16,78 @@ class AttachmentInline(admin.TabularInline): readonly_fields = ['url'] -class EntryAdmin(admin.ModelAdmin): - date_hierarchy = 'date' - readonly_fields = ('date', 'changed_at') + translated_fields(('published_at',)) - fieldsets = ( - (None, {'fields': (('type', 'promo'), 'author', 'author_email', 'image', 'date', 'changed_at')}), - ) + tuple( - (ln, {'fields': ( - ('published_%s' % lc), - 'published_at_%s' % lc, - 'title_%s' % lc, - 'slug_%s' % lc, - 'lead_%s' % lc, - 'body_%s' % lc, - )}) - for lc, ln in app_settings.OBLIGATORY_LANGUAGES - ) + tuple( - (ln, {'fields': ( - ('needed_%s' % lc, 'published_%s' % lc), - 'published_at_%s' % lc, - 'title_%s' % lc, - 'slug_%s' % lc, - 'lead_%s' % lc, - 'body_%s' % lc, - )}) - for lc, ln in app_settings.OPTIONAL_LANGUAGES - ) + ( - (_('Categories'), {'fields': ('categories',)}), - ) - prepopulated_fields = dict([ - ("slug_%s" % lang_code, ("title_%s" % lang_code,)) - for lang_code, lang_name in settings.LANGUAGES - ]) +def filtered_entry_admin(typ): + class EntryAdmin(admin.ModelAdmin): + def queryset(self, request): + return self.model.objects.filter(type=typ) - list_display = translated_fields(('title',), app_settings.OBLIGATORY_LANGUAGES - ) + ('type', 'date', 'author', 'promo' - ) + translated_fields(('published',) - ) + translated_fields(('needed',), app_settings.OPTIONAL_LANGUAGES) - list_filter = ('type', 'promo') + translated_fields(('published',) - ) + translated_fields(('needed',), app_settings.OPTIONAL_LANGUAGES) - inlines = (AttachmentInline,) + date_hierarchy = 'date' + readonly_fields = ('date', 'changed_at') + \ + translated_fields(('published_at',)) + _promo_if_necessary = ('promo',) if typ.promotable else () + fieldsets = ( + (None, { + 'fields': _promo_if_necessary + ( + 'author', 'author_email', 'image', 'date', 'changed_at') + }), + ) + tuple( + (ln, {'fields': ( + ('published_%s' % lc), + 'published_at_%s' % lc, + 'title_%s' % lc, + 'slug_%s' % lc, + 'lead_%s' % lc, + 'body_%s' % lc, + )}) + for lc, ln in app_settings.OBLIGATORY_LANGUAGES + ) + tuple( + (ln, {'fields': ( + ('needed_%s' % lc, 'published_%s' % lc), + 'published_at_%s' % lc, + 'title_%s' % lc, + 'slug_%s' % lc, + 'lead_%s' % lc, + 'body_%s' % lc, + )}) + for lc, ln in app_settings.OPTIONAL_LANGUAGES + ) -class CategoryAdmin(admin.ModelAdmin): - list_display = translated_fields(('title', 'slug')) + ('taxonomy',) - prepopulated_fields = dict([ - ("slug_%s" % lang_code, ("title_%s" % lang_code,)) - for lang_code, lang_name in settings.LANGUAGES - ]) + if typ.categorized: + fieldsets += ( + (_('Categories'), {'fields': ('categories',)}), + ) + prepopulated_fields = dict([ + ("slug_%s" % lang_code, ("title_%s" % lang_code,)) + for lang_code, lang_name in settings.LANGUAGES + ]) + list_display = translated_fields(('title',), + app_settings.OBLIGATORY_LANGUAGES) + \ + ('date', 'author') + \ + _promo_if_necessary + \ + translated_fields(('published_at',)) + \ + translated_fields(('needed',), app_settings.OPTIONAL_LANGUAGES) + list_filter = _promo_if_necessary + \ + translated_fields(('published',)) + \ + translated_fields(('needed',), app_settings.OPTIONAL_LANGUAGES) + inlines = (AttachmentInline,) + search_fields = ('title_pl', 'title_en') + return EntryAdmin -admin.site.register(Entry, EntryAdmin) -admin.site.register(Category, CategoryAdmin) + +for typ in app_settings.TYPES: + newmodel = filtered_model("Entry_%s" % typ.db, Entry, 'type', typ.db, typ.slug) + admin.site.register(newmodel, filtered_entry_admin(typ)) + + +if app_settings.TAXONOMIES: + from migdal.models import Category + + class CategoryAdmin(admin.ModelAdmin): + list_display = translated_fields(('title', 'slug')) + ('taxonomy',) + prepopulated_fields = dict([ + ("slug_%s" % lang_code, ("title_%s" % lang_code,)) + for lang_code, lang_name in settings.LANGUAGES + ]) + admin.site.register(Category, CategoryAdmin) diff --git a/migdal/helpers.py b/migdal/helpers.py index 8a6513d..4e1a16e 100644 --- a/migdal/helpers.py +++ b/migdal/helpers.py @@ -11,8 +11,16 @@ from django.core.urlresolvers import LocaleRegexURLResolver from django.utils.translation import get_language, string_concat -class EntryType(namedtuple('EntryType', 'db slug commentable on_main')): - __slots__ = () +class EntryType(object): + def __init__(self, db, slug, commentable=False, on_main=False, + promotable=False, categorized=False): + self.db = db + self.slug = slug + self.commentable = commentable + self.on_main = on_main + self.promotable = promotable + self.categorized = categorized + def __unicode__(self): return unicode(self.slug) diff --git a/migdal/templatetags/migdal_tags.py b/migdal/templatetags/migdal_tags.py index 380cb56..d12920f 100644 --- a/migdal/templatetags/migdal_tags.py +++ b/migdal/templatetags/migdal_tags.py @@ -124,18 +124,14 @@ class EntryTypeMenuItem(object): @register.inclusion_tag('migdal/menu.html', takes_context=True) def main_menu(context, chooser=None, value=None): items = [ - ModelMenuItem(Entry.objects.get(slug_pl='o-nas')), - EntryTypeMenuItem(_(u'Publications'), u'publications'), - MenuItem(_(u'Events'), reverse('events')), - CategoryMenuItem(Category.objects.get(slug_pl='stanowisko'), - title=_('Positions')), - #CategoryMenuItem(Category.objects.get(slug_pl='pierwsza-pomoc'), - # title=_('First aid in copyright')), + #ModelMenuItem(Entry.objects.get(slug_pl='o-nas')), + #MenuItem(_(u'Events'), reverse('events')), ] - #if context['request'].LANGUAGE_CODE == 'pl': - # items.append(MenuItem(u'en', '/en/', html_id='item-lang')) - #else: - # items.append(MenuItem(u'pl', '/', html_id='item-lang')) + # TODO: context-aware language switcher + if context['request'].LANGUAGE_CODE == 'pl': + items.append(MenuItem(u'en', '/en/', html_id='item-lang')) + else: + items.append(MenuItem(u'pl', '/', html_id='item-lang')) for item in items: item.check_active(chooser, value) return {'items': items} diff --git a/migdal/urls.py b/migdal/urls.py index c7db6f4..3a58123 100644 --- a/migdal/urls.py +++ b/migdal/urls.py @@ -26,11 +26,7 @@ for t in app_settings.TYPES: ] -# Disable en for now. -urlpatterns = patterns('', - url(r'^en/', handler404), -) -urlpatterns += i18n_patterns('', +urlpatterns = i18n_patterns('', # main page url(r'^$', 'migdal.views.entry_list', name='migdal_main'), url(r'^rss.xml$', feeds.EntriesFeed(), name='migdal_main_feed'), diff --git a/prawokultury/helpers.py b/prawokultury/helpers.py index 5877e0b..23520ec 100644 --- a/prawokultury/helpers.py +++ b/prawokultury/helpers.py @@ -23,7 +23,7 @@ def textile_restricted_pl(text): text, rel='nofollow') -class LazyUGettextLazy(): +class LazyUGettextLazy(object): """You can use it to internationalize strings in settings. Just import this class as gettext. diff --git a/prawokultury/model_helpers.py b/prawokultury/model_helpers.py new file mode 100755 index 0000000..4a734b6 --- /dev/null +++ b/prawokultury/model_helpers.py @@ -0,0 +1,20 @@ +from django.utils.translation import string_concat + +def filtered_model(name, model, field, value, verbose_extra=None): + """Creates a proxy model filtering objects by a field.""" + verbose_extra = verbose_extra or value + class Meta: + proxy = True + app_label = model._meta.app_label + verbose_name = string_concat(model._meta.verbose_name, + ': ', verbose_extra) + verbose_name_plural = string_concat(model._meta.verbose_name_plural, + ': ', verbose_extra) + + def save(self, *args, **kwargs): + if not getattr(self, field): + setattr(self, field, value) + return model.save(self, *args, **kwargs) + + attrs = {'__module__': '', 'Meta': Meta, 'save': save} + return type(name, (model,), attrs) diff --git a/prawokultury/settings.d/30-apps.conf b/prawokultury/settings.d/30-apps.conf index 5aa5144..0671f62 100755 --- a/prawokultury/settings.d/30-apps.conf +++ b/prawokultury/settings.d/30-apps.conf @@ -1,12 +1,13 @@ INSTALLED_APPS = ( 'prawokultury', - 'events', + #'events', 'migdal', + #'forms', 'gravatar', 'south', - 'django.contrib.comments', - 'django_comments_xtd', + #'django.contrib.comments', + #'django_comments_xtd', 'pipeline', 'haystack', 'pagination', diff --git a/prawokultury/settings.d/40-auth.conf b/prawokultury/settings.d/40-auth.conf new file mode 100755 index 0000000..675db9d --- /dev/null +++ b/prawokultury/settings.d/40-auth.conf @@ -0,0 +1,5 @@ +if 'django_cas' in INSTALLED_APPS: + AUTHENTICATION_BACKENDS = ( + 'django.contrib.auth.backends.ModelBackend', + 'django_cas.backends.CASBackend', + ) diff --git a/prawokultury/settings.d/40-middleware.conf b/prawokultury/settings.d/40-middleware.conf index eedc50e..cde9886 100755 --- a/prawokultury/settings.d/40-middleware.conf +++ b/prawokultury/settings.d/40-middleware.conf @@ -6,6 +6,14 @@ MIDDLEWARE_CLASSES = ( 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', +) + +if 'django_cas' in INSTALLED_APPS: + MIDDLEWARE_CLASSES += ( + 'django_cas.middleware.CASMiddleware', + ) + +MIDDLEWARE_CLASSES += ( 'django.contrib.messages.middleware.MessageMiddleware', 'piwik.django.middleware.PiwikMiddleware', # Uncomment the next line for simple clickjacking protection: diff --git a/prawokultury/settings.d/50-contrib.conf b/prawokultury/settings.d/50-contrib.conf index 12d387e..27a516c 100755 --- a/prawokultury/settings.d/50-contrib.conf +++ b/prawokultury/settings.d/50-contrib.conf @@ -12,3 +12,6 @@ COMMENTS_XTD_LIST_URL_ACTIVE = True THUMBNAIL_QUALITY = 95 GRAVATAR_DEFAULT_IMAGE = 'http://localhost:8000/static/img/avatar.png' + +CAS_SERVER_URL = 'http://logowanie.nowoczesnapolska.org.pl/cas/' +CAS_VERSION = '1' diff --git a/prawokultury/settings.d/60-custom.conf b/prawokultury/settings.d/60-custom.conf index e69de29..ea1112c 100755 --- a/prawokultury/settings.d/60-custom.conf +++ b/prawokultury/settings.d/60-custom.conf @@ -0,0 +1,8 @@ +from prawokultury.helpers import LazyUGettextLazy as gettext +from migdal.helpers import EntryType + +MIGDAL_TYPES = ( + EntryType('info', gettext('info'), commentable=False, on_main=False), +) + +MIGDAL_TAXONOMIES = () \ No newline at end of file diff --git a/prawokultury/templates/base.html b/prawokultury/templates/base.html index 0a92ff7..57ea892 100755 --- a/prawokultury/templates/base.html +++ b/prawokultury/templates/base.html @@ -1,18 +1,18 @@ {% load url from future %} {% load i18n static %} -{% load common_tags migdal_tags events_tags share %} +{% load common_tags migdal_tags share %} {% load compressed %} - {% block "titleextra" %}{% endblock %}{% trans "Culture's right" %} + {% block "titleextra" %}{% endblock %}CopyCamp {% compressed_css 'base' %} - - - + + + @@ -22,20 +22,13 @@
-
- {% trans "Organizer" %}
- - {% trans -
- {% trans "Sponsor" %}
- - {% trans +
@@ -59,23 +52,7 @@ diff --git a/prawokultury/urls.py b/prawokultury/urls.py index 4db309c..1b78033 100644 --- a/prawokultury/urls.py +++ b/prawokultury/urls.py @@ -19,6 +19,9 @@ urlpatterns = patterns('', url(r'^media/(?P.*)$', 'django.views.static.serve', { 'document_root': settings.MEDIA_ROOT, }), + + (r'^accounts/login/$', 'django_cas.views.login'), + (r'^accounts/logout/$', 'django_cas.views.logout'), ) + i18n_patterns('', url(string_concat(r'^', _('events'), r'/'), include('events.urls')), url(r'^comments/', include('django_comments_xtd.urls')), diff --git a/requirements.txt b/requirements.txt index eb707fd..4fb7200 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,9 +1,14 @@ Django>=1.4,<1.5 +#django_cas +-e hg+https://bitbucket.org/cpcc/django-cas@197f156ee943#egg=django_cas South>=0.7.4 PIL sorl-thumbnail>=11.09,<12 django-pagination +#django-jsonfield +-e git+git://github.com/bradjasper/django-jsonfield.git@2f427368ad70bf8d9a0580df58ec0eb0654d62ae#egg=django-jsonfield + textile django-markupfield django-gravatar