|
|
@@ -88,9 +88,40 @@ class MediaPath(): |
|
|
|
elif MediaType=='Other' and len( os.path.splitext(filename)[1] ): |
|
|
|
filelist.append(tmpurl) |
|
|
|
return filelist |
|
|
|
|
|
|
|
|
|
|
|
def move_mediapath(self, media_table, from_id, to_id): |
|
|
|
""" |
|
|
|
Move target media folder to follow database |
|
|
|
:param media_table: type of media |
|
|
|
:param from_id: source |
|
|
|
:param to_id: destination |
|
|
|
:return: Error if any |
|
|
|
""" |
|
|
|
if media_table in ['tiers', 'place', 'salle', 'users']: |
|
|
|
src = IMAGEPATH + [ media_table, from_id ] |
|
|
|
dst = IMAGEPATH + [ media_table, to_id ] |
|
|
|
else: |
|
|
|
raise RuntimeError("Sorry, Media '%s' not supported yet for move." % media_table) |
|
|
|
|
|
|
|
src_path = os.path.join('jm2l/upload', *src) |
|
|
|
dst_path = os.path.join('jm2l/upload', *dst) |
|
|
|
if not os.path.isdir(src_path): |
|
|
|
# Nothing to do ... |
|
|
|
return False |
|
|
|
if os.path.isdir(dst_path): |
|
|
|
raise RuntimeError('Destination path already exist') |
|
|
|
|
|
|
|
shutil.move(src_path, dst_path) |
|
|
|
|
|
|
|
return True |
|
|
|
|
|
|
|
def get_mediapath(self, media_table, linked_id, name): |
|
|
|
|
|
|
|
""" |
|
|
|
:param media_table: type of media |
|
|
|
:param linked_id: id of media |
|
|
|
:param name: filename |
|
|
|
:return: full relative path on server side |
|
|
|
""" |
|
|
|
linked_id = str(linked_id) |
|
|
|
if media_table in ['tiers', 'place', 'salle']: |
|
|
|
# Retrieve Slug |
|
|
@@ -113,20 +144,13 @@ class MediaPath(): |
|
|
|
elif media_table in ['RIB', 'Justif']: |
|
|
|
slug = User.by_id(linked_id).slug |
|
|
|
p = IMAGEPATH + ['users', slug , media_table ] |
|
|
|
elif media_table=='users': |
|
|
|
user = User.by_id(linked_id) |
|
|
|
if not user: |
|
|
|
raise HTTPNotFound() |
|
|
|
else: |
|
|
|
slug = user.slug |
|
|
|
p = IMAGEPATH + ['users', slug ] |
|
|
|
elif media_table=='badge': |
|
|
|
elif media_table in ['users', 'badge']: |
|
|
|
user = User.by_id(linked_id) |
|
|
|
if not user: |
|
|
|
raise HTTPNotFound() |
|
|
|
else: |
|
|
|
slug = user.slug |
|
|
|
p = IMAGEPATH + ['badge', slug ] |
|
|
|
p = IMAGEPATH + [media_table, slug ] |
|
|
|
elif media_table=='event': |
|
|
|
ev = Event.by_id(linked_id) |
|
|
|
slug = ev.slug |
|
|
|