예제 #1
0
def govil_markdown_extract(package_id, text, extract_length=190):
    ''' return the plain text representation of markdown encoded text.  That
    is the texted without any html tags.  If extract_length is 0 then it
    will not be truncated.'''
    RE_MD_HTML_TAGS = re.compile('<[^><]*>')

    if not text:
        return ''
    plain = RE_MD_HTML_TAGS.sub('', markdown(text))
    if not extract_length or len(plain) < extract_length:
        return literal(plain)

    end_a_tag = '<a data-toggle="collapse"' + \
                  ' onclick="$(\'#short_pack_des_'+package_id+'\').hide()"' + \
                  ' href="#full_pack_des_' + package_id + '"' + \
                  ' role="button"'+ \
                  ' aria-expanded="false"'+ \
                  ' aria-controls="full_pack_des_' + package_id + '">...</a>'

    return literal(
        text_type(
            truncate(plain,
                     length=extract_length,
                     indicator=end_a_tag,
                     whole_word=True)))
예제 #2
0
def field_readonly_renderer(key, value, newline_reqd=False):
    if value is None:
        value = ''
    html = literal('<p>%s</p>') % value
    if newline_reqd:
        html += literal('<br/>')
    return html
예제 #3
0
def build_harvest_source_form():
    builder = FormBuilder(HarvestSource)
    builder.set_field_text('url', 'URL for source of metadata', literal("""
        <br/>This should include the <tt>http://</tt> part of the URL and can point to either:
        <ul>
            <li>A server's CSW interface</li>
            <li>A Web Accessible Folder (WAF) displaying a list of GEMINI 2.1 documents</li>
            <li>A single GEMINI 2.1 document</li>
        </ul>
        <br />
        """
    ))
    builder.set_field_option('url', 'validate', harvest_source_url_validator)
    builder.set_field_option('url', 'with_html', {'size':'80'})
    builder.set_field_option('description', 'textarea', {'size':'60x5'})
    builder.set_field_text('description', 'Description', literal('''
        You can add your own notes here about what the URL above represents to remind you later.
        '''
    ))
    builder.set_field_text('type', 'Source Type', literal('''
        Which type of source does the URL above represent?
        '''
    ))
    builder.set_field_option('type', 'validate', harvest_source_type_validator)
    builder.set_field_option('type', 'dropdown', {'options':['CSW Server','Web Accessible Folder (WAF)','Single Document']})
#    displayed_fields = ['url','type','active','description']
    displayed_fields = ['url','type','description']
    builder.set_displayed_fields(OrderedDict([('Details', displayed_fields)]))
    builder.set_label_prettifier(common.prettify)
    return builder  
예제 #4
0
        def render(self, options, **kwargs):
            selected = self.value
            if selected is None:
                selected = self.field.default
            options = [('', '')
                       ] + options + [(_('other - please specify'), 'other')]
            option_keys = [key for value, key in options]
            if selected in option_keys:
                select_field_selected = selected
                text_field_value = u''
            elif selected:
                select_field_selected = u'other'
                text_field_value = selected or u''
            else:
                select_field_selected = u''
                text_field_value = u''
            fa_version_nums = formalchemy.__version__.split('.')
            # Requires FA 1.3.2 onwards for this select i/f
            html = literal(
                fa_h.select(self.name,
                            select_field_selected,
                            options,
                            class_="short",
                            **kwargs))

            other_name = self.name + '-other'
            html += literal('<label class="inline" for="%s">%s: %s</label>'
                            ) % (other_name, _('Other'),
                                 literal(
                                     fa_h.text_field(other_name,
                                                     value=text_field_value,
                                                     class_="medium-width",
                                                     **kwargs)))
            return html
예제 #5
0
파일: plugin.py 프로젝트: CI-WATER/portal
def uebpackage_build_main_navigation(*args):
    output = h.build_nav_main(*args)
    # show ciwater related menu options only if the user is loggedin
    if c.user:        
        link_pkg = h.url_for(controller='ckanext.uebpackage.controllers.packagecreate:PackagecreateController', action='packagecreateform')
        link_run = h.url_for(controller='ckanext.uebpackage.controllers.uebexecute:UEBexecuteController', action='select_model_package')
        if p.toolkit.c.action == 'packagecreateform' or p.toolkit.c.action == 'select_model_package':
            menu = h.literal('<li class="dropdown">')
        else:
            menu = h.literal('<li class="dropdown">')
        
        menu += h.literal('<a id="drop1" role="button" data-toggle="dropdown"  class="dropdown-toggle" href="#">')
        menu += 'UEB' + h.literal('<b><span class="caret"></span></b>')
        menu += h.literal('</a>')
        menu += h.literal('<ul class="dropdown-menu" role="menu" area-labelledby="drop1">')
                
        li = h.literal('<li role="presentation"><a role="menuitem" tabindex="-1" href=') + link_pkg + h.literal('>UEB Model Package</a>') + h.literal('</li>')
        menu += li
        
        li = h.literal('<li role="presentation"><a role="menuitem" tabindex="-1" href=') + link_run + h.literal('>Run UEB</a>') + h.literal('</li>')
        menu += li
        menu += h.literal('</ul>')
        menu += h.literal('</li>')

        output = menu + output
                
    return output
예제 #6
0
def field_readonly_renderer(key, value, newline_reqd=False):
    if value is None:
        value = ''
    html = literal('<p>%s</p>') % value
    if newline_reqd:
        html += literal('<br/>')
    return html
예제 #7
0
def build_pages_nav_main(*args):

    about_menu = p.toolkit.asbool(config.get('ckanext.pages.about_menu', True))
    group_menu = p.toolkit.asbool(config.get('ckanext.pages.group_menu', True))
    org_menu = p.toolkit.asbool(
        config.get('ckanext.pages.organization_menu', True))

    new_args = []
    for arg in args:
        if arg[0] == 'about' and not about_menu:
            continue
        if arg[0] == 'organizations_index' and not org_menu:
            continue
        if arg[0] == 'group_index' and not group_menu:
            continue
        new_args.append(arg)

    output = h.build_nav_main(*new_args)

    # do not display any private datasets in menu even for sysadmins
    pages_list = p.toolkit.get_action('ckanext_pages_list')(None, {
        'order': True,
        'private': False
    })

    page_name = ''

    if (p.toolkit.c.action in ('pages_show', 'blog_show')
            and p.toolkit.c.controller
            == 'ckanext.pages.controller:PagesController'):
        page_name = p.toolkit.c.environ['routes.url'].current().split('/')[-1]

    desired_lang_code = pylons.request.environ['CKAN_LANG']
    acceptable_lang_codes = [
        desired_lang_code,
        desired_lang_code.split('_', 1)[0]
    ]

    for page in pages_list:
        if page.get('lang') and page.get('lang') not in acceptable_lang_codes:
            continue

        if page['page_type'] == 'blog':
            link = h.tags.link_to(page.get('title'),
                                  h.url_for('/blog/' + str(page['name'])))
        else:
            link = h.tags.link_to(page.get('title'),
                                  h.url_for('/pages/' + str(page['name'])))

        if page['name'] == page_name:
            li = h.literal('<li class="active">') + link + h.literal('</li>')
        else:
            li = h.literal('<li>') + link + h.literal('</li>')
        output = output + li

    return output
예제 #8
0
def build_pages_nav_main(*args):

    about_menu = toolkit.asbool(config.get('ckanext.pages.about_menu', True))
    group_menu = toolkit.asbool(config.get('ckanext.pages.group_menu', True))
    org_menu = toolkit.asbool(
        config.get('ckanext.pages.organization_menu', True))

    new_args = []
    for arg in args:
        if arg[0] == 'about' and not about_menu:
            continue
        if arg[0] == 'organizations_index' and not org_menu:
            continue
        if arg[0] == 'group_index' and not group_menu:
            continue
        new_args.append(arg)

    output = h.build_nav_main(*new_args)

    # do not display any private datasets in menu even for sysadmins
    pages_list = toolkit.get_action('ckanext_pages_list')(None, {
        'order': True,
        'private': False
    })

    page_name = ''

    if (toolkit.c.action in ('pages_show', 'blog_show')
            and toolkit.c.controller
            == 'ckanext.pages.controller:PagesController'):
        page_name = toolkit.c.environ['routes.url'].current().split('/')[-1]

    desired_lang_code = pylons.request.environ['CKAN_LANG']
    acceptable_lang_codes = [
        desired_lang_code,
        desired_lang_code.split('_', 1)[0]
    ]

    for page in pages_list:

        if page.get('lang') and page.get('lang') not in acceptable_lang_codes:
            continue

        type_ = 'blog' if page['page_type'] == 'blog' else 'pages'
        name = urllib.quote(page['name'].encode('utf-8')).decode('utf-8')
        title = cgi.escape(page['title'])
        link = h.literal(u'<a href="/{}/{}">{}</a>'.format(type_, name, title))
        if page['name'] == page_name:
            li = h.literal('<li class="active">') + link + h.literal('</li>')
        else:
            li = h.literal('<li>') + link + h.literal('</li>')
        output = output + li

    return output
예제 #9
0
 def render(self, **kwargs):
     value = self._get_value()
     kwargs['size'] = '40'
     html = u''
     for i, region in enumerate(GeoCoverageType.get_instance().regions):
         region_str, region_munged = region
         id = '%s-%s' % (self.name, region_munged)
         checked = region_munged in value
         cb = literal(h.check_box(id, True, checked=checked, **kwargs))
         html += literal('<label for="%s">%s %s</label>') % (id, cb, region_str)
     return html
예제 #10
0
파일: plugin.py 프로젝트: CI-WATER/portal
def delineate_build_main_navigation(*args):
    output = h.build_nav_main(*args)
    if c.user: 
        link = h.link_to('Delineate', h.url_for(controller='ckanext.delineate.controllers.delineatewatershed:DelineatewatershedController', action='show_form'))

        if p.toolkit.c.action == 'show_form':
            li = h.literal('<li class="active">') + link + h.literal('</li>')
        else:
            li = h.literal('<li>') + link + h.literal('</li>')

        output = li + output

    return output
