From: Radek Czajka Date: Fri, 16 Dec 2011 16:03:43 +0000 (+0100) Subject: infopages: allow template tags, some cleaning X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/066ffa84ce4d577668b1a49140fb7facc19451c3 infopages: allow template tags, some cleaning --- diff --git a/apps/infopages/admin.py b/apps/infopages/admin.py index 66f2996c5..e5bc93cc6 100644 --- a/apps/infopages/admin.py +++ b/apps/infopages/admin.py @@ -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 index 000000000..6ecd60b8f --- /dev/null +++ b/apps/infopages/migrations/0002_auto__del_field_infopage_page_title__del_field_infopage_page_title_en_.py @@ -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'] diff --git a/apps/infopages/models.py b/apps/infopages/models.py index 9fe7b3287..cf9e9bf66 100644 --- a/apps/infopages/models.py +++ b/apps/infopages/models.py @@ -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 index 000000000..2d00d5d0e --- /dev/null +++ b/apps/infopages/templates/infopages/infopage.html @@ -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 %} +

{{ page.title }}

+ + {% autoescape off %} +
+ {{ left_column }} +
+
+ {{ right_column }} +
+ {% endautoescape %} +{% endblock %} diff --git a/apps/infopages/templates/infopages/on_main.html b/apps/infopages/templates/infopages/on_main.html new file mode 100755 index 000000000..dc0103c61 --- /dev/null +++ b/apps/infopages/templates/infopages/on_main.html @@ -0,0 +1,5 @@ + diff --git a/apps/infopages/templatetags/infopages_tags.py b/apps/infopages/templatetags/infopages_tags.py new file mode 100755 index 000000000..d7c93ca8f --- /dev/null +++ b/apps/infopages/templatetags/infopages_tags.py @@ -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 index 000000000..081e0ef39 --- /dev/null +++ b/apps/infopages/urls.py @@ -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[a-zA-Z0-9_-]+)/$', 'infopage', name='infopage'), +) + diff --git a/apps/infopages/views.py b/apps/infopages/views.py index 07a416bbf..d457653d1 100644 --- a/apps/infopages/views.py +++ b/apps/infopages/views.py @@ -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)) diff --git a/wolnelektury/templates/base.html b/wolnelektury/templates/base.html index 3a15613fd..9d490ae3f 100644 --- a/wolnelektury/templates/base.html +++ b/wolnelektury/templates/base.html @@ -7,7 +7,8 @@ - {% block title %}WolneLektury.pl{% endblock %} + {% trans "Wolne Lektury internet library" %} + {% block titleextra %}{% endblock %} {% compressed_css "all" %} diff --git a/wolnelektury/templates/info/base.html b/wolnelektury/templates/info/base.html deleted file mode 100644 index ea1513641..000000000 --- a/wolnelektury/templates/info/base.html +++ /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 %} -

{{ object.title }}

-
-

{{ form.q }} {%trans "or" %} {% trans "return to the main page" %}

-
- - {% autoescape off %} -
- {{ object.left_column }} -
-
- {{ object.right_column }} -
- {% endautoescape %} -{% endblock %} diff --git a/wolnelektury/templates/info/join_us.html b/wolnelektury/templates/info/join_us.html index 92c1fd044..415b13afc 100644 --- a/wolnelektury/templates/info/join_us.html +++ b/wolnelektury/templates/info/join_us.html @@ -19,4 +19,4 @@ or transferring 1% of your income tax.

{% 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 %} -{% trans "More..." %}

+{% trans "More..." %}

diff --git a/wolnelektury/templates/main_page.html b/wolnelektury/templates/main_page.html index 889e0721a..56dc7e1f1 100755 --- a/wolnelektury/templates/main_page.html +++ b/wolnelektury/templates/main_page.html @@ -1,5 +1,5 @@ {% extends "base.html" %} -{% load cache i18n catalogue_tags %} +{% load cache i18n catalogue_tags infopages_tags %} {% block body %} @@ -48,12 +48,12 @@ @@ -61,12 +61,7 @@

Informacje

- + {% infopages_on_main %}