def db_to_form_schema(self):
        # in CKAN 2.3: schema = ckan.logic.schema.default_show_group_schema()
        # TODO should be called by ckan.lib.plugins.DefaultGroupForm.db_to_form_schema
        # or return {}

        # CKAN 2.2
        schema = self._default_show_group_schema()

        from_extras = tk.get_converter('convert_from_extras')
        optional = tk.get_validator('ignore_missing')
        not_empty = tk.get_validator('not_empty')

        default_validators = [from_extras, optional]
        schema.update({
            # If i don't put these 'extras' entries in schema
            # dictization_functions.augment_data converts ('extras', '0', 'key') -> string
            # to ('extras', '0', '__extras') -> dict
            # and from_extras is cannot match ('extras', '0', 'key') and does nothing
            'extras': {
                'value': [],
                'key': []
            },
            'address_city': default_validators,
            'address_postal_code': default_validators,
            'address_street': default_validators,
            'website': default_validators,
            'email': default_validators,
            'tel': default_validators,
            'fax': default_validators,
            'regon': default_validators,
            'epuap': default_validators
        })
        return schema
예제 #2
0
    def db_to_form_schema(self):
        # in CKAN 2.3: schema = ckan.logic.schema.default_show_group_schema()
        # TODO should be called by ckan.lib.plugins.DefaultGroupForm.db_to_form_schema
        # or return {}

        # CKAN 2.2
        schema = self._default_show_group_schema()

        from_extras = tk.get_converter("convert_from_extras")
        optional = tk.get_validator("ignore_missing")
        not_empty = tk.get_validator("not_empty")

        default_validators = [from_extras, optional]
        schema.update(
            {
                # If i don't put these 'extras' entries in schema
                # dictization_functions.augment_data converts ('extras', '0', 'key') -> string
                # to ('extras', '0', '__extras') -> dict
                # and from_extras is cannot match ('extras', '0', 'key') and does nothing
                "extras": {"value": [], "key": []},
                "address_city": default_validators,
                "address_postal_code": default_validators,
                "address_street": default_validators,
                "website": default_validators,
                "email": default_validators,
                "tel": default_validators,
                "fax": default_validators,
                "regon": default_validators,
                "epuap": default_validators,
            }
        )
        return schema
예제 #3
0
 def _modify_package_schema(self, schema):
     schema.update({
         'inventory_entry_id': [get_converter('convert_to_extras'),
                                get_validator('ignore_missing'),
         ]
     })
     return schema
예제 #4
0
 def show_package_schema(self):
     schema = super(InventoryPluginFix, self).show_package_schema()
     schema.update({
         'inventory_entry_id': [get_converter('convert_from_extras'),
                                get_validator('ignore_missing')]
     })
     return schema
예제 #5
0
def test_convert_from_extras():
    from ckan import logic

    context = {"model": ckan.model, "session": ckan.model.Session}
    schema = ckan.logic.schema.default_create_package_schema()
    schema.update({"my_field": [logic.converters.convert_from_extras]})
    data_dict = {
        "name":
        "my-pkg",
        "extras": [
            {
                "key": "my_field",
                "value": "hola"
            },
            {
                "key": "another_extra",
                "value": "caracola"
            },
        ],
    }
    data, errors = validate(data_dict, schema, context)

    assert "my_field" in data
    assert data["my_field"] == "hola"
    assert data["extras"][0]["key"] == "another_extra"
예제 #6
0
파일: create.py 프로젝트: nigelbabu/ckan
def resource_view_create(context, data_dict):
    '''Creates a new resource view.

    :param resource_id: id of the resource
    :type resource_id: string
    :param title: the title of the view
    :type title: string
    :param description: a description of the view (optional)
    :type description: string
    :param view_type: type of view
    :type view_type: string
    :param config: options necessary to recreate a view state (optional)
    :type config: JSON string

    :returns: the newly created resource view
    :rtype: dictionary

    '''
    model = context['model']

    resource_id = _get_or_bust(data_dict, 'resource_id')
    view_type = _get_or_bust(data_dict, 'view_type')
    view_plugin = ckan.lib.datapreview.get_view_plugin(view_type)

    if not view_plugin:
        raise ValidationError(
            {"view_type": "No plugin found for view_type {view_type}".format(
                view_type=view_type
            )}
        )

    default = logic.schema.default_create_resource_view_schema(view_plugin)
    schema = context.get('schema', default)
    plugin_schema = view_plugin.info().get('schema', {})
    schema.update(plugin_schema)

    data, errors = _validate(data_dict, schema, context)
    if errors:
        model.Session.rollback()
        raise ValidationError(errors)

    _check_access('resource_view_create', context, data_dict)

    if context.get('preview'):
        return data

    max_order = model.Session.query(
        func.max(model.ResourceView.order)
        ).filter_by(resource_id=resource_id).first()

    order = 0
    if max_order[0] is not None:
        order = max_order[0] + 1
    data['order'] = order

    resource_view = model_save.resource_view_dict_save(data, context)
    if not context.get('defer_commit'):
        model.repo.commit()
    return model_dictize.resource_view_dictize(resource_view, context)
