summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2018-08-28 12:25:57 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2018-08-28 12:25:57 +0200
commit9dc2b92191ca9e372743788d44386b7b7673cbdc (patch)
treece0b704e88037faccbcf74e665851c878958146e
parentaf865c9ecc18fe31e56c7aff26ab05e8ef40421a (diff)
downloadIshtar-9dc2b92191ca9e372743788d44386b7b7673cbdc.tar.bz2
Ishtar-9dc2b92191ca9e372743788d44386b7b7673cbdc.zip
Add files to document management (refs #4191)
-rw-r--r--archaeological_files/migrations/0013_file_documents.py21
-rw-r--r--archaeological_files/models.py10
-rw-r--r--ishtar_common/forms_common.py3
-rw-r--r--ishtar_common/models.py6
-rw-r--r--ishtar_common/templates/ishtar/sheet_document.html1
5 files changed, 37 insertions, 4 deletions
diff --git a/archaeological_files/migrations/0013_file_documents.py b/archaeological_files/migrations/0013_file_documents.py
new file mode 100644
index 000000000..ca731e531
--- /dev/null
+++ b/archaeological_files/migrations/0013_file_documents.py
@@ -0,0 +1,21 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.10 on 2018-08-28 11:43
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('ishtar_common', '0069_userprofile_show_field_number'),
+ ('archaeological_files', '0012_auto_20180403_1120'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='file',
+ name='documents',
+ field=models.ManyToManyField(blank=True, related_name='files', to='ishtar_common.Document', verbose_name='Documents'),
+ ),
+ ]
diff --git a/archaeological_files/models.py b/archaeological_files/models.py
index a4de6e0e4..3a397e551 100644
--- a/archaeological_files/models.py
+++ b/archaeological_files/models.py
@@ -33,7 +33,7 @@ from ishtar_common.utils import cached_label_changed, get_cache, \
from ishtar_common.models import GeneralType, BaseHistorizedItem, \
HistoricalRecords, OwnPerms, Person, Organization, Department, Town, \
Dashboard, DashboardFormItem, ValueGetter, ShortMenuItem, \
- OperationType, get_external_id, post_save_cache
+ OperationType, get_external_id, post_save_cache, Document
from archaeological_operations.models import get_values_town_related, \
ClosedItem
@@ -312,6 +312,11 @@ class File(ClosedItem, BaseHistorizedItem, OwnPerms, ValueGetter,
mh_listing = models.NullBooleanField(
u"Sur Monument Historique inscrit", blank=True, null=True)
# <-- research archaeology
+
+ documents = models.ManyToManyField(
+ Document, related_name="files", verbose_name=_(u"Documents"),
+ blank=True)
+
cached_label = models.TextField(_(u"Cached name"), null=True, blank=True,
db_index=True)
imported_line = models.TextField(_(u"Imported line"), null=True,
@@ -347,6 +352,9 @@ class File(ClosedItem, BaseHistorizedItem, OwnPerms, ValueGetter,
return k
return u""
+ def _get_base_image_path(self):
+ return u"{}/{}".format(self.SLUG, self.reference or self.short_label)
+
@property
def short_class_name(self):
return _(u"FILE")
diff --git a/ishtar_common/forms_common.py b/ishtar_common/forms_common.py
index 33f124d31..99ad857b3 100644
--- a/ishtar_common/forms_common.py
+++ b/ishtar_common/forms_common.py
@@ -1180,6 +1180,9 @@ class DocumentForm(forms.ModelForm, CustomForm, ManageOldType):
if new_pk in initial.keys():
continue
related.add(related.model.objects.get(pk=new_pk))
+ item = models.Document.objects.get(pk=item.pk)
+ item.skip_history_when_saving = True
+ item.save() # resave to regen the attached items
return item
diff --git a/ishtar_common/models.py b/ishtar_common/models.py
index 51d3550e9..f80e50a18 100644
--- a/ishtar_common/models.py
+++ b/ishtar_common/models.py
@@ -3346,12 +3346,12 @@ class Document(OwnPerms, ImageModel, FullSearch, Imported):
# other will be symbolic links
RELATED_MODELS = [
'treatment_files', 'treatments', 'finds', 'context_records',
- 'operations', 'sites', 'warehouses',
+ 'operations', 'sites', 'warehouses', 'files'
]
# same fields but in order for forms
RELATED_MODELS_ALT = [
- 'finds', 'context_records', 'operations', 'sites', 'warehouses',
- 'treatments', 'treatment_files',
+ 'finds', 'context_records', 'operations', 'sites', 'files',
+ 'warehouses', 'treatments', 'treatment_files',
]
SLUG = 'document'
LINK_SPLIT = u"<||>"
diff --git a/ishtar_common/templates/ishtar/sheet_document.html b/ishtar_common/templates/ishtar/sheet_document.html
index 465c02db5..3b178c29e 100644
--- a/ishtar_common/templates/ishtar/sheet_document.html
+++ b/ishtar_common/templates/ishtar/sheet_document.html
@@ -49,6 +49,7 @@
{% block related %}
{% if item.has_related %}
<h2>{% trans "Related items" %}</h2>
+{% field_flex_full "Files" item.files|add_links %}
{% field_flex_full "Sites" item.sites|add_links %}
{% field_flex_full "Operations" item.operations|add_links %}
{% field_flex_full "Context records" item.context_records|add_links %}