def import_from_zip(self):
        """Method that renders the form and receive submition of the form."""
        context = {
            'model': model,
            'session': model.Session,
            'user': c.user or c.author,
            'for_view': True,
            'auth_user_obj': c.userobj
        }

        try:
            check_access('package_create', context)
        except NotAuthorized:
            abort(401, _('Unauthorized to create package'))
        except NotFound:
            abort(404, _('Dataset not found'))

        if request.method == 'POST':

            try:
                zip_file = request.params.get('dataset_zip').filename
                get_helpers.get('validate_file_ext')(zip_file)
            except ValidationError, e:
                h.flash_error(e.error_dict['message'])
            except AttributeError, e:
                h.flash_error('Upload field is empty')
    def create_resource(self, context, data_dict, sheet, archive):
        """Create resource with file source or url source."""
        rows = sheet.iter_rows(row_offset=1)
        list_files = archive.namelist()

        for row in rows:
            resource_from = row[1].value
            resource_format = row[2].value
            resource_title = row[3].value
            resource_desc = row[5].value
            if resource_from:
                if not resource_from.startswith('http'):
                    if resource_from in list_files:
                        read_data = archive.read(resource_from)
                        parse_data = io.BytesIO(read_data)
                        fs = get_helpers.get('prepare_file')(read_data,
                                                             parse_data,
                                                             resource_from)

                        tk.get_action('resource_create')(
                            context,
                            {
                                'package_id': data_dict['id'],
                                # url must be provided, even for uploads
                                'url': resource_from,
                                'format': resource_format,
                                'name': resource_title,
                                'description': resource_desc,
                                'url_type': 'upload',
                                'upload': fs
                            })

                elif resource_from:
                    tk.get_action('resource_create')(
                        context, {
                            'package_id': data_dict['id'],
                            'url': resource_from,
                            'name': resource_title,
                            'format': resource_format,
                            'description': resource_desc,
                        })
                        filename=io.BytesIO(metadata), data_only=True)

                    # Get metadata sheet
                    try:
                        metadata_sheet = metadata_xlsx.get_sheet_by_name(
                            METADATA_SHEET[md_file[0]])
                    except KeyError, e:
                        h.flash_error(e)
                    else:
                        #  Get resources sheet
                        resources_sheet = metadata_xlsx.get_sheet_by_name(
                            'Resources')
                        data_dict = {}
                        rows = metadata_sheet.iter_rows(row_offset=1)
                        try:
                            get_helpers.get('prepare_data_dict')(data_dict,
                                                                 rows)
                        except KeyError, e:
                            h.flash_error('Not mapped field: {0}'.format(e))

                        if not data_dict.get('id', False):
                            self.run_create(context, data_dict,
                                            resources_sheet, archive)
                        else:
                            pkg = tk.get_action('package_show')(
                                None, {
                                    'id': data_dict['id']
                                })
                            if pkg:
                                h.flash_error(
                                    'Dataset with id {0} exists'.format(
                                        data_dict['id']))