From: Radek Czajka Date: Mon, 23 Jan 2012 13:25:37 +0000 (+0100) Subject: selected cites in admin X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/d0072de89eb395f99aedcdf7804e48b547cbbeca?ds=inline;hp=-c selected cites in admin --- d0072de89eb395f99aedcdf7804e48b547cbbeca diff --git a/apps/catalogue/templatetags/catalogue_tags.py b/apps/catalogue/templatetags/catalogue_tags.py index f6347e95d..ba8139a5e 100644 --- a/apps/catalogue/templatetags/catalogue_tags.py +++ b/apps/catalogue/templatetags/catalogue_tags.py @@ -323,8 +323,8 @@ def work_list(context, object_list): return locals() -@register.inclusion_tag('catalogue/chosen_fragment.html') -def promo_fragment(arg=None): +@register.inclusion_tag('catalogue/fragment_promo.html') +def fragment_promo(arg=None): if arg is None: fragments = Fragment.objects.all().order_by('?') fragment = fragments[0] if fragments.exists() else None diff --git a/apps/social/admin.py b/apps/social/admin.py new file mode 100755 index 000000000..298638ae5 --- /dev/null +++ b/apps/social/admin.py @@ -0,0 +1,10 @@ +# -*- 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.contrib import admin + +from social.models import Cite + + +admin.site.register(Cite) diff --git a/apps/social/migrations/0001_initial.py b/apps/social/migrations/0001_initial.py new file mode 100644 index 000000000..09ccc7fc4 --- /dev/null +++ b/apps/social/migrations/0001_initial.py @@ -0,0 +1,64 @@ +# 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): + + # Adding model 'Cite' + db.create_table('social_cite', ( + ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)), + ('book', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['catalogue.Book'])), + ('text', self.gf('django.db.models.fields.TextField')()), + ('vip', self.gf('django.db.models.fields.CharField')(max_length=128, null=True, blank=True)), + ('link', self.gf('django.db.models.fields.URLField')(max_length=200)), + )) + db.send_create_signal('social', ['Cite']) + + + def backwards(self, orm): + + # Deleting model 'Cite' + db.delete_table('social_cite') + + + 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', 'db_index': 'True'}), + 'cover': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'null': 'True', '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': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'blank': 'True'}), + 'extra_info': ('catalogue.fields.JSONField', [], {'default': "'{}'"}), + 'gazeta_link': ('django.db.models.fields.CharField', [], {'max_length': '240', 'blank': 'True'}), + 'html_file': ('django.db.models.fields.files.FileField', [], {'max_length': '100', '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': ('django.db.models.fields.files.FileField', [], {'max_length': '100', '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': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'blank': 'True'}), + 'slug': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '120', 'db_index': 'True'}), + 'sort_key': ('django.db.models.fields.CharField', [], {'max_length': '120', 'db_index': 'True'}), + 'title': ('django.db.models.fields.CharField', [], {'max_length': '120'}), + 'txt_file': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'blank': 'True'}), + 'wiki_link': ('django.db.models.fields.CharField', [], {'max_length': '240', 'blank': 'True'}), + 'xml_file': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'blank': 'True'}) + }, + 'social.cite': { + 'Meta': {'object_name': 'Cite'}, + 'book': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['catalogue.Book']"}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'link': ('django.db.models.fields.URLField', [], {'max_length': '200'}), + 'text': ('django.db.models.fields.TextField', [], {}), + 'vip': ('django.db.models.fields.CharField', [], {'max_length': '128', 'null': 'True', 'blank': 'True'}) + } + } + + complete_apps = ['social'] diff --git a/apps/social/models.py b/apps/social/models.py index 71a836239..225477e20 100644 --- a/apps/social/models.py +++ b/apps/social/models.py @@ -1,3 +1,18 @@ +# -*- 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.db import models +from django.utils.translation import ugettext_lazy as _ -# Create your models here. +from catalogue.models import Book + + +class Cite(models.Model): + book = models.ForeignKey(Book) + text = models.TextField(_('text')) + vip = models.CharField(_('VIP'), max_length=128, null=True, blank=True) + link = models.URLField(_('link')) + + def get_absolute_url(self): + return self.link diff --git a/apps/social/templates/social/cite_promo.html b/apps/social/templates/social/cite_promo.html new file mode 100755 index 000000000..5caaf1db5 --- /dev/null +++ b/apps/social/templates/social/cite_promo.html @@ -0,0 +1,18 @@ +{% load i18n %} + +{% if cite %} + + {% if cite.vip %} +

{{ cite.vip }} {% trans "recommends" %}:

+ {% endif %} +
+ {{ cite.text|linebreaks|safe }} +
+

{{ cite.book.pretty_title }}

