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
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/")
width: 100%;
}
}
+
+.pdf-viewer {
+ width: 100%;
+ min-height: 32rem;
+}
--- /dev/null
+{% extends "../base.html" %}
+
+{% block title %}{{ file.filename }}{% end block %}
+
+{% block main %}
+ <div class="card mb-4">
+ <div class="card-body">
+ {% if file.is_image() %}
+ <img class="img-fluid img-thumbnail" src="{{ file.url }}?s=768" alt="{{ file.filename }}">
+ {% elif file.is_pdf() %}
+ <object class="pdf-viewer" data="{{ file.url }}"
+ title="{{ file.filename }}" type="{{ file.mimetype }}">
+ <p>
+ {{ _("This PDF attachment could not be displayed.") }}
+ <a href="{{ file.url }}">{{ _("Click here to download") }}</a>
+ </p>
+ </object>
+ {% end %}
+
+ <a class="btn btn-primary btn-lg btn-block my-3" href="{{ file.url }}">
+ <span class="fas fa-file-download"></span>
+ {{ _("Download") }} ({{ format_size(file.size) }})
+ </a>
+
+ <dl class="row mb-0">
+ <dt class="col-sm-3">{{ _("Filename") }}</dt>
+ <dd class="col-sm-9">{{ file.filename }}</dd>
+
+ {% if file.author %}
+ <dt class="col-sm-3">{{ _("Author") }}</dt>
+ <dd class="col-sm-9">
+ <a href="/users/{{ file.author.uid }}">{{ file.author }}</a>
+ </dd>
+ {% end %}
+
+ <dt class="col-sm-3">{{ _("Uploaded at") }}</dt>
+ <dd class="col-sm-9">{{ locale.format_date(file.created_at) }}</dd>
+ </dl>
+ </div>
+ </div>
+{% end block %}
{% if f.is_image() %}
<div class="col-sm-6 col-md-4">
<figure class="figure">
- <img class="figure-img img-fluid img-thumbnail" src="{{ f.url }}?s=256" alt="{{ f.filename }}">
- <figcaption class="figure-caption">{{ f.filename }}</figcaption>
+ <a href="{{ f.url }}?action=detail">
+ <img class="figure-img img-fluid img-thumbnail" src="{{ f.url }}?s=256" alt="{{ f.filename }}">
+ <figcaption class="figure-caption">{{ f.filename }}</figcaption>
+ </a>
</figure>
</div>
{% end %}
<span class="fas fa-file fa-fw"></span>
{% end %}
- <a href="{{ f.url }}">{{ f.filename }}</a>
+ <a href="{{ f.url }}?action=detail">{{ f.filename }}</a>
</li>
{% end %}
{% end %}
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