infopages: allow template tags, some cleaning
authorRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Fri, 16 Dec 2011 16:03:43 +0000 (17:03 +0100)
committerRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Fri, 16 Dec 2011 16:03:56 +0000 (17:03 +0100)
14 files changed:
apps/infopages/admin.py
apps/infopages/migrations/0002_auto__del_field_infopage_page_title__del_field_infopage_page_title_en_.py [new file with mode: 0644]
apps/infopages/models.py
apps/infopages/templates/infopages/infopage.html [new file with mode: 0755]
apps/infopages/templates/infopages/on_main.html [new file with mode: 0755]
apps/infopages/templatetags/infopages_tags.py [new file with mode: 0755]
apps/infopages/urls.py [new file with mode: 0755]
apps/infopages/views.py
wolnelektury/templates/base.html
wolnelektury/templates/info/base.html [deleted file]
wolnelektury/templates/info/join_us.html
wolnelektury/templates/main_page.html
wolnelektury/translation.py
wolnelektury/urls.py

index 66f2996..e5bc93c 100644 (file)
@@ -4,6 +4,6 @@ from modeltranslation.admin import TranslationAdmin
 from infopages.models import InfoPage
 
 class InfoPageAdmin(TranslationAdmin):
-    list_display = ('title',)
+    list_display = ('title', 'slug', 'main_page')
 
 admin.site.register(InfoPage, InfoPageAdmin)
\ No newline at end of file
diff --git a/apps/infopages/migrations/0002_auto__del_field_infopage_page_title__del_field_infopage_page_title_en_.py b/apps/infopages/migrations/0002_auto__del_field_infopage_page_title__del_field_infopage_page_title_en_.py
new file mode 100644 (file)
index 0000000..6ecd60b
--- /dev/null
@@ -0,0 +1,111 @@
+# encoding: utf-8
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+class Migration(SchemaMigration):
+
+    def forwards(self, orm):
+        
+        # Deleting field 'InfoPage.page_title'
+        db.delete_column('infopages_infopage', 'page_title')
+
+        # Deleting field 'InfoPage.page_title_en'
+        db.delete_column('infopages_infopage', 'page_title_en')
+
+        # Deleting field 'InfoPage.page_title_es'
+        db.delete_column('infopages_infopage', 'page_title_es')
+
+        # Deleting field 'InfoPage.page_title_fr'
+        db.delete_column('infopages_infopage', 'page_title_fr')
+
+        # Deleting field 'InfoPage.page_title_uk'
+        db.delete_column('infopages_infopage', 'page_title_uk')
+
+        # Deleting field 'InfoPage.page_title_de'
+        db.delete_column('infopages_infopage', 'page_title_de')
+
+        # Deleting field 'InfoPage.page_title_lt'
+        db.delete_column('infopages_infopage', 'page_title_lt')
+
+        # Deleting field 'InfoPage.page_title_pl'
+        db.delete_column('infopages_infopage', 'page_title_pl')
+
+        # Deleting field 'InfoPage.page_title_ru'
+        db.delete_column('infopages_infopage', 'page_title_ru')
+
+        # Adding field 'InfoPage.main_page'
+        db.add_column('infopages_infopage', 'main_page', self.gf('django.db.models.fields.IntegerField')(null=True, blank=True), keep_default=False)
+
+
+    def backwards(self, orm):
+        
+        # Adding field 'InfoPage.page_title'
+        db.add_column('infopages_infopage', 'page_title', self.gf('django.db.models.fields.CharField')(default='', max_length=120, blank=True), keep_default=False)
+
+        # Adding field 'InfoPage.page_title_en'
+        db.add_column('infopages_infopage', 'page_title_en', self.gf('django.db.models.fields.CharField')(max_length=120, null=True, blank=True), keep_default=False)
+
+        # Adding field 'InfoPage.page_title_es'
+        db.add_column('infopages_infopage', 'page_title_es', self.gf('django.db.models.fields.CharField')(max_length=120, null=True, blank=True), keep_default=False)
+
+        # Adding field 'InfoPage.page_title_fr'
+        db.add_column('infopages_infopage', 'page_title_fr', self.gf('django.db.models.fields.CharField')(max_length=120, null=True, blank=True), keep_default=False)
+
+        # Adding field 'InfoPage.page_title_uk'
+        db.add_column('infopages_infopage', 'page_title_uk', self.gf('django.db.models.fields.CharField')(max_length=120, null=True, blank=True), keep_default=False)
+
+        # Adding field 'InfoPage.page_title_de'
+        db.add_column('infopages_infopage', 'page_title_de', self.gf('django.db.models.fields.CharField')(max_length=120, null=True, blank=True), keep_default=False)
+
+        # Adding field 'InfoPage.page_title_lt'
+        db.add_column('infopages_infopage', 'page_title_lt', self.gf('django.db.models.fields.CharField')(max_length=120, null=True, blank=True), keep_default=False)
+
+        # Adding field 'InfoPage.page_title_pl'
+        db.add_column('infopages_infopage', 'page_title_pl', self.gf('django.db.models.fields.CharField')(max_length=120, null=True, blank=True), keep_default=False)
+
+        # Adding field 'InfoPage.page_title_ru'
+        db.add_column('infopages_infopage', 'page_title_ru', self.gf('django.db.models.fields.CharField')(max_length=120, null=True, blank=True), keep_default=False)
+
+        # Deleting field 'InfoPage.main_page'
+        db.delete_column('infopages_infopage', 'main_page')
+
+
+    models = {
+        'infopages.infopage': {
+            'Meta': {'ordering': "('main_page', 'slug')", 'object_name': 'InfoPage'},
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'left_column': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+            'left_column_de': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
+            'left_column_en': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
+            'left_column_es': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
+            'left_column_fr': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
+            'left_column_lt': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
+            'left_column_pl': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
+            'left_column_ru': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
+            'left_column_uk': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
+            'main_page': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
+            'right_column': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+            'right_column_de': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
+            'right_column_en': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
+            'right_column_es': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
+            'right_column_fr': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
+            'right_column_lt': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
+            'right_column_pl': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
+            'right_column_ru': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
+            'right_column_uk': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
+            'slug': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '120', 'db_index': 'True'}),
+            'title': ('django.db.models.fields.CharField', [], {'max_length': '120', 'blank': 'True'}),
+            'title_de': ('django.db.models.fields.CharField', [], {'max_length': '120', 'null': True, 'blank': True}),
+            'title_en': ('django.db.models.fields.CharField', [], {'max_length': '120', 'null': True, 'blank': True}),
+            'title_es': ('django.db.models.fields.CharField', [], {'max_length': '120', 'null': True, 'blank': True}),
+            'title_fr': ('django.db.models.fields.CharField', [], {'max_length': '120', 'null': True, 'blank': True}),
+            'title_lt': ('django.db.models.fields.CharField', [], {'max_length': '120', 'null': True, 'blank': True}),
+            'title_pl': ('django.db.models.fields.CharField', [], {'max_length': '120', 'null': True, 'blank': True}),
+            'title_ru': ('django.db.models.fields.CharField', [], {'max_length': '120', 'null': True, 'blank': True}),
+            'title_uk': ('django.db.models.fields.CharField', [], {'max_length': '120', 'null': True, 'blank': True})
+        }
+    }
+
+    complete_apps = ['infopages']
index 9fe7b32..cf9e9bf 100644 (file)
@@ -6,21 +6,22 @@ from django.db import models
 from django.utils.translation import ugettext_lazy as _
 
 class InfoPage(models.Model):
-    """
-    An InfoPage is used to display a two-column flatpage
-    """
+    """An InfoPage is used to display a two-column flatpage."""
 
-    page_title = models.CharField(_('page title'), max_length=120, blank=True)
+    main_page = models.IntegerField(_('main page priority'), null=True, blank=True)
     slug = models.SlugField(_('slug'), max_length=120, unique=True, db_index=True)
     title = models.CharField(_('title'), max_length=120, blank=True)
     left_column = models.TextField(_('left column'), blank=True)
     right_column = models.TextField(_('right column'), blank=True)
 
     class Meta:
-        ordering = ('slug',)
+        ordering = ('main_page', 'slug',)
         verbose_name = _('info page')
         verbose_name_plural = _('info pages')
 
     def __unicode__(self):
         return self.title
 
+    @models.permalink
+    def get_absolute_url(self):
+        return ('infopage', [self.slug])
diff --git a/apps/infopages/templates/infopages/infopage.html b/apps/infopages/templates/infopages/infopage.html
new file mode 100755 (executable)
index 0000000..2d00d5d
--- /dev/null
@@ -0,0 +1,20 @@
+{% extends "base.html" %}
+{% load i18n %}
+{% load chunks %}
+
+{% block titleextra %}:: {{ page.title }}{% endblock %}
+
+{% block metadescription %}{{ left_column|striptags|truncatewords:10 }}{% endblock %}
+
+{% block body %}
+    <h1>{{ page.title }}</h1>
+
+    {% autoescape off %}
+    <div class="column-left">
+       {{ left_column }}
+    </div>
+    <div class="column-right">
+       {{ right_column }}
+    </div>
+    {% endautoescape %}
+{% endblock %}
diff --git a/apps/infopages/templates/infopages/on_main.html b/apps/infopages/templates/infopages/on_main.html
new file mode 100755 (executable)
index 0000000..dc0103c
--- /dev/null
@@ -0,0 +1,5 @@
+<ul>
+{% for page in objects %}
+    <li><a href="{{ page.get_absolute_url }}">{{ page.title }}</a></li>
+{% endfor %}
+</ul>
diff --git a/apps/infopages/templatetags/infopages_tags.py b/apps/infopages/templatetags/infopages_tags.py
new file mode 100755 (executable)
index 0000000..d7c93ca
--- /dev/null
@@ -0,0 +1,14 @@
+# -*- coding: utf-8 -*-
+# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
+# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
+#
+from django import template
+from infopages.models import InfoPage
+
+register = template.Library()
+
+
+@register.inclusion_tag('infopages/on_main.html')
+def infopages_on_main():
+    objects = InfoPage.objects.exclude(main_page=None)
+    return {"objects": objects}
diff --git a/apps/infopages/urls.py b/apps/infopages/urls.py
new file mode 100755 (executable)
index 0000000..081e0ef
--- /dev/null
@@ -0,0 +1,11 @@
+# -*- coding: utf-8 -*-
+# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
+# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
+#
+from django.conf.urls.defaults import *
+
+
+urlpatterns = patterns('infopages.views',
+    url(r'^(?P<slug>[a-zA-Z0-9_-]+)/$', 'infopage', name='infopage'),
+)
+
index 07a416b..d457653 100644 (file)
@@ -2,15 +2,19 @@
 # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
 #
