detailed status implemented
authorbeowulf
Wed, 21 Jun 2023 00:52:38 +0200
changeset 311 81916344c63b
parent 310 352850d4fb4b
child 312 42fd5075a5d1
detailed status implemented
iro/controller/viewinterface.py
--- a/iro/controller/viewinterface.py	Sat Jul 27 13:37:23 2019 +0200
+++ b/iro/controller/viewinterface.py	Wed Jun 21 00:52:38 2023 +0200
@@ -21,6 +21,7 @@
 
 # -*- coding: utf-8 -*-
 from ..model.decorators import vUser, vRoute, dbdefer, vTyp
+from ..model.job import exJobs
 from ..model.message import SMS, Fax, Mail
 
 from ..validate import validate, vBool, vTel, vEmail, vInteger
@@ -45,8 +46,6 @@
            - `key` -- is the job id
            - [`key`][**'status'**] -- status of the job
 
-        .. warning:: detailed is not used yet.
-        
         >>> status(APIKEY)
         {"1":  {"status":"sended"},
          "2":  {"status":"error"},
@@ -54,6 +53,10 @@
 
         >>> status(APIKEY,10)
         {"10": {"status":"sending"}}
+
+        >>> status(APIKEY,10,True)
+        {"10": {"status":"sending",
+            "tasks": {"recipient1": "sended", "recipient2": "waiting" }}}
         '''
         user = session.merge(user)
         ret={}
@@ -62,7 +65,18 @@
                 ret[str(job.id)]={"status":job.status}
         else:
             ret[str(id)]={"status":user.job(id).status}
-        
+
+            if detailed:
+                def _status(task):
+                    if task.error:
+                        return "Error: " + task.status
+                    elif task.status is None:
+                        return "waiting"
+                    else:
+                        return "sended"
+
+                ret[str(id)]["tasks"] = {task.recipient: _status(task) for task in exJobs[id].tasks.values()}
+
         return ret
    
     @validate(kwd="recipients",func=vTel)