Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
clinicaltrials
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
david Chavalarias
clinicaltrials
Commits
d8de98a5
Commit
d8de98a5
authored
Feb 27, 2017
by
Romain Loth
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make image path a constant and handle rm old image after change
parent
5c6bdc51
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
4 deletions
+32
-4
main.py
services/main.py
+24
-2
tools.py
services/tools.py
+8
-2
No files found.
services/main.py
View file @
d8de98a5
...
...
@@ -26,7 +26,7 @@ __status__ = "Dev"
# ============== imports ==============
from
re
import
sub
from
os
import
path
from
os
import
path
,
remove
from
json
import
dumps
from
datetime
import
timedelta
from
urllib.parse
import
unquote
...
...
@@ -450,6 +450,10 @@ def profile():
the_id_to_delete
=
current_user
.
uid
mlog
(
"INFO"
,
"executing DELETE scholar's data at the request of user
%
s"
%
str
(
the_id_to_delete
))
# remove saved image if any
if
current_user
.
info
[
'pic_fname'
]:
remove
(
path
.
join
(
*
tools
.
IMAGE_SAVING_POINT
,
current_user
.
info
[
'pic_fname'
]))
logout_user
()
dbcrud
.
rm_scholar
(
the_id_to_delete
)
...
...
@@ -460,6 +464,14 @@ def profile():
# input fields data ~> normalized {cols:values}
our_records
=
read_record_from_request
(
request
)
# small gotcha: absence of the file input is the default in GUI
# (even when we keep the image)
if
'pic_fname'
not
in
our_records
and
'pic_fname'
in
current_user
.
info
and
current_user
.
info
[
'pic_fname'
]:
our_records
[
'pic_fname'
]
=
current_user
.
info
[
'pic_fname'
]
# POSS:
# a dedicated button to indicate that the pic should be rm
# special action CREATE for a new user already known to doors
if
current_user
.
empty
:
mlog
(
"DEBUG"
,
...
...
@@ -760,6 +772,16 @@ def save_form(clean_records, update_flag=False, previous_user_info=None):
return
None
else
:
dbcrud
.
save_full_scholar
(
clean_records
,
reg_db
,
update_user
=
previous_user_info
)
# remove previous image from filesystem if changed
if
(
previous_user_info
[
'pic_fname'
]
and
(
'pic_fname'
in
clean_records
and
previous_user_info
[
'pic_fname'
]
!=
clean_records
[
'pic_fname'
])):
remove
(
path
.
join
(
*
tools
.
IMAGE_SAVING_POINT
,
previous_user_info
[
'pic_fname'
]))
else
:
luid
=
int
(
dbcrud
.
save_full_scholar
(
clean_records
,
reg_db
))
...
...
@@ -858,7 +880,7 @@ def read_record_from_request(request):
if
hasattr
(
request
,
"files"
)
and
'pic_file'
in
request
.
files
and
request
.
files
[
'pic_file'
]:
new_fname
=
tools
.
pic_blob_to_filename
(
request
.
files
[
'pic_file'
])
clean_records
[
'pic_fname'
]
=
new_fname
mlog
(
"
INFO"
,
"new_
fname"
,
new_fname
)
mlog
(
"
DEBUG"
,
"new pic with
fname"
,
new_fname
)
return
clean_records
...
...
services/tools.py
View file @
d8de98a5
...
...
@@ -45,6 +45,9 @@ CONFIGMENU = [
{
"sec"
:
'content'
,
"var"
:
'HAPAX_THRESHOLD'
,
"def"
:
'1 '
}
]
IMAGE_SAVING_POINT
=
[
'data'
,
'shared_user_img'
]
def
home_path
():
"""
returns ./../.. in any OS
...
...
@@ -246,7 +249,7 @@ def format_err(err):
from
uuid
import
uuid4
from
imghdr
import
what
# diagnoses filetype and returns ext
def
pic_blob_to_filename
(
pic_blob
,
path_elts
=
[
'data'
,
'shared_user_img'
]
):
def
pic_blob_to_filename
(
pic_blob
):
"""
Saves a pic blob, returns the relative path
...
...
@@ -256,10 +259,13 @@ def pic_blob_to_filename(pic_blob, path_elts=['data', 'shared_user_img']):
output "12345.png"
+ saved in /data/shared_user_img/12345.png
"""
# our path starts with a working copy of the saving point
path_elts
=
list
(
IMAGE_SAVING_POINT
)
# random 32 hex chars
filename
=
uuid4
()
.
hex
fileext
=
what
(
pic_blob
.
stream
)
fbasename
=
filename
+
'.'
+
fileext
fbasename
=
str
(
filename
)
+
'.'
+
str
(
fileext
)
path_elts
.
append
(
fbasename
)
new_img_relpath
=
path
.
join
(
*
path_elts
)
# save
...
...
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