Skip to content

Instantly share code, notes, and snippets.

@nkeilar
Created June 14, 2013 01:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nkeilar/5778759 to your computer and use it in GitHub Desktop.
Save nkeilar/5778759 to your computer and use it in GitHub Desktop.
filebrowser with sorl thumbnails for thumbnail generation. Gets thumbnails working on S3.
{% load i18n future static fb_tags mezzanine_tags %}
{% load sorl_thumbnail %}
{% if query.pop %}
<style>
{% if query.pop == '4' %}
#media-library-popup #header, #media-library-popup .object-tools {display: none;}
#media-library-popup h1 {margin: -60px 0 15px 0;}
{% else %}
h1 {margin:-30px 0 15px 0;}
{% endif %}
</style>
{% endif %}
{% for file in page.object_list %}
<tr class="{% cycle 'row1' 'row2' %}">
<!-- FILESELECT FOR FILEBROWSEFIELD -->
{% ifequal query.pop '1' %}
{% if results_var.select_total %}
<td class="fb_icon">
{% selectable file.filetype query.type %}
{% if selectable %}
{% sorl_thumbnail file.path "100x100" as im %}
<a href="javascript://" onclick="FileSubmit('{{ file.path }}', '{% ifequal file.filetype 'Image' %}{{ im.url }}{% else %}{{ MEDIA_URL }}{{ file.path }}{% endifequal %}', '{{ file.filetype }}');" class="fb_selectlink" title="{% trans 'Select' %}"></a>
{% endthumbnail %}
{% else %}
<img src="{{ settings_var.URL_FILEBROWSER_MEDIA }}img/filebrowser_icon_select_disabled.gif" width="23" height="17" />
{% endif %}
</td>
{% endif %}
{% endifequal %}
<!-- FILESELECT FOR RTE/TINYMCE -->
{% ifequal query.pop '2' %}
{% if results_var.select_total %}
<td class="fb_icon">
{% selectable file.filetype query.type %}
{% if selectable %}
<a href="javascript:FileBrowserDialogue.fileSubmit('{{ file.url|escapejs }}');" class="fb_selectlink" title="{% trans 'Select File' %}"></a>
{% else %}
<img src="{{ settings_var.URL_FILEBROWSER_MEDIA }}img/filebrowser_icon_select_disabled.gif" width="23" height="17" />
{% endif %}
</td>
{% endif %}
{% endifequal %}
<!-- FILESELECT FOR CKEDITOR (FORMER "FCKEDITOR") -->
{% ifequal query.pop '3' %}
{% if results_var.select_total %}
<td class="fb_icon">
{% selectable file.filetype query.type %}
{% if selectable %}
<a href="#" onclick="OpenFile(ProtectPath('{{ file.url|escapejs }}'));return false;" class="fb_selectlink" title="{% trans 'Select File' %}"></a>
{% else %}
<img src="{{ settings_var.URL_FILEBROWSER_MEDIA }}img/filebrowser_icon_select_disabled.gif" width="23" height="17" />
{% endif %}
</td>
{% endif %}
{% endifequal %}
<!-- GENERIC FILESELECT: opener grabs file url from rel attribute dynamically on click -->
{% ifequal query.pop '4' %}
{% if results_var.select_total %}
<td class="fb_icon">
{% selectable file.filetype query.type %}
{% if selectable %}
<a href="#" rel="{{ file.url|escape }}" class="fb_selectlink" title="{% trans 'Select File' %}"></a>
{% else %}
<img src="{{ settings_var.URL_FILEBROWSER_MEDIA }}img/filebrowser_icon_select_disabled.gif" width="23" height="17" />
{% endif %}
</td>
{% endif %}
{% endifequal %}
<!-- FILEICON -->
<td class="fb_icon"><img src="{{ settings_var.URL_FILEBROWSER_MEDIA }}img/filebrowser_type_{{ file.filetype|lower }}.gif" /></td>
<!-- THUMBNAIL -->
{% if results_var.images_total %}
<td class="fb_icon">
{% ifequal file.filetype 'Image' %}
{% sorl_thumbnail file.path "100x100" as im %}
<img class="group1" src="{{ im.url }}" alt="{% trans 'View Image' %}"/>
{% endthumbnail %}
{% endifequal %}
</td>
{% endif %}
<!-- FILENAME/DIMENSIONS -->
{% ifequal file.filetype 'Folder' %}
<td><b><a href="{% url "fb_browse" %}{% query_string "" "q,dir,p" %}&amp;dir={{ file.path_relative_directory|urlencode }}">{{ file.filename }}</a></b></td>
{% else %}
<td><b><a href="{{ file.url }}" target="_blank">{{ file.filename }}</a></b></td>
{% endifequal %}
<!-- RENAME -->
{% if query.pop != '4' %}
<td class="fb_icon"><a href="{% url "fb_rename" %}{% query_string %}&amp;filename={{ file.filename }}" class="fb_renamelink" title="{% trans 'Rename' %}"></a></td>
{% endif %}
<!-- SIZE -->
<td>{{ file.filesize|filesizeformat }}</td>
<!-- DATE -->
<td>{{ file.datetime|date:"N j, Y" }}</td>
<!-- DELETE -->
{% if query.pop != '4' %}
<td class="fb_icon">
{% ifnotequal file.filetype 'Folder' %}
<form method="POST" action="{% url "fb_delete" %}{% query_string %}&amp;filename={{ file.filename }}&amp;filetype={{ file.filetype }}" id="delete-{{ forloop.counter0 }}">{% csrf_token %}</form>
<a href="#" class="fb_deletelink" onclick="if (confirm('{% trans "Are you sure you want to delete this file?" %}')) {$('#delete-{{ forloop.counter0 }}').submit();} return false;" title="{% trans 'Delete File' %}"></a>
{% else %}
<form method="POST" action="{% url "fb_delete" %}{% query_string %}&amp;filename={{ file.filename }}&amp;filetype={{ file.filetype }}" id="delete-{{ forloop.counter0 }}">{% csrf_token %}</form>
<a href="#" class="fb_deletelink" onclick="if (confirm('{% trans "Are you sure you want to delete this Folder?" %}')) {$('#delete-{{ forloop.counter0 }}').submit();} return false;" title="{% trans 'Delete Folder' %}"></a>
{% endifnotequal %}
</td>
{% endif %}
<!-- DEBUG -->
{% if settings_var.DEBUG %}
<td>
<strong>Filename</strong> {{ file.filename }}<br />
<strong>Filetype</strong> {{ file.filetype }}<br />
<strong>Filesize</strong> {{ file.filesize }}<br />
<strong>Extension</strong> {{ file.extension }}<br />
<strong>Date</strong> {{ file.date }}<br />
<strong>Datetime Object</strong> {{ file.datetime }}<br /><br />
<strong>Relative Path</strong> {{ file.path_relative }}<br />
<strong>Full Path</strong> {{ file.path_full }}<br />
<strong>Relative URL</strong> {{ file.url_relative }}<br />
<strong>Full URL</strong> {{ file.url }}<br /><br />
<strong>URL for FileBrowseField</strong> {{ file.url }}<br />
<strong>Thumbnail URL</strong> {{ file.url_thumbnail }}
{% ifequal file.filetype 'Image' %}<br /><br />
<strong>Dimensions</strong> {{ file.dimensions }}<br />
<strong>Width</strong> {{ file.width }}<br />
<strong>Height</strong> {{ file.height }}<br />
<strong>Orientation</strong> {{ file.orientation }}
{% endifequal %}
{% ifequal file.filetype 'Folder' %}<br /><br />
<strong>Is Empty</strong> {{ file.is_empty }}
{% endifequal %}
</td>
{% endif %}
</tr>
{% endfor %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment