Просмотр исходного кода

Merge branch 'tr4ck3ur/various_fixes_2017' of JM2L/jm2l into master

master
JM2L 7 лет назад
committed by Gogs
Родитель
Сommit
e7ace7cfca
2 измененных файлов: 47 добавлений и 12 удалений
  1. +35
    -11
      jm2l/upload.py
  2. +12
    -1
      jm2l/views.py

+ 35
- 11
jm2l/upload.py Просмотреть файл

@@ -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


+ 12
- 1
jm2l/views.py Просмотреть файл

@@ -7,7 +7,7 @@ from pyramid.view import view_config
from pyramid.response import Response
from mako.template import Template
from pyramid_mailer.message import Message
from .upload import IMAGEPATH
from .upload import IMAGEPATH, MediaPath
# Import Web Forms
from .forms import *
# Database access imports
@@ -739,16 +739,27 @@ def handle_salle_phy(request):
salle_id = request.matchdict.get('salle_id')
if salle_id:
Salle = SallePhy.by_id(int(salle_id))
orig_slug = Salle.slug
if not Salle:
raise HTTPNotFound()
form = EditSallePhyForm(request.POST, Salle, meta={'csrf_context': request.session})
else:
Salle = SallePhy()
orig_slug = None
form = SallePhyForm(request.POST, Salle, meta={'csrf_context': request.session})

if request.method == 'POST' and form.validate():
form.populate_obj(Salle)
dest_slug = slugify(Salle.name)
# Do a check in order to move attached files if any
if orig_slug and orig_slug!=dest_slug:
try:
mp = MediaPath().move_mediapath('salle', orig_slug, dest_slug)
except RuntimeError, err:
request.session.flash(('error', "Le nom de cette salle est déjà utilisé : " + err.message))
return {'form': form}
Salle.slug = slugify(Salle.name)

if 'uid' in form._fields.keys():
DBSession.merge(Salle)
else:


Загрузка…
Отмена
Сохранить