diff options
| -rw-r--r-- | archaeological_context_records/models.py | 10 | ||||
| -rw-r--r-- | archaeological_context_records/templates/ishtar/sheet_contextrecord.html | 17 | ||||
| -rw-r--r-- | archaeological_context_records/urls.py | 5 | ||||
| -rw-r--r-- | archaeological_context_records/views.py | 23 | ||||
| -rw-r--r-- | archaeological_operations/models.py | 10 | ||||
| -rw-r--r-- | ishtar_common/models.py | 19 | ||||
| -rw-r--r-- | ishtar_common/views.py | 1 | 
7 files changed, 67 insertions, 18 deletions
| diff --git a/archaeological_context_records/models.py b/archaeological_context_records/models.py index a3dcd5761..f6253bf68 100644 --- a/archaeological_context_records/models.py +++ b/archaeological_context_records/models.py @@ -33,7 +33,8 @@ from ishtar_common.utils import cached_label_changed  from ishtar_common.models import GeneralType, BaseHistorizedItem, \      HistoricalRecords, OwnPerms, ShortMenuItem, Source, GeneralRelationType,\      GeneralRecordRelations, post_delete_record_relation, get_image_path, \ -    ImageModel, post_save_cache, ValueGetter, BulkUpdatedItem, IshtarImage +    ImageModel, post_save_cache, ValueGetter, BulkUpdatedItem, IshtarImage, \ +    RelationItem  from archaeological_operations.models import Operation, Period, Parcel, \      ArchaeologicalSite @@ -205,7 +206,8 @@ class CRBulkView(object):  class ContextRecord(BulkUpdatedItem, BaseHistorizedItem, -                    ImageModel, OwnPerms, ValueGetter, ShortMenuItem): +                    ImageModel, OwnPerms, ValueGetter, ShortMenuItem, +                    RelationItem):      SHOW_URL = 'show-contextrecord'      SLUG = 'contextrecord'      EXTERNAL_ID_KEY = 'context_record_external_id' @@ -326,10 +328,6 @@ class ContextRecord(BulkUpdatedItem, BaseHistorizedItem,                                      blank=True)      cached_label = models.TextField(_(u"Cached name"), null=True, blank=True,                                      db_index=True) -    relation_image = models.FileField( -        _(u"Generated relation image (SVG)"), null=True, blank=True, -        upload_to=get_image_path -    )      PARENT_SEARCH_VECTORS = ['operation']      BASE_SEARCH_VECTORS = ["cached_label", "label", "location",                             "interpretation", "filling", "datings_comment", diff --git a/archaeological_context_records/templates/ishtar/sheet_contextrecord.html b/archaeological_context_records/templates/ishtar/sheet_contextrecord.html index dd0579271..d8d89e3c2 100644 --- a/archaeological_context_records/templates/ishtar/sheet_contextrecord.html +++ b/archaeological_context_records/templates/ishtar/sheet_contextrecord.html @@ -86,10 +86,23 @@      <img src="{{item.relation_image.url}}" class="img-fluid img-thumbnail">      {% if output != "ODT" %}</a>{% endif %}  </div> -<hr> -{% endif %}  {% endif %} +{% if DOT_GENERATION %} +<p class="text-center mt-1"> +    <a class="btn btn-secondary" +       onclick="long_wait();return true;" +       href="{% url 'generate-relation-image-contextrecord' item.pk %}"> +        {% if item.relation_image %} +        {% trans "Re-generate image" %} +        {% else %} +        {% trans "Generate image" %} +        {% endif %} +    </a> +</p> +{% endif %} +<hr> +{% endif %}  {% if item.operation %}  <h3>{% trans "Operation summary"%}</h3> diff --git a/archaeological_context_records/urls.py b/archaeological_context_records/urls.py index 86e4c3137..513e58543 100644 --- a/archaeological_context_records/urls.py +++ b/archaeological_context_records/urls.py @@ -71,6 +71,11 @@ urlpatterns = [          views.show_contextrecord, name='show-historized-contextrecord'),      url(r'revert-contextrecord/(?P<pk>.+)/(?P<date>.+)$',          views.revert_contextrecord, name='revert-contextrecord'), +    url(r'^display-contextrecord/(?P<pk>.+)/$', views.display_contextrecord, +        name='display-' + models.ContextRecord.SLUG), +    url(r'generate-relation-image-contextrecord/(?P<pk>.+)/', +        views.GenerateRelationImage.as_view(), +        name='generate-relation-image-contextrecord'),      url(r'get-contextrecord/own/(?P<type>.+)?$', views.get_contextrecord,          name='get-own-contextrecord', kwargs={'force_own': True}),      url(r'get-contextrecord/(?P<type>.+)?$', views.get_contextrecord, diff --git a/archaeological_context_records/views.py b/archaeological_context_records/views.py index 53ef90a40..9c2f14406 100644 --- a/archaeological_context_records/views.py +++ b/archaeological_context_records/views.py @@ -21,12 +21,14 @@ import json  from django.core.urlresolvers import reverse  from django.db.models import Q -from django.http import HttpResponse, HttpResponseRedirect +from django.http import HttpResponse, HttpResponseRedirect, Http404  from django.shortcuts import redirect +from django.views.generic import RedirectView  from django.utils.translation import ugettext_lazy as _  from ishtar_common.forms_common import AuthorFormset, SourceForm -from ishtar_common.views import get_item, show_item, revert_item +from ishtar_common.views import get_item, show_item, revert_item, \ +    IshtarMixin, LoginRequiredMixin, display_item  from archaeological_operations.views import site_extra_context  from ishtar_common.wizards import SearchWizard @@ -41,6 +43,7 @@ show_contextrecord = show_item(      extra_dct=site_extra_context  )  revert_contextrecord = revert_item(models.ContextRecord) +display_contextrecord = display_item(models.ContextRecord)  def autocomplete_contextrecord(request): @@ -194,3 +197,19 @@ def reset_wizards(request):              (RecordSourceWizard, 'record_source_modification'),              (RecordSourceDeletionWizard, 'record_source_deletion')):          wizard_class.session_reset(request, url_name) + + +class GenerateRelationImage(IshtarMixin, LoginRequiredMixin, RedirectView): +    def get_redirect_url(self, *args, **kwargs): +        return reverse('display-' + models.ContextRecord.SLUG, +                       args=[self.context_record.pk]) + +    def get(self, request, *args, **kwargs): +        try: +            self.context_record = models.ContextRecord.objects.get( +                pk=kwargs['pk'] +            ) +        except models.ContextRecord.DoesNotExist: +            raise Http404() +        self.context_record.generate_relation_image() +        return super(GenerateRelationImage, self).get(request, *args, **kwargs)
\ No newline at end of file diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py index 87ec89870..2a5f1cbe6 100644 --- a/archaeological_operations/models.py +++ b/archaeological_operations/models.py @@ -38,7 +38,8 @@ from ishtar_common.models import GeneralType, BaseHistorizedItem, \      SourceType, Person, Organization, Town, Dashboard, IshtarUser, ValueGetter,\      DocumentTemplate, ShortMenuItem, DashboardFormItem, GeneralRelationType,\      GeneralRecordRelations, post_delete_record_relation, OperationType, \ -    ImageModel, post_save_cache, PersonType, IshtarImage, get_image_path +    ImageModel, post_save_cache, PersonType, IshtarImage, get_image_path, \ +    RelationItem  class RemainType(GeneralType): @@ -271,7 +272,7 @@ class ClosedItem(object):  class Operation(ClosedItem, BaseHistorizedItem, ImageModel, OwnPerms, -                ValueGetter, ShortMenuItem, DashboardFormItem): +                ValueGetter, ShortMenuItem, DashboardFormItem, RelationItem):      QUALITY_DICT = dict(QUALITY)      SHOW_URL = 'show-operation'      TABLE_COLS = ['year', 'towns', 'common_name', 'operation_type', @@ -477,11 +478,6 @@ class Operation(ClosedItem, BaseHistorizedItem, ImageModel, OwnPerms,      finds_received = models.NullBooleanField(          _(u"Finds received"), blank=True, null=True) -    relation_image = models.FileField( -        _(u"Generated relation image (SVG)"), null=True, blank=True, -        upload_to=get_image_path -    ) -      # judiciary      seizure_name = models.TextField(_(u"Seizure name"), blank=True, null=True)      official_report_number = models.TextField(_(u"Official report number"), diff --git a/ishtar_common/models.py b/ishtar_common/models.py index cbf1431a7..4d8243af4 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -62,7 +62,8 @@ from simple_history.models import HistoricalRecords as BaseHistoricalRecords  from ishtar_common.model_merging import merge_model_objects  from ishtar_common.utils import get_cache, disable_for_loaddata, create_slug,\ -    get_all_field_names, merge_tsvectors, cached_label_changed +    get_all_field_names, merge_tsvectors, cached_label_changed, \ +    generate_relation_graph  from ishtar_common.models_imports import ImporterModel, ImporterType, \      ImporterDefault, ImporterDefaultValues, ImporterColumn, \ @@ -984,6 +985,22 @@ class BulkUpdatedItem(object):          return transaction_id, False +class RelationItem(models.Model): +    """ +    Items with relation between them +    """ +    relation_image = models.FileField( +        _(u"Generated relation image (SVG)"), null=True, blank=True, +        upload_to=get_image_path +    ) + +    class Meta: +        abstract = True + +    def generate_relation_image(self): +        generate_relation_graph(self) + +  class JsonDataSection(models.Model):      content_type = models.ForeignKey(ContentType)      name = models.CharField(_(u"Name"), max_length=200) diff --git a/ishtar_common/views.py b/ishtar_common/views.py index 945d4764c..f6468afd0 100644 --- a/ishtar_common/views.py +++ b/ishtar_common/views.py @@ -1353,6 +1353,7 @@ def show_item(model, name, extra_dct=None):                                       ).split('/')[:-2]) + u"/"          dct['CURRENCY'] = get_current_profile().currency          dct['ENCODING'] = settings.ENCODING +        dct['DOT_GENERATION'] = settings.DOT_BINARY and True          dct['current_window_url'] = url_name          date = None          if 'date' in dct: | 
