#
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
--- /dev/null
+# 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']
#
from django.db import models
from django.utils.translation import ugettext_lazy as _
+from django.core.urlresolvers import reverse
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)
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,
}