From: Marek Stępniowski Date: Thu, 4 Sep 2008 15:20:49 +0000 (+0200) Subject: Fragments. X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/6dde47a534420987b2c0e8075b10d2d569ff572f Fragments. --- diff --git a/catalogue/models.py b/catalogue/models.py index 4c6e15417..d252bbf69 100644 --- a/catalogue/models.py +++ b/catalogue/models.py @@ -159,8 +159,7 @@ class Book(models.Model): closed_fragments, open_fragments = html.extract_fragments(book.html_file.path) book_themes = [] for fragment in closed_fragments.values(): - new_fragment = Fragment(html=fragment.to_string(), short_html=fragment.to_string(), - anchor=fragment.id, book=book) + new_fragment = Fragment(html=fragment.to_string(), anchor=fragment.id, book=book) theme_names = [s.strip() for s in fragment.themes.split(',')] themes = [] @@ -192,13 +191,25 @@ class Book(models.Model): class Fragment(models.Model): html = models.TextField() - short_html = models.TextField() + _short_html = models.TextField(editable=False) anchor = models.IntegerField() book = models.ForeignKey(Book, related_name='fragments') - + objects = managers.ModelTaggedItemManager(Tag) tags = managers.TagDescriptor(Tag) + def short_html(self): + if len(self._short_html): + return mark_safe(self._short_html) + else: + book_authors = [u'%s' % (tag.get_absolute_url(), tag.name) + for tag in self.book.tags if tag.category == 'author'] + + self._short_html = render_to_string('catalogue/fragment_short.html', + {'fragment': self, 'book': self.book, 'book_authors': book_authors}) + self.save() + return mark_safe(self._short_html) + class Meta: ordering = ('book', 'anchor',) verbose_name = _('fragment') diff --git a/catalogue/views.py b/catalogue/views.py index 98d3f942f..0d174ce91 100644 --- a/catalogue/views.py +++ b/catalogue/views.py @@ -117,7 +117,7 @@ def tagged_book_list(request, tags=''): return tagged_object_list( request, tag_model=models.Tag, - queryset_or_model=models.Book, + queryset_or_model=model, tags=tags, template_name='catalogue/tagged_book_list.html', extra_context = {'categories': categories }, diff --git a/media/css/master.css b/media/css/master.css index 30ef55db6..bbce7b54b 100644 --- a/media/css/master.css +++ b/media/css/master.css @@ -396,3 +396,15 @@ em { padding: 0 2em; line-height: 2em; } + +/* ================= */ +/* = Fragment list = */ +/* ================= */ +.fragment { + margin-bottom: 1.5em; +} + +.fragment-text { + max-height: 12em; + overflow: hidden; +} diff --git a/media/js/catalogue.js b/media/js/catalogue.js index f4c680276..11d30b8c2 100644 --- a/media/js/catalogue.js +++ b/media/js/catalogue.js @@ -14,6 +14,14 @@ $('#login-form').show(); }); + $('.fragment-text').toggle( + function() { $(this).addClass('fragment-text-full').removeClass('fragment-text'); }, + function() { $(this).addClass('fragment-text').removeClass('fragment-text-full'); } + ).hover( + function() { $(this).css({background: '#F3F3F3', cursor: 'pointer'}); }, + function() { $(this).css({background: '#FFF'}); } + ) + $('#registration-form').ajaxForm({ dataType: 'json', beforeSubmit: function() { diff --git a/settings.py b/settings.py index 788e33e96..5f0be969c 100644 --- a/settings.py +++ b/settings.py @@ -89,7 +89,7 @@ TEMPLATE_DIRS = ( # CSS and JS files to compress COMPRESS_CSS = { 'all': { - 'source_filenames': ('css/master.css', 'css/jquery.autocomplete.css',), + 'source_filenames': ('css/master.css', 'css/jquery.autocomplete.css', 'css/master.plain.css',), 'output_filename': 'css/all.min.css', } } diff --git a/templates/catalogue/book_detail.html b/templates/catalogue/book_detail.html index a23e6315e..f95683c40 100644 --- a/templates/catalogue/book_detail.html +++ b/templates/catalogue/book_detail.html @@ -28,10 +28,10 @@

{{ book.title }}, {{ categories.author|join:", " }}

    - {% for tag in tags %} -
  1. {{ tag }} | x
  2. - {% endfor %} -
  3. {{ book.title }} | x
  4. + {# {% for tag in tags %} #} + {#
  5. {{ tag }} | x
  6. #} + {# {% endfor %} #} +
  7. {{ book.title }} | x