mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-22 14:13:21 +00:00
Add thumbnails to albums
This commit is contained in:
parent
7e335cfbd7
commit
7453b857fb
@ -572,10 +572,14 @@ class SithFile(models.Model):
|
|||||||
code='duplicate',
|
code='duplicate',
|
||||||
)
|
)
|
||||||
if self.is_folder:
|
if self.is_folder:
|
||||||
try:
|
if self.file:
|
||||||
self.file.delete()
|
try:
|
||||||
except: pass
|
import imghdr
|
||||||
self.file = None
|
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"
|
self.mime_type = "inode/directory"
|
||||||
if self.is_file and (self.file is None or self.file == ""):
|
if self.is_file and (self.file is None or self.file == ""):
|
||||||
raise ValidationError(_("You must provide a 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.
|
iterator for chunks of 8KB.
|
||||||
"""
|
"""
|
||||||
f = file_class.objects.filter(id=file_id).first()
|
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)
|
return not_found(request)
|
||||||
from counter.models import Counter
|
from counter.models import Counter
|
||||||
if not (can_view(f, request.user) or
|
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">
|
<a href="{{ url("sas:album", album_id=a.id) }}" style="display: inline-block">
|
||||||
<div class="album">
|
<div class="album">
|
||||||
<div>
|
<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 %}">
|
<img src="{{ a.children.filter(is_folder=False).first().as_picture.get_download_thumb_url() }}" alt="{% trans %}preview{% endtrans %}">
|
||||||
{% else %}
|
{% else %}
|
||||||
<img src="{{ static('core/img/sas.jpg') }}" alt="{% trans %}preview{% endtrans %}">
|
<img src="{{ static('core/img/sas.jpg') }}" alt="{% trans %}preview{% endtrans %}">
|
||||||
|
@ -8,12 +8,14 @@
|
|||||||
<h3>{% trans %}SAS{% endtrans %}</h3>
|
<h3>{% trans %}SAS{% endtrans %}</h3>
|
||||||
<hr>
|
<hr>
|
||||||
<div>
|
<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 %}
|
{% if a.is_moderated %}
|
||||||
<a href="{{ url("sas:album", album_id=a.id) }}">
|
<a href="{{ url("sas:album", album_id=a.id) }}">
|
||||||
<div class="album">
|
<div class="album">
|
||||||
<div>
|
<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 %}">
|
<img src="{{ a.children.filter(is_folder=False).first().as_picture.get_download_thumb_url() }}" alt="{% trans %}preview{% endtrans %}">
|
||||||
{% else %}
|
{% else %}
|
||||||
<img src="{{ static('core/img/sas.jpg') }}" alt="{% trans %}preview{% endtrans %}">
|
<img src="{{ static('core/img/sas.jpg') }}" alt="{% trans %}preview{% endtrans %}">
|
||||||
|
@ -202,16 +202,16 @@ class PictureEditForm(forms.ModelForm):
|
|||||||
class AlbumEditForm(forms.ModelForm):
|
class AlbumEditForm(forms.ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Album
|
model = Album
|
||||||
fields=['name', 'parent']
|
fields=['name', 'file', 'parent']
|
||||||
parent = make_ajax_field(Album, 'parent', 'files', help_text="")
|
parent = make_ajax_field(Album, 'parent', 'files', help_text="")
|
||||||
|
|
||||||
class PictureEditView(UpdateView):
|
class PictureEditView(CanEditMixin, UpdateView):
|
||||||
model=Picture
|
model=Picture
|
||||||
form_class=PictureEditForm
|
form_class=PictureEditForm
|
||||||
template_name='core/edit.jinja'
|
template_name='core/edit.jinja'
|
||||||
pk_url_kwarg = "picture_id"
|
pk_url_kwarg = "picture_id"
|
||||||
|
|
||||||
class AlbumEditView(UpdateView):
|
class AlbumEditView(CanEditMixin, UpdateView):
|
||||||
model=Album
|
model=Album
|
||||||
form_class=AlbumEditForm
|
form_class=AlbumEditForm
|
||||||
template_name='core/edit.jinja'
|
template_name='core/edit.jinja'
|
||||||
|
Loading…
Reference in New Issue
Block a user