def link_publication_document(self, work, info): params = info.get('params') locality_code = self.locality.code if self.locality else None finder = plugins.for_locale('publications', self.country.code, None, locality_code) if not finder or not params.get('date'): return self.create_task(work, info, task_type='link-publication-document') try: publications = finder.find_publications(params) except requests.HTTPError: return self.create_task(work, info, task_type='link-publication-document') if len(publications) != 1: return self.create_task(work, info, task_type='link-publication-document') pub_doc_details = publications[0] pub_doc = PublicationDocument() pub_doc.work = work pub_doc.file = None pub_doc.trusted_url = pub_doc_details.get('url') pub_doc.size = pub_doc_details.get('size') pub_doc.save()
def get_publication_document(self, params, work, form): finder = plugins.for_locale('publications', self.country, None, self.locality) if finder: try: publications = finder.find_publications(params) if len(publications) == 1: pub_doc_details = publications[0] pub_doc = PublicationDocument() pub_doc.work = work pub_doc.file = None pub_doc.trusted_url = pub_doc_details.get('url') pub_doc.size = pub_doc_details.get('size') pub_doc.save() self.pub_doc_task(work, form, task_type='check') else: self.pub_doc_task(work, form, task_type='link') except ValueError as e: raise ValidationError({'message': e.message}) else: self.pub_doc_task(work, form, task_type='link')
def link_publication_document(self, work, row): locality_code = self.locality.code if self.locality else None finder = plugins.for_locale('publications', self.country.code, None, locality_code) if not finder or not row.params.get('date'): return self.create_task(work, row, task_type='link-gazette') try: publications = finder.find_publications(row.params) except requests.HTTPError: return self.create_task(work, row, task_type='link-gazette') if len(publications) != 1: return self.create_task(work, row, task_type='link-gazette') # don't actually create it for dry_run if not self.dry_run: pub_doc_details = publications[0] pub_doc = PublicationDocument() pub_doc.work = work pub_doc.file = None pub_doc.trusted_url = pub_doc_details.get('url') pub_doc.size = pub_doc_details.get('size') pub_doc.save()
def get_publication_document(self, params, work, user): finder = plugins.for_work('publications', work) if finder: try: publications = finder.find_publications(params) if len(publications) == 1: pub_doc_details = publications[0] self.stdout.write( self.style.NOTICE( "Linking publication document {} to {}".format( pub_doc_details.get('url'), work))) pub_doc = PublicationDocument() pub_doc.work = work pub_doc.file = None pub_doc.trusted_url = pub_doc_details.get('url') pub_doc.size = pub_doc_details.get('size') if not self.dry_run: pub_doc.save() else: self.pub_doc_task(work, user) except ValueError as e: raise ValidationError({'message': str(e)}) else: self.pub_doc_task(work, user)