summaryrefslogtreecommitdiff
path: root/ishtar_common/models_rest.py
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 /ishtar_common/models_rest.py
parentdce7ab14dfb23d953598a92a578b8cb9e0738fff (diff)
downloadIshtar-66ba898ce0797fd51a826f6ea654b87a3487e8bb.tar.bz2
Ishtar-66ba898ce0797fd51a826f6ea654b87a3487e8bb.zip
Syndication - attach the generated match document to the source
Diffstat (limited to 'ishtar_common/models_rest.py')
-rw-r--r--ishtar_common/models_rest.py21
1 files changed, 18 insertions, 3 deletions
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):