Commit 7453b857 authored by Skia's avatar Skia

Add thumbnails to albums

parent 7e335cfb
Pipeline #456 passed with stage
in 2 minutes and 35 seconds
......@@ -572,10 +572,14 @@ class SithFile(models.Model):
code='duplicate',
)
if self.is_folder:
try:
self.file.delete()
except: pass
self.file = None
if self.file:
try:
import imghdr
if imghdr.what(None, self.file.read()) not in ['gif', 'png', 'jpeg']:
self.file.delete()
self.file = None
except:
self.file = None
self.mime_type = "inode/directory"
if self.is_file and (self.file is None or self.file == ""):
raise ValidationError(_("You must provide a file"))
......
......@@ -26,7 +26,7 @@ def send_file(request, file_id, file_class=SithFile, file_attr="file"):
iterator for chunks of 8KB.
"""
f = file_class.objects.filter(id=file_id).first()
if f is None or f.is_folder:
if f is None or not f.file:
return not_found(request)
from counter.models import Counter
if not (can_view(f, request.user) or
......
......@@ -22,7 +22,9 @@
<a href="{{ url("sas:album", album_id=a.id) }}" style="display: inline-block">
<div class="album">
<div>
{% if a.children.filter(is_folder=False, is_moderated=True).exists() %}
{% if a.file %}
<img src="{{ a.as_picture.get_download_url() }}" alt="{% trans %}preview{% endtrans %}">
{% elif a.children.filter(is_folder=False, is_moderated=True).exists() %}
<img src="{{ a.children.filter(is_folder=False).first().as_picture.get_download_thumb_url() }}" alt="{% trans %}preview{% endtrans %}">
{% else %}
<img src="{{ static('core/img/sas.jpg') }}" alt="{% trans %}preview{% endtrans %}">
......
......@@ -8,12 +8,14 @@
<h3>{% trans %}SAS{% endtrans %}</h3>
<hr>
<div>
{% for a in root_file.children.filter(is_folder=True).all() %}
{% for a in root_file.children.filter(is_folder=True).order_by('date') %}
{% if a.is_moderated %}
<a href="{{ url("sas:album", album_id=a.id) }}">
<div class="album">
<div>
{% if a.children.filter(is_folder=False, is_moderated=True).exists() %}
{% if a.file %}
<img src="{{ a.as_picture.get_download_url() }}" alt="{% trans %}preview{% endtrans %}">
{% elif a.children.filter(is_folder=False, is_moderated=True).exists() %}
<img src="{{ a.children.filter(is_folder=False).first().as_picture.get_download_thumb_url() }}" alt="{% trans %}preview{% endtrans %}">
{% else %}
<img src="{{ static('core/img/sas.jpg') }}" alt="{% trans %}preview{% endtrans %}">
......
......@@ -202,16 +202,16 @@ class PictureEditForm(forms.ModelForm):
class AlbumEditForm(forms.ModelForm):
class Meta:
model = Album
fields=['name', 'parent']
fields=['name', 'file', 'parent']
parent = make_ajax_field(Album, 'parent', 'files', help_text="")
class PictureEditView(UpdateView):
class PictureEditView(CanEditMixin, UpdateView):
model=Picture
form_class=PictureEditForm
template_name='core/edit.jinja'
pk_url_kwarg = "picture_id"
class AlbumEditView(UpdateView):
class AlbumEditView(CanEditMixin, UpdateView):
model=Album
form_class=AlbumEditForm
template_name='core/edit.jinja'
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment