From: Marek Stępniowski Date: Tue, 16 Sep 2008 14:44:03 +0000 (+0200) Subject: Changed path for importing books. X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/f062d83d5999fa0540aabef056fa21ef225728fd?ds=sidebyside;hp=e09496eb5725b2dd860dfc6b91cbfc88b6237041 Changed path for importing books. --- diff --git a/apps/catalogue/models.py b/apps/catalogue/models.py index 05009a5bc..5f4ec923c 100644 --- a/apps/catalogue/models.py +++ b/apps/catalogue/models.py @@ -69,6 +69,12 @@ class Tag(TagBase): return TagBase.get_tag_list(tags) +def book_upload_path(ext): + def get_dynamic_path(book, filename): + return 'lektura/%s.%s' % (book.slug, ext) + return get_dynamic_path + + class Book(models.Model): title = models.CharField(_('title'), max_length=120) slug = models.SlugField(_('slug'), max_length=120, unique=True, db_index=True) @@ -77,11 +83,11 @@ class Book(models.Model): _short_html = models.TextField(_('short HTML'), editable=False) # 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) - txt_file = models.FileField(_('TXT file'), upload_to='books/txt', blank=True) + xml_file = models.FileField(_('XML file'), upload_to=book_upload_path('xml'), blank=True) + html_file = models.FileField(_('HTML file'), upload_to=book_upload_path('html'), blank=True) + pdf_file = models.FileField(_('PDF file'), upload_to=book_upload_path('pdf'), blank=True) + odt_file = models.FileField(_('ODT file'), upload_to=book_upload_path('odt'), blank=True) + txt_file = models.FileField(_('TXT file'), upload_to=book_upload_path('txt'), blank=True) parent = models.ForeignKey('self', blank=True, null=True, related_name='children') @@ -228,7 +234,10 @@ class Fragment(models.Model): {'fragment': self, 'book': self.book, 'book_authors': book_authors})) self.save() return mark_safe(self._short_html) - + + def get_absolute_url(self): + return '%s#m%s' % (self.book.html_file.url, self.anchor) + class Meta: ordering = ('book', 'anchor',) verbose_name = _('fragment')