diff --git a/ckanext/odsh/helpers.py b/ckanext/odsh/helpers.py index 10b5675b210f72e2d7d216e915059a371b82c696..8fa9e8b88a5955f661b2362b0ebe2396942e6108 100644 --- a/ckanext/odsh/helpers.py +++ b/ckanext/odsh/helpers.py @@ -1,10 +1,10 @@ import logging import traceback import ast +import ckan.plugins.toolkit as toolkit log = logging.getLogger(__name__) - def odsh_openness_score_dataset_html(dataset): score = 0 #dataset = json.loads(dataset) @@ -15,7 +15,11 @@ def odsh_openness_score_dataset_html(dataset): r_qa = resource.get('qa') if r_qa: try: - qa = ast.literal_eval(r_qa) + qa = None + if isinstance(r_qa, basestring): # r_qa might be a string of a dictionary when 'dataset' is send from solr + qa = ast.literal_eval(r_qa) + else: + qa = r_qa resource_score = qa.get('openness_score') if resource_score > score: score = resource_score @@ -23,3 +27,9 @@ def odsh_openness_score_dataset_html(dataset): log.error('Error while calculating openness score %s: %s\nException: %s', e.__class__.__name__, unicode(e), traceback.format_exc()) return score + +def odsh_get_resource_details(resource_id): + resource_details = toolkit.get_action('resource_show')( + data_dict={'id': resource_id}) + return resource_details + diff --git a/ckanext/odsh/plugin.py b/ckanext/odsh/plugin.py index 1f50abaf545228acd30262906bf856f0fba683c3..f5ac1dabcf335f6123ffdcae05d782e9a80a095a 100644 --- a/ckanext/odsh/plugin.py +++ b/ckanext/odsh/plugin.py @@ -85,6 +85,7 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm 'odsh_group_id_selected': odsh_group_id_selected, 'odsh_get_facet_items_dict': odsh_get_facet_items_dict, 'odsh_openness_score_dataset_html': odsh_helpers.odsh_openness_score_dataset_html, + 'odsh_get_resource_details': odsh_helpers.odsh_get_resource_details } def before_map(self, map): diff --git a/ckanext/odsh/public/odsh.css b/ckanext/odsh/public/odsh.css index 392473fdeb203ee965faa6fd22bab98abc6e1e52..8b03c88f095e62def9156160e9fd6205677fcdfd 100644 --- a/ckanext/odsh/public/odsh.css +++ b/ckanext/odsh/public/odsh.css @@ -60,7 +60,7 @@ input, button, select, textarea { width: 1000px; } -.search-form { +.search-form, .odsh-dataset-heading { border-bottom: 4px solid #dbdbdb; padding-bottom: 5px; } @@ -73,7 +73,7 @@ input, button, select, textarea { color: black; } -.search-form h2 { +.search-form h2, .odsh-dataset-heading h2 { margin-top: 0px; font-size: 25px; color: #003064; @@ -114,6 +114,7 @@ input[type=radio], input[type=checkbox] { .secondary.span3 { width: 210px; + max-width: 210px; padding: 20px 16px 0px; } @@ -621,3 +622,87 @@ label:after { .controls select { width: 100%; } + +.page-header { + border: none; +} + +.module .module-content { + margin: 0px; +} + +.info-detail { + margin-bottom: 20px; + font-size: 12px; + color: black; +} + +.odsh-dataset-heading { + margin-bottom: 30px; +} + +.odsh-dataset-heading .dataset-stars { + margin-bottom: 5px; +} + +.notes { + margin-bottom: 30px; +} + +.resource-list { + margin: 0px; +} + +.resource-item { + background: #f2f2f2; + margin-top: 10px; + padding: 15px 15px 15px 15px; +} + +.resource-dataformat-label { + font-size: 18px; + padding-top: 6px; + padding-bottom: 6px; + float: left; +} + +.resource-title { + float: left; + margin-left: 5px; + color: black; +} + +.resource-description-container { + margin-top: 8px; +} + +.resource-description-container .description { + line-height: 1.3; + color: black; +} + +.resource-title { + cursor: pointer; +} + +.resource-details-left { + padding-right: 20px; +} + +.resource-icons { + font-size: 28px; +} + +.resource-icons a { + color: #1c355e; +} + +.resource-icons a:hover { + color: #d7004d; + text-decoration: none; +} + +.resource-item .container-fluid { + padding-right: 0px; + padding-left: 0px; +} diff --git a/ckanext/odsh/templates/package/read.html b/ckanext/odsh/templates/package/read.html index df0ea11bdf259ace9844e5cfca74ea840644f945..a7e25a67b33de5df9a944ad19014da508b9fcb18 100644 --- a/ckanext/odsh/templates/package/read.html +++ b/ckanext/odsh/templates/package/read.html @@ -2,6 +2,9 @@ {% set pkg = c.pkg_dict %} + +{% set stars = h.odsh_openness_score_dataset_html(pkg) %} + {% block breadcrumb_content %} {% if pkg %} {% set dataset = h.dataset_display_name(pkg) %} @@ -27,11 +30,12 @@ <i class="fa fa-lock"></i> {{ _('Private') }} </span> +{% endif %} <div class="follow_button pull-right"> {{ h.follow_button('dataset', pkg.name) }} </div> -{% endif %} -<h1> +<div class="odsh-dataset-heading row-fluid"> + <h2> {% block page_heading %} {{ h.dataset_display_name(pkg) }} {% if pkg.state.startswith('draft') %} @@ -41,7 +45,12 @@ [{{ _('Deleted') }}] {% endif %} {% endblock %} -</h1> + </h2> + <div class="dataset-stars"> + {% snippet "qa/stars.html", stars=stars %} + </div> +</div> +{# {{ pkg.resources }} #} {% block package_notes %} {% if pkg.notes %} <div class="notes embedded-content"> @@ -57,4 +66,4 @@ {% snippet "package/snippets/resources_list.html", pkg=pkg, resources=pkg.resources %} {% endblock %} -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/ckanext/odsh/templates/package/read_base.html b/ckanext/odsh/templates/package/read_base.html index 85d54bd9b704d31245c743079aeea8b41a0e427d..6732400c825ce13811bdbcf65d7890a1eccf0b09 100644 --- a/ckanext/odsh/templates/package/read_base.html +++ b/ckanext/odsh/templates/package/read_base.html @@ -1,5 +1,8 @@ {% ckan_extends %} +{% block content_primary_nav %} +{% endblock %} + {% block secondary_content %} {% block package_organization %} @@ -30,4 +33,4 @@ {% endif %} {% endblock %} -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/ckanext/odsh/templates/package/snippets/info.html b/ckanext/odsh/templates/package/snippets/info.html index f9f7d62b74b35e558a1887f6e2b2533d2744d4bc..669c7e7518a9c781ff42bdca379b57cb10705440 100644 --- a/ckanext/odsh/templates/package/snippets/info.html +++ b/ckanext/odsh/templates/package/snippets/info.html @@ -16,38 +16,64 @@ Example: {% block package_info_inner %} {% block heading %} {% endblock %} + + {% block groups %} + <div class="groups-detail info-detail"> + <div>{{ _('Kategorie') }}:</div> + {{ pkg.groups|map(attribute='display_name')|join('; ') }} + </div> + {% endblock %} + {% block nums %} - <div class="nums"> - <p>{{ _('Followers') }}:</p> - <p>{{ h.follow_count('dataset', pkg.id) }}</span> + <div class="nums-detail info-detail"> + <div>{{ _('Followers') }}:</div> + <p>{{ h.follow_count('dataset', pkg.id) }}</p> </div> {% endblock %} - <p>{{ _('Spatial extension') }}:</p> - {%set ext=pkg.spatial_extension if pkg.spatial_extension else '-'%} - <p>{{ ext }}</span> - <p>{{ _('Tags') }}:</p> - {%if pkg.tags|length>0%} - <p> - {% for tag in pkg.tags %} - {{tag.display_name}} - {%endfor%} - </p> - {%else%} - <p>-</p> - {%endif%} - {% endblock %} + + {% block spatial %} + <div class="spatial-detail info-detail"> + <div>{{ _('Spatial extension') }}:</div> + {%set ext=pkg.spatial_extension if pkg.spatial_extension else '-'%} + <p>{{ ext }}</p> + </div> + {% endblock %} + + {% block tags %} + <div class="tags-detail info-detail"> + <div>{{ _('Tags') }}:</div> + <p>{{ pkg.tags|map(attribute='display_name')|join('; ') or '-'}}</p> + </div> + {% endblock %} + + {% block license %} + <div class="license-detail info-detail"> + <div>{{ _('License') }}:</div> {%set lic=pkg.license_title if pkg.license_title else '-'%} {%set name=' ('+pkg.access_constraints +')' if pkg.access_constraints else ''%} - <p>{{ _('License') }}:</p> - <p>{{ lic}}{{name}}</p> - <p>{{ _('timerange') }}:</p> + <p>{{ lic }}{{ name }}</p> + </div> + {% endblock %} + + {% block timerange %} + <div class="timerange-detail info-detail"> + <div>{{ _('timerange') }}:</div> {%set start=h.render_datetime(pkg.temporal_start,'%d.%m.%Y') if pkg.temporal_start else ''%} {%set end=h.render_datetime(pkg.temporal_end,'%d.%m.%Y') if pkg.temporal_end else ''%} - <p>{{ start}}-{{end}}</p> - <p>{{ _('last change') }}:</p> + <p>{{ start }} - {{ end }}</p> + </div> + {% endblock %} + + {% block last_change %} + <div class="last-change-detail info-detail"> + <div>{{ _('last change') }}:</div> {{h.render_datetime(pkg.metadata_modified,'%d.%m.%Y') }} + </div> + {% endblock %} + + {% endblock %} </div> </div> </section> {% endif %} -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/ckanext/odsh/templates/package/snippets/resource_item.html b/ckanext/odsh/templates/package/snippets/resource_item.html index f2b112e084dbacacca981420a9e6e0e3578b4010..d4dfd51f1c7fea9e9d357a3394c5615bd8d1c7f3 100644 --- a/ckanext/odsh/templates/package/snippets/resource_item.html +++ b/ckanext/odsh/templates/package/snippets/resource_item.html @@ -1,48 +1,46 @@ {% set url_action = 'resource_edit' if url_is_edit and can_edit else 'resource_read' %} {% set url = h.url_for(controller='package', action=url_action, id=pkg.name, resource_id=res.id) %} +{% set res_details = h.odsh_get_resource_details(res.id) %} + <li class="resource-item" data-id="{{ res.id }}"> - {% block resource_item_title %} - <a class="heading" href="{{ url }}" title="{{ res.name or res.description }}"> - {{ h.resource_display_name(res) | truncate(50) }}<span class="format-label" property="dc:format" data-format="{{ res.format.lower() or 'data' }}">{{ - h.get_translated(res, 'format') }}</span> - {{ h.popular('views', res.tracking_summary.total, min=10) }} - </a> - {% endblock %} - {% block resource_item_description %} - <p class="description"> - {% if res.description %} - {{ h.markdown_extract(h.get_translated(res, 'description'), extract_length=80) }} - {% endif %} - </p> - {% endblock %} - {% block resource_item_explore %} - {% if not url_is_edit %} - <div class=""> - {% block resource_item_explore_links %} - <a href="{{ url }}"> - {% if res.has_views %} - <i class="fa fa-bar-chart-o"></i> - {% else %} - <i class="fa fa-info-circle"></i> - {% endif %} - </a> - {% if res.url and h.is_url(res.url) %} - <a href="{{ res.url }}" class="resource-url-analytics" target="_blank"> - {% if res.has_views or res.url_type == 'upload' %} - <i class="fa fa-arrow-circle-o-down"></i> - {% else %} - <i class="fa fa-external-link"></i> + + <div class="container-fluid"> + <div class="row"> + <div class="span8 resource-details-left"> + <div class="row"> + <div class="dataformat-label resource-dataformat-label label">{{res.format}}</div> + <div class="resource-title" title="{{ h.resource_display_name(res) }}"> + {{ h.resource_display_name(res) | truncate(65) }} + </div> + </div> + <div class="row resource-description-container"> + <p class="description"> + {% if res.description %} + {{ h.markdown_extract(h.get_translated(res, 'description'))}} {% endif %} - </a> - {% endif %} - {% if can_edit %} - <a href="{{ h.url_for(controller='package', action='resource_edit', id=pkg.name, resource_id=res.id) }}"> + Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. + </p> + </div> + </div> + <div class="span4"> + <div class="resource-icons"> + {% block resource_item_explore_links %} + <a href="{{ res.url or url }}"> + <i class="fa fa-download"></i> + </a> + <a href="#"> + <i class="fa fa-eye"></i> + </a> + {% if can_edit %} + <a href="{{ h.url_for(controller='package', action='resource_edit', id=pkg.name, resource_id=res.id) }}"> <i class="fa fa-pencil-square-o"></i> - </a> - {% endif %} - {% endblock %} + </a> + {% endif %} + {% endblock %} + </div> + </div> </div> - {% endif %} - {% endblock %} -</li> \ No newline at end of file + </div> + +</li> diff --git a/ckanext/odsh/templates/package/snippets/resources_list.html b/ckanext/odsh/templates/package/snippets/resources_list.html new file mode 100644 index 0000000000000000000000000000000000000000..588a573b5bc05b678195ee11fd1d8bc508e7170c --- /dev/null +++ b/ckanext/odsh/templates/package/snippets/resources_list.html @@ -0,0 +1,34 @@ +{# +Renders a list of resources with icons and view links. + +resources - A list of resources to render +pkg - A package object that the resources belong to. + +Example: + + {% snippet "package/snippets/resources_list.html", pkg=pkg, resources=pkg.resources %} + +#} +<section id="dataset-resources" class="resources"> + <h3>{{ _('Dateien') }}:</h3> + {% block resource_list %} + {% if resources %} + <ul class="{% block resource_list_class %}resource-list{% endblock %}"> + {% block resource_list_inner %} + {% set can_edit = h.check_access('package_update', {'id':pkg.id }) %} + {% for resource in resources %} + {% snippet 'package/snippets/resource_item.html', pkg=pkg, res=resource, can_edit=can_edit %} + {% endfor %} + {% endblock %} + </ul> + {% else %} + {% if h.check_access('resource_create', {'package_id': pkg['id']}) %} + {% trans url=h.url_for('resource.new', id=pkg.name) %} + <p class="empty">This dataset has no data, <a href="{{ url }}">why not add some?</a></p> + {% endtrans %} + {% else %} + <p class="empty">{{ _('This dataset has no data') }}</p> + {% endif %} + {% endif %} + {% endblock %} +</section>