summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2021-10-19 22:46:56 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2022-12-12 12:20:59 +0100
commit66ba898ce0797fd51a826f6ea654b87a3487e8bb (patch)
tree664d335474056350fd5e223a3ba582b7f97e6f90
parentdce7ab14dfb23d953598a92a578b8cb9e0738fff (diff)
downloadIshtar-66ba898ce0797fd51a826f6ea654b87a3487e8bb.tar.bz2
Ishtar-66ba898ce0797fd51a826f6ea654b87a3487e8bb.zip
Syndication - attach the generated match document to the source
-rw-r--r--archaeological_operations/tests.py1
-rw-r--r--ishtar_common/admin.py6
-rw-r--r--ishtar_common/migrations/0217_auto_20211019_2242.py (renamed from ishtar_common/migrations/0217_auto_20211018_1741.py)21
-rw-r--r--ishtar_common/models_rest.py21
4 files changed, 35 insertions, 14 deletions
diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py
index ee1f2645c..409ee5079 100644
--- a/archaeological_operations/tests.py
+++ b/archaeological_operations/tests.py
@@ -4686,7 +4686,6 @@ class ApiTest(OperationInitTest, APITestCase):
params["action"] = "generate_match_document"
response = self.client.post(url, params, follow=True)
- #src_doc = source.generate_match_document()
zip_file = zipfile.ZipFile(BytesIO(response.content))
self.assertIsNone(
diff --git a/ishtar_common/admin.py b/ishtar_common/admin.py
index 8124bbeed..761d07b4d 100644
--- a/ishtar_common/admin.py
+++ b/ishtar_common/admin.py
@@ -2217,6 +2217,8 @@ def update_types_from_source(modeladmin, request, queryset):
)
return response
+update_types_from_source.short_description = _("Update types from source")
+
def generate_match_document(modeladmin, request, queryset):
return_url = (
@@ -2251,6 +2253,9 @@ def generate_match_document(modeladmin, request, queryset):
return response
+generate_match_document.short_description = _("Generate match document")
+
+
class ApiExternalSourceAdmin(admin.ModelAdmin):
model = models_rest.ApiExternalSource
actions = [update_types_from_source, generate_match_document]
@@ -2272,4 +2277,5 @@ class ApiKeyMatchAdmin(admin.ModelAdmin):
change_value("do_not_match", True, _("Disable match")),
]
+
admin_site.register(models_rest.ApiKeyMatch, ApiKeyMatchAdmin)
diff --git a/ishtar_common/migrations/0217_auto_20211018_1741.py b/ishtar_common/migrations/0217_auto_20211019_2242.py
index d79224b5a..4a0851691 100644
--- a/ishtar_common/migrations/0217_auto_20211018_1741.py
+++ b/ishtar_common/migrations/0217_auto_20211019_2242.py
@@ -1,4 +1,4 @@
-# Generated by Django 2.2.24 on 2021-10-18 17:41
+# Generated by Django 2.2.24 on 2021-10-19 22:42
from django.conf import settings
import django.contrib.postgres.fields
@@ -10,8 +10,8 @@ import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
- ('auth', '0011_update_proxy_permissions'),
('contenttypes', '0002_remove_content_type_name'),
+ ('auth', '0011_update_proxy_permissions'),
('ishtar_common', '0216_auto_20210805_1703'),
]
@@ -23,10 +23,11 @@ class Migration(migrations.Migration):
('url', models.URLField(verbose_name='URL')),
('name', models.CharField(max_length=200, verbose_name='Name')),
('key', models.CharField(max_length=40, verbose_name='Key')),
+ ('match_document', models.FileField(blank=True, help_text='First use the "Update types from source" action. Then use the action "Generate match document" action to create a default match document. Complete it and attach it back to the source to finally use the action "Modify association from match document".', null=True, upload_to='', verbose_name='Match document')),
],
options={
- 'verbose_name': 'API - External source',
- 'verbose_name_plural': 'API - External sources',
+ 'verbose_name': 'API - Search - External source',
+ 'verbose_name_plural': 'API - Search - External sources',
},
),
migrations.CreateModel(
@@ -36,8 +37,8 @@ class Migration(migrations.Migration):
('ip', models.GenericIPAddressField(verbose_name='IP')),
],
options={
- 'verbose_name': 'API - User',
- 'verbose_name_plural': 'API - Users',
+ 'verbose_name': 'API - Remote access - User',
+ 'verbose_name_plural': 'API - Remote access - Users',
},
),
migrations.AlterField(
@@ -184,8 +185,8 @@ class Migration(migrations.Migration):
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='ishtar_common.ApiUser')),
],
options={
- 'verbose_name': 'API - Search model',
- 'verbose_name_plural': 'API - Search models',
+ 'verbose_name': 'API - Remote access - Search model',
+ 'verbose_name_plural': 'API - Remote access - Search models',
},
),
migrations.CreateModel(
@@ -203,8 +204,8 @@ class Migration(migrations.Migration):
('source', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='ishtar_common.ApiExternalSource')),
],
options={
- 'verbose_name': 'API - Key match',
- 'verbose_name_plural': 'API - Keys matches',
+ 'verbose_name': 'API - Search - Key match',
+ 'verbose_name_plural': 'API - Search - Keys matches',
},
),
]
diff --git a/ishtar_common/models_rest.py b/ishtar_common/models_rest.py
index bb260c30d..61b3ce042 100644
--- a/ishtar_common/models_rest.py
+++ b/ishtar_common/models_rest.py
@@ -55,6 +55,17 @@ class ApiExternalSource(models.Model):
url = models.URLField(verbose_name=_("URL"))
name = models.CharField(verbose_name=_("Name"), max_length=200)
key = models.CharField(_("Key"), max_length=40)
+ match_document = models.FileField(
+ _("Match document"),
+ blank=True,
+ null=True,
+ help_text=_(
+ 'First use the "Update types from source" action. Then use the action '
+ '"Generate match document" action to create a default match document. '
+ "Complete it and attach it back to the source to finally use the action "
+ '"Modify association from match document".'
+ ),
+ )
class Meta:
verbose_name = _("API - Search - External source")
@@ -146,10 +157,14 @@ class ApiExternalSource(models.Model):
for idx, tpe in enumerate(types):
self._generate_match_page(idx, tpe, uno, calc, lst_sheet)
tmpdir = tempfile.mkdtemp(prefix="ishtar-matches-")
- dest_filename = "{}{}{}-{}.ods".format(tmpdir, os.sep,
- datetime.date.today().isoformat(),
- slugify(self.name))
+ base = "{}-{}.ods".format(datetime.date.today().isoformat(), slugify(self.name))
+ dest_filename = "{}{}{}".format(tmpdir, os.sep, base)
uno.save_calc(calc, dest_filename)
+ from django.core.files import File
+
+ with open(dest_filename, "rb") as fle:
+ self.match_document = File(fle, base)
+ self.save()
return dest_filename
def _generate_match_page(self, page_number, tpe, uno, calc, lst_sheet):