Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
concrexit
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
70
Issues
70
List
Boards
Labels
Service Desk
Milestones
Merge Requests
10
Merge Requests
10
Operations
Operations
Incidents
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
thalia
concrexit
Commits
515ecc33
Unverified
Commit
515ecc33
authored
Mar 14, 2018
by
Thom Wiggers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix uploading gifs
Closes
#610
parent
c7030ca1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
4 deletions
+29
-4
website/members/models.py
website/members/models.py
+17
-2
website/photos/models.py
website/photos/models.py
+12
-2
No files found.
website/members/models.py
View file @
515ecc33
import
operator
import
os
import
logging
from
datetime
import
timedelta
from
functools
import
reduce
...
...
@@ -19,6 +20,9 @@ from localflavor.generic.models import IBANField
from
activemembers.models
import
Committee
logger
=
logging
.
getLogger
(
__name__
)
class
MemberManager
(
UserManager
):
"""Get all members, i.e. all users with a profile."""
...
...
@@ -427,15 +431,26 @@ class Profile(models.Model):
elif
self
.
photo
and
self
.
_orig_image
!=
self
.
photo
.
path
:
image_path
=
self
.
photo
.
path
image
=
Image
.
open
(
image_path
)
image_path
,
_ext
=
os
.
path
.
splitext
(
image_path
)
image_path
=
"{}.jpg"
.
format
(
image_path
)
# Image.thumbnail does not upscale an image that is smaller
logger
.
debug
(
"Converting image %s"
,
image_path
)
image
.
thumbnail
(
settings
.
PHOTO_UPLOAD_SIZE
,
Image
.
ANTIALIAS
)
image
.
save
(
image_path
,
"JPEG"
)
image
.
convert
(
"RGB"
).
save
(
image_path
,
"JPEG"
)
image_name
,
_ext
=
os
.
path
.
splitext
(
self
.
photo
.
name
)
self
.
photo
.
name
=
"{}.jpg"
.
format
(
image_name
)
super
().
save
(
*
args
,
**
kwargs
)
try
:
os
.
remove
(
self
.
_orig_image
)
if
self
.
_orig_image
:
logger
.
info
(
"deleting"
,
self
.
_orig_image
)
os
.
remove
(
self
.
_orig_image
)
except
FileNotFoundError
:
pass
self
.
_orig_image
=
self
.
photo
.
path
else
:
logging
.
warning
(
"We already had this image"
)
def
__str__
(
self
):
return
str
(
self
.
user
)
...
...
website/photos/models.py
View file @
515ecc33
import
hashlib
import
os
import
random
import
logging
from
PIL.JpegImagePlugin
import
JpegImageFile
from
django.conf
import
settings
...
...
@@ -26,6 +27,9 @@ EXIF_ORIENTATION = {
}
logger
=
logging
.
getLogger
(
__name__
)
def
photo_uploadto
(
instance
,
filename
):
num
=
instance
.
album
.
photo_set
.
count
()
extension
=
os
.
path
.
splitext
(
filename
)[
1
]
...
...
@@ -91,13 +95,19 @@ class Photo(models.Model):
if
self
.
_orig_file
!=
self
.
file
.
path
:
image_path
=
self
.
file
.
path
image
=
Image
.
open
(
image_path
)
image_path
,
_ext
=
os
.
path
.
splitext
(
image_path
)
image_path
=
"{}.jpg"
.
format
(
image_path
)
self
.
rotation
=
determine_rotation
(
image
)
# Image.thumbnail does not upscale an image that is smaller
image
.
thumbnail
(
settings
.
PHOTO_UPLOAD_SIZE
,
Image
.
ANTIALIAS
)
image
.
save
(
image_path
,
"JPEG"
)
self
.
_orig_file
=
self
.
file
.
path
logger
.
info
(
"Trying to save to %s"
,
image_path
)
image
.
convert
(
"RGB"
).
save
(
image_path
,
"JPEG"
)
self
.
_orig_file
=
image_path
image_name
,
_ext
=
os
.
path
.
splitext
(
self
.
file
.
name
)
self
.
file
.
name
=
"{}.jpg"
.
format
(
image_name
)
hash_sha1
=
hashlib
.
sha1
()
for
chunk
in
iter
(
lambda
:
self
.
file
.
read
(
4096
),
b""
):
...
...
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