From: Radek Czajka Date: Tue, 19 Nov 2013 13:10:35 +0000 (+0100) Subject: Merge branch 'master' into rwd X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/64cf4d889127d7dc3ea893e8a27711468276dc47?hp=09896b8a45c2ece2748710090b6130ba32cf9706 Merge branch 'master' into rwd Conflicts: apps/catalogue/templates/catalogue/book_short.html apps/funding/static/funding/funding.css apps/wolnelektury_core/templates/main_page.html --- diff --git a/apps/api/handlers.py b/apps/api/handlers.py index da5c0ed27..b436024b1 100644 --- a/apps/api/handlers.py +++ b/apps/api/handlers.py @@ -18,6 +18,7 @@ from api.helpers import timestamp from api.models import Deleted from catalogue.forms import BookImportForm from catalogue.models import Book, Tag, BookMedia, Fragment, Collection +from catalogue.utils import related_tag_name from picture.models import Picture from picture.forms import PictureImportForm @@ -244,7 +245,7 @@ def _tags_getter(category): def _tag_getter(category): @classmethod def get_tag(cls, book): - return ", ".join(t[0] for t in book.related_info()['tags'].get(category, [])) + return ", ".join(related_tag_name(t) for t in book.related_info()['tags'].get(category, [])) return get_tag for plural, singular in category_singular.items(): setattr(BookDetails, plural, _tags_getter(singular)) diff --git a/apps/catalogue/constants.py b/apps/catalogue/constants.py index bfad4b075..36f4f5dd3 100644 --- a/apps/catalogue/constants.py +++ b/apps/catalogue/constants.py @@ -21,3 +21,18 @@ EBOOK_FORMATS_WITH_CHILDREN = ['pdf', 'epub', 'mobi'] EBOOK_FORMATS_WITH_COVERS = ['pdf', 'epub', 'mobi'] EBOOK_FORMATS = EBOOK_FORMATS_WITHOUT_CHILDREN + EBOOK_FORMATS_WITH_CHILDREN + +LANGUAGES_3TO2 = { + 'deu': 'de', + 'ger': 'de', + 'eng': 'en', + 'spa': 'es', + 'fra': 'fr', + 'fre': 'fr', + 'ita': 'it', + 'jpn': 'jp', + 'lit': 'lt', + 'pol': 'pl', + 'rus': 'ru', + 'ukr': 'uk', +} diff --git a/apps/catalogue/fields.py b/apps/catalogue/fields.py index bb9f26efe..e2978e877 100644 --- a/apps/catalogue/fields.py +++ b/apps/catalogue/fields.py @@ -7,6 +7,7 @@ from django.core.files import File from django.db import models from django.db.models.fields.files import FieldFile from catalogue import app_settings +from catalogue.constants import LANGUAGES_3TO2 from catalogue.utils import remove_zip, truncate_html_words from celery.task import Task, task from waiter.utils import clear_cache @@ -140,6 +141,11 @@ class BuildHtml(BuildEbook): html_output = self.transform( book.wldocument(parse_dublincore=False), fieldfile) + lang = book.language + lang = LANGUAGES_3TO2.get(lang, lang) + if lang not in [ln[0] for ln in settings.LANGUAGES]: + lang = None + if html_output: fieldfile.save(None, ContentFile(html_output.get_string()), save=False) @@ -167,14 +173,26 @@ class BuildHtml(BuildEbook): for theme_name in theme_names: if not theme_name: continue - tag, created = Tag.objects.get_or_create( - slug=slughifi(theme_name), - category='theme') - if created: - tag.name = theme_name - tag.sort_key = sortify(theme_name.lower()) - tag.save() - themes.append(tag) + if lang == settings.LANGUAGE_CODE: + # Allow creating themes if book in default language. + tag, created = Tag.objects.get_or_create( + slug=slughifi(theme_name), + category='theme') + if created: + tag.name = theme_name + setattr(tag, "name_%s" % lang, theme_name) + tag.sort_key = sortify(theme_name.lower()) + tag.save() + themes.append(tag) + elif lang is not None: + # Don't create unknown themes in non-default languages. + try: + tag = Tag.objects.get(category='theme', + **{"name_%s" % lang: theme_name}) + except Tag.DoesNotExist: + pass + else: + themes.append(tag) if not themes: continue diff --git a/apps/catalogue/migrations/0007_auto__add_field_tag_name_de__add_field_tag_name_en__add_field_tag_name.py b/apps/catalogue/migrations/0007_auto__add_field_tag_name_de__add_field_tag_name_en__add_field_tag_name.py new file mode 100644 index 000000000..641095791 --- /dev/null +++ b/apps/catalogue/migrations/0007_auto__add_field_tag_name_de__add_field_tag_name_en__add_field_tag_name.py @@ -0,0 +1,289 @@ +# -*- 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 'Tag.name_de' + db.add_column(u'catalogue_tag', 'name_de', + self.gf('django.db.models.fields.CharField')(blank=True, max_length=50, null=True, db_index=True), + keep_default=False) + + # Adding field 'Tag.name_en' + db.add_column(u'catalogue_tag', 'name_en', + self.gf('django.db.models.fields.CharField')(blank=True, max_length=50, null=True, db_index=True), + keep_default=False) + + # Adding field 'Tag.name_es' + db.add_column(u'catalogue_tag', 'name_es', + self.gf('django.db.models.fields.CharField')(blank=True, max_length=50, null=True, db_index=True), + keep_default=False) + + # Adding field 'Tag.name_fr' + db.add_column(u'catalogue_tag', 'name_fr', + self.gf('django.db.models.fields.CharField')(blank=True, max_length=50, null=True, db_index=True), + keep_default=False) + + # Adding field 'Tag.name_it' + db.add_column(u'catalogue_tag', 'name_it', + self.gf('django.db.models.fields.CharField')(blank=True, max_length=50, null=True, db_index=True), + keep_default=False) + + # Adding field 'Tag.name_lt' + db.add_column(u'catalogue_tag', 'name_lt', + self.gf('django.db.models.fields.CharField')(blank=True, max_length=50, null=True, db_index=True), + keep_default=False) + + # Adding field 'Tag.name_pl' + db.add_column(u'catalogue_tag', 'name_pl', + self.gf('django.db.models.fields.CharField')(blank=True, max_length=50, null=True, db_index=True), + keep_default=False) + + # Adding field 'Tag.name_ru' + db.add_column(u'catalogue_tag', 'name_ru', + self.gf('django.db.models.fields.CharField')(blank=True, max_length=50, null=True, db_index=True), + keep_default=False) + + # Adding field 'Tag.name_uk' + db.add_column(u'catalogue_tag', 'name_uk', + self.gf('django.db.models.fields.CharField')(blank=True, max_length=50, null=True, db_index=True), + keep_default=False) + + # Adding field 'Tag.description_de' + db.add_column(u'catalogue_tag', 'description_de', + self.gf('django.db.models.fields.TextField')(null=True, blank=True), + keep_default=False) + + # Adding field 'Tag.description_en' + db.add_column(u'catalogue_tag', 'description_en', + self.gf('django.db.models.fields.TextField')(null=True, blank=True), + keep_default=False) + + # Adding field 'Tag.description_es' + db.add_column(u'catalogue_tag', 'description_es', + self.gf('django.db.models.fields.TextField')(null=True, blank=True), + keep_default=False) + + # Adding field 'Tag.description_fr' + db.add_column(u'catalogue_tag', 'description_fr', + self.gf('django.db.models.fields.TextField')(null=True, blank=True), + keep_default=False) + + # Adding field 'Tag.description_it' + db.add_column(u'catalogue_tag', 'description_it', + self.gf('django.db.models.fields.TextField')(null=True, blank=True), + keep_default=False) + + # Adding field 'Tag.description_lt' + db.add_column(u'catalogue_tag', 'description_lt', + self.gf('django.db.models.fields.TextField')(null=True, blank=True), + keep_default=False) + + # Adding field 'Tag.description_pl' + db.add_column(u'catalogue_tag', 'description_pl', + self.gf('django.db.models.fields.TextField')(null=True, blank=True), + keep_default=False) + + # Adding field 'Tag.description_ru' + db.add_column(u'catalogue_tag', 'description_ru', + self.gf('django.db.models.fields.TextField')(null=True, blank=True), + keep_default=False) + + # Adding field 'Tag.description_uk' + db.add_column(u'catalogue_tag', 'description_uk', + self.gf('django.db.models.fields.TextField')(null=True, blank=True), + keep_default=False) + + + def backwards(self, orm): + # Deleting field 'Tag.name_de' + db.delete_column(u'catalogue_tag', 'name_de') + + # Deleting field 'Tag.name_en' + db.delete_column(u'catalogue_tag', 'name_en') + + # Deleting field 'Tag.name_es' + db.delete_column(u'catalogue_tag', 'name_es') + + # Deleting field 'Tag.name_fr' + db.delete_column(u'catalogue_tag', 'name_fr') + + # Deleting field 'Tag.name_it' + db.delete_column(u'catalogue_tag', 'name_it') + + # Deleting field 'Tag.name_lt' + db.delete_column(u'catalogue_tag', 'name_lt') + + # Deleting field 'Tag.name_pl' + db.delete_column(u'catalogue_tag', 'name_pl') + + # Deleting field 'Tag.name_ru' + db.delete_column(u'catalogue_tag', 'name_ru') + + # Deleting field 'Tag.name_uk' + db.delete_column(u'catalogue_tag', 'name_uk') + + # Deleting field 'Tag.description_de' + db.delete_column(u'catalogue_tag', 'description_de') + + # Deleting field 'Tag.description_en' + db.delete_column(u'catalogue_tag', 'description_en') + + # Deleting field 'Tag.description_es' + db.delete_column(u'catalogue_tag', 'description_es') + + # Deleting field 'Tag.description_fr' + db.delete_column(u'catalogue_tag', 'description_fr') + + # Deleting field 'Tag.description_it' + db.delete_column(u'catalogue_tag', 'description_it') + + # Deleting field 'Tag.description_lt' + db.delete_column(u'catalogue_tag', 'description_lt') + + # Deleting field 'Tag.description_pl' + db.delete_column(u'catalogue_tag', 'description_pl') + + # Deleting field 'Tag.description_ru' + db.delete_column(u'catalogue_tag', 'description_ru') + + # Deleting field 'Tag.description_uk' + db.delete_column(u'catalogue_tag', 'description_uk') + + + models = { + u'auth.group': { + 'Meta': {'object_name': 'Group'}, + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}), + 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}) + }, + u'auth.permission': { + 'Meta': {'ordering': "(u'content_type__app_label', u'content_type__model', u'codename')", 'unique_together': "((u'content_type', u'codename'),)", 'object_name': 'Permission'}, + 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['contenttypes.ContentType']"}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}) + }, + u'auth.user': { + 'Meta': {'object_name': 'User'}, + 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), + 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}), + 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), + 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), + 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), + 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), + 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}), + 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}), + 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'}) + }, + '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'}), + u'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'}) + }, + 'catalogue.bookmedia': { + 'Meta': {'ordering': "('type', 'name')", 'object_name': 'BookMedia'}, + 'book': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'media'", 'to': "orm['catalogue.Book']"}), + 'extra_info': ('jsonfield.fields.JSONField', [], {'default': '{}'}), + 'file': ('catalogue.fields.OverwritingFileField', [], {'max_length': '100'}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': "'100'"}), + 'source_sha1': ('django.db.models.fields.CharField', [], {'max_length': '40', 'null': 'True', 'blank': 'True'}), + 'type': ('django.db.models.fields.CharField', [], {'max_length': "'100'", 'db_index': 'True'}), + 'uploaded_at': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'db_index': 'True', 'blank': 'True'}) + }, + 'catalogue.collection': { + 'Meta': {'ordering': "('title',)", 'object_name': 'Collection'}, + 'book_slugs': ('django.db.models.fields.TextField', [], {}), + 'description': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}), + 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '120', 'primary_key': 'True'}), + 'title': ('django.db.models.fields.CharField', [], {'max_length': '120', 'db_index': 'True'}) + }, + 'catalogue.fragment': { + 'Meta': {'ordering': "('book', 'anchor')", 'object_name': 'Fragment'}, + 'anchor': ('django.db.models.fields.CharField', [], {'max_length': '120'}), + 'book': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'fragments'", 'to': "orm['catalogue.Book']"}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'short_text': ('django.db.models.fields.TextField', [], {}), + 'text': ('django.db.models.fields.TextField', [], {}) + }, + 'catalogue.tag': { + 'Meta': {'ordering': "('sort_key',)", 'unique_together': "(('slug', 'category'),)", 'object_name': 'Tag'}, + 'book_count': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}), + 'category': ('django.db.models.fields.CharField', [], {'max_length': '50', 'db_index': 'True'}), + 'changed_at': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'db_index': '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'}), + 'description_de': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}), + 'description_en': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}), + 'description_es': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}), + 'description_fr': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}), + 'description_it': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}), + 'description_lt': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}), + 'description_pl': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}), + 'description_ru': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}), + 'description_uk': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}), + 'gazeta_link': ('django.db.models.fields.CharField', [], {'max_length': '240', 'blank': 'True'}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '50', 'db_index': 'True'}), + 'name_de': ('django.db.models.fields.CharField', [], {'blank': True, 'max_length': '50', 'null': True, 'db_index': 'True'}), + 'name_en': ('django.db.models.fields.CharField', [], {'blank': True, 'max_length': '50', 'null': True, 'db_index': 'True'}), + 'name_es': ('django.db.models.fields.CharField', [], {'blank': True, 'max_length': '50', 'null': True, 'db_index': 'True'}), + 'name_fr': ('django.db.models.fields.CharField', [], {'blank': True, 'max_length': '50', 'null': True, 'db_index': 'True'}), + 'name_it': ('django.db.models.fields.CharField', [], {'blank': True, 'max_length': '50', 'null': True, 'db_index': 'True'}), + 'name_lt': ('django.db.models.fields.CharField', [], {'blank': True, 'max_length': '50', 'null': True, 'db_index': 'True'}), + 'name_pl': ('django.db.models.fields.CharField', [], {'blank': True, 'max_length': '50', 'null': True, 'db_index': 'True'}), + 'name_ru': ('django.db.models.fields.CharField', [], {'blank': True, 'max_length': '50', 'null': True, 'db_index': 'True'}), + 'name_uk': ('django.db.models.fields.CharField', [], {'blank': True, 'max_length': '50', 'null': True, 'db_index': 'True'}), + 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '120'}), + 'sort_key': ('django.db.models.fields.CharField', [], {'max_length': '120', 'db_index': 'True'}), + 'user': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['auth.User']", 'null': 'True', 'blank': 'True'}), + 'wiki_link': ('django.db.models.fields.CharField', [], {'max_length': '240', 'blank': 'True'}) + }, + 'catalogue.tagrelation': { + 'Meta': {'unique_together': "(('tag', 'content_type', 'object_id'),)", 'object_name': 'TagRelation', 'db_table': "u'catalogue_tag_relation'"}, + 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['contenttypes.ContentType']"}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'object_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}), + 'tag': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'items'", 'to': "orm['catalogue.Tag']"}) + }, + u'contenttypes.contenttype': { + 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"}, + 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}) + } + } + + complete_apps = ['catalogue'] \ No newline at end of file diff --git a/apps/catalogue/migrations/0008_clear_related.py b/apps/catalogue/migrations/0008_clear_related.py new file mode 100644 index 000000000..3a9892d8e --- /dev/null +++ b/apps/catalogue/migrations/0008_clear_related.py @@ -0,0 +1,155 @@ +# -*- coding: utf-8 -*- +import datetime +from south.db import db +from south.v2 import DataMigration +from django.db import models +from django.conf import settings + +class Migration(DataMigration): + + def forwards(self, orm): + "Write your forwards methods here." + # Note: Remember to use orm['appname.ModelName'] rather than "from appname.models..." + for t in orm.Tag.objects.filter(category__in=('author', 'epoch', 'genre', 'kind', 'theme')): + setattr(t, "name_%s" % settings.LANGUAGE_CODE, t.name) + t.save() + orm.Book.objects.all().update(_related_info=None) + + def backwards(self, orm): + "Write your backwards methods here." + orm.Book.objects.all().update(_related_info=None) + + + models = { + u'auth.group': { + 'Meta': {'object_name': 'Group'}, + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}), + 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}) + }, + u'auth.permission': { + 'Meta': {'ordering': "(u'content_type__app_label', u'content_type__model', u'codename')", 'unique_together': "((u'content_type', u'codename'),)", 'object_name': 'Permission'}, + 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['contenttypes.ContentType']"}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}) + }, + u'auth.user': { + 'Meta': {'object_name': 'User'}, + 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), + 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}), + 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), + 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), + 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), + 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), + 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}), + 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}), + 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'}) + }, + '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'}), + u'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'}) + }, + 'catalogue.bookmedia': { + 'Meta': {'ordering': "('type', 'name')", 'object_name': 'BookMedia'}, + 'book': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'media'", 'to': "orm['catalogue.Book']"}), + 'extra_info': ('jsonfield.fields.JSONField', [], {'default': '{}'}), + 'file': ('catalogue.fields.OverwritingFileField', [], {'max_length': '100'}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': "'100'"}), + 'source_sha1': ('django.db.models.fields.CharField', [], {'max_length': '40', 'null': 'True', 'blank': 'True'}), + 'type': ('django.db.models.fields.CharField', [], {'max_length': "'100'", 'db_index': 'True'}), + 'uploaded_at': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'db_index': 'True', 'blank': 'True'}) + }, + 'catalogue.collection': { + 'Meta': {'ordering': "('title',)", 'object_name': 'Collection'}, + 'book_slugs': ('django.db.models.fields.TextField', [], {}), + 'description': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}), + 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '120', 'primary_key': 'True'}), + 'title': ('django.db.models.fields.CharField', [], {'max_length': '120', 'db_index': 'True'}) + }, + 'catalogue.fragment': { + 'Meta': {'ordering': "('book', 'anchor')", 'object_name': 'Fragment'}, + 'anchor': ('django.db.models.fields.CharField', [], {'max_length': '120'}), + 'book': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'fragments'", 'to': "orm['catalogue.Book']"}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'short_text': ('django.db.models.fields.TextField', [], {}), + 'text': ('django.db.models.fields.TextField', [], {}) + }, + 'catalogue.tag': { + 'Meta': {'ordering': "('sort_key',)", 'unique_together': "(('slug', 'category'),)", 'object_name': 'Tag'}, + 'book_count': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}), + 'category': ('django.db.models.fields.CharField', [], {'max_length': '50', 'db_index': 'True'}), + 'changed_at': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'db_index': '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'}), + 'description_de': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}), + 'description_en': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}), + 'description_es': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}), + 'description_fr': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}), + 'description_it': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}), + 'description_lt': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}), + 'description_pl': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}), + 'description_ru': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}), + 'description_uk': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}), + 'gazeta_link': ('django.db.models.fields.CharField', [], {'max_length': '240', 'blank': 'True'}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '50', 'db_index': 'True'}), + 'name_de': ('django.db.models.fields.CharField', [], {'blank': True, 'max_length': '50', 'null': True, 'db_index': 'True'}), + 'name_en': ('django.db.models.fields.CharField', [], {'blank': True, 'max_length': '50', 'null': True, 'db_index': 'True'}), + 'name_es': ('django.db.models.fields.CharField', [], {'blank': True, 'max_length': '50', 'null': True, 'db_index': 'True'}), + 'name_fr': ('django.db.models.fields.CharField', [], {'blank': True, 'max_length': '50', 'null': True, 'db_index': 'True'}), + 'name_it': ('django.db.models.fields.CharField', [], {'blank': True, 'max_length': '50', 'null': True, 'db_index': 'True'}), + 'name_lt': ('django.db.models.fields.CharField', [], {'blank': True, 'max_length': '50', 'null': True, 'db_index': 'True'}), + 'name_pl': ('django.db.models.fields.CharField', [], {'blank': True, 'max_length': '50', 'null': True, 'db_index': 'True'}), + 'name_ru': ('django.db.models.fields.CharField', [], {'blank': True, 'max_length': '50', 'null': True, 'db_index': 'True'}), + 'name_uk': ('django.db.models.fields.CharField', [], {'blank': True, 'max_length': '50', 'null': True, 'db_index': 'True'}), + 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '120'}), + 'sort_key': ('django.db.models.fields.CharField', [], {'max_length': '120', 'db_index': 'True'}), + 'user': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['auth.User']", 'null': 'True', 'blank': 'True'}), + 'wiki_link': ('django.db.models.fields.CharField', [], {'max_length': '240', 'blank': 'True'}) + }, + 'catalogue.tagrelation': { + 'Meta': {'unique_together': "(('tag', 'content_type', 'object_id'),)", 'object_name': 'TagRelation', 'db_table': "u'catalogue_tag_relation'"}, + 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['contenttypes.ContentType']"}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'object_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}), + 'tag': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'items'", 'to': "orm['catalogue.Tag']"}) + }, + u'contenttypes.contenttype': { + 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"}, + 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}) + } + } + + complete_apps = ['catalogue'] + symmetrical = True diff --git a/apps/catalogue/models/book.py b/apps/catalogue/models/book.py index d69cf2aca..c865d1d87 100644 --- a/apps/catalogue/models/book.py +++ b/apps/catalogue/models/book.py @@ -3,7 +3,7 @@ # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # import re -from django.conf import settings as settings +from django.conf import settings from django.core.cache import get_cache from django.db import models from django.db.models import permalink @@ -14,7 +14,7 @@ import jsonfield from catalogue import constants from catalogue.fields import EbookField from catalogue.models import Tag, Fragment, BookMedia -from catalogue.utils import create_zip, split_tags, book_upload_path +from catalogue.utils import create_zip, split_tags, book_upload_path, related_tag_name from catalogue import app_settings from catalogue import tasks from newtagging import managers @@ -36,7 +36,7 @@ class Book(models.Model): created_at = models.DateTimeField(_('creation date'), auto_now_add=True, db_index=True) changed_at = models.DateTimeField(_('creation date'), auto_now=True, db_index=True) parent_number = models.IntegerField(_('parent number'), default=0) - extra_info = jsonfield.JSONField(_('extra information'), default='{}') + extra_info = jsonfield.JSONField(_('extra information'), default={}) gazeta_link = models.CharField(blank=True, max_length=240) wiki_link = models.CharField(blank=True, max_length=240) # files generated during publication @@ -402,8 +402,15 @@ class Book(models.Model): 'author', 'kind', 'genre', 'epoch')) tags = split_tags(tags) for category in tags: - rel['tags'][category] = [ - (t.name, t.slug) for t in tags[category]] + cat = [] + for tag in tags[category]: + tag_info = {'slug': tag.slug} + for lc, ln in settings.LANGUAGES: + tag_name = getattr(tag, "name_%s" % lc) + if tag_name: + tag_info["name_%s" % lc] = tag_name + cat.append(tag_info) + rel['tags'][category] = cat for media_format in BookMedia.formats: rel['media'][media_format] = self.has_media(media_format) @@ -487,8 +494,8 @@ class Book(models.Model): def pretty_title(self, html_links=False): book = self rel_info = book.related_info() - names = [(name, Tag.create_url('author', slug)) - for name, slug in rel_info['tags']['author']] + names = [(related_tag_name(tag), Tag.create_url('author', tag['slug'])) + for tag in rel_info['tags'].get('author', ())] if 'parents' in rel_info: books = [(name, Book.create_url(slug)) for name, slug in rel_info['parents']] diff --git a/apps/catalogue/models/bookmedia.py b/apps/catalogue/models/bookmedia.py index 88f60f16a..186bb405c 100644 --- a/apps/catalogue/models/bookmedia.py +++ b/apps/catalogue/models/bookmedia.py @@ -27,7 +27,7 @@ class BookMedia(models.Model): name = models.CharField(_('name'), max_length="100") file = OverwritingFileField(_('file'), upload_to=book_upload_path()) uploaded_at = models.DateTimeField(_('creation date'), auto_now_add=True, editable=False, db_index=True) - extra_info = jsonfield.JSONField(_('extra information'), default='{}', editable=False) + extra_info = jsonfield.JSONField(_('extra information'), default={}, editable=False) book = models.ForeignKey('Book', related_name='media') source_sha1 = models.CharField(null=True, blank=True, max_length=40, editable=False) diff --git a/apps/catalogue/models/listeners.py b/apps/catalogue/models/listeners.py index 373a2fcc8..5ef7e9efd 100644 --- a/apps/catalogue/models/listeners.py +++ b/apps/catalogue/models/listeners.py @@ -8,6 +8,7 @@ from django.db.models.signals import post_save, pre_delete, post_delete import django.dispatch from catalogue.models import Tag, BookMedia, Book, Fragment, Collection from catalogue import tasks +from catalogue.utils import delete_from_cache_by_language from newtagging.models import tags_updated @@ -43,8 +44,8 @@ pre_delete.connect(_pre_delete_handler) def _post_delete_handler(sender, instance, **kwargs): """ refresh Book on BookMedia delete """ if sender == Collection: - permanent_cache.delete('catalogue.collection:%s' % instance.slug) - permanent_cache.delete('catalogue.catalogue') + delete_from_cache_by_language(permanent_cache, 'catalogue.collection:%s/%%s' % instance.slug) + delete_from_cache_by_language(permanent_cache, 'catalogue.catalogue/%s') post_delete.connect(_post_delete_handler) @@ -52,17 +53,17 @@ def _post_save_handler(sender, instance, **kwargs): """ refresh all the short_html stuff on BookMedia update """ if sender == BookMedia: instance.book.save() - permanent_cache.delete_many([ - 'catalogue.audiobook_list', 'catalogue.daisy_list']) + delete_from_cache_by_language(permanent_cache, 'catalogue.audiobook_list/%s') + delete_from_cache_by_language(permanent_cache, 'catalogue.daisy_list/%s') elif sender == Collection: - permanent_cache.delete('catalogue.collection:%s' % instance.slug) - permanent_cache.delete('catalogue.catalogue') + delete_from_cache_by_language(permanent_cache, 'catalogue.collection:%s/%%s' % instance.slug) + delete_from_cache_by_language(permanent_cache, 'catalogue.catalogue/%s') post_save.connect(_post_save_handler) def post_publish(sender, **kwargs): - permanent_cache.delete('catalogue.book_list') - permanent_cache.delete('catalogue.catalogue') + delete_from_cache_by_language(permanent_cache, 'catalogue.book_list/%s') + delete_from_cache_by_language(permanent_cache, 'catalogue.catalogue/%s') Book.published.connect(post_publish) diff --git a/apps/catalogue/models/tag.py b/apps/catalogue/models/tag.py index b0c75fbb4..1309cbbd2 100644 --- a/apps/catalogue/models/tag.py +++ b/apps/catalogue/models/tag.py @@ -2,6 +2,7 @@ # 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 import settings from django.contrib.auth.models import User from django.core.exceptions import ValidationError from django.db import models @@ -166,14 +167,26 @@ class Tag(TagBase): # For instance, Pictures do not have 'genre' field. continue for tag_name in tag_names: + lang = getattr(tag_name, 'lang', settings.LANGUAGE_CODE) tag_sort_key = tag_name if category == 'author': tag_sort_key = tag_name.last_name tag_name = tag_name.readable() - tag, created = Tag.objects.get_or_create(slug=slughifi(tag_name), category=category) - if created: - tag.name = tag_name - tag.sort_key = sortify(tag_sort_key.lower()) - tag.save() - meta_tags.append(tag) + if lang == settings.LANGUAGE_CODE: + # Allow creating new tag, if it's in default language. + tag, created = Tag.objects.get_or_create(slug=slughifi(tag_name), category=category) + if created: + tag.name = tag_name + setattr(tag, "name_%s" % lang, tag_name) + tag.sort_key = sortify(tag_sort_key.lower()) + tag.save() + meta_tags.append(tag) + else: + # Ignore unknown tags in non-default languages. + try: + tag = Tag.objects.get(category=category, **{"name_%s" % lang: tag_name}) + except Tag.DoesNotExist: + pass + else: + meta_tags.append(tag) return meta_tags diff --git a/apps/catalogue/templates/catalogue/book_detail.html b/apps/catalogue/templates/catalogue/book_detail.html index bf8a726f1..480c85a28 100644 --- a/apps/catalogue/templates/catalogue/book_detail.html +++ b/apps/catalogue/templates/catalogue/book_detail.html @@ -1,7 +1,7 @@ {% extends "base.html" %} -{% load cache i18n %} +{% load i18n %} {% load thumbnail %} -{% load common_tags catalogue_tags pagination_tags %} +{% load common_tags catalogue_tags %} {% block titleextra %}{{ book.pretty_title }}{% endblock %} {% block ogimage %}{% if book.cover %}{{ book.cover.url|build_absolute_uri:request }}{% endif %}{% endblock %} diff --git a/apps/catalogue/templates/catalogue/book_short.html b/apps/catalogue/templates/catalogue/book_short.html index c8fb9520b..4acefe285 100644 --- a/apps/catalogue/templates/catalogue/book_short.html +++ b/apps/catalogue/templates/catalogue/book_short.html @@ -28,8 +28,8 @@
- {% for name, slug in related.tags.author %} - {{ name }}{% if not forloop.last %}, + {% for tag in related.tags.author %} + {% related_tag_name tag %}{% if not forloop.last %}, {% endif %}{% endfor %}{% for title, slug in related.parents %}, {{ title }}{% endfor %}
@@ -59,24 +59,24 @@ {% trans "Epoch" %}:  - {% for name, slug in related.tags.epoch %} - {{ name }} + {% for tag in related.tags.epoch %} + {% related_tag_name tag %} {% if not forloop.last %}, {% endif %} {% endfor %} {% trans "Kind" %}:  - {% for name, slug in related.tags.kind %} - {{ name }} + {% for tag in related.tags.kind %} + {% related_tag_name tag %} {% if not forloop.last %}, {% endif %} {% endfor %} {% trans "Genre" %}:  - {% for name, slug in related.tags.genre %} - {{ name }} + {% for tag in related.tags.genre %} + {% related_tag_name tag %} {% if not forloop.last %}, {% endif %} {% endfor %} diff --git a/apps/catalogue/templatetags/catalogue_tags.py b/apps/catalogue/templatetags/catalogue_tags.py index 6a30a9c26..d6a795fb4 100644 --- a/apps/catalogue/templatetags/catalogue_tags.py +++ b/apps/catalogue/templatetags/catalogue_tags.py @@ -14,7 +14,7 @@ from django.core.urlresolvers import reverse from django.contrib.auth.forms import UserCreationForm, AuthenticationForm from django.utils.translation import ugettext as _ -from catalogue.utils import split_tags +from catalogue.utils import split_tags, related_tag_name as _related_tag_name from catalogue.models import Book, BookMedia, Fragment, Tag from catalogue.constants import LICENSES @@ -350,8 +350,8 @@ def book_short(context, book): @register.inclusion_tag('catalogue/book_mini_box.html') def book_mini(book): - author_str = ", ".join(name - for name, url in book.related_info()['tags']['author']) + author_str = ", ".join(related_tag_name(tag) + for tag in book.related_info()['tags'].get('author', ())) return { 'book': book, 'author_str': author_str, @@ -463,3 +463,8 @@ def license_icon(license_url): "icon": "img/licenses/%s.png" % known['icon'], "license_description": known['description'], } + + +@register.simple_tag +def related_tag_name(tag, lang=None): + return _related_tag_name(tag, lang) diff --git a/apps/catalogue/tests/tags.py b/apps/catalogue/tests/tags.py index 2608eb632..99edebbe7 100644 --- a/apps/catalogue/tests/tags.py +++ b/apps/catalogue/tests/tags.py @@ -225,7 +225,7 @@ class TestIdenticalTag(WLTestCase): related_info = book.related_info() related_themes = book.related_themes() for category in 'author', 'kind', 'genre', 'epoch': - self.assertTrue('tag' in [tag[1] for tag in related_info['tags'][category]], + self.assertTrue('tag' in [tag['slug'] for tag in related_info['tags'][category]], 'missing related tag for %s' % category) self.assertTrue('tag' in [tag.slug for tag in related_themes]) @@ -271,9 +271,9 @@ class BookTagsTests(WLTestCase): related_themes = book.related_themes() self.assertEqual(related_info['tags']['author'], - [('Common Man', 'common-man')]) + [{'name_pl': 'Common Man', 'slug': 'common-man'}]) self.assertEqual(related_info['tags']['kind'], - [('Kind', 'kind')]) + [{'name_pl': 'Kind', 'slug': 'kind'}]) self.assertEqual([(tag.name, tag.count) for tag in related_themes], [('ChildTheme', 1), ('ParentTheme', 1), ('Theme', 2)]) diff --git a/apps/catalogue/utils.py b/apps/catalogue/utils.py index 5ae9db5f9..edc287f98 100644 --- a/apps/catalogue/utils.py +++ b/apps/catalogue/utils.py @@ -14,6 +14,7 @@ from django.http import HttpResponse from django.core.files.uploadedfile import UploadedFile from django.core.files.storage import DefaultStorage from django.utils.encoding import force_unicode +from django.utils.translation import get_language from django.conf import settings from os import mkdir, path, unlink from errno import EEXIST, ENOENT @@ -312,4 +313,12 @@ This can sometimes occupy lots of memory, so trim it here a bit. connection.queries = trim_to > 0 \ and connection.queries[-trim_to:] \ or [] - + + +def related_tag_name(tag_info, language=None): + return tag_info.get("name_%s" % (language or get_language()), + tag_info.get("name_%s" % settings.LANGUAGE_CODE, "")) + + +def delete_from_cache_by_language(cache, key_template): + cache.delete_many([key_template % lc for lc, ln in settings.LANGUAGES]) diff --git a/apps/catalogue/views.py b/apps/catalogue/views.py index 50b6e3e73..b0575403b 100644 --- a/apps/catalogue/views.py +++ b/apps/catalogue/views.py @@ -17,7 +17,7 @@ from django.contrib.auth.decorators import login_required, user_passes_test from django.utils.datastructures import SortedDict from django.utils.http import urlquote_plus from django.utils import translation -from django.utils.translation import ugettext as _, ugettext_lazy +from django.utils.translation import get_language, ugettext as _, ugettext_lazy from django.views.decorators.vary import vary_on_headers from ajaxable.utils import JSONResponse, AjaxableFormView @@ -36,7 +36,7 @@ permanent_cache = get_cache('permanent') @vary_on_headers('X-Requested-With') def catalogue(request): - cache_key='catalogue.catalogue' + cache_key='catalogue.catalogue/' + get_language() output = permanent_cache.get(cache_key) if output is None: tags = models.Tag.objects.exclude( @@ -70,6 +70,7 @@ def book_list(request, filter=None, get_filter=None, context=None, ): """ generates a listing of all books, optionally filtered with a test function """ + cache_key = "%s/%s" % (cache_key, get_language()) cached = permanent_cache.get(cache_key) if cached is not None: rendered_nav, rendered_book_list = cached diff --git a/apps/funding/models.py b/apps/funding/models.py index de52ac9d8..ba1494753 100644 --- a/apps/funding/models.py +++ b/apps/funding/models.py @@ -12,7 +12,7 @@ from django.db import models from django.utils.translation import ugettext_lazy as _, ugettext, override import getpaid from catalogue.models import Book -from catalogue.utils import get_random_hash +from catalogue.utils import get_random_hash, related_tag_name from polls.models import Poll from django.contrib.sites.models import Site from . import app_settings @@ -175,7 +175,7 @@ class Offer(models.Model): 'funding/email/published.txt', { 'offer': self, 'book': self.book, - 'author': ", ".join(a[0] for a in self.book.related_info()['tags']['author']), + 'author': ", ".join(related_tag_name(a) for a in self.book.related_info()['tags']['author']), 'current': self.current(), }) diff --git a/apps/sponsors/models.py b/apps/sponsors/models.py index 2d18d1664..cbc8d9ba4 100644 --- a/apps/sponsors/models.py +++ b/apps/sponsors/models.py @@ -35,7 +35,7 @@ class Sponsor(models.Model): class SponsorPage(models.Model): name = models.CharField(_('name'), max_length=120) - sponsors = JSONField(_('sponsors'), default='{}') + sponsors = JSONField(_('sponsors'), default={}) _html = models.TextField(blank=True, editable=False) sprite = models.ImageField(upload_to='sponsorzy/sprite', blank=True) diff --git a/apps/wolnelektury_core/templates/main_page.html b/apps/wolnelektury_core/templates/main_page.html index 54ca0031f..fd51cf371 100755 --- a/apps/wolnelektury_core/templates/main_page.html +++ b/apps/wolnelektury_core/templates/main_page.html @@ -28,7 +28,7 @@

