[ckan-dev] Displaying custom tags

Koebrick, Andrew (MNIT) andrew.koebrick at state.mn.us
Thu Jun 11 18:01:04 UTC 2015


I just set up a custom tag vocabulary as documented here:
http://docs.ckan.org/en/latest/extensions/adding-custom-fields.html

In my case I am creating a drop down for selecting cartographic projections.  It all seems to be working, except that when I display it back in a template the values are surrounded by  [u''] like this:

[u'State Plane Coordinate System', u'Minnesota Coordinate System', u'Universal Transverse Mercator']

(Just testing the Multiple here; I realize having multiple projections does not make sense)

I guess this means they are being pulled out as Unicode.  Where would be the most CKANish place to convert these to strings?

Here are the relevant bits of my plugin:

#From the plugin:
def create_projection():
    user = toolkit.get_action('get_site_user')({'ignore_auth': True}, {})
    context = {'user': user['name']}
    try:
        data = {'id': 'projection'}
        toolkit.get_action('vocabulary_show')(context, data)
    except toolkit.ObjectNotFound:
        data = {'name': 'projection'}
        vocab = toolkit.get_action('vocabulary_create')(context, data)
        for tag in (u'geographic', u'State Plane Coordinate System', u'Universal Transverse Mercator', u'Minnesota Coordinate System', u'Albers'):
            data = {'name': tag, 'vocabulary_id': vocab['id']}
            toolkit.get_action('tag_create')(context, data)

def projection():
    create_projection()
    try:
        tag_list = toolkit.get_action('tag_list')
        projection = tag_list(data_dict={'vocabulary_id': 'projection'})
        return 'projection'
    except toolkit.ObjectNotFound:
            return None

#From the template:
    {% if pkg_dict.projection %}
    <tr>
      <th scope="row" class="dataset-label">{{ _("Projection") }}</th>
      <td class="dataset-details">{{ pkg_dict.projection }}</td>
    </tr>
  {% endif %}


Andrew Koebrick  |  MINNESOTA GEOSPATIAL INFORMATION OFFICE
Web Coordinator / Systems administrator / Librarian
MN.IT Services @ MNGEO
651-201-2465 (w)  |   651-296-6398 (f) |  andrew.koebrick at state.mn.us<mailto:andrew.koebrick at state.mn.us>
658 Cedar St., Room 300, St. Paul, MN 55155, www.mngeo.state.mn.us<http://www.mngeo.state.mn.us/>

[cid:image002.jpg at 01CE61F8.52552AE0]<http://www.mn.gov/oet>

Information Technology for Minnesota Government   |   mn.gov/mnit<http://www.mn.gov/oet>



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.okfn.org/pipermail/ckan-dev/attachments/20150611/d1893c82/attachment-0002.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.jpg
Type: image/jpeg
Size: 1624 bytes
Desc: image001.jpg
URL: <http://lists.okfn.org/pipermail/ckan-dev/attachments/20150611/d1893c82/attachment-0002.jpg>


More information about the ckan-dev mailing list