def build_pages_nav_main(*args):
    about_menu = toolkit.asbool(config.get('ckanext.pages.about_menu', False))
    group_menu = toolkit.asbool(config.get('ckanext.pages.group_menu', False))
    org_menu = toolkit.asbool(
        config.get('ckanext.pages.organization_menu', True))

    new_args = []
    for arg in args:
        if arg[0] == 'home.about' and not about_menu:
            continue
        if arg[0] == 'organizations_index' and not org_menu:
            continue
        if arg[0] == 'group_index' and not group_menu:
            continue
        new_args.append(arg)

    output = h.build_nav_main(*new_args)

    # add forum link
    forum_url = config.get('ckan.pages.forum.link', False)
    if forum_url:
        link = h.literal(u'<a href="/{}/{}">{}</a>'.format(
            h.lang(), 'forum', "Forum"))
        li = h.literal('<li>') + link + h.literal('</li>')
        output = output + li

    # do not display any private datasets in menu even for sysadmins
    pages_list = toolkit.get_action('ckanext_pages_list')(None, {
        'order': True,
        'private': False
    })

    page_name = ''

    if (toolkit.c.action in ('pages_show', 'blog_show')
            and toolkit.c.controller
            == 'ckanext.pages.controller:PagesController'):
        page_name = toolkit.c.environ['routes.url'].current().split('/')[-1]

    for page in pages_list:
        type_ = 'blog' if page['page_type'] == 'blog' else 'pages'
        name = urllib.quote(page['name'].encode('utf-8')).decode('utf-8')
        title = cgi.escape(pages_page_title(h.lang(), page))
        if h.lang():
            link = h.literal(u'<a href="/{}/{}/{}">{}</a>'.format(
                h.lang(), type_, name, title))
        else:
            link = h.literal(u'<a href="/{}/{}">{}</a>'.format(
                type_, name, title))
        if page['name'] == page_name:
            li = h.literal('<li class="active">') + link + h.literal('</li>')
        else:
            li = h.literal('<li>') + link + h.literal('</li>')
        output = output + li

    return output
예제 #12
0
def build_pages_nav_main(*args):

    about_menu = toolkit.asbool(config.get('ckanext.pages.about_menu', True))
    group_menu = toolkit.asbool(config.get('ckanext.pages.group_menu', True))
    org_menu = toolkit.asbool(
        config.get('ckanext.pages.organization_menu', True))

    # Different CKAN versions use different route names - gotta catch em all!
    about_menu_routes = ['about', 'home.about']
    group_menu_routes = ['group_index', 'home.group_index']
    org_menu_routes = ['organizations_index', 'home.organizations_index']

    new_args = []
    for arg in args:
        if arg[0] in about_menu_routes and not about_menu:
            continue
        if arg[0] in org_menu_routes and not org_menu:
            continue
        if arg[0] in group_menu_routes and not group_menu:
            continue
        new_args.append(arg)

    output = h.build_nav_main(*new_args)

    # do not display any private datasets in menu even for sysadmins
    pages_list = toolkit.get_action('ckanext_pages_list')(None, {
        'order': True,
        'private': False
    })

    page_name = ''

    if (hasattr(toolkit.c, 'action')
            and toolkit.c.action in ('pages_show', 'blog_show')
            and toolkit.c.controller
            == 'ckanext.pages.controller:PagesController'):
        page_name = toolkit.c.environ['routes.url'].current().split('/')[-1]

    for page in pages_list:
        type_ = 'blog' if page['page_type'] == 'blog' else 'pages'
        name = urllib.quote(page['name'].encode('utf-8')).decode('utf-8')
        title = cgi.escape(page['title'])
        link = h.literal(u'<a href="/{}/{}">{}</a>'.format(type_, name, title))
        if page['name'] == page_name:
            li = h.literal('<li class="active">') + link + h.literal('</li>')
        else:
            li = h.literal('<li>') + link + h.literal('</li>')
        output = output + li

    return output
예제 #13
0
def build_pages_nav_main(*args):

    about_menu = p.toolkit.asbool(config.get('ckanext.pages.about_menu', True))
    group_menu = p.toolkit.asbool(config.get('ckanext.pages.group_menu', True))
    org_menu = p.toolkit.asbool(config.get('ckanext.pages.organization_menu', True))

    new_args = []
    for arg in args:
        if arg[0] == 'about' and not about_menu:
            continue
        if arg[0] == 'organizations_index' and not org_menu:
            continue
        if arg[0] == 'group_index' and not group_menu:
            continue
        new_args.append(arg)

    output = h.build_nav_main(*new_args)

    # do not display any private datasets in menu even for sysadmins
    pages_list = p.toolkit.get_action('ckanext_pages_list')(None, {'order': True, 'private': False})

    page_name = ''

    if (p.toolkit.c.action in ('pages_show', 'blog_show') and
            p.toolkit.c.controller == 'ckanext.pages.controller:PagesController'):
        page_name = p.toolkit.c.environ['routes.url'].current().split('/')[-1]

    desired_lang_code = pylons.request.environ['CKAN_LANG']
    acceptable_lang_codes = [desired_lang_code, desired_lang_code.split('_', 1)[0]]

    for page in pages_list:
        if page.get('lang') and page.get('lang') not in acceptable_lang_codes:
            continue

        if page['page_type'] == 'blog':
            link = h.tags.link_to(page.get('title'),
                             h.url_for('/blog/' + str(page['name'])))
        else:
            link = h.tags.link_to(page.get('title'),
                             h.url_for('/pages/' + str(page['name'])))

        if page['name'] == page_name:
            li = h.literal('<li class="active">') + link + h.literal('</li>')
        else:
            li = h.literal('<li>') + link + h.literal('</li>')
        output = output + li

    return output
예제 #14
0
 def document(self):
     """Render the error document"""
     original_request = request.environ.get('pylons.original_request')
     original_response = request.environ.get('pylons.original_response')
     # When a request (e.g. from a web-bot) is direct, not a redirect
     # from a page. #1176
     if not original_response:
         return 'There is no error.'
     # Bypass error template for API operations.
     if (original_request
             and (original_request.path.startswith('/api')
                  or original_request.path.startswith('/fanstatic'))):
         return original_response.body
     # If the charset has been lost on the middleware stack, use the
     # default one (utf-8)
     if not original_response.charset and original_response.default_charset:
         original_response.charset = original_response.default_charset
     # Otherwise, decorate original response with error template.
     content = literal(original_response.unicode_body) or \
         cgi.escape(request.GET.get('message', ''))
     prefix = request.environ.get('SCRIPT_NAME', ''),
     code = cgi.escape(
         request.GET.get('code', str(original_response.status_int)))
     extra_vars = {'code': code, 'content': content, 'prefix': prefix}
     return render('error_document_template.html', extra_vars=extra_vars)
def render_snippet(*template_names, **kw):
    ''' Helper function for rendering snippets. Rendered html has
    comment tags added to show the template used. NOTE: unlike other
    render functions this takes a list of keywords instead of a dict for
    the extra template variables.

    :param template_names: the template to render, optionally with fallback
        values, for when the template can't be found. For each, specify the
        relative path to the template inside the registered tpl_dir.
    :type template_names: str
    :param kw: extra template variables to supply to the template
    :type kw: named arguments of any type that are supported by the template
    '''

    exc = None
    for template_name in template_names:
        try:
            output = render(template_name, extra_vars=kw)
            if config.get('debug'):
                output = (
                    '\n<!-- Snippet %s start -->\n%s\n<!-- Snippet %s end -->'
                    '\n' % (template_name, output, template_name))
            return h.literal(output)
        except TemplateNotFound as exc:
            if exc.name == template_name:
                # the specified template doesn't exist - try the next fallback
                continue
            # a nested template doesn't exist - don't fallback
            raise exc
    else:
        raise exc or TemplateNotFound
예제 #16
0
def hdx_build_nav_icon_with_message(menu_item, title, **kw):
    htmlResult = h.build_nav_icon(menu_item, title, **kw)
    if 'message' not in kw or not kw['message']:
        return htmlResult
    else:
        newResult = str(htmlResult).replace('</a>',
                                            ' <span class="nav-short-message">{message}</span></a>'.format(message=kw['message']))
        return h.literal(newResult)
예제 #17
0
def hdx_build_nav_icon_with_message(menu_item, title, **kw):
    htmlResult = h.build_nav_icon(menu_item, title, **kw)
    if 'message' not in kw or not kw['message']:
        return htmlResult
    else:
        newResult = str(htmlResult).replace('</a>',
                                            ' <span class="nav-short-message">{message}</span></a>'.format(
                                                message=kw['message']))
        return h.literal(newResult)
예제 #18
0
 def render(self, **kwargs):
     fs = self.field.parent
     pkg_dict = {}
     for field_name, field in fs.render_fields.items():
         pkg_dict[field_name] = field.renderer.value
     tag_suggestions = suggest_tags(pkg_dict)
     html = literal(_("<div>Suggestions (preview refreshes): %s</div>")) % ' '.join(tag_suggestions)
     html += common.TagField.TagEditRenderer.render(self, **kwargs)
     return html
예제 #19
0
파일: plugin.py 프로젝트: CI-WATER/portal
def delineate_build_main_navigation(*args):
    output = h.build_nav_main(*args)
    if c.user:
        link = h.link_to(
            'Delineate',
            h.url_for(
                controller=
                'ckanext.delineate.controllers.delineatewatershed:DelineatewatershedController',
                action='show_form'))

        if p.toolkit.c.action == 'show_form':
            li = h.literal('<li class="active">') + link + h.literal('</li>')
        else:
            li = h.literal('<li>') + link + h.literal('</li>')

        output = li + output

    return output
