From: Radek Czajka Date: Thu, 6 Sep 2012 13:45:03 +0000 (+0200) Subject: Cites: sticky and custom backgrounds. X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/7c8f6fe9ddb0285e0b7c80bc0ff8814304ac2f6e?hp=--cc Cites: sticky and custom backgrounds. --- 7c8f6fe9ddb0285e0b7c80bc0ff8814304ac2f6e diff --git a/apps/social/admin.py b/apps/social/admin.py index f32f42612..bc0ac0b75 100755 --- a/apps/social/admin.py +++ b/apps/social/admin.py @@ -3,12 +3,27 @@ # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # from django.contrib import admin +from django.utils.translation import ugettext_lazy as _ from social.models import Cite class CiteAdmin(admin.ModelAdmin): - list_display = ['text', 'vip', 'small'] + list_display = ['text', 'sticky', 'vip', 'small', 'has_image'] + fieldsets = ( + (None, {'fields': ('book', 'text', 'small', 'vip', 'link', 'sticky')}), + ( + _('Background'), + {'fields': ('image', 'image_title', 'image_author', + 'image_link', 'image_license', 'image_license_link') + } + ) + ) + + def has_image(self, cite): + return bool(cite.image) + has_image.description = _('image') + has_image.boolean = True admin.site.register(Cite, CiteAdmin) diff --git a/apps/social/locale/pl/LC_MESSAGES/django.mo b/apps/social/locale/pl/LC_MESSAGES/django.mo index 6a9092134..ae0df5a5d 100644 Binary files a/apps/social/locale/pl/LC_MESSAGES/django.mo and b/apps/social/locale/pl/LC_MESSAGES/django.mo differ diff --git a/apps/social/locale/pl/LC_MESSAGES/django.po b/apps/social/locale/pl/LC_MESSAGES/django.po index 2ebcd09a6..fa7b35d3e 100644 --- a/apps/social/locale/pl/LC_MESSAGES/django.po +++ b/apps/social/locale/pl/LC_MESSAGES/django.po @@ -7,16 +7,24 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2012-07-19 11:40+0200\n" -"PO-Revision-Date: 2012-07-16 15:13+0100\n" -"Last-Translator: Marcin Koziej \n" +"POT-Creation-Date: 2012-09-06 15:41+0200\n" +"PO-Revision-Date: 2012-09-06 15:43+0100\n" +"Last-Translator: Radek Czajka \n" "Language-Team: LANGUAGE \n" "Language: \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"Plural-Forms: nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 " -"|| n%100>=20) ? 1 : 2)\n" +"Plural-Forms: nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2)\n" + +#: admin.py:16 +msgid "Background" +msgstr "Obraz tła" + +#: admin.py:25 +#: models.py:22 +msgid "image" +msgstr "obraz" #: forms.py:23 msgid "Tags (comma-separated)" @@ -24,7 +32,11 @@ msgstr "Tagi (rozdzielone przecinkami)" #: forms.py:47 msgid "Name of the new shelf" -msgstr "" +msgstr "Nazwa nowej półki" + +#: models.py:13 +msgid "book" +msgstr "książka" #: models.py:14 msgid "text" @@ -34,35 +46,65 @@ msgstr "tekst" msgid "small" msgstr "mały" -#: models.py:15 +#: models.py:16 msgid "Make this cite display smaller." msgstr "Sprawia, że cytat wyświetla się mniejszym fontem." -#: models.py:16 +#: models.py:17 msgid "VIP" -msgstr "" +msgstr "VIP" -#: models.py:17 +#: models.py:18 +#: models.py:28 msgid "link" -msgstr "" +msgstr "odnośnik" + +#: models.py:19 +msgid "sticky" +msgstr "przyklejony" + +#: models.py:20 +msgid "Sticky cites will take precedense." +msgstr "Przyklejone cytaty mają pierwszeństwo." + +#: models.py:24 +msgid "title" +msgstr "tytuł" + +#: models.py:26 +msgid "author" +msgstr "autor" + +#: models.py:29 +msgid "license name" +msgstr "nazwa licencji" + +#: models.py:31 +msgid "license link" +msgstr "adres licencji" + +#: models.py:35 +msgid "cite" +msgstr "cytat" + +#: models.py:36 +msgid "cites" +msgstr "cytaty" #: templates/social/cite_promo.html:6 msgid "recommends" msgstr "poleca" -#: templates/social/my_shelf.html:5 templates/social/my_shelf.html.py:11 +#: templates/social/my_shelf.html:5 +#: templates/social/my_shelf.html.py:11 msgid "My shelf" msgstr "Moja półka" #: templates/social/my_shelf.html:16 -msgid "" -"Add works to your shelf by clicking on the star on the page of the work. The " -"work will then show up on My shelf page." -msgstr "" -"Aby dodać pozycję do swojej półki, należy zaznaczyć gwiazdkę znajdującą się " -"na stronie utworu. Po jej zaznaczeniu publikacja pojawi się w zakładce Moja " -"półka." +msgid "Add works to your shelf by clicking on the star on the page of the work. The work will then show up on My shelf page." +msgstr "Aby dodać pozycję do swojej półki, należy zaznaczyć gwiazdkę znajdującą się na stronie utworu. Po jej zaznaczeniu publikacja pojawi się w zakładce Moja półka." #: templates/social/sets_form.html:7 msgid "Remove from my shelf" msgstr "Usuń z mojej półki" + diff --git a/apps/social/migrations/0002_auto__add_field_cite_sticky__add_field_cite_image__add_field_cite_imag.py b/apps/social/migrations/0002_auto__add_field_cite_sticky__add_field_cite_image__add_field_cite_imag.py new file mode 100644 index 000000000..32e8c4357 --- /dev/null +++ b/apps/social/migrations/0002_auto__add_field_cite_sticky__add_field_cite_image__add_field_cite_imag.py @@ -0,0 +1,115 @@ +# -*- coding: 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): + # Adding field 'Cite.sticky' + db.add_column('social_cite', 'sticky', + self.gf('django.db.models.fields.BooleanField')(default=False), + keep_default=False) + + # Adding field 'Cite.image' + db.add_column('social_cite', 'image', + self.gf('django.db.models.fields.files.ImageField')(max_length=100, null=True, blank=True), + keep_default=False) + + # Adding field 'Cite.image_title' + db.add_column('social_cite', 'image_title', + self.gf('django.db.models.fields.CharField')(max_length=255, null=True, blank=True), + keep_default=False) + + # Adding field 'Cite.image_author' + db.add_column('social_cite', 'image_author', + self.gf('django.db.models.fields.CharField')(max_length=255, null=True, blank=True), + keep_default=False) + + # Adding field 'Cite.image_link' + db.add_column('social_cite', 'image_link', + self.gf('django.db.models.fields.URLField')(max_length=200, null=True, blank=True), + keep_default=False) + + # Adding field 'Cite.image_license' + db.add_column('social_cite', 'image_license', + self.gf('django.db.models.fields.CharField')(max_length=255, null=True, blank=True), + keep_default=False) + + # Adding field 'Cite.image_license_link' + db.add_column('social_cite', 'image_license_link', + self.gf('django.db.models.fields.URLField')(max_length=200, null=True, blank=True), + keep_default=False) + + + def backwards(self, orm): + # Deleting field 'Cite.sticky' + db.delete_column('social_cite', 'sticky') + + # Deleting field 'Cite.image' + db.delete_column('social_cite', 'image') + + # Deleting field 'Cite.image_title' + db.delete_column('social_cite', 'image_title') + + # Deleting field 'Cite.image_author' + db.delete_column('social_cite', 'image_author') + + # Deleting field 'Cite.image_link' + db.delete_column('social_cite', 'image_link') + + # Deleting field 'Cite.image_license' + db.delete_column('social_cite', 'image_license') + + # Deleting field 'Cite.image_license_link' + db.delete_column('social_cite', 'image_license_link') + + + models = { + 'catalogue.book': { + 'Meta': {'ordering': "('sort_key',)", 'object_name': 'Book'}, + '_related_info': ('jsonfield.fields.JSONField', [], {'null': 'True', 'blank': 'True'}), + 'changed_at': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'db_index': 'True', 'blank': 'True'}), + 'common_slug': ('django.db.models.fields.SlugField', [], {'max_length': '120'}), + 'cover': ('catalogue.fields.EbookField', [], {'max_length': '100', 'null': 'True', 'format_name': "'cover'", 'blank': 'True'}), + 'created_at': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'db_index': 'True', 'blank': 'True'}), + 'description': ('django.db.models.fields.TextField', [], {'blank': 'True'}), + 'epub_file': ('catalogue.fields.EbookField', [], {'default': "''", 'max_length': '100', 'format_name': "'epub'", 'blank': 'True'}), + 'extra_info': ('jsonfield.fields.JSONField', [], {'default': "'{}'"}), + 'fb2_file': ('catalogue.fields.EbookField', [], {'default': "''", 'max_length': '100', 'format_name': "'fb2'", 'blank': 'True'}), + 'gazeta_link': ('django.db.models.fields.CharField', [], {'max_length': '240', 'blank': 'True'}), + 'html_file': ('catalogue.fields.EbookField', [], {'default': "''", 'max_length': '100', 'format_name': "'html'", 'blank': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'language': ('django.db.models.fields.CharField', [], {'default': "'pol'", 'max_length': '3', 'db_index': 'True'}), + 'mobi_file': ('catalogue.fields.EbookField', [], {'default': "''", 'max_length': '100', 'format_name': "'mobi'", 'blank': 'True'}), + 'parent': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'children'", 'null': 'True', 'to': "orm['catalogue.Book']"}), + 'parent_number': ('django.db.models.fields.IntegerField', [], {'default': '0'}), + 'pdf_file': ('catalogue.fields.EbookField', [], {'default': "''", 'max_length': '100', 'format_name': "'pdf'", 'blank': 'True'}), + 'slug': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '120'}), + 'sort_key': ('django.db.models.fields.CharField', [], {'max_length': '120', 'db_index': 'True'}), + 'title': ('django.db.models.fields.CharField', [], {'max_length': '120'}), + 'txt_file': ('catalogue.fields.EbookField', [], {'default': "''", 'max_length': '100', 'format_name': "'txt'", 'blank': 'True'}), + 'wiki_link': ('django.db.models.fields.CharField', [], {'max_length': '240', 'blank': 'True'}), + 'xml_file': ('catalogue.fields.EbookField', [], {'default': "''", 'max_length': '100', 'format_name': "'xml'", 'blank': 'True'}) + }, + 'social.cite': { + 'Meta': {'ordering': "('vip', 'text')", 'object_name': 'Cite'}, + 'book': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['catalogue.Book']"}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'image': ('django.db.models.fields.files.ImageField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}), + 'image_author': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}), + 'image_license': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}), + 'image_license_link': ('django.db.models.fields.URLField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}), + 'image_link': ('django.db.models.fields.URLField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}), + 'image_title': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}), + 'link': ('django.db.models.fields.URLField', [], {'max_length': '200'}), + 'small': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'sticky': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'text': ('django.db.models.fields.TextField', [], {}), + 'vip': ('django.db.models.fields.CharField', [], {'max_length': '128', 'null': 'True', 'blank': 'True'}) + } + } + + complete_apps = ['social'] \ No newline at end of file diff --git a/apps/social/models.py b/apps/social/models.py index 753980577..e1c7e379a 100644 --- a/apps/social/models.py +++ b/apps/social/models.py @@ -10,14 +10,30 @@ from catalogue.models import Book class Cite(models.Model): - book = models.ForeignKey(Book) + book = models.ForeignKey(Book, verbose_name=_('book')) text = models.TextField(_('text')) - small = models.BooleanField(_('small'), default=False, help_text=_('Make this cite display smaller.')) + small = models.BooleanField(_('small'), default=False, + help_text=_('Make this cite display smaller.')) vip = models.CharField(_('VIP'), max_length=128, null=True, blank=True) link = models.URLField(_('link')) + sticky = models.BooleanField(_('sticky'), default=False, db_index=True, + help_text=_('Sticky cites will take precedense.')) + + image = models.ImageField(_('image'), upload_to='social/cite', + null=True, blank=True) + image_title = models.CharField(_('title'), max_length=255, + null=True, blank=True) + image_author = models.CharField(_('author'), + max_length=255, blank=True, null=True) + image_link = models.URLField(_('link'), blank=True, null=True) + image_license = models.CharField(_('license name'), + max_length=255, blank=True, null=True) + image_license_link = models.URLField(_('license link'), blank=True, null=True) class Meta: ordering = ('vip', 'text') + verbose_name = _('cite') + verbose_name_plural = _('cites') def __unicode__(self): return u"%s: %s…" % (self.vip, self.text[:60]) diff --git a/apps/social/templatetags/social_tags.py b/apps/social/templatetags/social_tags.py index 29a43098b..889160200 100755 --- a/apps/social/templatetags/social_tags.py +++ b/apps/social/templatetags/social_tags.py @@ -12,9 +12,9 @@ register = template.Library() register.filter('likes', likes) -@register.inclusion_tag('social/cite_promo.html', takes_context=True) -def cite_promo(context, ctx=None, fallback=False): - """Choose""" +@register.assignment_tag(takes_context=True) +def choose_cite(context, ctx=None): + """Choose a cite for main page, for book or for set of tags.""" try: request = context['request'] assert request.user.is_staff @@ -29,10 +29,21 @@ def cite_promo(context, ctx=None, fallback=False): cites = cites_for_tags([ctx.book_tag()]) else: cites = cites_for_tags(ctx) - cite = cites.order_by('?')[0] if cites.exists() else None + cite = cites.order_by('-sticky', '?')[0] if cites.exists() else None + return cite + +@register.inclusion_tag('social/cite_promo.html') +def render_cite(cite): return { 'cite': cite, + } + + +@register.inclusion_tag('social/cite_promo.html', takes_context=True) +def cite_promo(context, ctx=None, fallback=False): + return { + 'cite': choose_cite(context, ctx), 'fallback': fallback, 'ctx': ctx, } diff --git a/apps/wolnelektury_core/templates/main_page.html b/apps/wolnelektury_core/templates/main_page.html index f9ff45ec4..9932b677b 100755 --- a/apps/wolnelektury_core/templates/main_page.html +++ b/apps/wolnelektury_core/templates/main_page.html @@ -7,9 +7,8 @@ {% block ogtitle %}{% trans "Wolne Lektury internet library" %}{% endblock %} {% block body %} - -
- {% cite_promo %} +
+ {% render_cite cite %}
{% spaceless %} @@ -89,8 +88,19 @@ {% block add_footer %}

