From: Radek Czajka Date: Wed, 25 Jan 2012 12:56:45 +0000 (+0100) Subject: allow marking long cites X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/640c22a3277a1483410fbff1696cf25881c2daad?ds=sidebyside allow marking long cites --- diff --git a/apps/catalogue/views.py b/apps/catalogue/views.py index 20fecb724..69bde8f2d 100644 --- a/apps/catalogue/views.py +++ b/apps/catalogue/views.py @@ -4,32 +4,25 @@ # import re import itertools -from datetime import datetime from django.conf import settings from django.template import RequestContext from django.shortcuts import render_to_response, get_object_or_404 from django.http import HttpResponse, HttpResponseRedirect, Http404, HttpResponsePermanentRedirect from django.core.urlresolvers import reverse -from django.db.models import Count, Sum, Q +from django.db.models import Q from django.contrib.auth.decorators import login_required, user_passes_test from django.utils.datastructures import SortedDict -from django.views.decorators.http import require_POST -from django.contrib import auth -from django.contrib.auth.forms import UserCreationForm, AuthenticationForm from django.utils.http import urlquote_plus -from django.views.decorators import cache from django.utils import translation from django.utils.translation import ugettext as _ -from django.views.generic.list_detail import object_list -from ajaxable.utils import LazyEncoder, JSONResponse, AjaxableFormView +from ajaxable.utils import JSONResponse, AjaxableFormView from catalogue import models from catalogue import forms from catalogue.utils import (split_tags, AttachmentHttpResponse, async_build_pdf, MultiQuerySet) -from catalogue.tasks import touch_tag from pdcounter import models as pdcounter_models from pdcounter import views as pdcounter_views from suggest.forms import PublishingSuggestForm diff --git a/apps/social/admin.py b/apps/social/admin.py index 298638ae5..f32f42612 100755 --- a/apps/social/admin.py +++ b/apps/social/admin.py @@ -7,4 +7,8 @@ from django.contrib import admin from social.models import Cite -admin.site.register(Cite) +class CiteAdmin(admin.ModelAdmin): + list_display = ['text', 'vip', 'small'] + + +admin.site.register(Cite, CiteAdmin) diff --git a/apps/social/migrations/0002_auto__add_field_cite_small.py b/apps/social/migrations/0002_auto__add_field_cite_small.py new file mode 100644 index 000000000..4490f74b5 --- /dev/null +++ b/apps/social/migrations/0002_auto__add_field_cite_small.py @@ -0,0 +1,58 @@ +# 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 field 'Cite.small' + db.add_column('social_cite', 'small', self.gf('django.db.models.fields.BooleanField')(default=False), keep_default=False) + + + def backwards(self, orm): + + # Deleting field 'Cite.small' + db.delete_column('social_cite', 'small') + + + 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'}), + 'small': ('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'] diff --git a/apps/social/models.py b/apps/social/models.py index 225477e20..753980577 100644 --- a/apps/social/models.py +++ b/apps/social/models.py @@ -4,6 +4,7 @@ # from django.db import models from django.utils.translation import ugettext_lazy as _ +from django.core.urlresolvers import reverse from catalogue.models import Book @@ -11,8 +12,16 @@ from catalogue.models import Book class Cite(models.Model): book = models.ForeignKey(Book) text = models.TextField(_('text')) + 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')) + class Meta: + ordering = ('vip', 'text') + + def __unicode__(self): + return u"%s: %s…" % (self.vip, self.text[:60]) + def get_absolute_url(self): - return self.link + """This is used for testing.""" + return "%s?choose_cite=%d" % (reverse('main_page'), self.id) diff --git a/apps/social/templates/social/cite_promo.html b/apps/social/templates/social/cite_promo.html index 04866f14b..ab4e6dd73 100755 --- a/apps/social/templates/social/cite_promo.html +++ b/apps/social/templates/social/cite_promo.html @@ -1,7 +1,7 @@ {% load i18n %} {% if cite %} - + {% if cite.vip %}

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

{% endif %} diff --git a/apps/social/templatetags/social_tags.py b/apps/social/templatetags/social_tags.py index e78f20f0a..29a43098b 100755 --- a/apps/social/templatetags/social_tags.py +++ b/apps/social/templatetags/social_tags.py @@ -12,20 +12,27 @@ register = template.Library() register.filter('likes', likes) -@register.inclusion_tag('social/cite_promo.html') -def cite_promo(ctx=None, fallback=False): +@register.inclusion_tag('social/cite_promo.html', takes_context=True) +def cite_promo(context, 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) + try: + request = context['request'] + assert request.user.is_staff + assert 'choose_cite' in request.GET + cite = Cite.objects.get(pk=request.GET['choose_cite']) + except AssertionError, Cite.DoesNotExist: + 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) + cite = cites.order_by('?')[0] if cites.exists() else None return { - 'cite': cites.order_by('?')[0] if cites.exists() else None, + 'cite': cite, 'fallback': fallback, 'ctx': ctx, } diff --git a/wolnelektury/static/css/cite.css b/wolnelektury/static/css/cite.css index c86ea6504..c06777f7e 100755 --- a/wolnelektury/static/css/cite.css +++ b/wolnelektury/static/css/cite.css @@ -21,6 +21,11 @@ a.cite { } +/* a long cite displays smaller */ +.cite-small .cite-body { + font-size: 1.4em; +} + #big-cite { @@ -46,6 +51,10 @@ a.cite { line-height: 1.2em; color: #191919; } +/* a long cite displays smaller */ +#big-cite .cite-small .cite-body { + font-size: 2em; +} #big-cite .source { diff --git a/wolnelektury/templates/catalogue/book_short.html b/wolnelektury/templates/catalogue/book_short.html index 9eae96fd8..dfe9ac5c6 100644 --- a/wolnelektury/templates/catalogue/book_short.html +++ b/wolnelektury/templates/catalogue/book_short.html @@ -40,8 +40,7 @@ {% for name, slug in related.tags.author %}
{{ name }}{% if not forloop.last %}, {% endif %}{% endfor %}{% for title, slug in related.parents %}, - {{ title }} - {% endfor %} + {{ title }}{% endfor %}
{{ book.title }}