예제 #20
0
def build_harvest_source_form():
    builder = FormBuilder(model.HarvestSource)
    builder.set_field_text('url', 'Location (required)', literal("<br/><strong>URL</strong> for source of metadata.<br/>"))
    builder.set_field_option('url', 'validate', harvest_source_url_validator)
    builder.set_field_option('description', 'textarea', {'size':'60x15'})
    displayed_fields = ['url', 'description']
    builder.set_displayed_fields(OrderedDict([('Details', displayed_fields)]))
    builder.set_label_prettifier(common.prettify)
    return builder  
예제 #21
0
 def _tag_links(self):
     tags = self.value
     tag_links = [
         h.link_to(
             tagname,
             h.url_for(controller='tag', action='read', id=tagname))
         for tagname in tags
     ]
     return literal(' '.join(tag_links))
예제 #22
0
 def get_user_selector(self):
     users = [user.name for user in model.Session.query(model.User)]
     for potential_default_user in self.default_users:
         if potential_default_user in users:
             default_user = potential_default_user
             break
     else:
         default_user = users[0]                
     return literal('<label for="user_name">User:</label>') + \
            select('user_name', default_user, users, 'user_name')
예제 #23
0
파일: common.py 프로젝트: okfn/ckan-old
 def render(self, **kwargs):
     kwargs['value'] = ' '.join(self.value)
     kwargs['size'] = 60
     api_url = config.get('ckan.api_url', '/').rstrip('/')
     tagcomplete_url = api_url+h.url_for(controller='apiv2/package', action='autocomplete', id=None)
     kwargs['data-tagcomplete-url'] = tagcomplete_url
     kwargs['data-tagcomplete-queryparam'] = 'incomplete'
     kwargs['class'] = 'long tagComplete'
     html = literal(fa_h.text_field(self.name, **kwargs))
     return html
예제 #24
0
 def get_user_selector(self):
     users = [user.name for user in model.Session.query(model.User)]
     for potential_default_user in self.default_users:
         if potential_default_user in users:
             default_user = potential_default_user
             break
     else:
         default_user = users[0]
     return literal('<label for="user_name">User:</label>') + \
            select('user_name', default_user, users, 'user_name')
예제 #25
0
파일: common.py 프로젝트: okfn/ckan-old
 def render(self, options, **kwargs):
     selected = self.value
     options = [('', '')] + options + [(_('other - please specify'), 'other')]
     option_keys = [key for value, key in options]
     if selected in option_keys:
         select_field_selected = selected
         text_field_value = u''
     elif selected:
         select_field_selected = u'other'
         text_field_value = selected or u''
     else:
         select_field_selected = u''
         text_field_value = u''
     fa_version_nums = formalchemy.__version__.split('.')
     # Requires FA 1.3.2 onwards for this select i/f
     html = literal(fa_h.select(self.name, select_field_selected, options, class_="short", **kwargs))
         
     other_name = self.name+'-other'
     html += literal('<label class="inline" for="%s">%s: %s</label>') % (other_name, _('Other'), literal(fa_h.text_field(other_name, value=text_field_value, class_="medium-width", **kwargs)))
     return html
def build_authorization_group_form(is_admin=False, with_users=False):
    builder = FormBuilder(model.AuthorizationGroup)
    builder.set_field_text('name', 'Name', literal("<br/><strong>Unique identifier</strong> for group.<br/>2+ chars, lowercase, using only 'a-z0-9' and '-_'"))
    builder.set_field_option('name', 'validate', common.group_name_validator)
    displayed_fields = ['name']
    if with_users:
        builder.add_field(UsersField('users'))
        displayed_fields.append('users')
    builder.set_displayed_fields(OrderedDict([('Details', displayed_fields)]))
    builder.set_label_prettifier(common.prettify)
    return builder  
예제 #27
0
def hdx_build_nav_no_icon(menu_item, title, **kw):
    html_result = str(h.build_nav_icon(menu_item, title, **kw))
    print html_result
    start = html_result.find('<i ') - 1
    end = html_result.find('</i>') + 4
    if start > 0:
        new_result = html_result[0:start] + ' class="no-icon">' + html_result[end:]
    else:
        new_result = html_result
    print new_result
    return h.literal(new_result)
예제 #28
0
 def render(self, **kwargs):
     kwargs['value'] = ' '.join(self.value)
     kwargs['size'] = 60
     api_url = config.get('ckan.api_url', '/').rstrip('/')
     tagcomplete_url = api_url + h.url_for(
         controller='api', action='tag_autocomplete', id=None)
     kwargs['data-tagcomplete-url'] = tagcomplete_url
     kwargs['data-tagcomplete-queryparam'] = 'incomplete'
     kwargs['class'] = 'long tagComplete'
     html = literal(fa_h.text_field(self.name, **kwargs))
     return html
예제 #29
0
def linked_user(user, maxlength=0, avatar=20):
    if not isinstance(user, model.User):
        user_name = helpers.text_type(user)
        user = model.User.get(user_name)
        if not user:
            return user_name
    if user:
        name = user.name if model.User.VALID_NAME.match(user.name) else user.id
        displayname = user.display_name

        if maxlength and len(user.display_name) > maxlength:
            displayname = displayname[:maxlength] + '...'

        if user.state == 'deleted' and not authz.is_sysadmin(c.user):
            return helpers.literal(helpers.text_type("Anonymous"))

        return helpers.literal(u'{icon} {link}'.format(
            icon=helpers.user_image(user.id, size=avatar),
            link=helpers.link_to(displayname,
                                 helpers.url_for('user.read', id=name))))
예제 #30
0
def build_authorization_group_form(is_admin=False, with_users=False):
    builder = FormBuilder(model.AuthorizationGroup)
    builder.set_field_text('name', 'Name', literal("<br/><strong>Unique identifier</strong> for group.<br/>2+ chars, lowercase, using only 'a-z0-9' and '-_'"))
    builder.set_field_option('name', 'validate', common.group_name_validator)
    builder.set_field_option('name', 'required')
    displayed_fields = ['name']
    if with_users:
        builder.add_field(UsersField('users'))
        displayed_fields.append('users')
    builder.set_displayed_fields(OrderedDict([('Details', displayed_fields)]))
    builder.set_label_prettifier(common.prettify)
    return builder  
예제 #31
0
def gbif_get_geography(occurrence):
    '''
    :param occurrence:
    '''
    geography = []
    for geographic_part in ['continent', 'country', 'stateprovince']:
        value = occurrence.get(geographic_part, None)

        if value:
            geography.append(value.replace('_', ' '))

    return literal(' <i class="icon-angle-right"></i> '.join(geography))
예제 #32
0
파일: plugin.py 프로젝트: CIOIL/DataGovIL
def build_pages_nav_main(*args):

    about_menu = toolkit.asbool(config.get('ckanext.pages.about_menu', True))
    group_menu = toolkit.asbool(config.get('ckanext.pages.group_menu', True))
    org_menu = toolkit.asbool(config.get('ckanext.pages.organization_menu', True))


    new_args = []
    for arg in args:
        if arg[0] == 'about' and not about_menu:
            continue
        if arg[0] == 'organizations_index' and not org_menu:
            continue
        if arg[0] == 'group_index' and not group_menu:
            continue
        new_args.append(arg)

    output = h.build_nav_main(*new_args)

    # do not display any private datasets in menu even for sysadmins
    pages_list = toolkit.get_action('ckanext_pages_list')(None, {'order': True, 'private': False})

    page_name = ''

    if (toolkit.c.action in ('pages_show', 'blog_show')
       and toolkit.c.controller == 'ckanext.pages.controller:PagesController'):
        page_name = toolkit.c.environ['routes.url'].current().split('/')[-1]

    for page in pages_list:
        type_ = 'blog' if page['page_type'] == 'blog' else 'pages'
        name = urllib.quote(page['name'].encode('utf-8')).decode('utf-8')
        title = cgi.escape(page['title'])
        link = h.literal(u'<a href="/{}/{}">{}</a>'.format(type_, name, title))
        if page['name'] == page_name:
            li = h.literal('<li class="active">') + link + h.literal('</li>')
        else:
            li = h.literal('<li>') + link + h.literal('</li>')
        output = output + li

    return output
예제 #33
0
def build_harvest_source_form():
    builder = FormBuilder(HarvestSource)
    builder.set_field_text(
        'url', 'URL for source of metadata',
        literal("""
        <br/>This should include the <tt>http://</tt> part of the URL and can point to either:
        <ul>
            <li>A server's CSW interface</li>
            <li>A Web Accessible Folder (WAF) displaying a list of GEMINI 2.1 documents</li>
            <li>A single GEMINI 2.1 document</li>
        </ul>
        <br />
        """))
    builder.set_field_option('url', 'validate', harvest_source_url_validator)
    builder.set_field_option('url', 'with_html', {'size': '80'})
    builder.set_field_option('description', 'textarea', {'size': '60x5'})
    builder.set_field_text(
        'description', 'Description',
        literal('''
        You can add your own notes here about what the URL above represents to remind you later.
        '''))
    builder.set_field_text(
        'type', 'Source Type',
        literal('''
        Which type of source does the URL above represent?
        '''))
    builder.set_field_option('type', 'validate', harvest_source_type_validator)
    builder.set_field_option(
        'type', 'dropdown', {
            'options':
            ['CSW Server', 'Web Accessible Folder (WAF)', 'Single Document']
        })
    #    displayed_fields = ['url','type','active','description']
    displayed_fields = ['url', 'type', 'description']
    builder.set_displayed_fields(OrderedDict([('Details', displayed_fields)]))
    builder.set_label_prettifier(common.prettify)
    return builder
예제 #34
0
    def __init__(self):
        super(FormApiTestController, self).__init__()
        self.form_template = literal('''
<html>
  <form id="test" action="" method="post">    
    %s
    <input type="submit" name="send" />
  </form>
</html>''')
        self.success_template = literal('''
<html>
  <h1>Success %s</h1>
  <p>
    %s
  </p>
</html>''')
        self.error_template = literal('''
<html>
  <h1>Error %s</h1>
  <p>
    %s
  </p>
</html>''')
        self.default_users = ['okfn', 'tester', 'joeadmin']