예제 #7
0
    def db_to_form_schema(data, package_type=None):
        schema = logic.schema.package_form_schema()
        schema.update({
            'id': [ignore_missing, unicode],
            'tags': {
                '__extras': [keep_extras, free_tags_only]
            },
            'alternative_title': [convert_from_extras, ignore_missing],
            'status': [convert_from_tags(STATUS_VOCAB_NAME), ignore_missing],
            'identifier': [convert_from_extras, ignore_missing],
            'interoperability_level': [convert_from_tags(INTEROP_VOCAB_NAME),
                                       ignore_missing],
            'type_of_dataset': [convert_from_tags(DATASET_TYPE_VOCAB_NAME),
                                ignore_missing],
            'published_by': [convert_from_groups('name')],
            'capacity': [convert_from_groups('capacity')],
            'release_date': [convert_from_extras, ignore_missing],
            'modified_date': [convert_from_extras, ignore_missing],
            'accrual_periodicity': [convert_from_extras, ignore_missing],
            'temporal_coverage_from': [convert_from_extras, ignore_missing],
            'temporal_coverage_to': [convert_from_extras, ignore_missing],
            'temporal_granularity': [convert_from_tags(TEMPORAL_VOCAB_NAME),
                                     ignore_missing],
            'geographical_coverage': [convert_from_tags(GEO_VOCAB_NAME),
                                      ignore_missing],
            'language': [convert_from_tags(LANGUAGE_VOCAB_NAME),
                         ignore_missing],
            'metadata_language': [convert_from_extras, ignore_missing],
            'version_description': [convert_from_extras, ignore_missing],
            'rdf': [convert_from_extras, ignore_missing],
            'contact_name': [convert_from_extras, ignore_missing],
            'contact_email': [convert_from_extras, ignore_missing],
            'contact_address': [convert_from_extras, ignore_missing],
            'contact_telephone': [convert_from_extras, ignore_missing],
            'contact_webpage': [convert_from_extras, ignore_missing],
            'license_url': [ignore_missing],
            'license_title': [ignore_missing],
            'metadata_created': [ignore_missing],
            'metadata_modified': [ignore_missing],
            '__after': [duplicate_extras_key,
                        rename('tags', 'keywords'),
                        rename('notes', 'description')]
        })

        schema['groups'].update({
            'name': [not_empty, unicode],
            'title': [ignore_missing],
            'capacity': [ignore_missing, unicode]
        })

        schema['resources'].update({
            'created': [ignore_missing],
            'position': [not_empty],
            'last_modified': [ignore_missing],
            'cache_last_updated': [ignore_missing],
            'webstore_last_updated': [ignore_missing]
        })

        return schema
예제 #8
0
 def _modify_package_schema(self, schema):
     schema.update({
         'inventory_entry_id': [
             get_converter('convert_to_extras'),
             get_validator('ignore_missing'),
         ]
     })
     return schema
예제 #9
0
 def _modify_package_schema(self, schema):
     schema.update({
         'inventory_entry_id': [
             get_converter('convert_to_extras'),
             get_converter('update_package_inventory_entry')
         ]
     })
     return schema
예제 #10
0
 def form_to_db_schema(self):
     schema = super(InventoryPlugin, self).form_to_db_schema()
     schema.update({
         'inventory_organization_id': [
             get_validator('ignore_missing'),
             get_converter('convert_to_extras')]
     })
     return schema
예제 #11
0
 def db_to_form_schema(self):
     schema = ckan.logic.schema.default_show_group_schema()
     schema.update({
         'inventory_organization_id': [
             get_validator('ignore_missing'),
             get_converter('convert_from_extras')]
     })
     return schema
예제 #12
0
def resource_view_create(context, data_dict):
    '''Creates a new resource view.

    :param resource_id: id of the resource
    :type resource_id: string
    :param title: the title of the view
    :type title: string
    :param description: a description of the view (optional)
    :type description: string
    :param view_type: type of view
    :type view_type: string
    :param config: options necessary to recreate a view state (optional)
    :type config: JSON string

    :returns: the newly created resource view
    :rtype: dictionary

    '''
    model = context['model']

    resource_id = _get_or_bust(data_dict, 'resource_id')
    view_type = _get_or_bust(data_dict, 'view_type')
    view_plugin = ckan.lib.datapreview.get_view_plugin(view_type)

    if not view_plugin:
        raise ValidationError({
            "view_type":
            "No plugin found for view_type {view_type}".format(
                view_type=view_type)
        })

    default = logic.schema.default_create_resource_view_schema(view_plugin)
    schema = context.get('schema', default)
    plugin_schema = view_plugin.info().get('schema', {})
    schema.update(plugin_schema)

    data, errors = _validate(data_dict, schema, context)
    if errors:
        model.Session.rollback()
        raise ValidationError(errors)

    _check_access('resource_view_create', context, data_dict)

    if context.get('preview'):
        return data

    max_order = model.Session.query(func.max(
        model.ResourceView.order)).filter_by(resource_id=resource_id).first()

    order = 0
    if max_order[0] is not None:
        order = max_order[0] + 1
    data['order'] = order

    resource_view = model_save.resource_view_dict_save(data, context)
    if not context.get('defer_commit'):
        model.repo.commit()
    return model_dictize.resource_view_dictize(resource_view, context)
예제 #13
0
 def show_package_schema(self):
     schema = super(InventoryPluginFix, self).show_package_schema()
     schema.update({
         'inventory_entry_id': [
             get_converter('convert_from_extras'),
             get_validator('ignore_missing')
         ]
     })
     return schema
예제 #14
0
 def db_to_form_schema(self):
     schema = ckan.logic.schema.default_show_group_schema()
     schema.update({
         'inventory_organization_id': [
             get_validator('ignore_missing'),
             get_converter('convert_from_extras')
         ]
     })
     return schema
예제 #15
0
 def form_to_db_schema(self):
     schema = super(InventoryPlugin, self).form_to_db_schema()
     schema.update({
         'inventory_organization_id': [
             get_validator('ignore_missing'),
             get_converter('convert_to_extras')
         ]
     })
     return schema
예제 #16
0
    def _db_to_edit_form_schema(self):
        schema = self._unique_email_user_schema(logic.schema.default_user_schema())

        from_json = convert_from_json('about')
        ignore_missing = tk.get_validator('ignore_missing')
        schema.update({
            'official_position': [from_json, ignore_missing],
            'official_phone': [from_json, ignore_missing],
            'about': []
        })

        return schema
예제 #17
0
    def form_to_db_schema(self, package_type=None):
        schema = logic.schema.package_form_schema()
        schema.update({
            'name': [not_empty, unicode, ecportal_name_validator,
                     package_name_validator],
            'license_id': [ignore_missing, reduce_list, map_licenses, unicode],
            'keyword_string': [ignore_missing, keyword_string_convert],
            'alternative_title': [ignore_missing, unicode, convert_to_extras],
            'description': [not_empty, unicode],
            'status': [not_empty, convert_to_tags(STATUS_VOCAB_NAME)],
            'identifier': [ignore_missing, unicode, convert_to_extras],
            'interoperability_level': [ignore_missing, convert_to_tags(INTEROP_VOCAB_NAME)],
            'type_of_dataset': [ignore_missing, convert_to_tags(DATASET_TYPE_VOCAB_NAME)],
            'published_by': [not_empty, unicode, publisher_exists,
                             convert_to_groups('name')],
            'capacity': [ignore_missing, unicode, default(u'private'),
                         convert_to_groups('capacity')],
            'release_date': [ignore_missing, ecportal_date_to_db, convert_to_extras],
            'modified_date': [ignore_missing, ecportal_date_to_db, convert_to_extras],
            'accrual_periodicity': [ignore_missing, unicode, convert_to_extras],
            'temporal_coverage_from': [ignore_missing, ecportal_date_to_db,
                                       convert_to_extras],
            'temporal_coverage_to': [ignore_missing, ecportal_date_to_db,
                                     convert_to_extras],
            'temporal_granularity': [ignore_missing, convert_to_tags(TEMPORAL_VOCAB_NAME)],
            'geographical_coverage': [ignore_missing, convert_to_tags(GEO_VOCAB_NAME)],
            'language': [ignore_missing, convert_to_tags(LANGUAGE_VOCAB_NAME)],
            'metadata_language': [ignore_missing, member_of_vocab(LANGUAGE_VOCAB_NAME), convert_to_extras],
            'version_description': [ignore_missing, unicode, convert_to_extras],
            'rdf': [ignore_missing, unicode, update_rdf, convert_to_extras],
            'contact_name': [ignore_missing, unicode, convert_to_extras],
            'contact_email': [ignore_missing, requires_field('contact_name'),
                              unicode, convert_to_extras],
            'contact_address': [ignore_missing, requires_field('contact_name'),
                                unicode, convert_to_extras],
            'contact_telephone': [ignore_missing, requires_field('contact_name'),
                                  unicode, convert_to_extras],
            'contact_webpage': [ignore_missing, requires_field('contact_name'),
                                unicode, convert_to_extras],
            '__after': [duplicate_extras_key,
                        rename('keywords', 'tags'),
                        rename('description', 'notes')],
        })

        schema['groups'].update({
            'capacity': [ignore_missing, unicode]
        })

        schema['resources'].update({
            'type': [ignore_missing, unicode, convert_resource_type]
        })

        return schema
예제 #18
0
    def form_to_db_schema(self):
        '''Return the schema for mapping group data from the form to the db.'''
        schema = ckan.logic.schema.group_form_schema()

        # Add CMAP's custom Group Type metadata field to the schema.
        schema.update({
           'cmap_group_type': [validators.ignore_missing, unicode,
               converters.convert_to_extras]
           })

        # Add CMAP's custom Website URL metadata field to the schema.
        schema.update({'website_url': [validators.ignore_missing, unicode,
                    converters.convert_to_extras]})

        return schema
예제 #19
0
    def form_to_db_schema(self):
        '''Return the schema for mapping group data from the form to the db.'''
        schema = ckan.logic.schema.group_form_schema()

        # Add CMAP's custom Group Type metadata field to the schema.
        schema.update({
            'cmap_group_type':
            [validators.ignore_missing, unicode, converters.convert_to_extras]
        })

        # Add CMAP's custom Website URL metadata field to the schema.
        schema.update({
            'website_url':
            [validators.ignore_missing, unicode, converters.convert_to_extras]
        })

        return schema
    def _form_to_db_schema(self, schema):
        to_extras = tk.get_converter('convert_to_extras')
        optional = tk.get_validator('ignore_missing')
        not_empty = tk.get_validator('not_empty')

        default_validators = [not_empty, to_extras]
        schema.update({
            'address_city': default_validators,
            'address_postal_code': default_validators,
            'address_street': default_validators,
            'website': default_validators,
            'email': default_validators,
            'tel': default_validators,
            'fax': default_validators,
            'regon': default_validators,
            'epuap': default_validators
        })
        return schema
예제 #21
0
    def test_convert_from_extras(self):
        from ckan import logic
        context = {'model': ckan.model,
                   'session': ckan.model.Session}
        schema = ckan.logic.schema.default_create_package_schema()
        schema.update({
            'my_field': [logic.converters.convert_from_extras]
        })
        data_dict = {
            'name': 'my-pkg',
            'extras': [
                {'key': 'my_field', 'value': 'hola'},
                {'key': 'another_extra', 'value': 'caracola'}
                ]
            }
        data, errors = validate(data_dict, schema, context)

        assert 'my_field' in data
        assert data['my_field'] == 'hola'
        assert data['extras'][0]['key'] ==  'another_extra'
예제 #22
0
    def _form_to_db_schema(self, schema):
        to_extras = tk.get_converter("convert_to_extras")
        optional = tk.get_validator("ignore_missing")
        not_empty = tk.get_validator("not_empty")

        default_validators = [not_empty, to_extras]
        schema.update(
            {
                "address_city": default_validators,
                "address_postal_code": default_validators,
                "address_street": default_validators,
                "website": default_validators,
                "email": default_validators,
                "tel": default_validators,
                "fax": default_validators,
                "regon": default_validators,
                "epuap": default_validators,
            }
        )
        return schema
예제 #23
0
    def test_convert_from_extras(self):
        from ckan import logic
        context = {'model': ckan.model, 'session': ckan.model.Session}
        schema = ckan.logic.schema.default_create_package_schema()
        schema.update({'my_field': [logic.converters.convert_from_extras]})
        data_dict = {
            'name':
            'my-pkg',
            'extras': [{
                'key': 'my_field',
                'value': 'hola'
            }, {
                'key': 'another_extra',
                'value': 'caracola'
            }]
        }
        data, errors = validate(data_dict, schema, context)

        assert 'my_field' in data
        assert data['my_field'] == 'hola'
        assert data['extras'][0]['key'] == 'another_extra'
예제 #24
0
    def form_to_db_schema_options(self, options):
        'Use ODP schema for WUI and API calls'
        schema = self.form_to_db_schema()

        if options.get('api'):
            schema.update({
                'keywords': logic.schema.default_tags_schema(),
                'groups': {
                    'id': [ignore_missing, unicode],
                    'name': [ignore_missing, unicode],
                    '__extras': [ignore],
                }
            })

            if options.get('type') == 'create':
                schema.update({'id': [empty]})
            else:
                schema.update({
                    'id': [ignore_missing, package_id_not_changed],
                    'name': [ignore_missing, ecportal_name_validator,
                             package_name_validator, unicode],
                    'title': [ignore_missing, unicode]
                })

        return schema
예제 #25
0
    def form_to_db_schema(self):
        schema = ckan.logic.schema.form_to_db_package_schema()

        schema['groups']['capacity'] = [validators.ignore_missing, unicode]
        schema['__after'] = [group_required]

        schema.update({'cmap_geographical_level': [validators.ignore_missing, unicode, converters.convert_to_extras]})
        schema.update({'cmap_data_family': [validators.ignore_missing, unicode, converters.convert_to_extras]})
        schema.update({'cmap_data_category': [validators.ignore_missing, unicode, converters.convert_to_extras]})
        schema.update({'cmap_data_subcategory': [validators.ignore_missing, unicode, converters.convert_to_extras]})
        schema.update({'cmap_data_field': [validators.ignore_missing, unicode, converters.convert_to_extras]})

        schema.update({'__junk': [validators.ignore]})

        return schema
예제 #26
0
    def form_to_db_schema(self):
        schema = super(YtpOrganizationsPlugin, self).form_to_db_schema()
        ignore_missing = toolkit.get_validator('ignore_missing')
        convert_to_extras = toolkit.get_converter('convert_to_extras')

        # schema for homepages
        # schema.update({'homepages': [ignore_missing, convert_to_list, unicode, convert_to_extras]})
        schema.update(
            {'homepage': [ignore_missing, unicode, convert_to_extras]})

        schema.update({
            'public_adminstration_organization':
            [ignore_missing, unicode, convert_to_extras]
        })
        schema.update(
            {'producer_type': [ignore_missing, unicode, convert_to_extras]})

        # schema for extra org info
        # schema.update({'business_id': [ignore_missing, unicode, convert_to_extras]})
        # schema.update({'oid': [ignore_missing, unicode, convert_to_extras]})
        # schema.update({'alternative_name': [ignore_missing, unicode, convert_to_extras]})
        schema.update({
            'valid_from': [ignore_missing, date_validator, convert_to_extras]
        })
        schema.update({
            'valid_till': [ignore_missing, date_validator, convert_to_extras]
        })

        # schema for organisation address
        schema.update(
            {'street_address': [ignore_missing, unicode, convert_to_extras]})
        # schema.update({'street_address_pobox': [ignore_missing, unicode, convert_to_extras]})
        schema.update({
            'street_address_zip_code':
            [ignore_missing, unicode, convert_to_extras]
        })
        schema.update({
            'street_address_place_of_business':
            [ignore_missing, unicode, convert_to_extras]
        })
        # schema.update({'street_address_country': [ignore_missing, unicode, convert_to_extras]})
        # schema.update({'street_address_unofficial_name': [ignore_missing, unicode, convert_to_extras]})
        # schema.update({'street_address_building_id': [ignore_missing, unicode, convert_to_extras]})
        # schema.update({'street_address_getting_there': [ignore_missing, unicode, convert_to_extras]})
        # schema.update({'street_address_parking': [ignore_missing, unicode, convert_to_extras]})
        # schema.update({'street_address_public_transport': [ignore_missing, unicode, convert_to_extras]})
        # schema.update({'street_address_url_public_transport': [ignore_missing, unicode, convert_to_extras]})

        schema = add_translation_modify_schema(schema)
        schema = add_languages_modify(schema, self._localized_fields)

        return schema
예제 #27
0
    def db_to_form_schema(self):
        schema = ckan.logic.schema.group_form_schema()
        ignore_missing = toolkit.get_validator('ignore_missing')
        convert_from_extras = toolkit.get_converter('convert_from_extras')

        # add following since they are missing from schema
        schema.update({'num_followers': [ignore_missing]})
        schema.update({'package_count': [ignore_missing]})

        # Schema for homepages
        schema.update({'homepage': [convert_from_extras, ignore_missing]})

        # schema for extra org info
        schema.update({'valid_from': [convert_from_extras, ignore_missing]})
        schema.update({'valid_till': [convert_from_extras, ignore_missing]})

        # schema for organisation address
        schema.update(
            {'street_address': [convert_from_extras, ignore_missing]})
        schema.update(
            {'street_address_zip_code': [convert_from_extras, ignore_missing]})
        schema.update({
            'street_address_place_of_business':
            [convert_from_extras, ignore_missing]
        })

        schema.update({'producer_type': [convert_from_extras, ignore_missing]})
        schema.update({
            'public_adminstration_organization':
            [convert_from_extras, ignore_missing]
        })

        # old schema is used to display old data if it exists
        schema.update({
            'homepages':
            [convert_from_extras, from_json_to_object, ignore_missing]
        })
        schema.update({'business_id': [convert_from_extras, ignore_missing]})
        schema.update({'oid': [convert_from_extras, ignore_missing]})
        schema.update(
            {'alternative_name': [convert_from_extras, ignore_missing]})
        schema.update(
            {'street_address_pobox': [convert_from_extras, ignore_missing]})
        schema.update(
            {'street_address_country': [convert_from_extras, ignore_missing]})
        schema.update({
            'street_address_unofficial_name':
            [convert_from_extras, ignore_missing]
        })
        schema.update({
            'street_address_building_id':
            [convert_from_extras, ignore_missing]
        })
        schema.update({
            'street_address_getting_there':
            [convert_from_extras, ignore_missing]
        })
        schema.update(
            {'street_address_parking': [convert_from_extras, ignore_missing]})
        schema.update({
            'street_address_public_transport':
            [convert_from_extras, ignore_missing]
        })
        schema.update({
            'street_address_url_public_transport':
            [convert_from_extras, ignore_missing]
        })

        schema = add_translation_show_schema(schema)
        schema = add_languages_show(schema, self._localized_fields)

        return schema
예제 #28
0
    def form_to_db_schema(self):
        schema = ckan.logic.schema.form_to_db_package_schema()

        schema['groups']['capacity'] = [validators.ignore_missing, unicode]
        schema['__after'] = [group_required]

        schema.update({
            'cmap_geographical_level':
            [validators.ignore_missing, unicode, converters.convert_to_extras]
        })
        schema.update({
            'cmap_data_family':
            [validators.ignore_missing, unicode, converters.convert_to_extras]
        })
        schema.update({
            'cmap_data_category':
            [validators.ignore_missing, unicode, converters.convert_to_extras]
        })
        schema.update({
            'cmap_data_subcategory':
            [validators.ignore_missing, unicode, converters.convert_to_extras]
        })
        schema.update({
            'cmap_data_field':
            [validators.ignore_missing, unicode, converters.convert_to_extras]
        })

        schema.update({'__junk': [validators.ignore]})

        return schema
예제 #29
0
 def _unique_email_user_schema(self, schema):
     schema.update({
         'email': schema['email'] + [email_unique_validator]
     })
     return schema
예제 #30
0
파일: plugin.py 프로젝트: haphut/ytp
    def db_to_form_schema(self):
        schema = ckan.logic.schema.group_form_schema()
        ignore_missing = toolkit.get_validator('ignore_missing')
        convert_from_extras = toolkit.get_converter('convert_from_extras')

        # add following since they are missing from schema
        schema.update({'num_followers': [ignore_missing]})
        schema.update({'package_count': [ignore_missing]})

        # Schema for homepages
        schema.update({'homepage': [convert_from_extras, ignore_missing]})

        # schema for extra org info
        schema.update({'valid_from': [convert_from_extras, ignore_missing]})
        schema.update({'valid_till': [convert_from_extras, ignore_missing]})

        # schema for organisation address
        schema.update({'street_address': [convert_from_extras, ignore_missing]})
        schema.update({'street_address_zip_code': [convert_from_extras, ignore_missing]})
        schema.update({'street_address_place_of_business': [convert_from_extras, ignore_missing]})

        schema.update({'producer_type': [convert_from_extras, ignore_missing]})
        schema.update({'public_adminstration_organization': [convert_from_extras, ignore_missing]})

        # old schema is used to display old data if it exists
        schema.update({'homepages': [convert_from_extras, from_json_to_object, ignore_missing]})
        schema.update({'business_id': [convert_from_extras, ignore_missing]})
        schema.update({'oid': [convert_from_extras, ignore_missing]})
        schema.update({'alternative_name': [convert_from_extras, ignore_missing]})
        schema.update({'street_address_pobox': [convert_from_extras, ignore_missing]})
        schema.update({'street_address_country': [convert_from_extras, ignore_missing]})
        schema.update({'street_address_unofficial_name': [convert_from_extras, ignore_missing]})
        schema.update({'street_address_building_id': [convert_from_extras, ignore_missing]})
        schema.update({'street_address_getting_there': [convert_from_extras, ignore_missing]})
        schema.update({'street_address_parking': [convert_from_extras, ignore_missing]})
        schema.update({'street_address_public_transport': [convert_from_extras, ignore_missing]})
        schema.update({'street_address_url_public_transport': [convert_from_extras, ignore_missing]})

        schema = add_translation_show_schema(schema)
        schema = add_languages_show(schema, self._localized_fields)

        return schema