+
+{% else %} + {% if fallback %} + {% load fragment_promo from catalogue_tags %} + {% fragment_promo ctx %} + {% endif %} +{% endif %} diff --git a/apps/social/templatetags/social_tags.py b/apps/social/templatetags/social_tags.py index 1b26d91c4..deac93df0 100755 --- a/apps/social/templatetags/social_tags.py +++ b/apps/social/templatetags/social_tags.py @@ -3,8 +3,29 @@ # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # from django import template -from social.utils import likes +from catalogue.models import Book +from social.models import Cite +from social.utils import likes, cites_for_tags register = template.Library() register.filter('likes', likes) + + +@register.inclusion_tag('social/cite_promo.html') +def cite_promo(ctx=None, fallback=False): + """Choose""" + if ctx is None: + cites = Cite.objects.all() + elif isinstance(ctx, Book): + cites = ctx.cite_set.all() + if not cites.exists(): + cites = cites_for_tags([ctx.book_tag()]) + else: + cites = cites_for_tags(ctx) + + return { + 'cite': cites.order_by('?')[0] if cites.exists() else None, + 'fallback': fallback, + 'ctx': ctx, + } \ No newline at end of file diff --git a/apps/social/utils.py b/apps/social/utils.py index 96f0ca0c7..00cf43e28 100755 --- a/apps/social/utils.py +++ b/apps/social/utils.py @@ -1,7 +1,8 @@ from django.db.models import Q -from catalogue.models import Tag +from catalogue.models import Book, Tag from catalogue import utils from catalogue.tasks import touch_tag +from social.models import Cite def likes(user, work): @@ -33,3 +34,10 @@ def set_sets(user, work, sets): # delete empty tags Tag.objects.filter(category='set', user=user, book_count=0).delete() + + +def cites_for_tags(tags): + """Returns a QuerySet with all Cites for books with given tags.""" + books = Book.tagged.with_all(tags).order_by().values_list('id', flat=True) + books = list(books) + return Cite.objects.filter(book__id__in=books) diff --git a/wolnelektury/settings.py b/wolnelektury/settings.py index 01f5737db..be5f32cbf 100644 --- a/wolnelektury/settings.py +++ b/wolnelektury/settings.py @@ -190,6 +190,7 @@ COMPRESS_CSS = { 'css/jquery.countdown.css', 'css/base.css', + 'css/cite.css', 'css/header.css', 'css/main_page.css', 'css/dialogs.css', diff --git a/wolnelektury/static/css/base.css b/wolnelektury/static/css/base.css index 556d926c7..a188285e2 100755 --- a/wolnelektury/static/css/base.css +++ b/wolnelektury/static/css/base.css @@ -136,22 +136,6 @@ h2 { } -a.cite { - display: block; - color: black; - background: white; - padding: 3em 2em .1em 8em; -} -.cite-body { - font-size: 1.8em; - line-height: 1.3em; -} -.cite p { - color: #444; - font-size: 1.1em; - margin-top: 1.6em; -} - .see-also { margin-left: 8em; float: left; diff --git a/wolnelektury/static/css/book_box.css b/wolnelektury/static/css/book_box.css index aefb4550f..2df2fa4e4 100755 --- a/wolnelektury/static/css/book_box.css +++ b/wolnelektury/static/css/book_box.css @@ -314,35 +314,3 @@ ul.inline-items li { .snippets .anchor { display: none; } - - -.cite blockquote p { - margin: 0; -} - -.cite blockquote { - padding: 0; - margin: 0; -} - -.book-wide-box .cite { - /* @ 18pt */ - width: 100%; /*23.055em;*/ - height: 7.222em; - background-color: #f7f7f7; - margin: 0; - position: relative; - top: -0.444em; - right: -0.555em; - vertical-align: center; -} - -.abook-wide-box blockquote div.cite-text { - padding: 0.888em; -} - -.abook-wide-box blockquote p.cite-more { - display: inline; - font-size: 0.611em; - float: right; -} diff --git a/wolnelektury/static/css/cite.css b/wolnelektury/static/css/cite.css new file mode 100755 index 000000000..54632976b --- /dev/null +++ b/wolnelektury/static/css/cite.css @@ -0,0 +1,78 @@ +a.cite { + display: block; + color: black; + background: white; + padding: 3em 2em .1em 8em; +} +.cite-body { + font-size: 1.8em; + line-height: 1.3em; +} +.cite p { + color: #444; + font-size: 1.1em; + margin-top: 1.6em; +} + +.cite .vip { + margin-top: 0; +} + + + + +#big-cite { + background-color: white; + /*padding: 10.75em 10em 8.5em 18.2em;*/ + padding: 0; + margin: 0; +} + +#big-cite .cite { + padding: 10.75em 10em 8.5em 18.2em; +} + +#big-cite h2 { + margin: 0; + font-size: 1.1em; + color: #575c63; +} + + +#big-cite .cite-body { + margin: .05em; + font-size: 2.8em; + line-height: 1.2em; + color: #191919; +} + + +#big-cite .source { + color: #00a1ac; + margin: 0; + font-size: 1.1em; + margin: 1.1em 0.2em; +} + + + + +.cite blockquote p { + margin: 0; +} + +.cite blockquote { + padding: 0; + margin: 0; +} + +.book-wide-box .cite { + position: relative; + top: -0.8em; + right: -1em; + background-color: #f7f7f7; + vertical-align: center; + width: 39.5em; + margin: 0; + padding: 1em; +} diff --git a/wolnelektury/static/css/main_page.css b/wolnelektury/static/css/main_page.css index 545e8d673..b32655bfd 100755 --- a/wolnelektury/static/css/main_page.css +++ b/wolnelektury/static/css/main_page.css @@ -1,36 +1,3 @@ -#big-cite { - background-color: white; - padding: 10.75em 10em 8.5em 18.2em; - margin: 0; -} - -#big-cite a { - color: black; - display: block; -} - -#big-cite h2 { - margin: 0; - font-size: 1.1em; - color: #575c63; -} - - -#big-cite-text { - margin: .05em; - font-size: 2.8em; - line-height: 1.2em; - color: #191919; -} - - -#big-cite-source { - color: #00a1ac; - margin: 0; - font-size: 1.1em; - margin: 1.1em 0.2em; -} - #promo-box { float: right; diff --git a/wolnelektury/templates/catalogue/book_wide.html b/wolnelektury/templates/catalogue/book_wide.html index da2754e8a..ebbea8c02 100644 --- a/wolnelektury/templates/catalogue/book_wide.html +++ b/wolnelektury/templates/catalogue/book_wide.html @@ -1,13 +1,13 @@ {% extends "catalogue/book_short.html" %} {% load i18n %} -{% load promo_fragment from catalogue_tags %} +{% load cite_promo from social_tags %} {% block box-class %}book-wide-box{% endblock %} {% block right-column %}
- {% promo_fragment book %} + {% cite_promo book 1 %}
diff --git a/wolnelektury/templates/catalogue/chosen_fragment.html b/wolnelektury/templates/catalogue/chosen_fragment.html deleted file mode 100755 index a23638e98..000000000 --- a/wolnelektury/templates/catalogue/chosen_fragment.html +++ /dev/null @@ -1,11 +0,0 @@ -{% load i18n %} -{% load removewholetags from catalogue_tags %} - -{% if fragment %} - -
- {{ fragment.text|removewholetags:"a"|truncatewords_html:15|safe }} -
-

