making migdal more universal
authorRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Fri, 5 Oct 2012 07:25:05 +0000 (09:25 +0200)
committerRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Fri, 5 Oct 2012 07:25:05 +0000 (09:25 +0200)
15 files changed:
migdal/__init__.py
migdal/admin.py
migdal/helpers.py
migdal/templatetags/migdal_tags.py
migdal/urls.py
prawokultury/helpers.py
prawokultury/model_helpers.py [new file with mode: 0755]
prawokultury/settings.d/30-apps.conf
prawokultury/settings.d/40-auth.conf [new file with mode: 0755]
prawokultury/settings.d/40-middleware.conf
prawokultury/settings.d/50-contrib.conf
prawokultury/settings.d/60-custom.conf
prawokultury/templates/base.html
prawokultury/urls.py
requirements.txt

index 05322b4..0a04b06 100644 (file)
@@ -14,9 +14,9 @@ class Settings(AppSettings):
     # Types of entries:
     # (slug, commentable, on main)
     TYPES = (
     # 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 = (
         )
     TYPE_SUBMIT = 'news'
     TAXONOMIES = (
@@ -25,6 +25,8 @@ class Settings(AppSettings):
     )
     LAST_COMMENTS = 5
 
     )
     LAST_COMMENTS = 5
 
+    MENU = []
+
     TYPES_DICT = None
     def _more_TYPES_DICT(self, value):
         return dict((t.db, t) for t in self.TYPES)
     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)
 
     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
     OBLIGATORY_LANGUAGES = None
     def _more_OBLIGATORY_LANGUAGES(self, value):
         return value or tuple(lang for lang in settings.LANGUAGES
index d93a782..4043921 100644 (file)
@@ -5,9 +5,10 @@
 from django.conf import settings
 from django.contrib import admin
 from django.utils.translation import ugettext_lazy as _
 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 migdal import app_settings
 from migdal.helpers import translated_fields
+from prawokultury.model_helpers import filtered_model
 
 
 class AttachmentInline(admin.TabularInline):
 
 
 class AttachmentInline(admin.TabularInline):
@@ -15,55 +16,78 @@ class AttachmentInline(admin.TabularInline):
     readonly_fields = ['url']
 
 
     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)
index 8a6513d..4e1a16e 100644 (file)
@@ -11,8 +11,16 @@ from django.core.urlresolvers import LocaleRegexURLResolver
 from django.utils.translation import get_language, string_concat
 
 
 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)
 
     def __unicode__(self):
         return unicode(self.slug)
 
index 380cb56..d12920f 100644 (file)
@@ -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 = [
 @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}
     for item in items:
         item.check_active(chooser, value)
     return {'items': items}
index c7db6f4..3a58123 100644 (file)
@@ -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'),
     # main page
     url(r'^$', 'migdal.views.entry_list', name='migdal_main'),
     url(r'^rss.xml$', feeds.EntriesFeed(), name='migdal_main_feed'),
index 5877e0b..23520ec 100644 (file)
@@ -23,7 +23,7 @@ def textile_restricted_pl(text):
                         text, rel='nofollow')
 
 
                         text, rel='nofollow')
 
 
-class LazyUGettextLazy():
+class LazyUGettextLazy(object):
     """You can use it to internationalize strings in settings.
 
     Just import this class as gettext.
     """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 (executable)
