def save_transcripts(request): """ Saves video module with updated values of fields. Returns: status `Success` or status `Error` and HTTP 400. """ response = {'status': 'Error'} data = json.loads(request.GET.get('data', '{}')) if not data: return error_response(response, 'Incoming video data is empty.') try: item = _get_item(request, data) except (InvalidKeyError, ItemNotFoundError): return error_response(response, "Can't find item by locator.") metadata = data.get('metadata') if metadata is not None: new_sub = metadata.get('sub') for metadata_key, value in metadata.items(): setattr(item, metadata_key, value) item.save_with_metadata( request.user) # item becomes updated with new values if new_sub: manage_video_subtitles_save(item, request.user) else: # If `new_sub` is empty, it means that user explicitly does not want to use # transcripts for current video ids and we remove all transcripts from storage. current_subs = data.get('current_subs') if current_subs is not None: for sub in current_subs: remove_subs_from_store(sub, item) response['status'] = 'Success' return JsonResponse(response)
def save_transcripts(request): """ Saves video module with updated values of fields. Returns: status `Success` or status `Error` and HTTP 400. """ response = {'status': 'Error'} data = json.loads(request.GET.get('data', '{}')) if not data: return error_response(response, 'Incoming video data is empty.') try: item = _get_item(request, data) except (ItemNotFoundError, InvalidLocationError, InsufficientSpecificationError): return error_response(response, "Can't find item by locator.") metadata = data.get('metadata') if metadata is not None: new_sub = metadata.get('sub') for metadata_key, value in metadata.items(): setattr(item, metadata_key, value) item.save_with_metadata(request.user) # item becomes updated with new values if new_sub: manage_video_subtitles_save(item, request.user) else: # If `new_sub` is empty, it means that user explicitly does not want to use # transcripts for current video ids and we remove all transcripts from storage. current_subs = data.get('current_subs') if current_subs is not None: for sub in current_subs: remove_subs_from_store(sub, item) response['status'] = 'Success' return JsonResponse(response)
def save_transcripts(request): """ Saves video module with updated values of fields. Returns: status `Success` or status `Error` and HTTP 400. """ response = {"status": "Error"} data = json.loads(request.GET.get("data", "{}")) if not data: return error_response(response, "Incoming video data is empty.") try: item = _get_item(request, data) except (InvalidKeyError, ItemNotFoundError): return error_response(response, "Can't find item by locator.") metadata = data.get("metadata") if metadata is not None: new_sub = metadata.get("sub") for metadata_key, value in metadata.items(): setattr(item, metadata_key, value) item.save_with_metadata(request.user) # item becomes updated with new values if new_sub: manage_video_subtitles_save(item, request.user) else: # If `new_sub` is empty, it means that user explicitly does not want to use # transcripts for current video ids and we remove all transcripts from storage. current_subs = data.get("current_subs") if current_subs is not None: for sub in current_subs: remove_subs_from_store(sub, item) response["status"] = "Success" return JsonResponse(response)