From: Michael Tremer Date: Mon, 19 Nov 2018 15:49:10 +0000 (+0000) Subject: wiki: Add detail page for files X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8cb0bea4a443147c29cfbabf07bfb610a86ccd89;p=ipfire.org.git wiki: Add detail page for files Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index 1e5d43cf..0a9f7727 100644 --- a/Makefile.am +++ b/Makefile.am @@ -268,6 +268,7 @@ templates_wiki_DATA = \ templates_wikidir = $(templatesdir)/wiki templates_wiki_files_DATA = \ + src/templates/wiki/files/detail.html \ src/templates/wiki/files/index.html templates_wiki_filesdir = $(templates_wikidir)/files diff --git a/src/backend/wiki.py b/src/backend/wiki.py index 3d105f72..6defecbc 100644 --- a/src/backend/wiki.py +++ b/src/backend/wiki.py @@ -328,6 +328,18 @@ class File(misc.Object): def size(self): return self.data.size + @lazy_property + def author(self): + if self.data.author_uid: + return self.backend.accounts.get_by_uid(self.data.author_uid) + + @property + def created_at(self): + return self.data.created_at + + def is_pdf(self): + return self.mimetype in ("application/pdf", "application/x-pdf") + def is_image(self): return self.mimetype.startswith("image/") diff --git a/src/scss/style.scss b/src/scss/style.scss index 04e05d7d..04d3ae82 100644 --- a/src/scss/style.scss +++ b/src/scss/style.scss @@ -296,3 +296,8 @@ hr.divider { width: 100%; } } + +.pdf-viewer { + width: 100%; + min-height: 32rem; +} diff --git a/src/templates/wiki/files/detail.html b/src/templates/wiki/files/detail.html new file mode 100644 index 00000000..f712d9fd --- /dev/null +++ b/src/templates/wiki/files/detail.html @@ -0,0 +1,41 @@ +{% extends "../base.html" %} + +{% block title %}{{ file.filename }}{% end block %} + +{% block main %} +
+
+ {% if file.is_image() %} + {{ file.filename }} + {% elif file.is_pdf() %} + +

+ {{ _("This PDF attachment could not be displayed.") }} + {{ _("Click here to download") }} +

+
+ {% end %} + + + + {{ _("Download") }} ({{ format_size(file.size) }}) + + +
+
{{ _("Filename") }}
+
{{ file.filename }}
+ + {% if file.author %} +
{{ _("Author") }}
+
+ {{ file.author }} +
+ {% end %} + +
{{ _("Uploaded at") }}
+
{{ locale.format_date(file.created_at) }}
+
+
+
+{% end block %} diff --git a/src/templates/wiki/files/index.html b/src/templates/wiki/files/index.html index fa9c976d..7f697247 100644 --- a/src/templates/wiki/files/index.html +++ b/src/templates/wiki/files/index.html @@ -21,8 +21,10 @@ {% if f.is_image() %}
- {{ f.filename }} -
{{ f.filename }}
+ + {{ f.filename }} +
{{ f.filename }}
+
{% end %} @@ -39,7 +41,7 @@ {% end %} - {{ f.filename }} + {{ f.filename }} {% end %} {% end %} diff --git a/src/web/wiki.py b/src/web/wiki.py index b8058427..f02fce55 100644 --- a/src/web/wiki.py +++ b/src/web/wiki.py @@ -36,11 +36,20 @@ class FilesHandler(auth.CacheMixin, base.BaseHandler): class FileHandler(auth.CacheMixin, base.BaseHandler): + @property + def action(self): + return self.get_argument("action", None) + def get(self, path): file = self.backend.wiki.get_file_by_path(path) if not file: raise tornado.web.HTTPError(404, "Could not find %s" % path) + # Render detail page + if self.action == "detail": + self.render("wiki/files/detail.html", file=file) + return + size = self.get_argument_int("s", None) # Check if image should be resized