mirror of
				https://github.com/ae-utbm/sith.git
				synced 2025-11-04 11:03:04 +00:00 
			
		
		
		
	Add thumbnails to albums
This commit is contained in:
		@@ -572,9 +572,13 @@ class SithFile(models.Model):
 | 
			
		||||
                code='duplicate',
 | 
			
		||||
            )
 | 
			
		||||
        if self.is_folder:
 | 
			
		||||
            if self.file:
 | 
			
		||||
                try:
 | 
			
		||||
                    import imghdr
 | 
			
		||||
                    if imghdr.what(None, self.file.read()) not in ['gif', 'png', 'jpeg']:
 | 
			
		||||
                        self.file.delete()
 | 
			
		||||
            except: pass
 | 
			
		||||
                        self.file = None
 | 
			
		||||
                except:
 | 
			
		||||
                    self.file = None
 | 
			
		||||
            self.mime_type = "inode/directory"
 | 
			
		||||
        if self.is_file and (self.file is None or self.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'
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user