From: Radek Czajka Date: Tue, 19 Nov 2013 10:06:55 +0000 (+0100) Subject: Tags i18n. X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/2856ae6ae36213ca7997366e0c7790e3c855e62f?ds=inline;hp=--cc Tags i18n. --- 2856ae6ae36213ca7997366e0c7790e3c855e62f 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/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 02051fb29..0438afa21 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 @@ -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']['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/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/templates/catalogue/book_detail.html b/apps/catalogue/templates/catalogue/book_detail.html index 4c14158ef..f266742c1 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 73e5cb8fb..96ceaa6c6 100644 --- a/apps/catalogue/templates/catalogue/book_short.html +++ b/apps/catalogue/templates/catalogue/book_short.html @@ -41,8 +41,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 %}
@@ -57,22 +57,22 @@ {% spaceless %} {% 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..8c073c137 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']['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..17f9a7782 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')]) + [{'pl': 'Common Man', 'slug': 'common-man'}]) self.assertEqual(related_info['tags']['kind'], - [('Kind', 'kind')]) + [{'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..b023f1a2f 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 e9b1465dd..d2b79c7ee 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/wolnelektury_core/templates/main_page.html b/apps/wolnelektury_core/templates/main_page.html index a751022e1..812094fce 100755 --- a/apps/wolnelektury_core/templates/main_page.html +++ b/apps/wolnelektury_core/templates/main_page.html @@ -29,7 +29,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/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)