def create_iati_file(self): """ Create an IATI XML file. """ # Set status to 'In progress' self.update_status(2) # Retrieve all projects projects = self.projects.all() if projects: try: # Generate and save the IATI file iati_xml = IatiXML(projects, self.version, self) self.update_iati_file(iati_xml.save_file( str(self.reporting_organisation.pk), datetime.utcnow().strftime("%Y%m%d-%H%M%S") + '.xml') ) # All done, so update the status to 'Completed' self.update_status(3) except: # Something went wrong, so update the status to 'Cancelled' self.update_status(4) else: # No projects, so update the status to 'Cancelled' self.update_status(4)
def create_iati_file(self): """ Create an IATI XML file. """ # Set status to 'In progress' self.update_status(2) # Retrieve all projects projects = self.projects.all() if projects: try: # Generate and save the IATI file iati_xml = IatiXML(projects, self.version, self) self.update_iati_file( iati_xml.save_file( str(self.reporting_organisation.pk), datetime.utcnow().strftime("%Y%m%d-%H%M%S") + '.xml')) # All done, so update the status to 'Completed' self.update_status(3) except: # Something went wrong, so update the status to 'Cancelled' self.update_status(4) else: # No projects, so update the status to 'Cancelled' self.update_status(4)
def create_iati_file(self): """ Create an IATI XML file. """ self.update_status(self.STATUS_IN_PROGRESS) # Retrieve all projects projects = self.projects.all() if projects: try: # Generate and save the IATI file iati_xml = IatiXML(projects, self.version, self) self.update_iati_file(iati_xml.save_file( str(self.reporting_organisation.pk), datetime.utcnow().strftime("%Y%m%d-%H%M%S") + '.xml') ) self.update_status(self.STATUS_COMPLETED) except: self.update_status(self.STATUS_CANCELLED) else: self.update_status(self.STATUS_CANCELLED)
def create_iati_file(self): """ Create an IATI XML file. """ self.update_status(self.STATUS_IN_PROGRESS) # Retrieve all projects projects = self.projects.all() if projects: try: # Generate and save the IATI file iati_xml = IatiXML(projects, self.version, self) self.update_iati_file( iati_xml.save_file( str(self.reporting_organisation.pk), datetime.utcnow().strftime("%Y%m%d-%H%M%S") + '.xml')) self.update_status(self.STATUS_COMPLETED) except: self.update_status(self.STATUS_CANCELLED) else: self.update_status(self.STATUS_CANCELLED)
def create_iati_file(sender, **kwargs): """ Create an IATI XML file when an entry in the iati_export table is saved, with projects. :param sender: IatiExport model """ iati_export = kwargs.get("instance", None) projects = iati_export.projects.all() if iati_export and projects: post_save.disconnect(create_iati_file, sender=sender) try: iati_export.status = 2 iati_export.save() iati_xml = IatiXML(projects) iati_file = iati_xml.save_file(str(iati_export.reporting_organisation.pk), datetime.utcnow().strftime("%Y%m%d-%H%M%S") + '.xml') iati_export.iati_file = iati_file iati_export.status = 3 iati_export.save() except: iati_export.status = 4 iati_export.save() post_save.connect(create_iati_file, sender=sender)