예제 #35
0
    def __init__(self):
        super(FormApiTestController, self).__init__()
        self.form_template = literal('''
<html>
  <form id="test" action="" method="post">    
    %s
    <input type="submit" name="send" />
  </form>
</html>''')
        self.success_template = literal('''
<html>
  <h1>Success %s</h1>
  <p>
    %s
  </p>
</html>''')
        self.error_template = literal('''
<html>
  <h1>Error %s</h1>
  <p>
    %s
  </p>
</html>''')
        self.default_users = ['okfn', 'tester', 'joeadmin']
예제 #36
0
 def render(self, **kwargs):
     extras = self.value
     html = ''
     field_values = []
     for key, value in extras:
         field_values.append({
             'name': self.name + '-' + key,
             'key': key.capitalize(),
             'value': value,
         })
     for i in range(3):
         field_values.append({'name': '%s-newfield%s' % (self.name, i)})
     c.fields = field_values
     html = render('package/form_extra_fields.html')
     return h.literal(html)
예제 #37
0
 def render(self, **kwargs):
     extras = self.value
     html = ''
     field_values = []
     for key, value in extras:
         field_values.append({
             'name':self.name + '-' + key,
             'key':key.capitalize(),
             'value':value,})
     for i in range(3):
         field_values.append({
             'name':'%s-newfield%s' % (self.name, i)})
     c.fields = field_values
     html = render('package/form_extra_fields.html')
     return h.literal(html)
예제 #38
0
def build_group_form(is_admin=False, with_packages=False):
    builder = FormBuilder(model.Group)
    builder.set_field_text('name', _('Name'), literal("<br/><strong>Unique identifier</strong> for group.<br/>2+ chars, lowercase, using only 'a-z0-9' and '-_'"))
    builder.set_field_option('name', 'validate', common.group_name_validator)
    builder.set_field_option('description', 'textarea', {'size':'60x15'})
    builder.add_field(ExtrasField('extras', hidden_label=True))
    displayed_fields = ['name', 'title', 'description']
    if is_admin: 
        builder.set_field_option('state', 'dropdown', {'options':model.State.all})
        displayed_fields.append('state')
    if with_packages:
        builder.add_field(PackagesField('packages'))
        displayed_fields.append('packages')
    builder.set_displayed_fields(OrderedDict([(_('Details'), displayed_fields),
                                              (_('Extras'), ['extras'])]))
    builder.set_label_prettifier(common.prettify)
    return builder  
예제 #39
0
def build_group_form(is_admin=False, with_packages=False):
    builder = FormBuilder(model.Group)
    builder.set_field_text('name', _('Name'), literal("<strong>Unique identifier</strong> for group.<br/>2+ chars, lowercase, using only 'a-z0-9' and '-_'<p></p>"))
    builder.set_field_option('name', 'validate', common.group_name_validator)
    builder.set_field_option('description', 'textarea', {'size':'60x15'})
    builder.add_field(ExtrasField('extras', hidden_label=True))
    displayed_fields = ['name', 'title', 'description']
    if is_admin: 
        builder.set_field_option('state', 'dropdown', {'options':model.State.all})
        displayed_fields.append('state')
    if with_packages:
        builder.add_field(PackagesField('packages'))
        displayed_fields.append('packages')
    builder.set_displayed_fields(OrderedDict([(_('Details'), displayed_fields),
                                              (_('Extras'), ['extras'])]))
    builder.set_label_prettifier(common.prettify)
    return builder  
예제 #40
0
def build_pages_nav_main(*args):

    about_menu = toolkit.asbool(config.get('ckanext.pages.about_menu', True))
    group_menu = toolkit.asbool(config.get('ckanext.pages.group_menu', True))
    org_menu = toolkit.asbool(
        config.get('ckanext.pages.organization_menu', True))

    new_args = []
    for arg in args:
        if arg[0] == 'about' and not about_menu:
            continue
        if arg[0] == 'organizations_index' and not org_menu:
            continue
        if arg[0] == 'group_index' and not group_menu:
            continue
        new_args.append(arg)

    output = h.build_nav_main(*new_args)

    # do not display any private datasets in menu even for sysadmins
    pages_list = toolkit.get_action('ckanext_pages_list')(None, {
        'order': True,
        'private': False
    })

    page_name = ''

    try:
        if (toolkit.c.action in ('pages_show', 'blog_show')
                and toolkit.c.controller
                == 'ckanext.pages.controller:PagesController'):
            page_name = toolkit.c.environ['routes.url'].current().split(
                '/')[-1]
    except AttributeError:
        # NOTE(e0ne): we don't have 'action' attribute in Flask context.
        # We can igrore if it's Flask Bluprint-bases plugin
        pass

    for page in pages_list:
        if page['page_type'] == 'blog':
            link = h.literal('<a href="/blog/%s">%s</a>' %
                             (str(page['name']), str(page['title'])))
        else:
            link = h.literal('<a href="/pages/%s">%s</a>' %
                             (str(page['name']), str(page['title'])))

        if page['name'] == page_name:
            li = h.literal('<li class="active">') + link + h.literal('</li>')
        else:
            li = h.literal('<li>') + link + h.literal('</li>')
        output = output + li

    return output
예제 #41
0
def build_pages_nav_main(*args):

    about_menu = p.toolkit.asbool(config.get('ckanext.pages.about_menu', True))
    group_menu = p.toolkit.asbool(config.get('ckanext.pages.group_menu', True))
    org_menu = p.toolkit.asbool(
        config.get('ckanext.pages.organization_menu', True))

    new_args = []
    for arg in args:
        if arg[0] == 'about' and not about_menu:
            continue
        if arg[0] == 'organizations_index' and not org_menu:
            continue
        if arg[0] == 'group_index' and not group_menu:
            continue
        new_args.append(arg)

    output = h.build_nav_main(*new_args)

    # do not display any private datasets in menu even for sysadmins
    pages_list = p.toolkit.get_action('ckanext_pages_list')(None, {
        'order': True,
        'private': False
    })

    page_name = ''

    if (p.toolkit.c.action in ('pages_show', 'blog_show')
            and p.toolkit.c.controller
            == 'ckanext.pages.controller:PagesController'):
        page_name = p.toolkit.c.environ['routes.url'].current().split('/')[-1]

    for page in pages_list:
        if page['page_type'] == 'blog':
            link = h.literal(
                '<a href="/blog/%s">%s</a>' %
                (page['name'].encode('ascii'), page['title'].encode(
                    'ascii', 'xmlcharrefreplace')))
        else:
            link = h.literal(
                '<a href="/pages/%s">%s</a>' %
                (page['name'].encode('ascii'), page['title'].encode(
                    'ascii', 'xmlcharrefreplace')))

        if page['name'] == page_name:
            li = h.literal('<li class="active">') + link + h.literal('</li>')
        else:
            li = h.literal('<li>') + link + h.literal('</li>')
        output = output + li

    return output
예제 #42
0
def _make_menu_item_cread(menu_item, title, **kw):
    ''' build a navigation item used for example breadcrumbs

    outputs <li><a href="..."></i> title</a></li>

    :param menu_item: the name of the defined menu item defined in
    config/routing as the named route of the same name
    :type menu_item: string
    :param title: text used for the link
    :type title: string
    :param **kw: additional keywords needed for creating url eg id=...

    :rtype: HTML literal

    This function is called by wrapper functions.
    '''
    _menu_items = h.config['routes.named_routes']
    if menu_item not in _menu_items:
        raise Exception('menu item `%s` cannot be found' % menu_item)
    item = h.copy.copy(_menu_items[menu_item])
    item.update(kw)
    active = h._link_active(item)
    needed = item.pop('needed')
    for need in needed:
        if need not in kw:
            raise Exception('menu item `%s` need parameter `%s`'
                            % (menu_item, need))
    link = h._link_to(title, menu_item, suppress_active_class=True, **item)
    
    ##log.info('::::::::::::::::::::::::::: %r', menu_item)
	
    if active:
        return h.literal('<li class="active_cread">') + link + h.literal('</li>')
    
    if menu_item == "search": 
 	return h.literal('<li class="blue_bg">') + link + h.literal('</li>')
    if menu_item == "organizations_index":
	return h.literal('<li class="blue_bg">') + link + h.literal('</li>')	

    return h.literal('<li class="green_bg">') + link + h.literal('</li>')
예제 #43
0
def linked_user(user, maxlength=0, avatar=20):
    '''Brute force disable gravatar, mostly copied from ckan/lib/helpers'''
    from ckan import model
    if not isinstance(user, model.User):
        user_name = unicode(user)
        user = model.User.get(user_name)
        if not user:
            return user_name
    if user:
        name = user.name if model.User.VALID_NAME.match(user.name) else user.id
        displayname = user.display_name

        if maxlength and len(user.display_name) > maxlength:
            displayname = displayname[:maxlength] + '...'

        return h.literal(h.link_to(
                displayname,
                h.url_for(controller='user', action='read', id=name)
            )
        )
예제 #44
0
def gbif_get_classification(gbif_record):
    '''
    Loop through all the classification parts, building an array of parts

    :param gbif_record: return:
    '''
    classification = []

    url = 'http://www.gbif.org/species'
    for classification_part in [
            'kingdom', 'phylum', 'class', 'taxonorder', 'family', 'genus'
    ]:
        key = f'{classification_part}Key'
        key_value = gbif_record.get(key, None)
        name = gbif_record.get(classification_part, None)
        if key_value:
            classification.append(
                f'<a href="{url}/{key_value}" target="_blank" rel="nofollow">{name}</a>'
            )
        elif name:
            classification.append(name)

    return literal(' <i class="fa fa-angle-right"></i> '.join(classification))
