diff options
author | Étienne Loks <etienne.loks@proxience.com> | 2015-09-29 02:43:19 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@proxience.com> | 2015-09-29 02:43:19 +0200 |
commit | df2405cb949e268dda4c880d2685054c0eab4a80 (patch) | |
tree | e27f01bf29b9fe16dfccc157f2a1f2d6fcb872e4 | |
parent | fa03f91834500f7589ba1912a681227186d7974e (diff) | |
download | Ishtar-df2405cb949e268dda4c880d2685054c0eab4a80.tar.bz2 Ishtar-df2405cb949e268dda4c880d2685054c0eab4a80.zip |
Display dynamicaly large tables in windows
16 files changed, 153 insertions, 105 deletions
diff --git a/archaeological_context_records/models.py b/archaeological_context_records/models.py index 9c5cf52f4..d86d4aaa9 100644 --- a/archaeological_context_records/models.py +++ b/archaeological_context_records/models.py @@ -19,7 +19,6 @@ from django.conf import settings from django.contrib.gis.db import models -from django.core.exceptions import ValidationError from django.core.urlresolvers import reverse from django.db.models.signals import post_delete from django.utils.translation import ugettext_lazy as _, ugettext, pgettext @@ -284,6 +283,7 @@ class RelationType(GeneralRelationType): verbose_name_plural = _(u"Relation types") ordering = ('order',) + class RecordRelations(GeneralRecordRelations, models.Model): left_record = models.ForeignKey(ContextRecord, related_name='right_relations') diff --git a/archaeological_context_records/templates/ishtar/sheet_contextrecord.html b/archaeological_context_records/templates/ishtar/sheet_contextrecord.html index 1a18f1cd5..8d1a4de63 100644 --- a/archaeological_context_records/templates/ishtar/sheet_contextrecord.html +++ b/archaeological_context_records/templates/ishtar/sheet_contextrecord.html @@ -66,7 +66,7 @@ {% if item.right_relations.count %} <h3>{% trans "In relation with"%}</h3> -<table> +<table class='simple'> <tr> <th>{% trans "Relation type" %}</th> <th>{% trans "ID" %}</th> @@ -87,7 +87,7 @@ <td class='link'><a href="#" class='display_details' onclick='load_window("{%url show-contextrecord relation.right_record.pk ''%}")'>{% trans "Details" %}</a></td> </tr> {% endfor %} -<table> +<table class='simple'> {% endif %} @@ -126,7 +126,7 @@ {% trans "Document from this context record" as cr_docs %} {% if item.source.count %} {% table_document cr_docs item.source.all %}{% endif %} -<table> +<table class='simple'> <caption>{%trans "Finds"%}</caption> <tr> <th>{% trans "Complete Id" %}</th> diff --git a/archaeological_context_records/views.py b/archaeological_context_records/views.py index d92e162c3..483630b3c 100644 --- a/archaeological_context_records/views.py +++ b/archaeological_context_records/views.py @@ -49,6 +49,7 @@ get_contextrecordsource = get_item( extra_request_keys={ 'context_record__parcel__town': 'context_record__parcel__town__pk', 'context_record__operation__year': 'context_record__operation__year', + 'context_record__operation': 'context_record__operation__pk', 'context_record__datings__period': 'context_record__datings__period__pk', 'context_record__unit': 'context_record__unit__pk', diff --git a/archaeological_files/templates/ishtar/sheet_file.html b/archaeological_files/templates/ishtar/sheet_file.html index fc5ddbe70..0e68f8a98 100644 --- a/archaeological_files/templates/ishtar/sheet_file.html +++ b/archaeological_files/templates/ishtar/sheet_file.html @@ -100,7 +100,7 @@ {% trans "Administrativ acts" as administrativeacts_label %} {% table_administrativact administrativeacts_label item.administrative_act.all %} -<table> +<table class='simple'> <caption>{%trans "Associated operations"%}</caption> <tr> <th>{% trans "Ref." %}</th> @@ -126,7 +126,7 @@ {% endfor %} </table> -<table> +<table class='simple'> <caption>{%trans "Admninistrative acts linked to associated operations"%}</caption> <tr> <th>{% trans "Year" %}</th> diff --git a/archaeological_finds/templates/ishtar/sheet_find.html b/archaeological_finds/templates/ishtar/sheet_find.html index 94ec12903..660e32117 100644 --- a/archaeological_finds/templates/ishtar/sheet_find.html +++ b/archaeological_finds/templates/ishtar/sheet_find.html @@ -87,7 +87,7 @@ {% if forloop.counter0 %}<hr/>{% endif %} {% endfor %} -<table> +<table class='simple'> <caption>{%trans "Documents"%}</caption> <tr> <th>{% trans "Title" %}</th> diff --git a/archaeological_finds/views.py b/archaeological_finds/views.py index 2383dcad7..880a3bdfa 100644 --- a/archaeological_finds/views.py +++ b/archaeological_finds/views.py @@ -44,6 +44,8 @@ get_find = get_item( 'base_finds__context_record__parcel__town', 'base_finds__context_record__operation__year': 'base_finds__context_record__operation__year__contains', + 'base_finds__context_record__operation': + 'base_finds__context_record__operation__pk', 'base_finds__context_record__operation__code_patriarche': 'base_finds__context_record__operation__code_patriarche', 'dating__period': 'dating__period__pk', diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py index 977fbdb4a..90af1bd62 100644 --- a/archaeological_operations/models.py +++ b/archaeological_operations/models.py @@ -36,6 +36,7 @@ from ishtar_common.models import GeneralType, BaseHistorizedItem, \ DocumentTemplate, ShortMenuItem, DashboardFormItem, GeneralRelationType,\ GeneralRecordRelations, post_delete_record_relation FILES_AVAILABLE = 'archaeological_files' in settings.INSTALLED_APPS +FINDS_AVAILABLE = 'archaeological_finds' in settings.INSTALLED_APPS class OperationType(GeneralType): @@ -306,6 +307,17 @@ class Operation(BaseHistorizedItem, OwnPerms, ValueGetter, ShortMenuItem, def show_url(self): return reverse('show-operation', args=[self.pk, '']) + def has_finds(self): + if not FINDS_AVAILABLE: + return + from archaeological_finds.models import BaseFind + return BaseFind.objects.filter(context_record__operation=self).count() + + def finds(self): + if FINDS_AVAILABLE: + from archaeological_finds.models import BaseFind + return BaseFind.objects.filter(context_record__operation=self) + def get_reference(self, full=False): ref = "" if self.code_patriarche: diff --git a/archaeological_operations/templates/ishtar/blocks/window_tables/administrativacts.html b/archaeological_operations/templates/ishtar/blocks/window_tables/administrativacts.html index 9feb51e72..0be468b59 100644 --- a/archaeological_operations/templates/ishtar/blocks/window_tables/administrativacts.html +++ b/archaeological_operations/templates/ishtar/blocks/window_tables/administrativacts.html @@ -1,5 +1,5 @@ {% load i18n %} -<table> +<table class='simple'> <caption>{{caption}}</caption> <tr> <th>{% trans "Ref." %}</th> diff --git a/archaeological_operations/templates/ishtar/blocks/window_tables/parcels.html b/archaeological_operations/templates/ishtar/blocks/window_tables/parcels.html index 06a1fa7b1..e19b729fe 100644 --- a/archaeological_operations/templates/ishtar/blocks/window_tables/parcels.html +++ b/archaeological_operations/templates/ishtar/blocks/window_tables/parcels.html @@ -1,5 +1,5 @@ {% load i18n %} -<table> +<table class='simple'> <caption>{{ parcels_label }}</caption> <tr> <th>{% trans "Town" %}</th> diff --git a/archaeological_operations/templates/ishtar/sheet_operation.html b/archaeological_operations/templates/ishtar/sheet_operation.html index cc69abda0..daeea7c40 100644 --- a/archaeological_operations/templates/ishtar/sheet_operation.html +++ b/archaeological_operations/templates/ishtar/sheet_operation.html @@ -91,87 +91,25 @@ {% trans "Document from this operation" as operation_docs %} {% if item.source.count %} -{% table_document operation_docs item.source.all|slice:":15" %} -{% if item.source.count > 15 %} -<em>Seuls les 15 premiers éléments ont été affichés sur un total de {{item.source.count}}.</em> -{% endif %} +{% dynamic_table_document operation_docs 'operation_docs' 'operation' item.pk %} {% endif %} -<table> - <caption>{%trans "Context records"%}</caption> - <tr> - <th>{% trans "ID" %}</th> - <th>{% trans "Type" %}</th> - <th>{% trans "Chronology" %}</th> - <th>{% trans "Description" %}</th> - <th>{% trans "Parcel" %}</th> - <th class='link'> </th> - </tr> - {% for context_record in item.context_record.all|slice:"15" %} - <tr> - <td class='string'>{{ context_record.label }}</td> - <td class='string'>{{context_record.unit|default:""}}</td> - <td class='string'>{{ context_record.datings.all|join:", " }}</td>{# periods ?#} - <td class='string'>{{ context_record.description }}</td> - <td class='string'>{{ context_record.parcel.section }} - {{context_record.parcel.parcel_number}}</td> - <td class='link'><a href="#" class='display_details' onclick='load_window("{%url show-contextrecord context_record.pk ''%}")'>{% trans "Details" %}</a></td> - </tr> - {% empty %} - <tr><td colspan="6" class='no_items'>{% trans "No context record associated to this operation" %}</td></tr> - {% endfor %} -</table> -{% if item.context_record.count > 15 %} -<em>Seuls les 15 premiers éléments ont été affichés sur un total de {{item.context_record.count}}.</em> +{% trans "Context records" as context_records %} +{% if item.context_record.count %} +{% dynamic_table_document context_records 'context_records' 'operation' item.pk %} {% endif %} +{% comment %} {% trans "Documents from associated context records" as cr_docs %} -{% if item.context_record_docs_q.count %} {% table_document cr_docs item.context_record_docs_q.all|slice:"15" %}{% endif %} - -<div class='table'> -<table> - <caption>{%trans "Finds"%}</caption> - <tr> - <th>{% trans "Complete Id" %}</th> - <th>{% trans "Short Id" %}</th> - <th>{% trans "Material type" %}</th> - <th>{% trans "Context record" context "short"%}</th> - <th>{% trans "Periods" %}</th> - <th>{% trans "Description" %}</th> - <th>{% trans "Weight" %}</th> - <th>{% trans "Numbers" %}</th> - <th>{% trans "Parcel" %}</th> - <th>{% trans "Container ref." %}</th> - <th>{% trans "Warehouse" %}</th> - <th class='link'> </th> - </tr> - {% for context_record in item.context_record.all|slice:"5" %} - {% for find in context_record.base_finds.all|slice:"15" %} - <tr> - {# OPE|MAT.CODE|UE|FIND_index #} - <td class="ref">{{ find.complete_id|default:""}}</td> - {# OPE|FIND_index #} - <td class="ref">{{ find.short_id|default:"" }}</td> - <td class="string">{{ find.get_last_find.material_type|default:"" }}</td> - <td>{{find.context_record.label}}</td> - <td class='string'>{{ find.get_last_find.dating}}</td>{# TODO .all|join:", " ? #} - <td class='string'>{{ find.get_last_find.description }}</td> - <td>{{ find.get_last_find.weight|default:"" }}</td> - <td>{{ find.get_last_find.item_number }}</td> - <td class="ref">{{ context_record.parcel.short_label }}</td> - <td class='ref'>{{ find.get_last_find.container.reference|default:""}}</td> - <td class='string'>{{ find.get_last_find.container.location|default:""}}</td> - <td class='link'><a class='display_details' href="#">{% trans "Details" %}</a></td> - {#<a href="#" class='display_details' onclick='load_window("{% url show-find find.pk%}");'>{%trans "Details"%}</a></td>#} - </tr> - {% empty %} - <tr><td colspan="9" class='no_items'>{% trans "No find associated to context record" %} {{context_record.short_label}}</td></tr> - {% endfor %} - {% empty %} - <tr><td colspan="9" class='no_items'>{% trans "No find associated to parcel" %} {{parcel.short_label}} {% trans "(no context record)" %}</td></tr> - {% endfor %} -</table> -</div> -<em>Seuls les 15 premiers éléments des 5 premières UEs sont affichées</em> +{% if item.context_record_docs_q.count %} +{% dynamic_table_document cr_docs 'context_records_docs' 'context_record__operation' item.pk %} +{% endif %} +{% endcomment %} + +{% trans "Finds" as finds %} +{% if item.finds %} +{% dynamic_table_document finds 'finds' 'base_finds__context_record__operation' item.pk %} +{% endif %} {% comment %} {% trans "Documents from associated finds" as find_docs %} diff --git a/ishtar_common/static/media/style.css b/ishtar_common/static/media/style.css index a00fce2cf..babdae9f7 100644 --- a/ishtar_common/static/media/style.css +++ b/ishtar_common/static/media/style.css @@ -90,7 +90,7 @@ a { text-decoration:none; } -caption, h2, h3 { +caption, h2, h3, #window h4 { color:#922; font-weight:bold; } @@ -105,6 +105,10 @@ h3{ margin:1em 0 0.5em 0; } +#window h4 { + text-align: center; +} + h4{ margin:10px 0; } @@ -703,7 +707,7 @@ table.confirm tr.spacer td:last-child{ overflow:auto; } -#window table, .dashboard table.resume{ +#window table.simple, .dashboard table.resume{ font-size:0.9em; margin:10px 0; border-collapse:collapse; @@ -727,13 +731,13 @@ table.confirm tr.spacer td:last-child{ margin-top:1em; } -#window table th, .dashboard table.resume th{ +#window table.simple th, .dashboard table.resume th{ background-color:#922; border:1px solid #f1f2f6; color:#FFF; } -#window table th{ +#window table.simple th{ text-align:center; } @@ -759,7 +763,7 @@ table.confirm tr.spacer td:last-child{ text-align:left; } -#window table td, .dashboard table.resume td{ +#window table.simple td, .dashboard table.resume td{ text-align:right; padding:0 1em; border:1px solid #f1f2f6; diff --git a/ishtar_common/templates/ishtar/blocks/window_tables/documents.html b/ishtar_common/templates/ishtar/blocks/window_tables/documents.html index 9405bc3e8..f1592cc42 100644 --- a/ishtar_common/templates/ishtar/blocks/window_tables/documents.html +++ b/ishtar_common/templates/ishtar/blocks/window_tables/documents.html @@ -1,5 +1,5 @@ {% load i18n %} -<table> +<table class='simple'> <caption>{{caption}}</caption> <tr> <th>{% trans "Title" %}</th> diff --git a/ishtar_common/templates/ishtar/blocks/window_tables/dynamic_documents.html b/ishtar_common/templates/ishtar/blocks/window_tables/dynamic_documents.html new file mode 100644 index 000000000..bd83983f4 --- /dev/null +++ b/ishtar_common/templates/ishtar/blocks/window_tables/dynamic_documents.html @@ -0,0 +1,37 @@ +{% load i18n %} + +<h4>{{caption}}</h4> +<table id='grid_{{name}}' class='jqgrid'></table> +<div id='pager_{{name}}'></div> + +<script type="text/javascript" language='javascript'> + +setTimeout( + function(){ + jQuery("#grid_{{name}}").jqGrid({ + url:'{{source}}', + datatype: "json", + mtype: 'GET', + colNames:['id', '', {{col_names|safe}}], + colModel:[ + {name:'id', index:'id', hidden:true}, + {name:'link', index:'link', width:30}, + {{extra_cols|safe}} + ], + sortname: 'value', + viewrecords: true, + sortorder: "asc", + emptyrecords: "{{no_result}}", + loadtext: "{{loading}}", + pager: '#pager_{{name}}', + width:720, + rowNum:20, + jsonReader : {repeatitems: false}, + loadError: function (jqXHR, textStatus, errorThrown) { + alert("{% trans "An error as occured during search. Check your query fields." %}"); + } + }); +}, 200); + +</script> + diff --git a/ishtar_common/templatetags/table_form.py b/ishtar_common/templatetags/table_form.py index 0ab49d93f..6ee99b9a5 100644 --- a/ishtar_common/templatetags/table_form.py +++ b/ishtar_common/templatetags/table_form.py @@ -5,6 +5,7 @@ from django.template import Library register = Library() + @register.inclusion_tag('blocks/form_snippet.html') def table_form(form): return {'form': form} diff --git a/ishtar_common/templatetags/window_tables.py b/ishtar_common/templatetags/window_tables.py index 5eebf6359..a135ad5c0 100644 --- a/ishtar_common/templatetags/window_tables.py +++ b/ishtar_common/templatetags/window_tables.py @@ -1,4 +1,11 @@ +import time + from django import template +from django.template.defaultfilters import slugify +from django.utils.translation import ugettext_lazy as _ + +from ishtar_common.forms import reverse_lazy +from ishtar_common.widgets import JQueryJqGrid register = template.Library() @@ -6,3 +13,42 @@ register = template.Library() @register.inclusion_tag('ishtar/blocks/window_tables/documents.html') def table_document(caption, data): return {'caption': caption, 'data': data} + +ASSOCIATED_MODELS = {} +try: + from archaeological_operations.models import OperationSource + ASSOCIATED_MODELS['operation_docs'] = (OperationSource, + 'get-operationsource') +except: + pass + +try: + from archaeological_context_records.models import ContextRecord, \ + ContextRecordSource + ASSOCIATED_MODELS['context_records'] = (ContextRecord, 'get-contextrecord') + ASSOCIATED_MODELS['context_records_docs'] = (ContextRecordSource, + 'get-contextrecordsource') +except: + pass + +try: + from archaeological_finds.models import Find + ASSOCIATED_MODELS['finds'] = (Find, 'get-find') +except: + pass + + +@register.inclusion_tag('ishtar/blocks/window_tables/dynamic_documents.html') +def dynamic_table_document(caption, associated_model, key, value): + model, url = ASSOCIATED_MODELS[associated_model] + grid = JQueryJqGrid(None, None, model) + + col_names, extra_cols = grid.get_cols() + return {'caption': caption, + 'name': slugify(caption) + '{}'.format(int(time.time())), + 'source': unicode(reverse_lazy(url)) + '?{}={}'.format(key, value), + 'col_names': col_names, + 'extra_cols': extra_cols, + 'no_result': unicode(_("No results")), + 'loading': unicode(_("Loading...")), + } diff --git a/ishtar_common/widgets.py b/ishtar_common/widgets.py index 9bffe4ec5..66380db8b 100644 --- a/ishtar_common/widgets.py +++ b/ishtar_common/widgets.py @@ -524,19 +524,8 @@ class JQueryJqGrid(forms.RadioSelect): self.new, self.new_message = new, new_message self.source_full = source_full - def render(self, name, value=None, attrs=None): - t = loader.get_template('blocks/form_snippet.html') - form = self.form() - rendered = t.render(Context({'form': form})) - dct = {} - if self.new: - model_name = self.associated_model._meta.object_name.lower() - dct['url_new'] = reverse('new-' + model_name, args=['0']) - dct['new_message'] = self.new_message - extra_cols = [] - col_names, col_idx = [], [] - for k in form.get_input_ids(): - col_idx.append(u'"%s"' % k) + def get_cols(self): + col_names, extra_cols = [], [] for field_name in getattr(self.associated_model, self.table_cols): field = self.associated_model keys = field_name.split('.') @@ -557,8 +546,26 @@ class JQueryJqGrid(forms.RadioSelect): col_names.append(u'"%s"' % field_verbose_name) extra_cols.append(self.COL_TPL % {'idx': field_name}) col_names = col_names and ", ".join(col_names) or "" - col_idx = col_idx and ", ".join(col_idx) or "" extra_cols = extra_cols and ", ".join(extra_cols) or "" + return col_names, extra_cols + + def render(self, name, value=None, attrs=None): + t = loader.get_template('blocks/form_snippet.html') + form = self.form() + rendered = t.render(Context({'form': form})) + dct = {} + if self.new: + model_name = self.associated_model._meta.object_name.lower() + dct['url_new'] = reverse('new-' + model_name, args=['0']) + dct['new_message'] = self.new_message + + col_names, extra_cols = self.get_cols() + + col_idx = [] + for k in form.get_input_ids(): + col_idx.append(u'"%s"' % k) + col_idx = col_idx and ", ".join(col_idx) or "" + dct['encoding'] = settings.ENCODING or 'utf-8' dct['source'] = unicode(self.source) if unicode(self.source_full) and unicode(self.source_full) != 'None': |