Esempio n. 1
0
def qa_openness_stars_dataset_html(dataset):
    qa = dataset.get('qa')
    if not qa:
        return tk.literal('<!-- No qa info for this dataset -->')
    extra_vars = copy.deepcopy(qa)
    return tk.literal(
        tk.render('qa/openness_stars_brief.html',
                  extra_vars=extra_vars))
Esempio n. 2
0
def archiver_is_resource_broken_html(resource):
    archival = resource.get('archiver')
    if not archival:
        return tk.literal('<!-- No archival info for this resource -->')
    extra_vars = {'resource': resource}
    extra_vars.update(archival)
    return tk.literal(
        tk.render('archiver/is_resource_broken.html',
                  extra_vars=extra_vars))
Esempio n. 3
0
def qa_openness_stars_dataset_html(dataset):
    qa = dataset.get('qa')
    if not qa:
        return tk.literal('<!-- No qa info for this dataset -->')
    if not isinstance(qa, dict):
        return tk.literal('<!-- QA info was of the wrong type -->')
    extra_vars = copy.deepcopy(qa)
    return tk.literal(
        tk.render('qa/openness_stars_brief.html',
                  extra_vars=extra_vars))
Esempio n. 4
0
def qa_openness_stars_resource_html(resource):
    qa = resource.get('qa')
    if not qa:
        return tk.literal('<!-- No qa info for this resource -->')
    # Take a copy of the qa dict, because weirdly the renderer appears to add
    # keys to it like _ and app_globals. This is bad because when it comes to
    # render the debug in the footer those extra keys take about 30s to render,
    # for some reason.
    extra_vars = copy.deepcopy(qa)
    return tk.literal(
        tk.render('qa/openness_stars.html',
                  extra_vars=extra_vars))
Esempio n. 5
0
def render_mini_stars(stars):
    '''Returns HTML to show a number of stars out of five, with a reason and
    date, plus a tooltip describing the levels.'''

    if stars==0:
        stars_html = 5 * '&#9734'
    else:
        stars_html = (int(stars) or 0) * '&#9733'
        stars_html += (5-int(stars)) * '&#9734'

    reason = get_caption(int(stars))
    tooltip = t.literal('<div class="star-rating-reason">%s</div>' % escape(reason)) if reason else ''

    return t.literal('<span class="star-rating"><span class="tooltip">%s</span>%s</span>' % (tooltip, stars_html))
Esempio n. 6
0
def to_c14n_markup(markup, with_comments=True, pretty=False):
    if not isinstance(markup, basestring):
        markup = unicode(markup)
    el = etree.fromstring(markup)
    markup = etree.tostring(
        el, method='c14n', with_comments=with_comments, pretty_print=pretty)
    return toolkit.literal(markup.decode('utf-8'))
Esempio n. 7
0
def mini_stars_facet(num_stars):
    '''
    Returns HTML for a numbers of mini-stars with a caption describing the meaning.
    '''
    mini_stars = num_stars * '&#9733'
    mini_stars += '&#9734' * (5-num_stars)
    caption = get_caption[int(num_stars)]
    return t.literal('%s&nbsp; %s' % (mini_stars, caption))
Esempio n. 8
0
def render_stars(stars, reason, last_updated):
    '''Returns HTML to show a number of stars out of five, with a reason and
    date, plus a tooltip describing the levels.'''

    if stars==0:
        stars_html = 5 * '<i class="icon-star-empty"></i>'
    else:
        stars_html = (stars or 0) * '<i class="icon-star"></i>'
        stars_html += (5-stars) * '<i class="icon-star-empty"></i>'

    tooltip = t.literal('<div class="star-rating-reason"><b>' + _('Reason') + ': </b>%s</div>' % escape(_(reason))) if reason else ''
    for i in range(5,0,-1):
        classname = 'fail' if (i > (stars or 0)) else ''
        tooltip += t.literal('<div class="star-rating-entry %s">%s</div>' % (classname, mini_stars_and_caption(i)))

    if last_updated:
        datestamp = render_datestamp(last_updated)
        tooltip += t.literal('<div class="star-rating-last-updated"><b>' + _('Score updated') + ': </b>%s</div>' % datestamp)


    tooltipo = t.literal(_('Reason') + ': %s' % _(reason)) if reason else ''

    for i in range(5,0,-1):
        tooltipo += t.literal("&#xa;%s" % mini_stars_and_caption(i))

    if last_updated:
        datestamp = render_datestamp(last_updated)
        tooltipo += t.literal(_('Score updated') + ' %s' % datestamp)

    return t.literal(_('Openness Rating') + ': <span class="star-rating"><span class="tooltip" style="display:none">%s</span>'
                                            '<a href="http://lab.linkeddata.deri.ie/2010/star-scheme-by-example/" target="_blank">%s</a>'
                                            '</span>' % (tooltip, stars_html))