예제 #45
0
def build_pages_nav_main(*args):

    about_menu = p.toolkit.asbool(config.get('ckanext.pages.about_menu', True))
    group_menu = p.toolkit.asbool(config.get('ckanext.pages.group_menu', True))
    org_menu = p.toolkit.asbool(config.get('ckanext.pages.organization_menu', True))

    new_args = []
    for arg in args:
        if arg[0] == 'about' and not about_menu:
            continue
        if arg[0] == 'organizations_index' and not org_menu:
            continue
        if arg[0] == 'group_index' and not group_menu:
            continue
        new_args.append(arg)

    output = h.build_nav_main(*new_args)

    # do not display any private datasets in menu even for sysadmins
    pages_list = p.toolkit.get_action('ckanext_pages_list')(None, {'order': True, 'private': False})

    page_name = ''

    if (p.toolkit.c.action in ('pages_show', 'blog_show')
       and p.toolkit.c.controller == 'ckanext.pages.controller:PagesController'):
        page_name = p.toolkit.c.environ['routes.url'].current().split('/')[-1]

    for page in pages_list:
        if page['page_type'] == 'blog':
            link = h.literal('<a href="/blog/%s">%s</a>' % (page['name'], page['title']))
        else:
            link = h.literal('<a href="/pages/%s">%s</a>' % (page['name'], page['title']))

        if page['name'] == page_name:
            li = h.literal('<li class="active">') + link + h.literal('</li>')
        else:
            li = h.literal('<li>') + link + h.literal('</li>')
        output = output + li

    return output
예제 #46
0
        def render(self, **kwargs):
            # Get groups which are editable by the user.
            editable_groups = self._get_user_editable_groups()

            # Get groups which are already selected.
            selected_groups = self._get_value()

            # Make checkboxes HTML from selected groups.
            checkboxes_html = ''
            checkbox_action = '<input type="checkbox" name="%(name)s" checked="checked" value="%(id)s" />'
            checkbox_noaction = '&nbsp;'
            checkbox_template = '''
            <dt>
                %(action)s
            </dt>
            <dd>
                <label for="%(name)s">%(title)s</label><br/>
            </dd>
            '''
            for group in selected_groups:
                checkbox_context = {
                    'id': group.id,
                    'name': self.name + '-' + group.id,
                    'title': group.display_name
                }
                action = checkbox_noaction
                if group in editable_groups:
                    context = {
                        'id': group.id,
                        'name': self.name + '-' + group.id
                    }
                    action = checkbox_action % context
                # Make checkbox HTML from a group.
                checkbox_context = {
                    'action': action,
                    'name': self.name + '-' + group.id,
                    'title': group.display_name
                }
                checkbox_html = checkbox_template % checkbox_context
                checkboxes_html += checkbox_html

            # Infer addable groups, subtract selected from editable groups.
            addable_groups = []
            for group in editable_groups:
                if group not in selected_groups:
                    addable_groups.append(group)

            # Construct addable options from addable groups.
            options = []
            if len(addable_groups):
                if self.field.allow_empty or len(selected_groups):
                    options.append(('', _('(None)')))
            for group in addable_groups:
                options.append((group.id, group.display_name))

            # Make select HTML.
            if len(options):
                new_name = self.name + '-new'
                select_html = h.select(new_name, None, options)
            else:
                # Todo: Translation call.
                select_html = _("Cannot add any groups.")

            # Make the field HTML.
            field_template = '''  
        <dl> %(checkboxes)s      
            <dt>
                %(label)s
            </dt>
            <dd> %(select)s
            </dd>
        </dl>
            '''
            field_context = {
                'checkboxes': checkboxes_html,
                'select': select_html,
                'label': _("Group"),
            } 
            field_html = field_template % field_context

            # Convert to literals.
            return h.literal(field_html)