{% trans "Recent publications" %}

- {% cache 60 last-published-on-main %} + {% cache 60 last-published-on-main LANGUAGE_CODE %} {% for book in last_published %} {% book_mini book %} {% endfor %} diff --git a/lib/librarian b/lib/librarian index a7d898e7b..6b327e1a3 160000 --- a/lib/librarian +++ b/lib/librarian @@ -1 +1 @@ -Subproject commit a7d898e7b37b773ec111aa395f9591d61b7a1d46 +Subproject commit 6b327e1a303fa8512cd5c56684bab2869198c01e diff --git a/requirements.txt b/requirements.txt index d6355f2cc..3ed01b3dd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,13 +3,13 @@ # django Django>=1.5,<1.6 -fnpdjango>=0.1.6,<0.2 +fnpdjango>=0.1.8,<0.2 South>=0.7 # migrations for django django-pipeline>=1.2.24,<1.3 django-pagination>=1.0 django-maintenancemode>=0.10 django-piston>=0.2.2.1,<0.2.3 --e git+git://github.com/bradjasper/django-jsonfield.git@e67ec8c3652e61d8b47cc8db012a63f5ad39323d#egg=django-jsonfield +jsonfield>=0.9.20 django-picklefield #django-allauth<0.10 with migration fix diff --git a/wolnelektury/translation.py b/wolnelektury/translation.py index cda9ebb81..dad3638fa 100644 --- a/wolnelektury/translation.py +++ b/wolnelektury/translation.py @@ -4,10 +4,15 @@ # from modeltranslation.translator import translator, TranslationOptions +from catalogue.models import Tag from infopages.models import InfoPage class InfoPageTranslationOptions(TranslationOptions): fields = ('title', 'left_column', 'right_column') +class TagTranslationOptions(TranslationOptions): + fields = ('name', 'description') + translator.register(InfoPage, InfoPageTranslationOptions) +translator.register(Tag, TagTranslationOptions)