Esempio n. 9
0
    def get_fields_markup(self):
        if request.method == 'POST':
            d = dict(request.params.items())
            response.headers['Content-Type'] = 'application/json' 
            return json.dumps(d)

        x = fixtures.foo1
        S = x.get_schema()
        test_fields = {
            'url': { 'title': u'Website URL' },
            'rating': { 'title': u'Foo Rating' },
            'grade': { 'title': u'Foo Grade' },
            'contacts': { 'title': u'Contacts', },
            'title': {
                'required': True,
                'classes': [ 'control-medium' ],
                'title': u'Title',
                'description': u'Blah blah',
                'placeholder': u'Enter a title',
                'attrs': { 'data-foo': 'baz', 'data-boo': 'faz', 'autocomplete': 'off' }
            },
            'temporal_extent': { 'title': u'Temporal Extent', },
            'reviewed': { 'title': u'Reviewed', },
            'description': { 'description': u'Add a detailed description', },
            'thematic_category': {},
            'tags': {},
            'created': { 'title': u'Created At', 'placeholder': datetime.datetime.now() },
            'wakeup_time': { 'title': u'Wakeup At',},
            'password': {},
        }
        c.form_sections = []
        for k, data in test_fields.items():
            f = x.get_field(k)
            c.form_sections.append({
                'heading': toolkit.literal('<h3>Field <code>%s</code></h3>' %(k)),
                'body': \
                    markup_for_field('edit', f, name_prefix='foo1', data=data) + \
                    toolkit.literal('<hr/>') + \
                    markup_for_field('read:bar', f, name_prefix='foo1', data=data)
            })
        #raise Exception('Break')
        c.form_class = 'form-horizontal' # 'form-horizontal'
        return render('tests/accordion-form.html')
Esempio n. 10
0
def mini_stars_and_caption(num_stars):
    '''
    Returns HTML for a numbers of mini-stars with a caption describing the meaning.
    '''
    mini_stars = num_stars * '&#9733'
    mini_stars += '&#9734' * (5-num_stars)
    caption = [
        _('Unavailable or not openly licensed'),
        _('Unstructured data (e.g. PDF)'),
        _('Structured data but proprietry format (e.g. Excel)'),
        _('Structured data in open format (e.g. CSV)'),
        _('Linkable data - served at URIs (e.g. RDF)'),
        _('Linked data - data URIs and linked to other data (e.g. RDF)')
    ]
    #log.debug(caption[num_stars])
    return t.literal('%s&nbsp; %s' % (mini_stars, caption[num_stars]))
Esempio n. 11
0
 def get_objects_markup(self):
     markup = ''
     c.form_sections = []
     
     # 1. A Point object
     obj = fixtures.pt1
     assert isinstance(obj, types.Point)
     data = {
         'required': False,
         'classes': [],
         'input_classes': [ 'input-small' ],
         'title': u'Point A',
     }
     c.form_sections.append({
         'heading': toolkit.literal('<h3>Object <code>Point</code></h3>'),
         'body': \
             markup_for_object('edit:baz', obj, name_prefix='pt1', data=data) + \
             toolkit.literal('<hr/>') + \
             markup_for_object('read:boz', obj, name_prefix='pt1', data={'title': u'Point B'})
     })
     
     # 2.1 A TemporalExtent object
     obj = fixtures.dt1
     assert isinstance(obj, types.TemporalExtent)
     c.form_sections.append({
         'heading': toolkit.literal('<h3>Object <code>TemporalExtent</code></h3>'),
         'body': markup_for_object('edit:faz.baz', obj, name_prefix='dt1', data={'title': u'Extent A'}) +
             toolkit.literal('<hr/>') +
             markup_for_object('read', obj, name_prefix='dt1', data={ 'title': u'Extent B' })
     })
     
     # 2.2 A TemporalExtent object (with errors)
     obj = types.TemporalExtent(
         start=datetime.date(2014, 1, 1), end=datetime.date(2013, 1, 1))
     errs = obj.validate()
     errs = obj.dictize_errors(errs)
     assert isinstance(obj, types.TemporalExtent)
     c.form_sections.append({
         'heading': toolkit.literal('<h3>Object <code>TemporalExtent</code></h3>'),
         'body': \
             markup_for_object('edit:faz.baz', obj, 
                 errors=errs, name_prefix='dt1', data={'title': u'Extent A'}) + \
             toolkit.literal('<hr/>') + \
             markup_for_object('read', obj, 
                 errors=errs, name_prefix='dt1', data={ 'title': u'Extent B' })
     })
    
     # 3. A PostalAddress object
     obj = types.PostalAddress(address=u'22 Acacia Avenue', postalcode=u'12345')
     c.form_sections.append({
         'heading': toolkit.literal('<h3>Object <code>PostalAddress</code></h3>'),
         'body': \
             markup_for_object('edit:comfortable', obj, 
                 name_prefix='contact_info', data={'title': u'Address A'}) + \
             toolkit.literal('<hr/>') + \
             markup_for_object('read', obj, 
                 name_prefix='contact_info', data={'title': u'Address B'})
     })
     
     # Render
     c.form_class = 'form-horizontal'
     return render('tests/accordion-form.html')