Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
AE UTBM
Sith
Commits
7453b857
Commit
7453b857
authored
Nov 30, 2016
by
Skia
🤘
Browse files
Add thumbnails to albums
parent
7e335cfb
Pipeline
#456
passed with stage
in 2 minutes and 35 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
core/models.py
View file @
7453b857
...
...
@@ -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"
))
...
...
core/views/files.py
View file @
7453b857
...
...
@@ -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
...
...
sas/templates/sas/album.jinja
View file @
7453b857
...
...
@@ -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
%}
"
>
...
...
sas/templates/sas/main.jinja
View file @
7453b857
...
...
@@ -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
%}
"
>
...
...
sas/views.py
View file @
7453b857
...
...
@@ -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'
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment