summaryrefslogtreecommitdiff
path: root/ishtar_common/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'ishtar_common/models.py')
-rw-r--r--ishtar_common/models.py49
1 files changed, 48 insertions, 1 deletions
diff --git a/ishtar_common/models.py b/ishtar_common/models.py
index fbab13010..5b9d48357 100644
--- a/ishtar_common/models.py
+++ b/ishtar_common/models.py
@@ -55,7 +55,7 @@ from django.contrib.gis.db import models
from django.contrib.gis.db.models.aggregates import Union
from django.contrib.gis.geos.polygon import Polygon
from django.contrib.gis.geos.collections import MultiPolygon
-from django.contrib.postgres.fields import JSONField
+from django.contrib.postgres.fields import JSONField, ArrayField
from django.contrib.postgres.indexes import GinIndex
from django.contrib.sites.models import Site
from django.core.cache import cache
@@ -3081,6 +3081,14 @@ class UserProfile(models.Model):
show_field_number = models.BooleanField(_("Show field number"), default=False)
auto_pin = models.BooleanField(_("Automatically pin"), default=False)
display_pin_menu = models.BooleanField(_("Display pin menu"), default=False)
+ background_tasks = models.BooleanField(
+ _("Use background tasks"), default=True,
+ help_text=_("If set to true, each import, export, document generation is set "
+ "as a background task.")
+ )
+ background_tasks_send_email = models.BooleanField(
+ _("Send email when the task is finished"), default=True,
+ )
person = models.ForeignKey(
Person,
verbose_name=_("Person"),
@@ -3175,6 +3183,45 @@ def post_save_userprofile(sender, **kwargs):
post_save.connect(post_save_userprofile, sender=UserProfile)
+TASK_STATE = (
+ ("S", _("Scheduled")),
+ ("P", _("In progress")),
+ ("F", _("Finished")),
+)
+
+BACKGROUND_TASKS = {
+ # key: (label, function)
+ "generate-labels": (
+ _("Generate label"), "ishtar_common.views.generate_label_view"
+ ),
+}
+
+
+BACKGROUND_TASKS_LIST = [
+ (k, BACKGROUND_TASKS[k][0]) for k in BACKGROUND_TASKS
+]
+
+
+class BackgroundTask(models.Model):
+ name = models.TextField(_("Name"))
+ view = models.CharField(_("View"), max_length=100, choices=BACKGROUND_TASKS_LIST)
+ args = ArrayField(models.TextField(),
+ verbose_name=_("Arguments"), blank=True, null=True)
+ profile = models.ForeignKey(UserProfile, on_delete=models.CASCADE)
+ state = models.CharField(
+ _("State"), max_length=2, choices=TASK_STATE, default="S"
+ )
+ 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)
+
+ class Meta:
+ verbose_name = _("Background task")
+ verbose_name_plural = _("Background tasks")
+ ordering = ["creation_date"]
+
+
class IshtarUser(FullSearch):
SLUG = "ishtaruser"
TABLE_COLS = (