def delete(request): """ deletu photo in db """ photo_id = request.POST.get('object_id') try: photo = Photo.objects.get(pk=photo_id) except KeyError: response = "KeyError for photo id" else: if 'TRAVIS' not in os.environ: from gdstorage.storage import GoogleDriveStorage gd_storage = GoogleDriveStorage() # delete image gd_storage.delete(photo.image.name) else: from django.core.files.storage import default_storage default_storage.delete(photo.image) photo.delete() response = "Photo supprimée" return response
def delete(request): """ deletu actu in db """ actu_id = request.POST.get('object_id') try: actu = Actu.objects.get(pk=actu_id) except KeyError: response = "KeyError for actu id" else: # delete image if 'TRAVIS' not in os.environ: from gdstorage.storage import GoogleDriveStorage gd_storage = GoogleDriveStorage() gd_storage.delete(actu.image.name) else: from django.core.files.storage import default_storage default_storage.delete(actu.image) actu.delete() response = "Actu supprimée" return response
def delete(request): """ deletu video in db """ video_id = request.POST.get('object_id') try: video = Video.objects.get(pk=video_id) except KeyError: response = "KeyError for video id" else: if 'TRAVIS' not in os.environ: from gdstorage.storage import GoogleDriveStorage gd_storage = GoogleDriveStorage() # delete video gd_storage.delete(video.video.name) else: from django.core.files.storage import default_storage default_storage.delete(video.video) video.delete() response = "Vidéo supprimée" return response
def update(request, form, actu_id): """ update actu """ try: actu = Actu.objects.get(pk=actu_id) except KeyError: pass else: form.errors change_field = False if form.instance.image != "": form_image = request.FILES['image'] if 'TRAVIS' not in os.environ: from gdstorage.storage import GoogleDriveStorage gd_storage = GoogleDriveStorage() # storage new and delete old image gd_storage.delete(actu.image.name) actu.image = gd_storage.save( "".join(["actus/", form_image.name]), form_image) actu.save() code_img = actu.image.url.split("/")[5] actu.display_url_img = "".join( ["https://drive.google.com/uc?id=", code_img]) else: from django.core.files.storage import default_storage new_image = default_storage.save( "".join(["actus/", form_image.name]), form_image) default_storage.delete(actu.image) actu.image = new_image change_field = True if actu.title != form.instance.title: # title actu.title = form.instance.title change_field = True if actu.text != form.instance.text: # text actu.text = form.instance.text change_field = True if change_field is True: actu.change_date = timezone.now() actu.author = request.user actu.save()