-from django.shortcuts import render_to_response
-from django.template import RequestContext
+from django.shortcuts import render_to_response, get_object_or_404
+from django.template import RequestContext, Template
 
-from catalogue.forms import SearchForm
 from infopages.models import InfoPage
 
+
 def infopage(request, slug):
-    form = SearchForm()
-    object = InfoPage.objects.get(slug=slug)
+    page = InfoPage.objects.get(slug=slug)
+
+    page = get_object_or_404(InfoPage, slug=slug)
+    rc = RequestContext(request)
+    left_column = Template(page.left_column).render(rc)
+    right_column = Template(page.right_column).render(rc)
 
-    return render_to_response('info/base.html', locals(),
-                context_instance=RequestContext(request))
\ No newline at end of file
+    return render_to_response('infopages/infopage.html', locals(),
+                context_instance=RequestContext(request))
index 3a15613..9d490ae 100644 (file)
@@ -7,7 +7,8 @@
         <meta http-equiv="Content-Style-Type" content="text/css" />
         <meta name="description" 
             content="{% block metadescription %}Darmowe opracowane, pełne teksty lektur, e-booki, audiobooki i pliki DAISY na wolnej licencji.{% endblock %}" />
-        <title>{% block title %}WolneLektury.pl{% endblock %}</title>
+        <title>{% trans "Wolne Lektury internet library" %}
+            {% block titleextra %}{% endblock %}</title>
         <link rel="icon" href="{{ STATIC_URL }}img/favicon.png" type="image/png" />
         <link rel="search" type="application/opensearchdescription+xml" title="Wolne Lektury" href="{{ STATIC_URL }}opensearch.xml" />
         {% compressed_css "all" %}
diff --git a/wolnelektury/templates/info/base.html b/wolnelektury/templates/info/base.html
deleted file mode 100644 (file)
index ea15136..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-{% extends "base.html" %}
-{% load i18n %}
-{% load chunks %}
-
-{% block title %}{{ object.page_title }}{% endblock %}
-
-{% block metadescription %}{{ object.left_column|striptags|truncatewords:10 }}{% endblock %}
-
-{% block body %}
-    <h1>{{ object.title }}</h1>
-    <form action="{% url search %}" method="get" accept-charset="utf-8" id="search-form">
-        <p>{{ form.q }} <input type="submit" value="{% trans "Search" %}" /> <strong>{%trans "or" %}</strong> <a href="{% url main_page %}">{% trans "return to the main page" %}</a></p>
-    </form>
-
-    {% autoescape off %}
-    <div class="column-left">
-       {{ object.left_column }}
-    </div>
-    <div class="column-right">
-       {{ object.right_column }}
-    </div>
-       {% endautoescape %}
-{% endblock %}
index 92c1fd0..415b13a 100644 (file)
@@ -19,4 +19,4 @@ or transferring 1&#37; of your income tax</a>.
 <p>{% blocktrans %}Become an editor of Wolne Lektury! Find out if
 we're currently working on a reading you're looking for and prepare
 a publication by yourself by logging into the Editorial Platform.{% endblocktrans %}
