Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Websites UFRPE
Wagtail Videos
Commits
0fb41adb
Commit
0fb41adb
authored
Jul 07, 2016
by
Seb
Browse files
Fix annoying thumbnail bug
parent
a7e0b168
Changes
3
Hide whitespace changes
Inline
Side-by-side
wagtailvideos/migrations/0006_auto_20160707_1413.py
0 → 100644
View file @
0fb41adb
# -*- coding: utf-8 -*-
# Generated by Django 1.9.7 on 2016-07-07 04:13
from
__future__
import
unicode_literals
from
django.db
import
migrations
,
models
import
wagtailvideos.models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'wagtailvideos'
,
'0005_videotranscode_error_message'
),
]
operations
=
[
migrations
.
AlterField
(
model_name
=
'video'
,
name
=
'thumbnail'
,
field
=
models
.
ImageField
(
blank
=
True
,
null
=
True
,
upload_to
=
wagtailvideos
.
models
.
get_upload_to
),
),
]
wagtailvideos/models.py
View file @
0fb41adb
...
...
@@ -51,7 +51,7 @@ class AbstractVideo(CollectionMember, TagSearchable):
title
=
models
.
CharField
(
max_length
=
255
,
verbose_name
=
_
(
'title'
))
file
=
models
.
FileField
(
verbose_name
=
_
(
'file'
),
upload_to
=
get_upload_to
)
thumbnail
=
models
.
ImageField
(
upload_to
=
get_upload_to
)
thumbnail
=
models
.
ImageField
(
upload_to
=
get_upload_to
,
null
=
True
,
blank
=
True
)
created_at
=
models
.
DateTimeField
(
verbose_name
=
_
(
'created at'
),
auto_now_add
=
True
,
db_index
=
True
)
uploaded_by_user
=
models
.
ForeignKey
(
settings
.
AUTH_USER_MODEL
,
verbose_name
=
_
(
'uploaded by user'
),
...
...
@@ -89,7 +89,6 @@ class AbstractVideo(CollectionMember, TagSearchable):
def
get_upload_to
(
self
,
filename
):
folder_name
=
'original_videos'
filename
=
self
.
file
.
field
.
storage
.
get_valid_name
(
filename
)
# do a unidecode in the filename and then
# replace non-ascii characters in filename with _ , to sidestep issues with filesystem encoding
filename
=
""
.
join
((
i
if
ord
(
i
)
<
128
else
'_'
)
for
i
in
unidecode
(
filename
))
...
...
@@ -123,7 +122,8 @@ class AbstractVideo(CollectionMember, TagSearchable):
self
.
file
.
field
.
storage
.
base_location
,
self
.
get_upload_to
(
self
.
filename
()))
print
(
file_path
)
try
:
output_dir
=
tempfile
.
mkdtemp
()
output_file
=
os
.
path
.
join
(
output_dir
,
self
.
filename
(
include_ext
=
False
)
+
'_thumb.jpg'
)
...
...
@@ -147,7 +147,6 @@ class AbstractVideo(CollectionMember, TagSearchable):
shutil
.
rmtree
(
output_dir
,
ignore_errors
=
True
)
def
save
(
self
,
**
kwargs
):
self
.
thumbnail
=
self
.
get_thumbnail
()
super
(
AbstractVideo
,
self
).
save
(
**
kwargs
)
@
property
...
...
@@ -264,6 +263,7 @@ class TranscodingThread(threading.Thread):
# Delete files when model is deleted
@
receiver
(
pre_delete
,
sender
=
Video
)
def
video_delete
(
sender
,
instance
,
**
kwargs
):
instance
.
thumbnail
.
delete
(
False
)
instance
.
file
.
delete
(
False
)
...
...
wagtailvideos/views/multiple.py
View file @
0fb41adb
...
...
@@ -61,6 +61,9 @@ def add(request):
video
.
uploaded_by_user
=
request
.
user
video
.
file_size
=
video
.
file
.
size
video
.
save
()
# Double save because the video file needs to *really* exists to generate thumbnail
video
.
thumbnail
=
video
.
get_thumbnail
()
video
.
save
(
update_fields
=
[
'thumbnail'
])
# Success! Send back an edit form
return
JsonResponse
({
...
...
Write
Preview
Markdown
is supported
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