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
Sith
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
59
Issues
59
List
Boards
Labels
Service Desk
Milestones
Merge Requests
9
Merge Requests
9
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
AE
Sith
Commits
60e2e0d4
Commit
60e2e0d4
authored
Mar 30, 2017
by
Sli
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Better to use os.path.join for paths
parent
1f844da0
Pipeline
#839
canceled with stage
in 34 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
16 additions
and
11 deletions
+16
-11
core/models.py
core/models.py
+4
-2
core/views/files.py
core/views/files.py
+3
-2
sas/models.py
sas/models.py
+3
-2
sas/templates/sas/picture.jinja
sas/templates/sas/picture.jinja
+6
-5
No files found.
core/models.py
View file @
60e2e0d4
...
...
@@ -12,6 +12,8 @@ from django.contrib.staticfiles.storage import staticfiles_storage
from
django.utils.html
import
escape
from
django.utils.functional
import
cached_property
import
os
from
phonenumber_field.modelfields
import
PhoneNumberField
from
datetime
import
datetime
,
timedelta
,
date
...
...
@@ -664,10 +666,10 @@ class SithFile(models.Model):
if
self
.
is_folder
:
for
c
in
self
.
children
.
all
():
c
.
move_to
(
self
)
shutil
.
rmtree
(
settings
.
MEDIA_ROOT
+
old_file_name
)
shutil
.
rmtree
(
os
.
path
.
join
(
settings
.
MEDIA_ROOT
,
old_file_name
)
)
else
:
self
.
file
.
save
(
name
=
self
.
name
,
content
=
self
.
file
)
os
.
remove
(
settings
.
MEDIA_ROOT
+
old_file_name
)
os
.
remove
(
os
.
path
.
join
(
settings
.
MEDIA_ROOT
,
old_file_name
)
)
def
__getattribute__
(
self
,
attr
):
if
attr
==
"is_file"
:
...
...
core/views/files.py
View file @
60e2e0d4
...
...
@@ -38,10 +38,11 @@ def send_file(request, file_id, file_class=SithFile, file_attr="file"):
):
raise
PermissionDenied
name
=
f
.
__getattribute__
(
file_attr
).
name
with
open
((
settings
.
MEDIA_ROOT
+
name
).
encode
(
'utf-8'
),
'rb'
)
as
filename
:
filepath
=
os
.
path
.
join
(
settings
.
MEDIA_ROOT
,
name
)
with
open
(
filepath
.
encode
(
'utf-8'
),
'rb'
)
as
filename
:
wrapper
=
FileWrapper
(
filename
)
response
=
HttpResponse
(
wrapper
,
content_type
=
f
.
mime_type
)
response
[
'Content-Length'
]
=
os
.
path
.
getsize
(
(
settings
.
MEDIA_ROOT
+
name
)
.
encode
(
'utf-8'
))
response
[
'Content-Length'
]
=
os
.
path
.
getsize
(
filepath
.
encode
(
'utf-8'
))
response
[
'Content-Disposition'
]
=
(
'inline; filename="%s"'
%
f
.
name
).
encode
(
'utf-8'
)
return
response
...
...
sas/models.py
View file @
60e2e0d4
...
...
@@ -7,6 +7,7 @@ from django.core.files.base import ContentFile
from
PIL
import
Image
from
io
import
BytesIO
import
os
from
core.models
import
SithFile
,
User
from
core.utils
import
resize_image
,
exif_auto_rotate
...
...
@@ -17,7 +18,7 @@ class Picture(SithFile):
@
property
def
is_vertical
(
self
):
with
open
(
(
settings
.
MEDIA_ROOT
+
self
.
file
.
name
).
encode
(
'utf-8'
),
'rb'
)
as
f
:
with
open
(
os
.
path
.
join
(
settings
.
MEDIA_ROOT
,
self
.
file
.
name
).
encode
(
'utf-8'
),
'rb'
)
as
f
:
im
=
Image
.
open
(
BytesIO
(
f
.
read
()))
(
w
,
h
)
=
im
.
size
return
(
w
/
h
)
<
1
...
...
@@ -67,7 +68,7 @@ class Picture(SithFile):
def
rotate
(
self
,
degree
):
for
attr
in
[
'file'
,
'compressed'
,
'thumbnail'
]:
name
=
self
.
__getattribute__
(
attr
).
name
with
open
(
(
settings
.
MEDIA_ROOT
+
name
).
encode
(
'utf-8'
),
'r+b'
)
as
file
:
with
open
(
os
.
path
.
join
(
settings
.
MEDIA_ROOT
,
name
).
encode
(
'utf-8'
),
'r+b'
)
as
file
:
if
file
:
im
=
Image
.
open
(
BytesIO
(
file
.
read
()))
file
.
seek
(
0
)
...
...
sas/templates/sas/picture.jinja
View file @
60e2e0d4
...
...
@@ -21,11 +21,12 @@
}
</style>
<link
rel=
"prefetch"
href=
"
{{
url
(
"sas:picture"
,
picture_id
=
picture.get_previous
()
.
id
}
}}
"
>
<!-- Firefox -->
<link
rel=
"prerender"
href=
"
{{
url
(
"sas:picture"
,
picture_id
=
picture.get_previous
()
.
id
}}
"
>
<!-- Chrome -->
<link
rel=
"prefetch"
href=
"
{{
url
(
"sas:picture"
,
picture_id
=
picture.get_next
()
.
id
}
}}
"
>
<!-- Firefox -->
<link
rel=
"prerender"
href=
"
{{
url
(
"sas:picture"
,
picture_id
=
picture.get_next
()
.
id
}}
"
>
<!-- Chrome -->
{%
if
picture.get_previous
()
%}
<link
rel=
"preload"
as=
"image"
href=
"
{{
url
(
"sas:download_compressed"
,
picture_id
=
picture.get_previous
()
.
id
)
}}
"
>
{%
endif
%}
{%
if
picture.get_next
()
%}
<link
rel=
"preload"
as=
"image"
href=
"
{{
url
(
"sas:download_compressed"
,
picture_id
=
picture.get_next
()
.
id
)
}}
"
>
{%
endif
%}
{%
endblock
%}
...
...
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