Skip to content

Commit

Permalink
Add research files thumbnails
Browse files Browse the repository at this point in the history
  • Loading branch information
gthole committed May 25, 2016
1 parent e7f5cb4 commit b8bc90c
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 8 deletions.
2 changes: 1 addition & 1 deletion gedgo/storages.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def search(self, query):
return self._list_from_contents(contents)

def preview(self, name):
return self.client.preview(self.path(name))
return self.client.thumbnail(self.path(name), 's')


class ResearchFileSystemStorage(FileSystemStorage):
Expand Down
1 change: 1 addition & 0 deletions gedgo/templates/default/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<title>{{ site_title }}{% if person %} : {{ person.full_name }}{% endif %}</title>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.min.css" rel="stylesheet">
<link href="//opensource.keycdn.com/fontawesome/4.6.3/font-awesome.min.css" rel="stylesheet">
<link href="{{ STATIC_URL }}styles/style-default.css" rel="stylesheet" type="text/css" >
</head>
<body>
Expand Down
26 changes: 24 additions & 2 deletions gedgo/templates/default/research.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,46 @@
<a class="btn btn-info visible-xs" href=".">Up a level</a>
{% endif %}
<h3>{{ current_level }}</h3>
{% if directories %}
<ul class="list-group">
{% for dir in directories %}
<li class="list-group-item">
<a href="/gedgo/research/{{ dir.path }}">
<span class="glyphicon glyphicon-folder-open"></span> &nbsp; {{ dir.name|truncatechars:45 }}
<div class="row">
<div class="col-xs-2 text-center">
<i class="fa fa-folder-open fa-2x"></i>
</div>
<div class="col-xs-10">
{{ dir.name|truncatechars:45 }}
</div>
</div>
</a>
</li>
{% endfor %}
</ul>
{% endif %}
{% if directories and files %}
<hr />
{% endif %}
{% if files %}
<ul class="list-group">
{% for f in files %}
<li class="list-group-item">
<a href="/gedgo/research/{{ f.path }}">
<span class="glyphicon glyphicon-{{ f.type }}"></span> &nbsp; {{ f.name|truncatechars:45 }}
<div class="row">
<div class="col-xs-2 text-center">
{% if f.preview %}<img class="center-block" src="/gedgo/research-preview/{{ f.path }}">
{% else %}<i class="fa fa-{{ f.type }} fa-2x"></i>
{% endif %}
</div>
<div class="col-xs-10">
{{ f.name|truncatechars:45 }}
</div>
</div>
</a>
</li>
{% endfor %}
</ul>
{% endif %}

{% endblock %}
1 change: 1 addition & 0 deletions gedgo/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
url(r'^blog/post/(?P<post_id>\d+)/$', views.blogpost),
url(r'^documentaries/$', views.documentaries),
url(r'^research/(?P<pathname>.*)$', views.research),
url(r'^research-preview/(?P<pathname>.*)$', views.research_preview),
url(r'^search/$', views.search),
url(r'^dashboard/$', views.dashboard),
url(r'^dashboard/user/(?P<user_id>\d+)/$', views.user_tracking),
Expand Down
4 changes: 2 additions & 2 deletions gedgo/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
from model_views import person, gedcom, documentaries
from dashboard import dashboard, user_tracking, worker_status
from blog import blog, blog_list, blogpost
from research import research
from research import research, research_preview
from visualizations import pedigree, timeline
from util import media, logout_view

__all__ = [
'person', 'gedcom', 'dashboard', 'search',
'documentaries', 'blogpost',
'documentaries', 'blogpost', 'research_preview',
'blog', 'blog_list', 'media', 'research', 'logout_view',
'pedigree', 'timeline', 'user_tracking', 'worker_status'
]
35 changes: 32 additions & 3 deletions gedgo/views/research.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.http import Http404
from django.contrib.auth.decorators import login_required
from django.core.files.storage import default_storage

from os import path
import mimetypes
Expand All @@ -8,6 +9,27 @@
from gedgo.storages import research_storage as storage


@login_required
def research_preview(request, pathname):
"""
Cached preview thumbnails for jpegs (supported by Dropbox)
"""
name = pathname.strip('/')
if not can_preview(name):
raise Http404

cache_name = path.join('research', 'preview-cache', name)
if default_storage.exists(cache_name):
return serve_content(default_storage, cache_name)
try:
content = storage.preview(name)
assert content
default_storage.save(cache_name, content)
return serve_content(default_storage, cache_name)
except:
raise Http404


@login_required
def research(request, pathname):
if storage is None:
Expand Down Expand Up @@ -47,20 +69,27 @@ def research(request, pathname):
raise Http404


def can_preview(name):
return (
hasattr(storage, 'preview') and
(name.lower().endswith('.jpeg') or name.lower().endswith('.jpg'))
)


def process_file(name, p, is_dir=False):
type_ = 'folder_open' if is_dir else _get_type(p)
return {
'type': type_,
'path': path.join(name, p),
'name': p,
'preview': type_ == 'image'
'preview': can_preview(p)
}

# glyphicon name mappings
MIMETYPE_MAPPING = {
'video': 'facetime-video',
'video': 'video-camera',
'audio': 'volume-up',
'image': 'picture'
'image': 'image'
}


Expand Down

0 comments on commit b8bc90c

Please sign in to comment.