예제 #47
0
def build_package_gov_form_v3(is_admin=False,
                              user_editable_groups=None,
                              publishers=None,
                              statistics=False,
                              **kwargs):
    '''Returns a fieldset for the government packages conforming to metadata v3.
    @param publishers - dictionary of publishers from Drupal: {ID: label}
    '''
    # Restrict fields
    restrict = str(kwargs.get('restrict', False)).lower() not in \
               ('0', 'no', 'false', 0, False)

    builder = FormBuilder(model.Package)

    # Extra fields
    builder.add_field(
        GroupSelectField('groups',
                         allow_empty=True,
                         user_editable_groups=user_editable_groups))
    builder.add_field(
        ResourcesField('resources',
                       hidden_label=True,
                       fields_required=set(['url', 'format'])))
    builder.add_field(TagField('tags'))
    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.DateExtraField('date_update_future'))
    builder.add_field(
        common.SuggestedTextExtraField(
            'update_frequency', options=schema.update_frequency_options))
    builder.add_field(
        common.SuggestedTextExtraField(
            'geographic_granularity',
            options=schema.geographic_granularity_options))
    builder.add_field(
        package_gov_fields.GeoCoverageExtraField('geographic_coverage'))
    builder.add_field(
        common.SuggestedTextExtraField(
            'temporal_granularity',
            options=schema.temporal_granularity_options))
    builder.add_field(common.DateRangeExtraField('temporal_coverage'))
    builder.add_field(common.TextExtraField('precision'))
    builder.add_field(common.TextExtraField('taxonomy_url'))
    builder.add_field(common.TextExtraField('mandate'))
    #builder.add_field(common.SuggestedTextExtraField('department', options=schema.government_depts))
    #builder.add_field(common.TextExtraField('agency'))
    # options are iterators of: (label, value)
    publisher_options = [(str(label), "%s [%s]" % (label, value))
                         for value, label in (publishers or {}).items()]
    publisher_options.sort()
    builder.add_field(
        package_gov_fields.PublisherField('published_by',
                                          options=publisher_options))
    builder.add_field(
        package_gov_fields.PublisherField('published_via',
                                          options=publisher_options))
    builder.add_field(common.CoreField('license_id', value='uk-ogl'))
    builder.add_field(common.CheckboxExtraField('national_statistic'))

    # Labels and instructions
    builder.set_field_text(
        'title',
        instructions='The title of the data set.',
        further_instructions=
        'The main subject of the data should be clear. For cross-government data requirements, such as spend data, specify the public body the data belongs to or its geographical coverage, in order to distinguish your data from other similar datasets in data.gov.uk. If the data relates to a period of time, include that in the name, although this would not be appropriate for data which is updated over time. It is not a description - save that for the Abstract element. Do not give a trailing full stop.',
        hints=literal(
            'e.g. Payments to suppliers with a value over &pound;500 from Harlow Council'
        ))
    builder.set_field_text(
        'name',
        'Identifier',
        instructions='A public unique identifier for the dataset',
        further_instructions=
        'It should be roughly readable, with dashes separating words.',
        hints=
        'Format: Two or more lowercase alphanumeric, dash (-) or underscore (_) characters. e.g. uk-road-traffic-statistics-2008 or local-authority-spend-over-500-harlow'
    )
    builder.set_field_text(
        'notes',
        'Abstract',
        instructions='The main description of the dataset',
        further_instructions=
        'It is often displayed with the package title. In particular, it should start with a short sentence that describes the data set succinctly, because the first few words alone may be used in some views of the data sets. Here is the place to state if there are any limitations or deficiencies to the data in order to enable users to evaluate the information; even incomplete data may be adequate for some users.'
    )
    builder.set_field_text(
        'date_released',
        instructions=
        'The date of the official release of the initial version of the dataset',
        further_instructions=
        'This is probably not the date that it is uploaded to data.gov.uk. Be careful not to confuse a new \'version\' of some data with a new dataset covering another time period or geographic area.',
        hints='DD/MM/YYYY')
    builder.set_field_text(
        'date_updated',
        instructions=
        'The date of release of the most recent version of the dataset',
        further_instructions=
        'This is not necessarily the date when it was updated on data.gov.uk. As with \'Date released\', this is for updates to a particular dataset, such as corrections or refinements, not for that of a new time period.',
        hints='DD/MM/YYYY')
    builder.set_field_text(
        'date_update_future',
        'Date to be published',
        instructions=
        'When the dataset will be updated in the future, if appropriate',
        hints='DD/MM/YYYY')
    builder.set_field_text(
        'update_frequency',
        instructions='How frequently the dataset is updated with new versions',
        further_instructions=
        'For one-off data, use \'never\'. For those once updated but now discontinued, use \'discontinued\'.'
    )
    builder.set_field_text(
        'precision',
        instructions=
        'Indicate the level of precision in the data, to avoid over-interpretation.',
        hints=
        "e.g. 'per cent to two decimal places' or 'as supplied by respondents'"
    )
    builder.set_field_text(
        'geographic_granularity',
        instructions='The lowest level of geographic detail',
        further_instructions=
        "This should give the lowest level of geographic detail given in the dataset if it is aggregated. If the data is not aggregated, and so the dataset goes down to the level of the entities being reported on (such as school, hospital, or police station), use 'point'. If none of the choices is appropriate or the granularity varies, please specify in the 'other' element."
    )
    builder.set_field_text(
        'geographic_coverage',
        instructions='The geographic coverage of this dataset.',
        further_instructions=
        'Where a dataset covers multiple areas, the system will automatically group these (e.g. \'England\', \'Scotland\' and \'Wales\' all being selected would be shown as \'Great Britain\').'
    )
    builder.set_field_text(
        'temporal_granularity',
        instructions='The lowest level of temporal detail granularity',
        further_instructions=
        "This should give the lowest level of temporal detail given in the dataset if it is aggregated, expressed as an interval of time. If the data is not aggregated over time, and so the dataset goes down to the instants that reported events occurred (such as the timings of high and low tides), use 'point'. If none of the choices is appropriate or the granularity varies, please specify in the 'other' element."
    )
    builder.set_field_text(
        'temporal_coverage',
        instructions='The temporal coverage of this dataset.',
        further_instructions=
        'If available, please indicate the time as well as the date. Where data covers only a single day, the \'To\' sub-element can be left blank.',
        hints='e.g. 21/03/2007 - 03/10/2009 or 07:45 31/03/2006')
    builder.set_field_text(
        'url',
        instructions='The Internet link to a web page discussing the dataset.',
        hints='e.g. http://www.somedept.gov.uk/growth-figures.html')
    builder.set_field_text(
        'taxonomy_url',
        instructions=
        'An Internet link to a web page describing the taxonomies used in the dataset, if any, to ensure they understand any terms used.',
        hints=
        'e.g. http://www.somedept.gov.uk/growth-figures-technical-details.html'
    )
    #builder.set_field_text('department', instructions='The Department under which the dataset is collected and published', further_instructions='Note, this department is not necessarily directly undertaking the collection/publication itself - use the Agency element where this applies.')
    #builder.set_field_text('agency', instructions='The agency or arms-length body responsible for the data collection', further_instructions='Please use the full title of the body without any abbreviations, so that all items from it appear together. The data.gov.uk system will automatically capture this where appropriate.', hints='e.g. Environment Agency')
    builder.set_field_text(
        'published_by',
        instructions=
        'The organisation (usually a public body) credited with or associated with the publication of this data.',
        further_instructions=
        'Often datasets are associated with both a government department and an outside agency, in which case this field should store the department and "Published via" should store the agency. When an organisation is not listed, please request it using the form found in your data.gov.uk user page under the "Publishers" tab. An asterisk (*) denotes an pre-existing value for this field, which is allowed, but the current user\'s permissions would not be able to change a package\s publisher to this value.'
    )
    builder.set_field_text(
        'published_via',
        instructions=
        'A second organisation that is credited with or associated with the publication of this data.',
        further_instructions=
        'Often datasets are associated with both a government department and an outside agency, in which case the "Published by" field should store the department and this field should store the agency. When an organisation is not listed, please request it using the form found in your data.gov.uk user page under the "Publishers" tab. An asterisk (*) denotes an pre-existing value for this field, which is allowed, but the current user\'s permissions would not be able to change a package\s publisher to this value.'
    )
    builder.set_field_text(
        'author',
        'Contact',
        instructions=
        'The permanent contact point for the public to enquire about this particular dataset. In addition, the Public Data and Transparency Team will use it for any suggestions for changes, feedback, reports of mistakes in the datasets or metadata.',
        further_instructions=
        'This should be the name of the section of the agency or Department responsible, and should not be a named person. Particular care should be taken in choosing this element.',
        hints=
        'Examples: Statistics team, Public consultation unit, FOI contact point'
    )
    builder.set_field_text(
        'author_email',
        'Contact email',
        instructions=
        'A generic official e-mail address for members of the public to contact, to match the \'Contact\' element.',
        further_instructions=
        'A new e-mail address may need to be created for this function.')
    builder.set_field_text(
        'national_statistic',
        'National Statistic',
        instructions='Indicate if the dataset is a National Statistic',
        further_instructions='This is so that it can be highlighted.')
    builder.set_field_text(
        'mandate',
        instructions=
        'An Internet link to the enabling legislation that serves as the mandate for the collection or creation of this data, if appropriate.',
        further_instructions=
        'This should be taken from The National Archives\' Legislation website, and where possible be a link directly to the relevant section of the Act.',
        hints=
        'For example Public Record Act s.2 would be: http://www.legislation.gov.uk/id/ukpga/Eliz2/6-7/51/section/2'
    )
    builder.set_field_text(
        'license_id',
        'Licence',
        instructions='The licence under which the dataset is released.',
        further_instructions=literal(
            'For most situations of central Departments\' and Local Authority data, this should be the \'Open Government Licence\'. If you wish to release the data under a different licence, please contact the <a href="mailto:[email protected]">Public Data and Transparency Team</a>.'
        ))
    builder.set_field_text(
        'resources',
        instructions=
        'The files containing the data or address of the APIs for accessing it',
        further_instructions=literal(
            'These can be repeated as required. For example if the data is being supplied in multiple formats, or split into different areas or time periods, each file is a different \'resource\' which should be described differently. They will all appear on the dataset page on data.gov.uk together.<br/> <b>URL:</b> This is the Internet link directly to the data - by selecting this link in a web browser, the user will immediately download the full data set. Note that datasets are not hosted by data.gov.uk, but by the responsible department<br/> e.g. http://www.somedept.gov.uk/growth-figures-2009.csv<br/><b>Format:</b> This should give the file format in which the data is supplied. You may supply the data in a form not listed here, constrained by the <a href="http://data.gov.uk/blog/new-public-sector-transparency-board-and-public-data-transparency-principles" target="_blank">Public Sector Transparency Board\'s principles</a> that require that all data is available in an \'open and standardised format\' that can be read by a machine. Data can also be released in formats that are not machine-processable (e.g. PDF) alongside this.<br/>'
        ),
        hints=
        'Format choices: CSV | RDF | XML | XBRL | SDMX | HTML+RDFa | Other as appropriate'
    )
    builder.set_field_text(
        'tags',
        instructions=
        'Tags can be thought of as the way that the packages are categorised, so are of primary importance.',
        further_instructions=literal(
            'One or more tags should be added to give the government department and geographic location the data covers, as well as general descriptive words. The <a href="http://www.esd.org.uk/standards/ipsv_abridged/" target="_blank">Integrated Public Sector Vocabulary</a> may be helpful in forming these.'
        ),
        hints=
        'Format: Two or more lowercase alphanumeric or dash (-) characters; different tags separated by spaces. As tags cannot contain spaces, use dashes instead. e.g. for a dataset containing statistics on burns to the arms in the UK in 2009: nhs uk arm burns medical-statistics'
    )
    # Options/settings
    builder.set_field_option('name', 'validate', package_name_validator)
    builder.set_field_option(
        'license_id', 'dropdown',
        {'options': [('', None)] + model.Package.get_license_options()})
    builder.set_field_option('state', 'dropdown', {'options': model.State.all})
    builder.set_field_option('notes', 'textarea', {'size': '60x15'})
    builder.set_field_option('title', 'required')
    builder.set_field_option('notes', 'required')
    builder.set_field_option('published_by', 'required')
    builder.set_field_option('license_id', 'required')
    builder.set_field_option('national_statistic', 'validate',
                             package_gov_fields.national_statistic_validator)

    if restrict:
        builder.set_field_option('national_statistic', 'readonly', True)

    # Layout
    field_groups = OrderedDict([
        ('Basic information', ['title', 'name', 'notes']),
        ('Details', [
            'date_released', 'date_updated', 'date_update_future',
            'update_frequency', 'precision', 'geographic_granularity',
            'geographic_coverage', 'temporal_granularity', 'temporal_coverage',
            'url', 'taxonomy_url'
        ]),
        ('Resources', ['resources']),
        ('More details', [
            'published_by', 'published_via', 'author', 'author_email',
            'mandate', 'license_id', 'tags'
        ]),
    ])
    field_groups['More details'].append('national_statistic')
    if is_admin:
        field_groups['More details'].append('state')
    builder.set_label_prettifier(package.prettify)
    builder.set_displayed_fields(field_groups)
    return builder
예제 #48
0
def hdx_linked_user(user, maxlength=0):
    response = h.linked_user(user, maxlength)
    changed_response = re.sub(r"<img[^>]+/>", "", response)
    return h.literal(changed_response)
예제 #49
0
 def _tag_links(self):
     tags = self.value
     tag_links = [h.link_to(tagname, h.url_for(controller='tag', action='read', id=tagname)) for tagname in tags]
     return literal(' '.join(tag_links))
예제 #50
0
파일: package.py 프로젝트: AltisCorp/ckan
def build_package_form(is_admin=False, user_editable_groups=None, **params):
    builder = FormBuilder(model.Package)

    # Extra fields
    builder.add_field(GroupSelectField('groups', allow_empty=True, user_editable_groups=user_editable_groups))
    builder.add_field(ResourcesField('resources', hidden_label=True))
    builder.add_field(TagField('tags'))
    builder.add_field(ExtrasField('extras', hidden_label=True))

    # Labels and instructions
    builder.set_field_text(
        'title',
        instructions=_('A short descriptive title for the data set.'),
        further_instructions=_('It should not be a description though - save that for the Notes field. Do not give a trailing full stop.'),
    )
    builder.set_field_text(
        'name', _('Name'),
        instructions=_('A unique identifier for the package.'),
        further_instructions=_('It should be broadly humanly readable, in the spirit of Semantic Web URIs. Only use an acronym if it is widely recognised. Renaming is possible but discouraged.'),
        hints=_("2+ characters, lowercase, using only 'a-z0-9' and '-_'")
    )
    builder.set_field_text(
        'version',
        instructions=_('A number representing the version (if applicable)'),
        hints='e.g. 1.2.0',
    )
    builder.set_field_text(
        'url',
        instructions=_('The URL for the web page describing the data (not the data itself).'),
        hints=_('e.g. http://www.example.com/growth-figures.html'),
    )
    builder.set_field_text(
        'author',
        instructions=_('The name of the main contact, for enquiries about this particular dataset, using the e-mail address in the following field.'),
    )
    builder.set_field_text(
        'maintainer',
        instructions=_('If there is another important contact person (in addition to the person in the Author field) then provide details here.'),
    )
    builder.set_field_text(
        'license_id',
        _('Licence'),
        instructions=_('The licence under which the dataset is released.'),
    )
    builder.set_field_text(
        'tags',
        _('Tags'),
        instructions=literal(_('Comma-separated terms that may link this dataset to similar ones. For more information on conventions, see <a href="%s">this wiki page</a>.') % 'http://wiki.okfn.org/ckan/doc/faq#TagConventions'),
        hints=_('e.g. pollution, rivers, water quality')
    )
    builder.set_field_text(
        'resources',
        instructions=_('The files containing the data or address of the APIs for accessing it.'),
        further_instructions=literal(_('<br />These can be repeated as required. For example if the data is being supplied in multiple formats, or split into different areas or time periods, each file is a different \'resource\' which should be described differently. They will all appear on the dataset page on CKAN together.<br /><br /> <b>URL:</b> This is the Internet link directly to the data - by selecting this link in a web browser, the user will immediately download the full data set. Note that datasets are not hosted on this site, but by the publisher of the data. Alternatively the URL can point to an API server such as a SPARQL endpoint or JSON-P service.<br /> <b>Format:</b> This should give the file format in which the data is supplied. <br /><b>Description</b> Any information you want to add to describe the resource.<br />')),
        hints=_('Format choices: CSV | RDF | XML | XBRL | SDMX | HTML+RDFa | Other as appropriate')
    )
    builder.set_field_text(
        'notes',
        _('Notes'),
        instructions=_('The main description of the dataset'),
        further_instructions=_('It is often displayed with the package title. In particular, it should start with a short sentence that describes the data set succinctly, because the first few words alone may be used in some views of the data sets.'),
        hints=literal(_('You can use %sMarkdown formatting%s here.') % ('<a href="http://daringfireball.net/projects/markdown/syntax">', '</a>'))
    )

    # Options/settings
    builder.set_field_option('name', 'validate', package_name_validator)
    builder.set_field_option('license_id', 'dropdown', {'options':[('', None)] + model.Package.get_license_options()})
    builder.set_field_option('state', 'dropdown', {'options':model.State.all})
    builder.set_field_option('notes', 'textarea', {'size':'60x15'})

    # Layout
    field_groups = OrderedDict([
        (_('Basic information'), ['title', 'name', 'url',
                               'notes', 'license_id', 'tags']),
        (_('Resources'), ['resources']),
        (_('Groups'), ['groups']),
        (_('Detail'), ['author', 'author_email',
                       'maintainer', 'maintainer_email',
                       'version',
                       ]),
        (_('Extras'), ['extras']),
        ])
    if is_admin:
        field_groups[_('Detail')].append('state')
    builder.set_displayed_fields(field_groups)
    builder.set_label_prettifier(prettify)
    return builder
    # Strings for i18n:
    [ _('Title'), _('Name'), _('Version'), _('URL'),
     _('Notes'), _('Resources'), _('Author'), _('Author email'), _('Maintainer'),
     _('Maintainer email'), _('License'), _('Tags'), _('Extras'), _('State')]
