def insert_or_update_media(id_media=None): """ Insertion ou mise à jour d'un média avec prise en compte des fichiers joints .. :quickref: Commons; """ if request.files: file = request.files["file"] else: file = None data = {} if request.form: formData = dict(request.form) for key in formData: data[key] = formData[key] if isinstance(data[key], list): data[key] = data[key][0] if key in ['id_table_location', 'id_nomenclature_media_type', 'id_media']: data[key] = int(data[key]) if data[key] == "true": data[key] = True if data[key] == "false": data[key] = False else: data = request.get_json(silent=True) m = TMediaRepository( data=data, file=file, id_media=id_media ).create_or_update_media() return m.as_dict()
def get_media(id_media): """ Retourne un media """ m = TMediaRepository(id_media=id_media).media if m: return m.as_dict()
def insert_or_update_media(id_media=None): """ Insertion ou mise à jour d'un média avec prise en compte des fichiers joints .. :quickref: Commons; """ if request.files: file = request.files["file"] else: file = None data = {} if request.form: formData = dict(request.form) for key in formData: data[key] = formData[key] if data[key] == 'true': data[key] = True if data[key] == 'false': data[key] = False else: data = request.get_json(silent=True) m = TMediaRepository(data=data, file=file, id_media=id_media).create_or_update_media() return m.as_dict()
def get_media(id_media): ''' Retourne un media ''' m = TMediaRepository(id_media=id_media).media if m: return m.as_dict()
def get_media(id_media): """ Retourne un media """ m = TMediaRepository(id_media=id_media).media if m: return m.as_dict()
def get_media(id_media): """ Retourne un media .. :quickref: Commons; """ m = TMediaRepository(id_media=id_media).media if m: return m.as_dict()
def attach_uuid_to_medium(medium, uuid_attached_row): ''' Fonction permettant de ratacher à posteriori une liste de media à une entité ''' for m in medium: m['uuid_attached_row'] = uuid_attached_row mr = TMediaRepository(data=m, id_media=m['id_media']) mr.media.uuid_attached_row = uuid_attached_row mr._persist_media_db()
def insert_or_update_media(id_media=None): """ Insertion ou mise à jour d'un média avec prise en compte des fichiers joints .. :quickref: Commons; """ # gestion des parametres de route if request.files: file = request.files["file"] else: file = None data = {} if request.form: formData = dict(request.form) for key in formData: data[key] = formData[key] if data[key] in ["null", "undefined"]: data[key] = None if isinstance(data[key], list): data[key] = data[key][0] if ( key in ["id_table_location", "id_nomenclature_media_type", "id_media"] and data[key] is not None ): data[key] = int(data[key]) if data[key] == "true": data[key] = True if data[key] == "false": data[key] = False else: data = request.get_json(silent=True) try: m = TMediaRepository( data=data, file=file, id_media=id_media ).create_or_update_media() except GeoNatureError as e: return str(e), 400 TMediumRepository.sync_medias() return m.as_dict()
def get_media_thumb(id_media, size): """ Retourne le thumbnail d'un media .. :quickref: Commons; """ media_repo = TMediaRepository(id_media=id_media) m = media_repo.media if not m: return {"msg": "Media introuvable"}, 404 try: url_thumb = media_repo.get_thumbnail_url(size) except GeoNatureError as e: return {"msg": str(e)}, 500 return redirect(url_thumb)
def delete_media(id_media): """ Suppression d'un media .. :quickref: Commons; """ TMediaRepository(id_media=id_media).delete() return {"resp": "media {} deleted".format(id_media)}
def insert_or_update_media(id_media=None): ''' Insertion ou mise à jour d'un média avec prise en compte des fichiers joints ''' if request.files: file = request.files['file'] else: file = None data = {} if request.form: formData = dict(request.form) for key in formData: data[key] = formData[key][0] else: data = request.get_json(silent=True) m = TMediaRepository(data=data, file=file, id_media=id_media).create_or_update_media() return m.as_dict()
def insert_or_update_media(id_media=None): """ Insertion ou mise à jour d'un média avec prise en compte des fichiers joints """ if request.files: file = request.files["file"] else: file = None data = {} if request.form: formData = dict(request.form) for key in formData: data[key] = formData[key][0] else: data = request.get_json(silent=True) m = TMediaRepository( data=data, file=file, id_media=id_media ).create_or_update_media() return m.as_dict()
def delete_media(id_media): ''' Suppression d'un media ''' TMediaRepository(id_media=id_media).delete() return {"resp": "media {} deleted".format(id_media)}