-<a href='{% url help_us %}'>{% trans "More..." %}</a></p>
+<a href='{% url infopage 'mozesz-nam-pomoc' %}'>{% trans "More..." %}</a></p>
index 889e072..56dc7e1 100755 (executable)
@@ -1,5 +1,5 @@
 {% extends "base.html" %}
-{% load cache i18n catalogue_tags %}
+{% load cache i18n catalogue_tags infopages_tags %}
 
 
 {% block body %}
 
         <ul>
             <li><a href="{% url suggest %}" id="suggest-link">{% trans "Report a bug" %}</a></li>
-            <li><a href="{% url suggest %}">Turniej Elektrybałtów</a></li>
-            <li><a href="{% url suggest %}">Leśmianator</a></li>
-            <li><a href="{% url suggest %}">{% trans "Mobile app" %}</a></li>
-            <li><a href="{% url suggest %}">{% trans "Widget" %}</a></li>
-            <li><a href="{% url suggest %}">{% trans "Public domain counter" %}</a></li>
-            <li><a href="{% url suggest %}">{% trans "Missing a book?" %}</a></li>
+            <li><a href="http://turniej.wolnelektury.pl">Turniej Elektrybałtów</a></li>
+            <li><a href="{% url lesmianator %}">Leśmianator</a></li>
+            <li><a href="">{% trans "Mobile app" %}</a></li>
+            <li><a href="{% url infopage "widget" %}">{% trans "Widget" %}</a></li>
+            <li><a href="">{% trans "Public domain counter" %}</a></li>
+            <li><a href="{% url suggest_publishing %}">{% trans "Missing a book?" %}</a></li>
         </ul>
     </div>
 
     <div class="infopages-box">
         <h2 class="grid-line"><span class='mono'>Informacje</span></h2>
 
-        <ul>
-            <li><a href="{% url suggest %}">{% trans "About the project" %}</a></li>
-            <li><a href="{% url suggest %}">{% trans "You can help us" %}</a></li>
-            <li><a href="{% url suggest %}">{% trans "Copyright" %}</a></li>
-            <li><a href="{% url suggest %}">{% trans "Team" %}</a></li>
-        </ul>
+        {% infopages_on_main %}
 
         <div class="social-links">
             <a href="http://pl-pl.facebook.com/pages/Wolne-Lektury/203084073268"><img src="{{ STATIC_URL }}img/social/facebook.png" alt="WolneLektury @ Facebook" /></a>
index f9f7ab9..cda9ebb 100644 (file)
@@ -7,7 +7,7 @@ from modeltranslation.translator import translator, TranslationOptions
 from infopages.models import InfoPage
 
 class InfoPageTranslationOptions(TranslationOptions):
-    fields = ('page_title', 'title', 'left_column', 'right_column')
+    fields = ('title', 'left_column', 'right_column')
 
 translator.register(InfoPage, InfoPageTranslationOptions)
 
index 2556a3d..307f3fa 100644 (file)
@@ -22,11 +22,6 @@ urlpatterns += patterns('',
     url(r'^raporty/', include('reporting.urls')),
     url(r'^info/', include('infopages.urls')),
 
-    # Static pages
-    url(r'^mozesz-nam-pomoc/$', 'infopages.views.infopage', {'slug': 'help_us'}, name='help_us'),
-    url(r'^o-projekcie/$', 'infopages.views.infopage', {'slug': 'about_us'}, name='about_us'),
-    url(r'^widget/$', 'infopages.views.infopage', {'slug': 'widget'}, name='widget'),
-
     # Admin panel
     url(r'^admin/catalogue/book/import$', 'catalogue.views.import_book', name='import_book'),
     url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
@@ -56,13 +51,13 @@ urlpatterns += patterns('django.views.generic.simple',
     url(r'^epub/$', 'redirect_to',
         {'url': '/katalog/lektury/'}),
     url(r'^mozesz-nam-pomoc/$', 'redirect_to',
-        {'url': '/info/mozesz-nam-pomoc'}, name='help_us'),
+        {'url': '/info/mozesz-nam-pomoc'}),
     url(r'^o-projekcie/$', 'redirect_to',
-        {'url': '/info/o-projekcie'}, name='about_us'),
+        {'url': '/info/o-projekcie'}),
     url(r'^widget/$', 'redirect_to',
         {'url': '/info/widget'}),
     url(r'^wolontariat/$', 'redirect_to',
-        {'url': '/mozesz-nam-pomoc/'}),
+        {'url': '/info/mozesz-nam-pomoc/'}),
 )