index 0000000..4a734b6
--- /dev/null
@@ -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)
index 5aa5144..0671f62 100755 (executable)
@@ -1,12 +1,13 @@
 INSTALLED_APPS = (
     'prawokultury',
 INSTALLED_APPS = (
     'prawokultury',
-    'events',
+    #'events',
     'migdal',
     'migdal',
+    #'forms',
 
     'gravatar',
     'south',
 
     'gravatar',
     'south',
-    'django.contrib.comments',
-    'django_comments_xtd',
+    #'django.contrib.comments',
+    #'django_comments_xtd',
     'pipeline',
     'haystack',
     'pagination',
     'pipeline',
     'haystack',
     'pagination',
diff --git a/prawokultury/settings.d/40-auth.conf b/prawokultury/settings.d/40-auth.conf
new file mode 100755 (executable)
index 0000000..675db9d
--- /dev/null
@@ -0,0 +1,5 @@
+if 'django_cas' in INSTALLED_APPS:
+    AUTHENTICATION_BACKENDS = (
+        'django.contrib.auth.backends.ModelBackend',
+        'django_cas.backends.CASBackend',
+    )
index eedc50e..cde9886 100755 (executable)
@@ -6,6 +6,14 @@ MIDDLEWARE_CLASSES = (
     'django.middleware.common.CommonMiddleware',
     'django.middleware.csrf.CsrfViewMiddleware',
     'django.contrib.auth.middleware.AuthenticationMiddleware',
     '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:
     'django.contrib.messages.middleware.MessageMiddleware',
     'piwik.django.middleware.PiwikMiddleware',
     # Uncomment the next line for simple clickjacking protection:
index 12d387e..27a516c 100755 (executable)
@@ -12,3 +12,6 @@ COMMENTS_XTD_LIST_URL_ACTIVE = True
 THUMBNAIL_QUALITY = 95
 
 GRAVATAR_DEFAULT_IMAGE = 'http://localhost:8000/static/img/avatar.png'
 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'
index e69de29..ea1112c 100755 (executable)
@@ -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
index 0a92ff7..57ea892 100755 (executable)
@@ -1,18 +1,18 @@
 <!DOCTYPE html>
 {% load url from future %}
 {% load i18n static %}
 <!DOCTYPE html>
 {% load url from future %}
 {% load i18n static %}
-{% load common_tags migdal_tags events_tags share %}
+{% load common_tags migdal_tags share %}
 {% load compressed %}
 <html prefix="og: http://ogp.me/ns#">
     <head>
 {% load compressed %}
 <html prefix="og: http://ogp.me/ns#">
     <head>
-       <title>{% block "titleextra" %}{% endblock %}{% trans "Culture's right" %}</title>
+       <title>{% block "titleextra" %}{% endblock %}CopyCamp</title>
        <link rel="shortcut icon" type="image/png" href="{% static "img/favicon.png" %}" />
         {% compressed_css 'base' %}
 
         <meta property='og:url' content='{% block "ogurl" %}{% url 'migdal_main' %}{% endblock %}' />
        <link rel="shortcut icon" type="image/png" href="{% static "img/favicon.png" %}" />
         {% compressed_css 'base' %}
 
         <meta property='og:url' content='{% block "ogurl" %}{% url 'migdal_main' %}{% endblock %}' />
-        <meta property='og:title' content='{% block "ogtitle" %}{% trans "Culture's right" %}{% endblock %}' />
-        <meta property='og:site_name' content='{% trans "Culture's right" %}' />
-        <meta property='og:description' content='{% block "ogdescription" %}Prawokultury.pl to strona edukacyjna mająca za zadanie w przystępny i rzetelny sposób informować o wszelkich kwestiach związanych z prawem autorskim.{% endblock %}' />
+        <meta property='og:title' content='{% block "ogtitle" %}CopyCamp{% endblock %}' />
+        <meta property='og:site_name' content='CopyCamp' />
+        <meta property='og:description' content='{% block "ogdescription" %}CopyCamp!{% endblock %}' />
         <meta property='og:type' content='{% block "ogtype" %}website{% endblock %}' />
         <meta property='og:image' content='{% block "ogimage" %}{{ "/static/img/square-logo.png"|build_absolute_uri:request }}{% endblock %}' />
         <meta property='og:locale' content='pl_PL' />
         <meta property='og:type' content='{% block "ogtype" %}website{% endblock %}' />
         <meta property='og:image' content='{% block "ogimage" %}{{ "/static/img/square-logo.png"|build_absolute_uri:request }}{% endblock %}' />
         <meta property='og:locale' content='pl_PL' />
         <div id="header-bar">
         <div class="bar-left">
             <a id="logo" href="{% url "migdal_main" %}">
         <div id="header-bar">
         <div class="bar-left">
             <a id="logo" href="{% url "migdal_main" %}">
-                <img alt="{% trans "Culture's right" %}"
+                <img alt="{% trans "CopyCamp" %}"
                     src="{% static "img/logo.png" %}" /></a>
         </div>
         <div class="bar-right">
                     src="{% static "img/logo.png" %}" /></a>
         </div>
         <div class="bar-right">
-            <div class="org-fnp">
-                <span>{% trans "Organizer" %}</span><br/>
-                <a href="http://nowoczesnapolska.org.pl">
-                    <img src="{% static 'img/logo-fnp.png' %}"
-                        alt="{% trans "Modern Poland Foundation" %}" /></a>
-            </div><div class="org-trust">
-                <span>{% trans "Sponsor" %}</span><br/>
-                <a href="http://ceetrust.org">
-                    <img src="{% static 'img/logo-trust.png' %}"
-                        alt="{% trans "Trust for Civil Society in Central and Eastern Europe" %}" /></a>
+            <div class="social">
+                {% url 'migdal_main' as main_url %}
+                {% share main_url "CopyCamp" "big" %}
             </div>
         </div>
         <div style="clear: both;"></div>
             </div>
         </div>
         <div style="clear: both;"></div>
         <div id="sidebar" class="bar-right">
             {% block "sidebar" %}
                 <div class="sidebar-box">
         <div id="sidebar" class="bar-right">
             {% block "sidebar" %}
                 <div class="sidebar-box">
-                    <h3><a href="{% url 'events' %}">{% trans "Upcoming events" %}</a></h3>
-                    {% events_box %}
-                </div>
-                <div id="sidebar-box-categories" class="sidebar-box">
-                    {% categories 'topics' %}
-                    {% categories 'types' %}
-                </div>
-                <div class="sidebar-box social">
-                    <a href="{% url 'migdal_main_feed' %}" title="RSS feed">
-                        <img src="{% static 'img/rss.png' %}" alt="RSS feed" /></a>
-                    {% url 'migdal_main' as main_url %}
-                    {% trans "Culture's right" as site_name %}
-                    {% share main_url site_name "big" %}
-                </div>
-                <div class="sidebar-box">
-                    <h3>{% trans "Latest comments" %}</h3>
-                    {% last_comments %}
+                    (Sponsorzy)
                 </div>
             {% endblock %}
         </div>
                 </div>
             {% endblock %}
         </div>
index 4db309c..1b78033 100644 (file)
@@ -19,6 +19,9 @@ urlpatterns = patterns('',
     url(r'^media/(?P<path>.*)$', 'django.views.static.serve', {
             'document_root': settings.MEDIA_ROOT,
         }),
     url(r'^media/(?P<path>.*)$', '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')),
 ) + i18n_patterns('',
     url(string_concat(r'^', _('events'), r'/'), include('events.urls')),
     url(r'^comments/', include('django_comments_xtd.urls')),
index eb707fd..4fb7200 100644 (file)
@@ -1,9 +1,14 @@
 Django>=1.4,<1.5
 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
 
 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
 textile
 django-markupfield
 django-gravatar