예제 #31
0
파일: plugin.py 프로젝트: haphut/ytp
    def form_to_db_schema(self):
        schema = super(YtpOrganizationsPlugin, self).form_to_db_schema()
        ignore_missing = toolkit.get_validator('ignore_missing')
        convert_to_extras = toolkit.get_converter('convert_to_extras')

        # schema for homepages
        # schema.update({'homepages': [ignore_missing, convert_to_list, unicode, convert_to_extras]})
        schema.update({'homepage': [ignore_missing, unicode, convert_to_extras]})

        schema.update({'public_adminstration_organization': [ignore_missing, unicode, convert_to_extras]})
        schema.update({'producer_type': [ignore_missing, unicode, convert_to_extras]})

        # schema for extra org info
        # schema.update({'business_id': [ignore_missing, unicode, convert_to_extras]})
        # schema.update({'oid': [ignore_missing, unicode, convert_to_extras]})
        # schema.update({'alternative_name': [ignore_missing, unicode, convert_to_extras]})
        schema.update({'valid_from': [ignore_missing, date_validator, convert_to_extras]})
        schema.update({'valid_till': [ignore_missing, date_validator, convert_to_extras]})

        # schema for organisation address
        schema.update({'street_address': [ignore_missing, unicode, convert_to_extras]})
        # schema.update({'street_address_pobox': [ignore_missing, unicode, convert_to_extras]})
        schema.update({'street_address_zip_code': [ignore_missing, unicode, convert_to_extras]})
        schema.update({'street_address_place_of_business': [ignore_missing, unicode, convert_to_extras]})
        # schema.update({'street_address_country': [ignore_missing, unicode, convert_to_extras]})
        # schema.update({'street_address_unofficial_name': [ignore_missing, unicode, convert_to_extras]})
        # schema.update({'street_address_building_id': [ignore_missing, unicode, convert_to_extras]})
        # schema.update({'street_address_getting_there': [ignore_missing, unicode, convert_to_extras]})
        # schema.update({'street_address_parking': [ignore_missing, unicode, convert_to_extras]})
        # schema.update({'street_address_public_transport': [ignore_missing, unicode, convert_to_extras]})
        # schema.update({'street_address_url_public_transport': [ignore_missing, unicode, convert_to_extras]})

        schema = add_translation_modify_schema(schema)
        schema = add_languages_modify(schema, self._localized_fields)

        return schema
예제 #32
0
    def db_to_form_schema(self):
        schema = ckan.logic.schema.db_to_form_package_schema()

        schema.update({
            'cmap_geographical_level':
            [converters.convert_from_extras, validators.ignore_missing]
        })
        schema.update({
            'cmap_data_family':
            [converters.convert_from_extras, validators.ignore_missing]
        })
        schema.update({
            'cmap_data_category':
            [converters.convert_from_extras, validators.ignore_missing]
        })
        schema.update({
            'cmap_data_subcategory':
            [converters.convert_from_extras, validators.ignore_missing]
        })
        schema.update({
            'cmap_data_field':
            [converters.convert_from_extras, validators.ignore_missing]
        })

        # CMAPPackageController adds group_image_url to package dicts, this
        # needs to be added to the schema so that validation doesn't remove it.
        schema.update({'group_image_url': [validators.ignore_missing]})

        # CMAPPackageController adds group_website_url to package dicts, this
        # needs to be added to the schema so that validation doesn't remove it.
        schema.update({'group_website_url': [validators.ignore_missing]})

        # Put group capacity (i.e. public or private) into the schema so it
        # doesn't get removed by validation.
        schema['groups']['capacity'] = []

        # Put a few more keys into the schema so they don't get removed by
        # validation. This stops the user profile page from crashing when the
        # user has some datasets.
        schema.update({'isopen': [validators.ignore_missing]})
        schema['tags'] = {
            'name': [
                validators.not_missing,
                validators.not_empty,
                unicode,
            ],
            'vocabulary_id': [validators.ignore_missing, unicode],
            'revision_timestamp': [validators.ignore],
            'state': [validators.ignore],
            'display_name': [validators.ignore_missing, unicode],
        }
        schema.update({'tracking_summary': [validators.ignore_missing]})

        # This fixes a crash when viewing historical versions of datasets.
        schema.update({'revision_id': [validators.ignore_missing, unicode]})
        schema.update(
            {'revision_timestamp': [validators.ignore_missing, unicode]})

        return schema