예제 #51
0
파일: helpers.py 프로젝트: skvisha/hdx-ckan
def hdx_linked_user(user, maxlength=0):
    response = h.linked_user(user, maxlength)
    changed_response = re.sub(r"<img[^>]+/>", "", response)
    return h.literal(changed_response)
예제 #52
0
def build_package_gov_form_v3(is_admin=False, user_editable_groups=None,
                              publishers=None,
                              statistics=False,
                              **kwargs):
    '''Returns a fieldset for the government packages conforming to metadata v3.
    @param publishers - dictionary of publishers from Drupal: {ID: label}
    '''
    # Restrict fields
    restrict = str(kwargs.get('restrict', False)).lower() not in \
               ('0', 'no', 'false', 0, False)
    
    builder = FormBuilder(model.Package)

    # Extra fields
    builder.add_field(GroupSelectField('groups', allow_empty=True, user_editable_groups=user_editable_groups))
    builder.add_field(ResourcesField('resources', hidden_label=True, fields_required=set(['url', 'format'])))
    builder.add_field(TagField('tags'))
    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.DateExtraField('date_update_future'))
    builder.add_field(common.SuggestedTextExtraField('update_frequency', options=schema.update_frequency_options))
    builder.add_field(common.SuggestedTextExtraField('geographic_granularity', options=schema.geographic_granularity_options))
    builder.add_field(package_gov_fields.GeoCoverageExtraField('geographic_coverage'))
    builder.add_field(common.SuggestedTextExtraField('temporal_granularity', options=schema.temporal_granularity_options))
    builder.add_field(common.DateRangeExtraField('temporal_coverage'))
    builder.add_field(common.TextExtraField('precision'))
    builder.add_field(common.TextExtraField('taxonomy_url'))
    builder.add_field(common.TextExtraField('mandate'))
    #builder.add_field(common.SuggestedTextExtraField('department', options=schema.government_depts))
    #builder.add_field(common.TextExtraField('agency'))
    # options are iterators of: (label, value)
    publisher_options = [(str(label), "%s [%s]" % (label, value)) for value, label in (publishers or {}).items()]
    publisher_options.sort()
    builder.add_field(package_gov_fields.PublisherField('published_by', options=publisher_options))
    builder.add_field(package_gov_fields.PublisherField('published_via', options=publisher_options))
    builder.add_field(common.CoreField('license_id', value='uk-ogl'))
    builder.add_field(common.CheckboxExtraField('national_statistic'))

    # Labels and instructions
    builder.set_field_text('title', instructions='The title of the data set.', further_instructions='The main subject of the data should be clear. For cross-government data requirements, such as spend data, specify the public body the data belongs to or its geographical coverage, in order to distinguish your data from other similar datasets in data.gov.uk. If the data relates to a period of time, include that in the name, although this would not be appropriate for data which is updated over time. It is not a description - save that for the Abstract element. Do not give a trailing full stop.', hints=literal('e.g. Payments to suppliers with a value over &pound;500 from Harlow Council'))
    builder.set_field_text('name', 'Identifier', instructions='A public unique identifier for the dataset', further_instructions='It should be roughly readable, with dashes separating words.', hints='Format: Two or more lowercase alphanumeric, dash (-) or underscore (_) characters. e.g. uk-road-traffic-statistics-2008 or local-authority-spend-over-500-harlow')
    builder.set_field_text('notes', 'Abstract', instructions='The main description of the dataset', further_instructions='It is often displayed with the package title. In particular, it should start with a short sentence that describes the data set succinctly, because the first few words alone may be used in some views of the data sets. Here is the place to state if there are any limitations or deficiencies to the data in order to enable users to evaluate the information; even incomplete data may be adequate for some users.')
    builder.set_field_text('date_released', instructions='The date of the official release of the initial version of the dataset', further_instructions='This is probably not the date that it is uploaded to data.gov.uk. Be careful not to confuse a new \'version\' of some data with a new dataset covering another time period or geographic area.', hints='DD/MM/YYYY')
    builder.set_field_text('date_updated', instructions='The date of release of the most recent version of the dataset', further_instructions='This is not necessarily the date when it was updated on data.gov.uk. As with \'Date released\', this is for updates to a particular dataset, such as corrections or refinements, not for that of a new time period.', hints='DD/MM/YYYY')
    builder.set_field_text('date_update_future', 'Date to be published', instructions='When the dataset will be updated in the future, if appropriate', hints='DD/MM/YYYY')
    builder.set_field_text('update_frequency', instructions='How frequently the dataset is updated with new versions', further_instructions='For one-off data, use \'never\'. For those once updated but now discontinued, use \'discontinued\'.')
    builder.set_field_text('precision', instructions='Indicate the level of precision in the data, to avoid over-interpretation.', hints="e.g. 'per cent to two decimal places' or 'as supplied by respondents'")
    builder.set_field_text('geographic_granularity', instructions='The lowest level of geographic detail', further_instructions="This should give the lowest level of geographic detail given in the dataset if it is aggregated. If the data is not aggregated, and so the dataset goes down to the level of the entities being reported on (such as school, hospital, or police station), use 'point'. If none of the choices is appropriate or the granularity varies, please specify in the 'other' element.")
    builder.set_field_text('geographic_coverage', instructions='The geographic coverage of this dataset.', further_instructions='Where a dataset covers multiple areas, the system will automatically group these (e.g. \'England\', \'Scotland\' and \'Wales\' all being selected would be shown as \'Great Britain\').')
    builder.set_field_text('temporal_granularity', instructions='The lowest level of temporal detail granularity', further_instructions="This should give the lowest level of temporal detail given in the dataset if it is aggregated, expressed as an interval of time. If the data is not aggregated over time, and so the dataset goes down to the instants that reported events occurred (such as the timings of high and low tides), use 'point'. If none of the choices is appropriate or the granularity varies, please specify in the 'other' element.")
    builder.set_field_text('temporal_coverage', instructions='The temporal coverage of this dataset.', further_instructions='If available, please indicate the time as well as the date. Where data covers only a single day, the \'To\' sub-element can be left blank.', hints='e.g. 21/03/2007 - 03/10/2009 or 07:45 31/03/2006')
    builder.set_field_text('url', instructions='The Internet link to a web page discussing the dataset.', hints='e.g. http://www.somedept.gov.uk/growth-figures.html')
    builder.set_field_text('taxonomy_url', instructions='An Internet link to a web page describing the taxonomies used in the dataset, if any, to ensure they understand any terms used.', hints='e.g. http://www.somedept.gov.uk/growth-figures-technical-details.html')
    #builder.set_field_text('department', instructions='The Department under which the dataset is collected and published', further_instructions='Note, this department is not necessarily directly undertaking the collection/publication itself - use the Agency element where this applies.')
    #builder.set_field_text('agency', instructions='The agency or arms-length body responsible for the data collection', further_instructions='Please use the full title of the body without any abbreviations, so that all items from it appear together. The data.gov.uk system will automatically capture this where appropriate.', hints='e.g. Environment Agency')
    builder.set_field_text('published_by', instructions='The organisation (usually a public body) credited with or associated with the publication of this data.', further_instructions='Often datasets are associated with both a government department and an outside agency, in which case this field should store the department and "Published via" should store the agency. When an organisation is not listed, please request it using the form found in your data.gov.uk user page under the "Publishers" tab. An asterisk (*) denotes an pre-existing value for this field, which is allowed, but the current user\'s permissions would not be able to change a package\s publisher to this value.')
    builder.set_field_text('published_via', instructions='A second organisation that is credited with or associated with the publication of this data.', further_instructions='Often datasets are associated with both a government department and an outside agency, in which case the "Published by" field should store the department and this field should store the agency. When an organisation is not listed, please request it using the form found in your data.gov.uk user page under the "Publishers" tab. An asterisk (*) denotes an pre-existing value for this field, which is allowed, but the current user\'s permissions would not be able to change a package\s publisher to this value.')
    builder.set_field_text('author', 'Contact', instructions='The permanent contact point for the public to enquire about this particular dataset. In addition, the Public Data and Transparency Team will use it for any suggestions for changes, feedback, reports of mistakes in the datasets or metadata.', further_instructions='This should be the name of the section of the agency or Department responsible, and should not be a named person. Particular care should be taken in choosing this element.', hints='Examples: Statistics team, Public consultation unit, FOI contact point')
    builder.set_field_text('author_email', 'Contact email', instructions='A generic official e-mail address for members of the public to contact, to match the \'Contact\' element.', further_instructions='A new e-mail address may need to be created for this function.')
    builder.set_field_text('national_statistic', 'National Statistic', instructions='Indicate if the dataset is a National Statistic', further_instructions='This is so that it can be highlighted.')
    builder.set_field_text('mandate', instructions='An Internet link to the enabling legislation that serves as the mandate for the collection or creation of this data, if appropriate.', further_instructions='This should be taken from The National Archives\' Legislation website, and where possible be a link directly to the relevant section of the Act.', hints='For example Public Record Act s.2 would be: http://www.legislation.gov.uk/id/ukpga/Eliz2/6-7/51/section/2')
    builder.set_field_text('license_id', 'Licence', instructions='The licence under which the dataset is released.', further_instructions=literal('For most situations of central Departments\' and Local Authority data, this should be the \'Open Government Licence\'. If you wish to release the data under a different licence, please contact the <a href="mailto:[email protected]">Public Data and Transparency Team</a>.'))
    builder.set_field_text('resources', instructions='The files containing the data or address of the APIs for accessing it', further_instructions=literal('These can be repeated as required. For example if the data is being supplied in multiple formats, or split into different areas or time periods, each file is a different \'resource\' which should be described differently. They will all appear on the dataset page on data.gov.uk together.<br/> <b>URL:</b> This is the Internet link directly to the data - by selecting this link in a web browser, the user will immediately download the full data set. Note that datasets are not hosted by data.gov.uk, but by the responsible department<br/> e.g. http://www.somedept.gov.uk/growth-figures-2009.csv<br/><b>Format:</b> This should give the file format in which the data is supplied. You may supply the data in a form not listed here, constrained by the <a href="http://data.gov.uk/blog/new-public-sector-transparency-board-and-public-data-transparency-principles" target="_blank">Public Sector Transparency Board\'s principles</a> that require that all data is available in an \'open and standardised format\' that can be read by a machine. Data can also be released in formats that are not machine-processable (e.g. PDF) alongside this.<br/>'), hints='Format choices: CSV | RDF | XML | XBRL | SDMX | HTML+RDFa | Other as appropriate')
    builder.set_field_text('tags', instructions='Tags can be thought of as the way that the packages are categorised, so are of primary importance.', further_instructions=literal('One or more tags should be added to give the government department and geographic location the data covers, as well as general descriptive words. The <a href="http://www.esd.org.uk/standards/ipsv_abridged/" target="_blank">Integrated Public Sector Vocabulary</a> may be helpful in forming these.'), hints='Format: Two or more lowercase alphanumeric or dash (-) characters; different tags separated by spaces. As tags cannot contain spaces, use dashes instead. e.g. for a dataset containing statistics on burns to the arms in the UK in 2009: nhs uk arm burns medical-statistics')
    # Options/settings
    builder.set_field_option('name', 'validate', package_name_validator)
    builder.set_field_option('license_id', 'dropdown', {'options':[('', None)] + model.Package.get_license_options()})
    builder.set_field_option('state', 'dropdown', {'options':model.State.all})
    builder.set_field_option('notes', 'textarea', {'size':'60x15'})
    builder.set_field_option('title', 'required')
    builder.set_field_option('notes', 'required')
    builder.set_field_option('published_by', 'required') 
    builder.set_field_option('license_id', 'required')
    builder.set_field_option('national_statistic', 'validate',
                             package_gov_fields.national_statistic_validator)
    
    if restrict:
        builder.set_field_option('national_statistic', 'readonly', True)
    
    # Layout
    field_groups = OrderedDict([
        ('Basic information', ['title', 'name',
                                  'notes']),
        ('Details', ['date_released', 'date_updated', 'date_update_future',
                        'update_frequency',
                        'precision', 
                        'geographic_granularity', 'geographic_coverage',
                        'temporal_granularity', 'temporal_coverage',
                        'url', 'taxonomy_url']),
        ('Resources', ['resources']),
        ('More details', ['published_by', 'published_via',
                             'author', 'author_email',
                             'mandate', 'license_id',
                             'tags']),
        ])
    field_groups['More details'].append('national_statistic')
    if is_admin:
        field_groups['More details'].append('state')
    builder.set_label_prettifier(package.prettify)
    builder.set_displayed_fields(field_groups)
    return builder
