def patch(self, request, guid, format=None): """ Update link. """ link = self.get_object_for_user_by_pk(request.user, guid) was_private = link.is_private data = request.data folder = AuthenticatedLinkListView.get_folder_from_request(request) if folder and folder.is_sponsored_root_folder: raise_general_validation_error("You can't move links to your Sponsored Links folder. Select a folder belonging to a sponsor or organization, or your Personal Links folder.") serializer = self.serializer_class(link, data=data, partial=True, context={'request': self.request}) if serializer.is_valid(): serializer.save() # move to new folder if folder: link.move_to_folder_for_user(folder, request.user) # handle file patch uploaded_file = request.data.get('file') if uploaded_file: if link.has_capture_job() and link.capture_job.status == 'in_progress' : raise_general_validation_error("Capture in progress: please wait until complete before uploading a replacement.") # delete related captures, delete warc (rename), mark capture job as superseded link.delete_related_captures() link.safe_delete_warc() link.mark_capturejob_superseded() # write new warc and capture link.write_uploaded_file(uploaded_file, cache_break=True) # delete the link from Webrecorder and # clear the user's Webrecorder session, if any, # so that the new warc is used for this visitor's # next playback of this link. link.delete_from_wr(request) clear_wr_session(request) # update internet archive if privacy changes if 'is_private' in data and was_private != bool(data.get("is_private")) and link.is_permanent(): if was_private: # if link was private but has been marked public, mark it for upload. link.internet_archive_upload_status = 'upload_or_reupload_required' else: # if link was public but has been marked private, mark it for deletion. link.internet_archive_upload_status = 'deletion_required' link.save(update_fields=["internet_archive_upload_status"]) # include remaining links in response links_remaining = request.user.get_links_remaining() serializer.data['links_remaining'] = 'Infinity' if links_remaining[0] == float('inf') else links_remaining[0] serializer.data['links_remaining_period'] = links_remaining[1] return Response(serializer.data) raise ValidationError(serializer.errors)
def patch(self, request, guid, format=None): """ Update link. """ link = self.get_object_for_user_by_pk(request.user, guid) was_private = link.is_private data = request.data serializer = self.serializer_class(link, data=data, partial=True, context={'request': self.request}) if serializer.is_valid(): serializer.save() # move to new folder folder = AuthenticatedLinkListView.get_folder_from_request(request) if folder: link.move_to_folder_for_user(folder, request.user) # handle file patch uploaded_file = request.data.get('file') if uploaded_file: # delete related cdxlines and captures, delete warc (rename) link.delete_related() link.safe_delete_warc() # write new warc and capture link.write_uploaded_file(uploaded_file, cache_break=True) # delete the link from Webrecorder and # clear the user's Webrecorder session, if any, # so that the new warc is used for this visitor's # next playback of this link. if settings.ENABLE_WR_PLAYBACK: link.delete_from_wr(request) clear_wr_session(request) # update internet archive if privacy changes if 'is_private' in data and was_private != bool(data.get("is_private")) and link.is_archive_eligible(): if was_private: # link was private but has been marked public run_task(upload_to_internet_archive.s(link_guid=link.guid)) else: # link was public but has been marked private run_task(delete_from_internet_archive.s(link_guid=link.guid)) # include remaining links in response links_remaining = request.user.get_links_remaining() serializer.data['links_remaining'] = 'Infinity' if links_remaining[0] == float('inf') else links_remaining[0] serializer.data['links_remaining_period'] = links_remaining[1] # clear out any caches that might be based on old link data link.clear_cache() return Response(serializer.data) raise ValidationError(serializer.errors)
def patch(self, request, guid, format=None): """ Update link. """ link = self.get_object_for_user_by_pk(request.user, guid) was_private = link.is_private data = request.data serializer = self.serializer_class(link, data=data, partial=True, context={'request': self.request}) if serializer.is_valid(): serializer.save() # move to new folder folder = AuthenticatedLinkListView.get_folder_from_request(request) if folder: link.move_to_folder_for_user(folder, request.user) # handle file patch uploaded_file = request.data.get('file') if uploaded_file: # delete related cdxlines and captures, delete warc (rename) link.delete_related() link.safe_delete_warc() # write new warc and capture link.write_uploaded_file(uploaded_file, cache_break=True) link.warc_size = default_storage.size(link.warc_storage_file()) link.save() # delete the link from Webrecorder and # clear the user's Webrecorder session, if any, # so that the new warc is used for this visitor's # next playback of this link. link.delete_from_wr(request) clear_wr_session(request) # update internet archive if privacy changes if 'is_private' in data and was_private != bool(data.get("is_private")) and link.is_archive_eligible(): if was_private: # link was private but has been marked public run_task(upload_to_internet_archive.s(link_guid=link.guid)) else: # link was public but has been marked private run_task(delete_from_internet_archive.s(link_guid=link.guid)) # include remaining links in response links_remaining = request.user.get_links_remaining() serializer.data['links_remaining'] = 'Infinity' if links_remaining[0] == float('inf') else links_remaining[0] serializer.data['links_remaining_period'] = links_remaining[1] return Response(serializer.data) raise ValidationError(serializer.errors)