From: Radek Czajka Date: Fri, 16 Sep 2011 08:13:41 +0000 (+0200) Subject: basic footnotes dictionary X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/5e983f642ea537225bf3a20e97fca281c8fdc915?ds=inline;hp=--cc basic footnotes dictionary --- 5e983f642ea537225bf3a20e97fca281c8fdc915 diff --git a/apps/catalogue/models.py b/apps/catalogue/models.py index d0a620a96..ead5ba040 100644 --- a/apps/catalogue/models.py +++ b/apps/catalogue/models.py @@ -6,6 +6,7 @@ from datetime import datetime from django.db import models from django.db.models import permalink, Q +import django.dispatch from django.core.cache import cache from django.utils.translation import ugettext_lazy as _ from django.contrib.auth.models import User @@ -302,6 +303,8 @@ class Book(models.Model): tagged = managers.ModelTaggedItemManager(Tag) tags = managers.TagDescriptor(Tag) + html_built = django.dispatch.Signal() + class AlreadyExists(Exception): pass @@ -611,6 +614,7 @@ class Book(models.Model): new_fragment.save() new_fragment.tags = set(meta_tags + themes + [book_tag] + ancestor_tags) self.save() + self.html_built.send(sender=self) return True return False diff --git a/apps/dictionary/__init__.py b/apps/dictionary/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/apps/dictionary/migrations/0001_initial.py b/apps/dictionary/migrations/0001_initial.py new file mode 100644 index 000000000..cf0c311fa --- /dev/null +++ b/apps/dictionary/migrations/0001_initial.py @@ -0,0 +1,59 @@ +# encoding: utf-8 +import datetime +from south.db import db +from south.v2 import SchemaMigration +from django.db import models + +class Migration(SchemaMigration): + + def forwards(self, orm): + + # Adding model 'Note' + db.create_table('dictionary_note', ( + ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)), + ('book', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['catalogue.Book'])), + ('anchor', self.gf('django.db.models.fields.CharField')(max_length=64)), + ('html', self.gf('django.db.models.fields.TextField')()), + ('sort_key', self.gf('django.db.models.fields.CharField')(max_length=128, db_index=True)), + )) + db.send_create_signal('dictionary', ['Note']) + + + def backwards(self, orm): + + # Deleting model 'Note' + db.delete_table('dictionary_note') + + + models = { + 'catalogue.book': { + 'Meta': {'ordering': "('sort_key',)", 'object_name': 'Book'}, + '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'}), + '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'}), + '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'}) + }, + 'dictionary.note': { + 'Meta': {'ordering': "['sort_key']", 'object_name': 'Note'}, + 'anchor': ('django.db.models.fields.CharField', [], {'max_length': '64'}), + 'book': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['catalogue.Book']"}), + 'html': ('django.db.models.fields.TextField', [], {}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'sort_key': ('django.db.models.fields.CharField', [], {'max_length': '128', 'db_index': 'True'}) + } + } + + complete_apps = ['dictionary'] diff --git a/apps/dictionary/migrations/__init__.py b/apps/dictionary/migrations/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/apps/dictionary/models.py b/apps/dictionary/models.py new file mode 100644 index 000000000..260617927 --- /dev/null +++ b/apps/dictionary/models.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- +# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. +# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. +# +from django.db import models + +from librarian import html +from sortify import sortify + +from catalogue.models import Book + + +class Note(models.Model): + book = models.ForeignKey(Book) + anchor = models.CharField(max_length=64) + html = models.TextField() + sort_key = models.CharField(max_length=128, db_index=True) + + class Meta: + ordering = ['sort_key'] + + +def notes_from_book(sender, **kwargs): + Note.objects.filter(book=sender).delete() + if sender.has_html_file: + for anchor, text_str, html_str in html.extract_annotations(sender.html_file.path): + Note.objects.create(book=sender, anchor=anchor, + html=html_str, sort_key=sortify(text_str)) + +Book.html_built.connect(notes_from_book) diff --git a/apps/dictionary/templates/dictionary/note_list.html b/apps/dictionary/templates/dictionary/note_list.html new file mode 100755 index 000000000..7f3b43690 --- /dev/null +++ b/apps/dictionary/templates/dictionary/note_list.html @@ -0,0 +1,19 @@ +{% extends "base.html" %} +{% load pagination_tags %} + +{% block body %} + + +{% autopaginate object_list 100 %} +{% paginate %} +{% for obj in object_list %} +
+ {{ obj.html|safe }} + +
+{% endfor %} +{% paginate %} + +{% endblock %} diff --git a/apps/dictionary/urls.py b/apps/dictionary/urls.py new file mode 100755 index 000000000..3c59be992 --- /dev/null +++ b/apps/dictionary/urls.py @@ -0,0 +1,14 @@ +# -*- coding: utf-8 -*- +# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. +# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. +# +from django.conf.urls.defaults import * +from dictionary.models import Note + + +all_notes = Note.objects.all() + +urlpatterns = patterns('django.views.generic.list_detail', + url(r'^$', 'object_list', {'queryset': all_notes}), +) + diff --git a/lib/librarian b/lib/librarian index 7e7eac17f..a6ee2dd83 160000 --- a/lib/librarian +++ b/lib/librarian @@ -1 +1 @@ -Subproject commit 7e7eac17f776821311bdcc305052575f7994989e +Subproject commit a6ee2dd83d3c4d5d2d3e8cb3401734ced2b12c22 diff --git a/wolnelektury/settings.py b/wolnelektury/settings.py index f1391a9f5..6c58bff46 100644 --- a/wolnelektury/settings.py +++ b/wolnelektury/settings.py @@ -133,6 +133,7 @@ INSTALLED_APPS = [ 'compress', 'modeltranslation', 'catalogue', + 'dictionary', 'lessons', 'piston', 'api', diff --git a/wolnelektury/static/css/master.css b/wolnelektury/static/css/master.css index a87ae3839..0da323672 100644 --- a/wolnelektury/static/css/master.css +++ b/wolnelektury/static/css/master.css @@ -56,8 +56,6 @@ h3 { } em { - font-style: normal; - background-color: #F5DC7D; } hr { @@ -1170,3 +1168,10 @@ div.shown-tags p, div.all-tags p { #presentation-frame { border: 0px none white; } + + +/* dictionary */ + +.dictionary-note-source { + margin-top: -1em; +} diff --git a/wolnelektury/urls.py b/wolnelektury/urls.py index 5586bf072..92e3dc505 100644 --- a/wolnelektury/urls.py +++ b/wolnelektury/urls.py @@ -18,6 +18,7 @@ urlpatterns = patterns('', url(r'^opds/', include('opds.urls')), url(r'^sugestia/', include('suggest.urls')), url(r'^lesmianator/', include('lesmianator.urls')), + url(r'^przypisy/', include('dictionary.urls')), # Static pages url(r'^mozesz-nam-pomoc/$', 'infopages.views.infopage', {'slug': 'help_us'}, name='help_us'),