X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/c7c8dfb7ad2240ffc0135dbd9dd871c85f211a29..05de464fd2f287d8ea3a26560c18afcac32d7f1e:/apps/catalogue/models.py
diff --git a/apps/catalogue/models.py b/apps/catalogue/models.py
index feccaedf4..05009a5bc 100644
--- a/apps/catalogue/models.py
+++ b/apps/catalogue/models.py
@@ -38,8 +38,9 @@ class Tag(TagBase):
sort_key = models.SlugField(_('sort key'), max_length=120, db_index=True)
category = models.CharField(_('category'), max_length=50, blank=False, null=False,
db_index=True, choices=TAG_CATEGORIES)
- description = models.TextField(blank=True)
-
+ description = models.TextField(_('description'), blank=True)
+ main_page = models.BooleanField(_('main page'), default=False, db_index=True, help_text=_('Show tag on main page'))
+
user = models.ForeignKey(User, blank=True, null=True)
def has_description(self):
@@ -77,9 +78,10 @@ class Book(models.Model):
# Formats
xml_file = models.FileField(_('XML file'), upload_to='books/xml', blank=True)
+ html_file = models.FileField(_('HTML file'), upload_to='books/html', blank=True)
pdf_file = models.FileField(_('PDF file'), upload_to='books/pdf', blank=True)
odt_file = models.FileField(_('ODT file'), upload_to='books/odt', blank=True)
- html_file = models.FileField(_('HTML file'), upload_to='books/html', blank=True)
+ txt_file = models.FileField(_('TXT file'), upload_to='books/txt', blank=True)
parent = models.ForeignKey('self', blank=True, null=True, related_name='children')
@@ -102,8 +104,8 @@ class Book(models.Model):
if self.odt_file:
formats.append(u'Plik ODT' % self.odt_file.url)
- self._short_html = render_to_string('catalogue/book_short.html',
- {'book': self, 'tags': tags, 'formats': formats})
+ self._short_html = unicode(render_to_string('catalogue/book_short.html',
+ {'book': self, 'tags': tags, 'formats': formats}))
self.save()
return mark_safe(self._short_html)
@@ -135,7 +137,8 @@ class Book(models.Model):
# Read book metadata
book_info = dcparser.parse(xml_file)
- book = Book(title=book_info.title, slug=slughifi(book_info.title))
+ book_base, book_slug = book_info.url.rsplit('/', 1)
+ book = Book(title=book_info.title, slug=book_slug)
book.save()
book_tags = []
@@ -207,7 +210,7 @@ class Fragment(models.Model):
text = models.TextField()
short_text = models.TextField(editable=False)
_short_html = models.TextField(editable=False)
- anchor = models.IntegerField()
+ anchor = models.CharField(max_length=120)
book = models.ForeignKey(Book, related_name='fragments')
objects = models.Manager()
@@ -221,8 +224,8 @@ class Fragment(models.Model):
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._short_html = unicode(render_to_string('catalogue/fragment_short.html',
+ {'fragment': self, 'book': self.book, 'book_authors': book_authors}))
self.save()
return mark_safe(self._short_html)