basic footnotes dictionary
authorRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Fri, 16 Sep 2011 08:13:41 +0000 (10:13 +0200)
committerRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Fri, 16 Sep 2011 08:13:41 +0000 (10:13 +0200)
apps/catalogue/models.py
apps/dictionary/__init__.py [new file with mode: 0644]
apps/dictionary/migrations/0001_initial.py [new file with mode: 0644]
apps/dictionary/migrations/__init__.py [new file with mode: 0644]
apps/dictionary/models.py [new file with mode: 0644]
apps/dictionary/templates/dictionary/note_list.html [new file with mode: 0755]
apps/dictionary/urls.py [new file with mode: 0755]
lib/librarian
wolnelektury/settings.py
wolnelektury/static/css/master.css
wolnelektury/urls.py

index d0a620a..ead5ba0 100644 (file)
@@ -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 (file)
index 0000000..e69de29
diff --git a/apps/dictionary/migrations/0001_initial.py b/apps/dictionary/migrations/0001_initial.py
new file mode 100644 (file)
index 0000000..cf0c311
--- /dev/null
@@ -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 (file)
index 0000000..e69de29
diff --git a/apps/dictionary/models.py b/apps/dictionary/models.py
new file mode 100644 (file)
index 0000000..2606179
--- /dev/null
@@ -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 (executable)
index 0000000..7f3b436
--- /dev/null
@@ -0,0 +1,19 @@
+{% extends "base.html" %}
+{% load pagination_tags %}
+
+{% block body %}
+
+
+{% autopaginate object_list 100 %}
+{% paginate %}
+{% for obj in object_list %}
+    <div class='dictionary-note'>
+    {{ obj.html|safe }}
+    <div class='dictionary-note-source'>
+    (<a href='{% url book_text obj.book.slug %}#{{ obj.anchor }}'>{{ obj.book.pretty_title }}</a>)
+    </div>
+    </div>
+{% endfor %}
+{% paginate %}
+
+{% endblock %}
diff --git a/apps/dictionary/urls.py b/apps/dictionary/urls.py
new file mode 100755 (executable)
index 0000000..3c59be9
--- /dev/null
@@ -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}),
+)
+
index 7e7eac1..a6ee2dd 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 7e7eac17f776821311bdcc305052575f7994989e
+Subproject commit a6ee2dd83d3c4d5d2d3e8cb3401734ced2b12c22
index f1391a9..6c58bff 100644 (file)
@@ -133,6 +133,7 @@ INSTALLED_APPS = [
     'compress',
     'modeltranslation',
     'catalogue',
+    'dictionary',
     'lessons',
     'piston',
     'api',
index a87ae38..0da3236 100644 (file)
@@ -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;
+}
index 5586bf0..92e3dc5 100644 (file)
@@ -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'),