예제 #33
0
    def db_to_form_schema(self):
        schema = ckan.logic.schema.db_to_form_package_schema()

        schema.update({'cmap_geographical_level': [converters.convert_from_extras, validators.ignore_missing]})
        schema.update({'cmap_data_family': [converters.convert_from_extras, validators.ignore_missing]})
        schema.update({'cmap_data_category': [converters.convert_from_extras, validators.ignore_missing]})
        schema.update({'cmap_data_subcategory': [converters.convert_from_extras, validators.ignore_missing]})
        schema.update({'cmap_data_field': [converters.convert_from_extras, validators.ignore_missing]})

        # CMAPPackageController adds group_image_url to package dicts, this
        # needs to be added to the schema so that validation doesn't remove it.
        schema.update({'group_image_url': [validators.ignore_missing]})

        # CMAPPackageController adds group_website_url to package dicts, this
        # needs to be added to the schema so that validation doesn't remove it.
        schema.update({'group_website_url': [validators.ignore_missing]})

        # Put group capacity (i.e. public or private) into the schema so it
        # doesn't get removed by validation.
        schema['groups']['capacity'] = []

        # Put a few more keys into the schema so they don't get removed by
        # validation. This stops the user profile page from crashing when the
        # user has some datasets.
        schema.update({'isopen': [validators.ignore_missing]})
        schema['tags'] = {
            'name': [validators.not_missing,
                    validators.not_empty,
                    unicode,
                    ],
            'vocabulary_id': [validators.ignore_missing, unicode],
            'revision_timestamp': [validators.ignore],
            'state': [validators.ignore],
            'display_name': [validators.ignore_missing, unicode],
            }
        schema.update({'tracking_summary': [validators.ignore_missing]})

        # This fixes a crash when viewing historical versions of datasets.
        schema.update({'revision_id': [validators.ignore_missing, unicode]})
        schema.update({'revision_timestamp':
            [validators.ignore_missing, unicode]})

        return schema
예제 #34
0
    def update_config_schema(self, schema):
        '''Add's new fields to the schema for run-time editable configuration
        options.
        '''
        ignore_missing = toolkit.get_validator('ignore_missing')
        # Added piece of mind.
        ignore_not_sysadmin = toolkit.get_validator('ignore_not_sysadmin')
        unicode_safe = toolkit.get_validator('unicode_safe')
        # Remove leading and trailing whitespace.
        remove_whitespace = toolkit.get_converter('remove_whitespace')

        schema.update({
            # Custom configuration options for home page content.
            'ckanext.ontario_theme.home_block_one-en':
            [ignore_missing, ignore_not_sysadmin, unicode_safe],
            'ckanext.ontario_theme.home_block_one-fr':
            [ignore_missing, ignore_not_sysadmin, unicode_safe],
            'ckanext.ontario_theme.home_block_one_image': [
                ignore_missing, ignore_not_sysadmin, unicode_safe,
                remove_whitespace
            ],
            'ckanext.ontario_theme.home_block_one_link-en': [
                ignore_missing, ignore_not_sysadmin, unicode_safe,
                remove_whitespace
            ],
            'ckanext.ontario_theme.home_block_one_link-fr': [
                ignore_missing, ignore_not_sysadmin, unicode_safe,
                remove_whitespace
            ],
            'ckanext.ontario_theme.home_block_two-en':
            [ignore_missing, ignore_not_sysadmin, unicode_safe],
            'ckanext.ontario_theme.home_block_two-fr':
            [ignore_missing, ignore_not_sysadmin, unicode_safe],
            'ckanext.ontario_theme.home_block_two_image': [
                ignore_missing, ignore_not_sysadmin, unicode_safe,
                remove_whitespace
            ],
            'ckanext.ontario_theme.home_block_two_link-en': [
                ignore_missing, ignore_not_sysadmin, unicode_safe,
                remove_whitespace
            ],
            'ckanext.ontario_theme.home_block_two_link-fr': [
                ignore_missing, ignore_not_sysadmin, unicode_safe,
                remove_whitespace
            ],
            'ckanext.ontario_theme.home_block_three-en':
            [ignore_missing, ignore_not_sysadmin, unicode_safe],
            'ckanext.ontario_theme.home_block_three-fr':
            [ignore_missing, ignore_not_sysadmin, unicode_safe],
            'ckanext.ontario_theme.home_block_three_image': [
                ignore_missing, ignore_not_sysadmin, unicode_safe,
                remove_whitespace
            ],
            'ckanext.ontario_theme.home_block_three_link-en': [
                ignore_missing, ignore_not_sysadmin, unicode_safe,
                remove_whitespace
            ],
            'ckanext.ontario_theme.home_block_three_link-fr': [
                ignore_missing, ignore_not_sysadmin, unicode_safe,
                remove_whitespace
            ],
        })

        return schema
예제 #35
0
 def _modify_package_schema(self, schema):
     schema.update({
         'inventory_entry_id': [get_converter('convert_to_extras'),
                                get_converter('update_package_inventory_entry')]
     })
     return schema