Skip to content

Commit

Permalink
[#2939] Organization ytemplates added
Browse files Browse the repository at this point in the history
  • Loading branch information
tobes committed Sep 25, 2012
1 parent 0ab4408 commit 2ecb361
Show file tree
Hide file tree
Showing 13 changed files with 370 additions and 0 deletions.
28 changes: 28 additions & 0 deletions ckan/templates/organization/base_form_page.html
@@ -0,0 +1,28 @@
{% extends "page.html" %}

{% block breadcrumb_content %}
<li>{{ h.nav_link(_('Organizations'), controller='organization', action='index') }}</li>
<li class="active">{% block breadcrumb_link %}{{ h.nav_link(_('Add a Organization'), controller='organization', action='new') }}{% endblock %}</li>
{% endblock %}

{% block primary_content %}
<div class="module">
<div class="module-content">
<h1 class="page-heading">{% block page_heading %}{{ _('Organization Form') }}{% endblock %}</h1>
{% block form %}
{{ c.form | safe }}
{% endblock %}
</div>
</div>
{% endblock %}

{% block secondary_content %}
<div class="module module-narrow module-shallow">
<h2 class="module-heading"><i class="icon-large icon-info-sign"></i> {{ _('What are Organizations?') }}</h2>
<div class="module-content">
{% trans %}
<p>good question<P/>
{% endtrans %}
</div>
</div>
{% endblock %}
19 changes: 19 additions & 0 deletions ckan/templates/organization/confirm_delete.html
@@ -0,0 +1,19 @@
{% extends "page.html" %}

{% block subtitle %}{{ _("Confirm Delete") }}{% endblock %}

{% block maintag %}<div class="row" role="main">{% endblock %}

{% block main_content %}
<section class="module span6 offset3">
<div class="module-content">
<p>{{ _('Are you sure you want to delete group - {name}?').format(name=c.group_dict.name) }}</p>
<p class="form-actions">
<form action="{% url_for controller='group', action='delete', id=c.group_dict.name %}" method="post">
<button class="btn" type="submit" name="cancel" >{{ _('Cancel') }}</button>
<button class="btn btn-primary" type="submit" name="delete" >{{ _('Confirm Delete') }}</button>
</form>
</p>
</div>
</section>
{% endblock %}
7 changes: 7 additions & 0 deletions ckan/templates/organization/edit.html
@@ -0,0 +1,7 @@
{% extends "organization/base_form_page.html" %}

{% block subtitle %}{{ _('Edit a Organization') }}{% endblock %}

{% block breadcrumb_link %}{% link_for _('Edit Organization'), controller='organization', action='edit', id=c.group.name %}{% endblock %}

{% block page_heading %}{{ _('Edit a Organization') }}{% endblock %}
41 changes: 41 additions & 0 deletions ckan/templates/organization/index.html
@@ -0,0 +1,41 @@
{% extends "page.html" %}

{% block subtitle %}{{ _('Organizations of Datasets') }}{% endblock %}

{% block breadcrumb_content %}
<li class="active">{% link_for _('Organizations'), controller='organization', action='index' %}</li>
{% endblock %}

{% block actions_content %}
<li>{% link_for _('Add Organization'), controller='organization', action='new', class_='btn', icon='plus' %}</li>
{% endblock %}

{% block primary_content %}
<div class="module">
<div class="module-content">
<h1 class="page-heading">{{ _('Organizations') }}</h1>
{% if c.page.items %}
{% snippet "organization/snippets/organization_list.html", organizations=c.page.items %}
{% else %}
<p class="empty">
{{ _('There are currently no organizations for this site') }}.
{% if h.check_access('organization_create') %}
{% link_for _('How about creating one?'), controller='organization', action='new' %}</a>.
{% endif %}
</p>
{% endif %}
</div>
{{ c.page.pager() }}
</div>
{% endblock %}

{% block secondary_content %}
<div class="module module-narrow module-shallow">
<h2 class="module-heading"><i class="icon-large icon-info-sign"></i> {{ _('What are Organizations?') }}</h2>
<div class="module-content">
{% trans %}
<p>I have no idea</p>
{% endtrans %}
</div>
</div>
{% endblock %}
7 changes: 7 additions & 0 deletions ckan/templates/organization/new.html
@@ -0,0 +1,7 @@
{% extends "organization/base_form_page.html" %}

{% block subtitle %}{{ _('Create a Organization') }}{% endblock %}

{% block breadcrumb_link %}{{ h.nav_link(_('Create Organization'), controller='organization', action='edit', id=c.organization.name) }}{% endblock %}

{% block page_heading %}{{ _('Create a Organization') }}{% endblock %}
25 changes: 25 additions & 0 deletions ckan/templates/organization/new_organization_form.html
@@ -0,0 +1,25 @@
{% extends "organization/snippets/organization_form.html" %}

{#
As the form is rendered as a seperate page we take advantage of this by
overriding the form blocks depending on the current context
#}
{% block dataset_fields %}
{% if action == "edit" %}{{ super() }}{% endif %}
{% endblock %}

{% block custom_fields %}
{% if action == "edit" %}{{ super() }}{% endif %}
{% endblock %}

{% block save_text %}
{%- if action == "edit" -%}
{{ _('Update Organization') }}
{%- else -%}
{{ _('Create Organization') }}
{%- endif -%}
{% endblock %}

{% block delete_button %}
{% if action == "edit" %}{{ super() }}{% endif %}
{% endblock %}
46 changes: 46 additions & 0 deletions ckan/templates/organization/read.html
@@ -0,0 +1,46 @@
{% extends "page.html" %}

{% block subtitle %}{{ c.group_dict.display_name }}{% endblock %}

{% block breadcrumb_content %}
<li>{% link_for _('Organizations'), controller='organization', action='index' %}</li>
<li class="active">{% link_for c.group_dict.display_name|truncate(35), controller='organization', action='read', id=c.group_dict.name %}</li>
{% endblock %}

{% block actions_content %}
{% if h.check_access('organization_update', {'id': c.group.id}) %}
<li>{% link_for _('Add Dataset to Organization'), controller='package', action='new', group=c.group_dict.id, class_='btn', icon='plus' %}</li>
<li>{% link_for _('Edit'), controller='organization', action='edit', id=c.group_dict.name, class_='btn', icon='cog' %}</li>
{% endif %}
{# <li>{% link_for _('History'), controller='organization', action='history', id=c.group_dict.name, class_='btn', icon='undo' %}</li> #}
{% endblock %}

{% block primary_content %}
<section class="module">
<div class="module-content">
{% include "package/snippets/search_form.html" %}
</div>
{{ c.page.pager(q=c.q) }}
</section>
{% endblock %}

{% block secondary_content %}
{% snippet 'snippets/organization.html', organization=c.group_dict %}

<section class="module module-narrow module-shallow">
<h2 class="module-heading"><i class="icon-large icon-user"></i> {{ _('Administrators') }}</h2>
<ul class="nav nav-simple">
{% for admin in c.group_admins %}
<li class="nav-item image">{{ h.linked_user(admin, 30) }}</li>
{% endfor %}
</ul>
</section>

{{ h.snippet('snippets/facet_list.html', title='Tags', name='tags', extras={'id':c.group_dict.id}) }}
{{ h.snippet('snippets/facet_list.html', title='Formats', name='res_format', extras={'id':c.group_dict.id}) }}
{% endblock %}

{% block links %}
{{ super() }}
{% include "organization/snippets/feeds.html" %}
{% endblock %}
4 changes: 4 additions & 0 deletions ckan/templates/organization/snippets/feeds.html
@@ -0,0 +1,4 @@
{%- set dataset_feed = h.url(controller='feed', action='group', id=c.group_dict.name) -%}
{%- set history_feed = h.url(controller='revision', action='list', format='atom', days=1) -%}
<link rel="alternate" type="application/atom+xml" title="{{ g.site_title }} - {{ _('Datasets in group: {group}').format(group=c.group_dict.display_name) }}" href="{{ dataset_feed }}" />
<link rel="alternate" type="application/atom+xml" title="{{ g.site_title }} - {{ _('Recent Revision History') }}" href="{{ history_feed }}" />
81 changes: 81 additions & 0 deletions ckan/templates/organization/snippets/organization_form.html
@@ -0,0 +1,81 @@
{% import 'macros/form.html' as form %}

<form class="dataset-form form-horizontal" method="post" data-module="basic-form">
{% block error_summary %}
{{ form.errors(error_summary) }}
{% endblock %}

{% block basic_fields %}
{% set attrs = {'data-module': 'slug-preview-target'} %}
{{ form.input('title', label=_('Title'), id='field-title', placeholder=_('My Organization'), value=data.title, error=errors.title, classes=['control-full'], attrs=attrs) }}

{# Perhaps these should be moved into the controller? #}
{% set prefix = h.url_for(controller='organization', action='read', id='') %}
{% set domain = h.url_for(controller='organization', action='read', id='', qualified=true) %}
{% set domain = domain|replace("http://", "")|replace("https://", "") %}
{% set attrs = {'data-module': 'slug-preview-slug', 'data-module-prefix': domain, 'data-module-placeholder': '<organization>'} %}

{{ form.prepend('name', label=_('URL'), prepend=prefix, id='field-url', placeholder=_('my-organization'), value=data.name, error=errors.name, attrs=attrs) }}

{{ form.markdown('description', label=_('Description'), id='field-description', placeholder=_('A little information about my organization...'), value=data.description, error=errors.description) }}

{{ form.input('image_url', label=_('Image URL'), id='field-image-url', type='url', placeholder=_('http://example.com/my-image.jpg'), value=data.image_url, error=errors.image_url, classes=['control-full']) }}

{% endblock %}

{% block custom_fields %}
{% for extra in data.extras %}
{% set prefix = 'extras__%d__' % loop.index0 %}
{{ form.custom(
names=(prefix ~ 'key', prefix ~ 'value', prefix ~ 'deleted'),
id='field-extras-%d' % loop.index,
label=_('Custom Field'),
values=(extra.key, extra.value, extra.deleted),
error=errors[prefix ~ 'key'] or errors[prefix ~ 'value']
) }}
{% endfor %}

{# Add a max if 3 empty columns #}
{% for extra in range(data.extras|count, 3) %}
{% set index = (loop.index0 + data.extras|count) %}
{% set prefix = 'extras__%d__' % index %}
{{ form.custom(
names=(prefix ~ 'key', prefix ~ 'value', prefix ~ 'deleted'),
id='field-extras-%d' % index,
label=_('Custom Field'),
values=(extra.key, extra.value, extra.deleted),
error=errors[prefix ~ 'key'] or errors[prefix ~ 'value']
) }}
{% endfor %}
{% endblock %}

{% block dataset_fields %}
{% if data.packages %}
<div class="control-group">
<label class="control-label">{{ _('Datasets') }}</label>
<div class="controls">
{% for dataset in data.packages %}
<label class="checkbox" for="field-dataset-{{ loop.index0 }}">
<input id="field-dataset-{{ loop.index0 }}" type="checkbox" name="packages__{{ loop.index0 }}__name" value="{{ dataset.name }}" checked="checked" />
{{ dataset.title }}
</label>
{% endfor %}
</div>
</div>
{% endif %}

{% set dataset_name = 'packages__%s__name' % data.packages|length %}
{% set dataset_attrs = {'data-module': 'autocomplete', 'data-module-source': '/dataset/autocomplete?q=?'} %}
{{ form.input(dataset_name, label=_('Add Dataset'), id="field-dataset", value=data[dataset_name], classes=['control-medium'], attrs=dataset_attrs) }}
{% endblock %}

<div class="form-actions">
{% block delete_button %}
{% if h.check_access('organization_delete', {'id': data.id}) %}
{% set locale = h.dump_json({'content': _('Are you sure you want to delete this Organization?')}) %}
<a class="btn btn-danger pull-left" href="{% url_for controller='organization', action='delete', id=data.id %}" data-module="confirm-action" data-module-i18n="{{ locale }}">{% block delete_button_text %}{{ _('Delete') }}{% endblock %}</a>
{% endif %}
{% endblock %}
<button class="btn btn-primary" name="save" type="submit">{% block save_text %}{{ _('Save Organization') }}{% endblock %}</button>
</div>
</form>
38 changes: 38 additions & 0 deletions ckan/templates/organization/snippets/organization_item.html
@@ -0,0 +1,38 @@
{#
Renders a media item for a organization. This should be used in a list.

organization - A organization dict.
first - Pass true if this is the first item in a row.
last - Pass true if this is the last item in a row.

Example:

<ul class="media-grid">
{% for organization in organizations %}
{% set first = loop.index0 % 3 == 0 %}
{% set last = loop.index0 % 3 == 2 %}
{% snippet "organization/snippets/organization_item.html", organization=organization, first=first, last=last %}
{% endfor %}
</ul>
#}
{% set url = h.url_for(organization.type ~ '_read', action='read', id=organization.name) %}
<li class="media-item media media-vertical{% if first %} first{% endif %}{% if last %} last{% endif %}">
<a class="media-image" href="{{ url }}"><img src="{{ organization.image_url or '/base/images/placeholder-organization.png' }}" alt="{{ organization.name }}" /></a>
<div class="media-content">
<h3 class="media-heading">
<a href="{{ url }}" title="{{ _('View {name}').format(name=organization.display_name) }}">
{{ organization.display_name }}
</a>
</h3>
{% if organization.description %}
<p>{{ h.truncate(organization.description, length=80, whole_word=True) }}...</p>
{% else %}
<p class="empty">{{ _('This organization has no description') }}</p>
{% endif %}
{% if organization.packages %}
<a class="btn btn-small btn-primary" href="{{ url }}">{{ ungettext('{num} Dataset', '{num} Datasets', organization.packages).format(num=organization.packages) }}</a>
{% else %}
<span class="btn btn-small disabled">{{ _('0 Datasets') }}</span>
{% endif %}
</div>
</li>
17 changes: 17 additions & 0 deletions ckan/templates/organization/snippets/organization_list.html
@@ -0,0 +1,17 @@
{#
Display a grid of organization items.

organizations - A list of organizations.

Example:

{% snippet "organization/snippets/organization_list.html" %}

#}
<ul class="media-grid">
{% for organization in organizations %}
{% set first = loop.index0 % 3 == 0 %}
{% set last = loop.index0 % 3 == 2 %}
{% snippet "organization/snippets/organization_item.html", organization=organization, first=first, last=last %}
{% endfor %}
</ul>
33 changes: 33 additions & 0 deletions ckan/templates/snippets/organization.html
@@ -0,0 +1,33 @@
{#
Embeds a organization within the sidebar of a page.

organization - The organization dict.
truncate - A max length for the organization description. If not provided the description
will be full length.

Example:

{% snippet 'snippets/organization, organization=c.group_dict %}

#}
{% with truncate=truncate or 0, url=h.url_for(controller='organization', action='read', id=organization.name) %}
<section class="module module-narrow module-shallow group">
<div class="module-content media media-vertical">
<a class="media-image" href="{{ url }}">
<img src="{{ organization.image_url or h.url_for_static('/base/images/placeholder-organization.png') }}" width="200" height="125" alt="{{ organization.name }}" />
</a>
<div class="media-content">
<h3 class="media-heading"><a href={{ url }}>{{ organization.title or organization.name }}</a></h3>
{% if organization.description %}
{% if truncate %}
<p>{{ organization.description }}</p>
{% else %}
<p>{{ h.markdown_extract(organization.description, truncate) }}</p>
{% endif %}
{% else %}
<p class="empty">{{ _('There is no description for this organization') }}</p>
{% endif %}
</div>
</div>
</section>
{% endwith %}
24 changes: 24 additions & 0 deletions ckan/templates/snippets/organization_item.html
@@ -0,0 +1,24 @@
<section class="span6 group-list module module-narrow module-shallow">
<header class="module-heading media">
{% set url=h.url_for(controller='organization', action='read', id=organization.name) %}
{% set truncate=truncate or 0 %}
<a class="media-image" href="{{ url }}">
<img src="{{ organization.image_url or h.url_for_static('/base/images/placeholder-organization.png') }}" width="100" height="60" alt="{{ organization.name }}" />
</a>
<div class="media-content">
<h3 class="media-heading"><a href={{ url }}>{{ organization.title or organization.name }}</a></h3>
{% if organization.description %}
{% if truncate == 0 %}
<p>{{ h.markdown_extract(organization.description)|urlize }}</p>
{% else %}
<p>{{ h.markdown_extract(organization.description, truncate)|urlize }}</p>
{% endif %}
{% else %}
<p class="empty">{{ _('There is no description for this organization') }}</p>
{% endif %}
</div>
</header>
{% set list_class = "unstyled dataset-list" %}
{% set item_class = "dataset-item module-content" %}
{% snippet 'snippets/package_list.html', packages=organization.packages, list_class=list_class, item_class=item_class, truncate=120 %}
</section>

0 comments on commit 2ecb361

Please sign in to comment.