예제 #53
0
def build_package_form(is_admin=False, user_editable_groups=None, **params):
    builder = FormBuilder(model.Package)

    # Extra fields
    builder.add_field(
        GroupSelectField('groups',
                         allow_empty=True,
                         user_editable_groups=user_editable_groups))
    builder.add_field(ResourcesField('resources', hidden_label=True))
    builder.add_field(TagField('tags'))
    builder.add_field(ExtrasField('extras', hidden_label=True))

    # Labels and instructions
    builder.set_field_text(
        'title',
        instructions=_('A short descriptive title for the data set.'),
        further_instructions=
        _('It should not be a description though - save that for the Notes field. Do not give a trailing full stop.'
          ),
    )
    builder.set_field_text(
        'name',
        _('Name'),
        instructions=_('A unique identifier for the package.'),
        further_instructions=
        _('It should be broadly humanly readable, in the spirit of Semantic Web URIs. Only use an acronym if it is widely recognised. Renaming is possible but discouraged.'
          ),
        hints=_("2+ characters, lowercase, using only 'a-z0-9' and '-_'"))
    builder.set_field_text(
        'version',
        instructions=_('A number representing the version (if applicable)'),
        hints='e.g. 1.2.0',
    )
    builder.set_field_text(
        'url',
        instructions=
        _('The URL for the web page describing the data (not the data itself).'
          ),
        hints=_('e.g. http://www.example.com/growth-figures.html'),
    )
    builder.set_field_text(
        'author',
        instructions=
        _('The name of the main contact, for enquiries about this particular dataset, using the e-mail address in the following field.'
          ),
    )
    builder.set_field_text(
        'maintainer',
        instructions=
        _('If there is another important contact person (in addition to the person in the Author field) then provide details here.'
          ),
    )
    builder.set_field_text(
        'license_id',
        _('Licence'),
        instructions=_('The licence under which the dataset is released.'),
    )
    builder.set_field_text(
        'tags',
        _('Tags'),
        instructions=literal(
            _('Terms that may link this dataset to similar ones. For more information on conventions, see <a href="%s">this wiki page</a>.'
              ) % 'http://wiki.okfn.org/ckan/doc/faq#TagConventions'),
        hints=_('e.g. pollution rivers water-quality'))
    builder.set_field_text(
        'resources',
        instructions=
        _('The files containing the data or address of the APIs for accessing it.'
          ),
        further_instructions=literal(
            _('<br />These can be repeated as required. For example if the data is being supplied in multiple formats, or split into different areas or time periods, each file is a different \'resource\' which should be described differently. They will all appear on the dataset page on CKAN together.<br /><br /> <b>URL:</b> This is the Internet link directly to the data - by selecting this link in a web browser, the user will immediately download the full data set. Note that datasets are not hosted on this site, but by the publisher of the data. Alternatively the URL can point to an API server such as a SPARQL endpoint or JSON-P service.<br /> <b>Format:</b> This should give the file format in which the data is supplied. <br /><b>Description</b> Any information you want to add to describe the resource.<br />'
              )),
        hints=
        _('Format choices: CSV | RDF | XML | XBRL | SDMX | HTML+RDFa | Other as appropriate'
          ))
    builder.set_field_text(
        'notes',
        _('Notes'),
        instructions=_('The main description of the dataset'),
        further_instructions=
        _('It is often displayed with the package title. In particular, it should start with a short sentence that describes the data set succinctly, because the first few words alone may be used in some views of the data sets.'
          ),
        hints=literal(
            _('You can use %sMarkdown formatting%s here.') %
            ('<a href="http://daringfireball.net/projects/markdown/syntax">',
             '</a>')))

    # Options/settings
    builder.set_field_option('name', 'validate', package_name_validator)
    builder.set_field_option(
        'license_id', 'dropdown',
        {'options': [('', None)] + model.Package.get_license_options()})
    builder.set_field_option('state', 'dropdown', {'options': model.State.all})
    builder.set_field_option('notes', 'textarea', {'size': '60x15'})

    # Layout
    field_groups = OrderedDict([
        (_('Basic information'),
         ['title', 'name', 'url', 'notes', 'license_id', 'tags']),
        (_('Resources'), ['resources']),
        (_('Groups'), ['groups']),
        (_('Detail'), [
            'author',
            'author_email',
            'maintainer',
            'maintainer_email',
            'version',
        ]),
        (_('Extras'), ['extras']),
    ])
    if is_admin:
        field_groups[_('Detail')].append('state')
    builder.set_displayed_fields(field_groups)
    builder.set_label_prettifier(prettify)
    return builder
    # Strings for i18n:
    [
        _('Title'),
        _('Name'),
        _('Version'),
        _('URL'),
        _('Notes'),
        _('Resources'),
        _('Author'),
        _('Author email'),
        _('Maintainer'),
        _('Maintainer email'),
        _('License'),
        _('Tags'),
        _('Extras'),
        _('State')
    ]