Exemplo n.º 1
0
 def get_xml_file(self, file_name):
     """
     Find and return the named XML file from the Cordaid Zip archive
     """
     if self.iati_xml_file and zipfile.is_zipfile(self.iati_xml_file):
         xml_file = file_from_zip_archive(self.iati_xml_file, file_name)
         if xml_file:
             return xml_file
         else:
             self.add_log('CordaidZip: {} file not found in ZIP.'.format(file_name),
                          LOG_ENTRY_TYPE.CRITICAL_ERROR)
             return None
Exemplo n.º 2
0
 def get_xml_file(self, file_name):
     """
     Find and return the named XML file from the Cordaid Zip archive
     """
     if self.iati_xml_file and zipfile.is_zipfile(self.iati_xml_file):
         xml_file = file_from_zip_archive(self.iati_xml_file, file_name)
         if xml_file:
             return xml_file
         else:
             self.add_log('CordaidZip: {} file not found in ZIP.'.format(file_name),
                          LOG_ENTRY_TYPE.CRITICAL_ERROR)
             return None
Exemplo n.º 3
0
    def do_import(self):
        """
        :return: List; contains fields that have changed
        """
        from . import same_data

        changes = []

        photo_id = self.get_attrib(self.parent_elem, akvo_ns('photo-id'),
                                   'current_image')
        current_image = file_from_zip_archive(
            self.iati_import_job.iati_xml_file,
            "out_proj/{}.jpg".format(photo_id))
        if current_image:
            tmp_file = NamedTemporaryFile()
            for line in current_image.readlines():
                tmp_file.write(line)
            tmp_file.flush()
            # update current image if it's different from the existing one
            try:
                old_file = self.project.current_image.file
            except (IOError, ValueError):
                old_file = None
            new_file = File(tmp_file)
            if not same_data(old_file, new_file):
                filename = model_and_instance_based_filename(
                    'Project', self.project.pk, 'current_image', 'image.jpg')
                new_file.seek(0)
                self.project.current_image.save(filename, new_file)
                changes += ['current_image']

        current_image_caption = self.get_attrib(self.parent_elem,
                                                akvo_ns('image-caption'),
                                                'current_image_caption')
        if current_image_caption:
            changes += self.update_project_field('current_image_caption',
                                                 current_image_caption)

        current_image_credit = self.get_attrib(self.parent_elem,
                                               akvo_ns('photo-credit'),
                                               'current_image_credit')
        if current_image_credit:
            changes += self.update_project_field('current_image_credit',
                                                 current_image_credit)

        return changes
Exemplo n.º 4
0
    def do_import(self):
        """
        :return: List; contains fields that have changed
        """
        from . import same_data

        changes = []

        photo_id = self.get_attrib(self.parent_elem, akvo_ns('photo-id'), 'current_image')
        current_image = file_from_zip_archive(
            self.iati_import_job.iati_xml_file, "out_proj/{}.jpg".format(photo_id))
        if current_image:
            tmp_file = NamedTemporaryFile()
            for line in current_image.readlines():
                tmp_file.write(line)
            tmp_file.flush()
            # update current image if it's different from the existing one
            try:
                old_file = self.project.current_image.file
            except (IOError, ValueError):
                old_file = None
            new_file = File(tmp_file)
            if not same_data(old_file, new_file):
                filename = model_and_instance_based_filename(
                    'Project', self.project.pk, 'current_image', 'image.jpg')
                new_file.seek(0)
                self.project.current_image.save(filename, new_file)
                changes += ['current_image']

        current_image_caption = self.get_attrib(
            self.parent_elem, akvo_ns('image-caption'), 'current_image_caption')
        if current_image_caption:
            changes += self.update_project_field('current_image_caption', current_image_caption)

        current_image_credit = self.get_attrib(
            self.parent_elem, akvo_ns('photo-credit'), 'current_image_credit')
        if current_image_credit:
            changes += self.update_project_field('current_image_credit', current_image_credit)

        return changes
Exemplo n.º 5
0
 def set_logo(self, organisation, identifier):
     """ Get the organisation's logo from the Cordaid zip archive """
     logo = file_from_zip_archive(
         self.iati_import_job.iati_xml_file, "out_rltn/{}.jpg".format(identifier))
     if logo:
         tmp_file = NamedTemporaryFile()
         for line in logo.readlines():
             tmp_file.write(line)
         tmp_file.flush()
         # update the logo if it's different from the existing one
         try:
             old_file = organisation.logo.file
         except (IOError, ValueError):
             old_file = None
         new_file = File(tmp_file)
         if not same_data(old_file, new_file):
             filename = model_and_instance_based_filename(
                 'Organisation', organisation.pk, 'logo', 'image.jpg')
             new_file.seek(0)
             organisation.logo.save(filename, new_file)
             return 'logo'
     return None
Exemplo n.º 6
0
 def set_logo(self, organisation, identifier):
     """ Get the organisation's logo from the Cordaid zip archive """
     logo = file_from_zip_archive(
         self.iati_import_job.iati_xml_file, "out_rltn/{}.jpg".format(identifier))
     if logo:
         tmp_file = NamedTemporaryFile()
         for line in logo.readlines():
             tmp_file.write(line)
         tmp_file.flush()
         # update the logo if it's different from the existing one
         try:
             old_file = organisation.logo.file
         except (IOError, ValueError):
             old_file = None
         new_file = File(tmp_file)
         if not same_data(old_file, new_file):
             filename = model_and_instance_based_filename(
                 'Organisation', organisation.pk, 'logo', 'image.jpg')
             new_file.seek(0)
             organisation.logo.save(filename, new_file)
             return 'logo'
     return None