diff options
Diffstat (limited to 'ishtar_common/models.py')
-rw-r--r-- | ishtar_common/models.py | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/ishtar_common/models.py b/ishtar_common/models.py index 0a5fc30bf..b3cc807a8 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -5675,3 +5675,64 @@ class AdministrationTask(models.Model): self.state = 'F' self.result = "{}".format(stdout.decode('utf-8')) self.save() + + +ITEM_TYPES = ( + ("O", _("Operation")), + ("S", _("Archaeological site")), + ("CR", _("Context record")), + ("F", _("Find")), + ("W", _("Warehouse")), +) + + +EXPORT_STATE = (("C", _("Created")),) + SCRIPT_STATE + + +class ExportTask(models.Model): + filter_type = models.CharField( + _("Filter on"), max_length=2, choices=ITEM_TYPES, null=True, blank=True + ) + filter_text = models.TextField( + _("Filter query"), null=True, blank=True, + help_text=_("Textual query on this item (try it on the main " + "interface)")) + geo = models.BooleanField( + _("Export geographic data"), default=True, + help_text=_("Geographic data can represent large volume of " + "information. Geographic data can be excluded from the " + "export")) + state = models.CharField(_("State"), max_length=2, choices=EXPORT_STATE, + default='C') + creation_date = models.DateTimeField(default=datetime.datetime.now) + launch_date = models.DateTimeField(null=True, blank=True) + finished_date = models.DateTimeField(null=True, blank=True) + result = models.FileField(_("Result"), null=True, blank=True, + upload_to="exports") + + class Meta: + verbose_name = _("Export task") + verbose_name_plural = _("Export tasks") + ordering = ['creation_date'] + + def __str__(self): + state = _("Unknown") + if self.state in SCRIPT_STATE_DCT: + state = str(SCRIPT_STATE_DCT[self.state]) + return "Export - {} - {}".format(self.creation_date, state) + + @property + def label(self): + fltr = _("Whole database") + if self.filter_type and self.filter_text: + dct = dict(ITEM_TYPES) + if self.filter_type in dct: + fltr = '{} "{}"'.format(dct[self.filter_type], self.filter_text) + return "{} - {}".format(fltr, self.creation_date) + + def clean(self): + if (self.filter_text and not self.filter_type) or ( + self.filter_type and not self.filter_type): + raise ValidationError( + _("To filter filter type and filter text must be filled.") + ) |