From 66ba898ce0797fd51a826f6ea654b87a3487e8bb Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Tue, 19 Oct 2021 22:46:56 +0200 Subject: Syndication - attach the generated match document to the source --- ishtar_common/models_rest.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'ishtar_common/models_rest.py') 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): -- cgit v1.2.3