{% trans "Image used:" %} -books about architecture, -saikofish@Flickr, -CC BY NC SA. +{% if cite.image %} + {% if cite.image_link %}{% endif %} + {% if cite.image_title %} + {{ cite.image_title }}{% else %} + untitled{% endif %}{% if cite.image_link %}{% endif %}, + {% if cite.image_author %}{{ cite.image_author }},{% endif %} + {% if cite.image_license_link %}{% endif %} + {{ cite.image_license }} + {% if cite.image_license_link %}{% endif %} +{% else %} + books about architecture, + saikofish@Flickr, + CC BY NC SA. +{% endif %}

{% endblock %} diff --git a/apps/wolnelektury_core/views.py b/apps/wolnelektury_core/views.py index f8de19efd..f62a1426a 100644 --- a/apps/wolnelektury_core/views.py +++ b/apps/wolnelektury_core/views.py @@ -16,11 +16,13 @@ from django.conf import settings from ajaxable.utils import AjaxableFormView from catalogue.models import Book from ajaxable.utils import placeholdized +from social.templatetags.social_tags import choose_cite @never_cache def main_page(request): last_published = Book.objects.filter(parent=None).order_by('-created_at')[:4] + cite = choose_cite(RequestContext(request)) return render_to_response("main_page.html", locals(), context_instance=RequestContext(request))