Adam Mickiewicz, Dziady część III

-
-{% endif %} diff --git a/wolnelektury/templates/catalogue/fragment_promo.html b/wolnelektury/templates/catalogue/fragment_promo.html new file mode 100755 index 000000000..a3b01be16 --- /dev/null +++ b/wolnelektury/templates/catalogue/fragment_promo.html @@ -0,0 +1,10 @@ +{% load removewholetags from catalogue_tags %} + +{% if fragment %} + +
+ {{ fragment.text|removewholetags:"a"|truncatewords_html:15|safe }} +
+

{{ fragment.book.pretty_title }}

+
+{% endif %} diff --git a/wolnelektury/templates/catalogue/tagged_object_list.html b/wolnelektury/templates/catalogue/tagged_object_list.html index 443276d0a..0777d84ee 100644 --- a/wolnelektury/templates/catalogue/tagged_object_list.html +++ b/wolnelektury/templates/catalogue/tagged_object_list.html @@ -1,6 +1,6 @@ {% extends "base.html" %} {% load i18n %} -{% load catalogue_tags switch_tag %} +{% load catalogue_tags switch_tag social_tags %} {% block titleextra %}{% title_from_tags tags %}{% endblock %} @@ -59,7 +59,7 @@
- {% promo_fragment tags %} + {% cite_promo tags 1 %}

{% trans "See also" %}:

diff --git a/wolnelektury/templates/main_page.html b/wolnelektury/templates/main_page.html index 988bbb344..b4907129b 100755 --- a/wolnelektury/templates/main_page.html +++ b/wolnelektury/templates/main_page.html @@ -1,21 +1,14 @@ {% extends "base.html" %} -{% load cache i18n catalogue_tags infopages_tags %} +{% load cache i18n catalogue_tags infopages_tags social_tags %} {% block title %}{% trans "Wolne Lektury internet library" %}{% endblock %} {% block body %} -
- -

Jarosław Lipszyc poleca:

-

Dobranoc, obróć jeszcze raz na mnie oczęta,
- (…) Daj mi pierś ucałować
- Dobranoc, zapięta.

-

Adam Mickiewicz, Dziady część III

-
-
- +
+ {% cite_promo %} +
{% spaceless %}