Skip to content

Commit

Permalink
[#178] Inline form for Organisation.internal_org_ids
Browse files Browse the repository at this point in the history
Add InternalOrganisationIDInline and include it in
OrganisationAdmin.inlines

Edit organisation/change_form.html to include the
InternalOrganisationIDInline at the end of the form
  • Loading branch information
zzgvh committed Apr 13, 2013
1 parent 5e3b55b commit c0083fa
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 21 deletions.
10 changes: 9 additions & 1 deletion akvo/rsr/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,21 @@ class OrganisationLocationInline(admin.StackedInline):
formset = RSR_LocationFormFormSet


class InternalOrganisationIDInline(admin.TabularInline):
model = get_model('rsr', 'Organisation').internal_org_ids.through
extra = 1
fk_name = 'recording_org'
verbose_name = 'internal organisation ID'
verbose_name_plural = 'internal organisation IDs'

class OrganisationAdmin(admin.ModelAdmin):
fieldsets = (
(_(u'General information'), {'fields': ('name', 'long_name', 'organisation_type', 'new_organisation_type', 'logo', 'url', 'iati_org_id', 'language',)}),
(_(u'Contact information'), {'fields': ('phone', 'mobile', 'fax', 'contact_person', 'contact_email', ), }),
(_(u'About the organisation'), {'fields': ('description', )}),
)
inlines = (OrganisationLocationInline,)
inlines = (OrganisationLocationInline, InternalOrganisationIDInline,)
exclude = ('internal_org_ids',)
list_display = ('name', 'long_name', 'website', 'language',)
search_fields = ('name', 'long_name',)

Expand Down
49 changes: 29 additions & 20 deletions akvo/templates/admin/rsr/organisation/change_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@


{% block pretitle %}
{{ block.super }}
<h2>{% trans 'Adding and Editing Organisations.' %}</h2>
<p>{% trans 'Describe your organisation to the international Akvo community of users: tell us who you are, what you do, and what you as an organisation hope to accomplish. Your audience may include people unfamiliar with the sector or with your sphere of operation, so a bit of explanation in plain language (no acronyms) might be helpful. Details will help viewers get a sense of who you are: do you work on all continents? In both water and sanitation, perhaps even with other goals in mind? Are you part of a network or programme? ' %}</p>
<br>
{{ block.super }}
<h2>{% trans 'Adding and Editing Organisations.' %}</h2>
<p>{% trans 'Describe your organisation to the international Akvo community of users: tell us who you are, what you do, and what you as an organisation hope to accomplish. Your audience may include people unfamiliar with the sector or with your sphere of operation, so a bit of explanation in plain language (no acronyms) might be helpful. Details will help viewers get a sense of who you are: do you work on all continents? In both water and sanitation, perhaps even with other goals in mind? Are you part of a network or programme? ' %}</p>
<br>
{% endblock pretitle %}

{% block content %}
Expand All @@ -18,46 +18,55 @@ <h2>{% trans 'Adding and Editing Organisations.' %}</h2>
<ul class="object-tools">
<li><a href="history/" class="historylink">{% trans "History" %}</a></li>
{% if has_absolute_url %}
<li><a href="../../../r/{{ content_type_id }}/{{ object_id }}/" class="viewsitelink">{% trans "View on site" %}</a></li>
{% endif%}
<li><a href="../../../r/{{ content_type_id }}/{{ object_id }}/"
class="viewsitelink">{% trans "View on site" %}</a></li>
{% endif %}
</ul>
{% endif %}
{% endif %}
{% endblock object-tools %}
<form {% if has_file_field %}enctype="multipart/form-data" {% endif %}action="{{ form_url }}" method="post" id="{{ opts.module_name }}_form">
<form {% if has_file_field %}enctype="multipart/form-data" {% endif %}action="{{ form_url }}" method="post"
id="{{ opts.module_name }}_form">
{% csrf_token %}
{% block form_top %}{% endblock %}
<div>
{% if is_popup %}<input type="hidden" name="_popup" value="1" />{% endif %}
{% if is_popup %}<input type="hidden" name="_popup" value="1"/>{% endif %}
{% if save_on_top %}{% submit_row %}{% endif %}
{% if errors %}
<p class="errornote">
{% blocktrans count errors|length as error_count %}Please correct the error below.{% plural %}Please correct the errors below.{% endblocktrans %}
{% blocktrans count errors|length as error_count %}Please correct the error below.{% plural %}Please correct
the errors below.{% endblocktrans %}
</p>
{{ adminform.form.non_field_errors }}
{% endif %}

{% for fieldset in adminform %}
{% include "admin/includes/fieldset.html" %}
{# hack to put the inlines at certain points in the form #}
{% if forloop.counter == 2 %}
{% for inline_admin_formset in inline_admin_formsets %}
{% include inline_admin_formset.opts.template %}
{% endfor %}
{% block after_related_objects %}{% endblock %}
{% with inline_admin_formset=inline_admin_formsets.0 %}
{% include inline_admin_formset.opts.template %}
{% endwith %}
{% endif %}
{% if forloop.counter == 3 %}
{% with inline_admin_formset=inline_admin_formsets.1 %}
{% include inline_admin_formset.opts.template %}
{% endwith %}
{% endif %}
{% endfor %}

{% block after_related_objects %}{% endblock %}

{% block after_field_sets %}{% endblock %}

{% submit_row %}

{% if adminform and add %}
<script type="text/javascript">document.getElementById("{{ adminform.first_field.auto_id }}").focus();</script>
<script type="text/javascript">document.getElementById("{{ adminform.first_field.auto_id }}").focus();</script>
{% endif %}

{# JavaScript for prepopulated fields #}
{% prepopulated_fields_js %}

</div>
</form>
</div>
Expand Down

0 comments on commit c0083fa

Please sign in to comment.