コード例 #1
0
def build_example_form(is_admin=False,
                       user_editable_groups=None,
                       **kwargs):
    """Customise the core CKAN dataset editing form by adding a new
    field "temporal coverage", and changing the layout of the core
    fields.
    """
    # Restrict fields
    builder = package.build_package_form(
        user_editable_groups=user_editable_groups)

    # Extra fields
    builder.add_field(common.DateRangeExtraField('temporal_coverage'))

    # Layout
    field_groups = OrderedDict([
        (_('Customised Basic information'), ['title', 'name', 'url',
                                  'notes', 'tags']),
        (_('Details'), ['author', 'author_email', 'groups',
                        'maintainer', 'maintainer_email',
                        'license_id', 'temporal_coverage' ]),
        (_('Resources'), ['resources']),
        ])
    builder.set_displayed_fields(field_groups)
    return builder
コード例 #2
0
def build_example_form(is_admin=False, user_editable_groups=None, **kwargs):
    """Customise the core CKAN dataset editing form by adding a new
    field "temporal coverage", and changing the layout of the core
    fields.
    """
    # Restrict fields
    builder = package.build_package_form(
        user_editable_groups=user_editable_groups)

    # Extra fields
    builder.add_field(common.DateRangeExtraField('temporal_coverage'))

    # Layout
    field_groups = OrderedDict([
        (_('Customised Basic information'),
         ['title', 'name', 'url', 'notes', 'tags']),
        (_('Details'), [
            'author', 'author_email', 'groups', 'maintainer',
            'maintainer_email', 'license_id', 'temporal_coverage'
        ]),
        (_('Resources'), ['resources']),
    ])
    builder.set_displayed_fields(field_groups)
    return builder
コード例 #3
0
ファイル: package_datano.py プロジェクト: okfn/ckanext-datano
def build_package_no_form(is_admin=False, user_editable_groups=None, **kwargs):
    # Restrict fields
    restrict = str(kwargs.get('restrict', False)).lower() not in \
               ('0', 'no', 'false', 0, False)

    builder = package.build_package_form(user_editable_groups=user_editable_groups)

    # Extra fields
    builder.add_field(common.TextExtraField('external_reference'))
    builder.add_field(common.DateExtraField('date_released'))
    builder.add_field(common.DateExtraField('date_updated'))
    builder.add_field(common.TextExtraField('update_frequency'))
    builder.add_field(common.SuggestedTextExtraField('geographic_granularity', options=schema_datano.geographic_granularity_options))
    builder.add_field(GeoCoverageExtraField('geographic_coverage'))
    builder.add_field(common.SuggestedTextExtraField('temporal_granularity', options=schema_datano.temporal_granularity_options))
    builder.add_field(common.DateRangeExtraField('temporal_coverage'))
    builder.add_field(common.SuggestedTextExtraField('categories', options=schema_datano.category_options))
    builder.add_field(common.CheckboxExtraField('national_statistic'))
    builder.add_field(common.TextExtraField('precision'))
    builder.add_field(common.SuggestedTextExtraField('department', options=schema_datano.government_depts))
    builder.add_field(common.TextExtraField('agency'))
    builder.add_field(common.TextExtraField('taxonomy_url'))
    builder.add_field(common.TextExtraField('title_en'))
    builder.add_field(common.TextExtraField('notes_en'))
    builder.add_field(common.TextExtraField('external_rss'))
    builder.add_field(common.TextExtraField('example_data'))


    # Labels and instructions
    builder.set_field_text('national_statistic', _('National Statistic'))
    builder.set_field_text('external_rss', _('External RSS'), instructions=_('Link to the data owner\'s external RSS feed.'))
    builder.set_field_text('title_en', _('Title EN'), instructions=_('Title in English. Translate what you wrote in the previous field to English.'))
    builder.set_field_text('notes_en', _('Notes EN'), instructions=_('Description in English. Translate what you wrote in the previous field to English.'))
    builder.set_field_text('date_released', _('Date released'), instructions=_('Date when data source was made available.'), hints=_('Format: DD/MM/YYYY'))
    builder.set_field_text('update_frequency', _('Update frequency'), instructions=_('How often will the data be updated.'), hints=_('e.g. annually, monthly'))
    builder.set_field_text('geographic_coverage', _('Geographic coverage'), instructions=_('Select geographic coverage for your data set.'))
    builder.set_field_text('temporal_coverage', _('Temporal coverage'), instructions=_('Temporal coverage for the data set.'), hints=_('Format: DD/MM/YYYY'))
    builder.set_field_text('author_email', _('Author email'), instructions=_('Email of the main contact for this data source.'))
    builder.set_field_text('maintainer_email', _('Maintainer email'), instructions=_('Email of a person that can be contacted for questions regarding this data source.'))
    builder.set_field_text('example_data', _('Data package example'), instructions=_('Example preview of the data available in this package.'))


    # Options/settings
    builder.set_field_option('tags', 'with_renderer', SuggestTagRenderer)
    builder.set_field_option('notes_en', 'textarea', {'size':'60x15'})
    builder.set_field_option('title', 'validate', required)
    builder.set_field_option('notes', 'validate', required)
    builder.set_field_option('example_data', 'textarea', {'size':'60x15'})

    
    if restrict:
        for field_name in ('name', 'department', 'national_statistic'):
            builder.set_field_option(field_name, 'readonly', True)

    # Layout
    field_groups = OrderedDict([
        (_('Basic information'), ['title', 'title_en', 'name', 'version',
                                  'notes', 'notes_en', 'tags']),
        (_('Details'), ['date_released', 'update_frequency',
                        'geographic_coverage',
                        'temporal_coverage',
                        'author', 'author_email',
                        'maintainer', 'maintainer_email',
                        'license_id',
                        'url', 'external_rss', 'example_data']),
        (_('Resources'), ['resources']),
        (_('More details'), []),
        ])
    if is_admin:
        field_groups[gettext('More details')].append('state')
    builder.set_displayed_fields(field_groups)
    return builder
    # Strings for i18n
    [_('External reference'),  _('Date released'), _('Date updated'),
     _('Update frequency'), _('Geographic granularity'),
     _('Geographic coverage'), _('Temporal granularity'),
     _('Temporal coverage'), _('Categories'), _('National Statistic'),
     _('Precision'), _('Taxonomy URL'), _('Department'), _('Agency'), 
     _('External RSS'), _('Data package example'),
     ]