Browse Source

attachment activity

aguryev 3 years ago
parent
commit
ea61c3c412
2 changed files with 66 additions and 9 deletions
  1. 50 9
      antrag.py
  2. 16 0
      pms/data/antrag_activities.json

+ 50 - 9
antrag.py

@@ -4,9 +4,11 @@
 
 from flask import url_for
 from polzybackend.mediators import Antrag
+from polzybackend.models import File
 from pms.fast_offer import get_fast_offer, get_value_lists
 from functools import reduce
 from time import sleep
+import json
 
 
 class SampleAntrag(Antrag):
@@ -59,6 +61,17 @@ class SampleAntrag(Antrag):
                 return target_field
 
 
+    def getValueList(self, valueListName):
+        #
+        # returns value-list with given name
+        #
+
+        # emulate delay
+        sleep(2)
+
+        return get_value_lists(valueListName)
+
+
     def update_auto_brands(self):
         #
         # update auto brands based on vehicle type 
@@ -79,24 +92,51 @@ class SampleAntrag(Antrag):
             #brand_field['valueChosenOrEntered'] = None
 
 
-    def getValueList(self, valueListName):
+    def update_attachments(self):
         #
-        # returns value-list with given name
+        # updates files in attachment activity
         #
 
-        # emulate delay
-        sleep(2)
+        print('\n*** Update Attachments')
 
-        return get_value_lists(valueListName)
+        # get attachment activity
+        attachment_activity = next(filter(
+            lambda activity: activity.get('name') == "Attachments",
+            self.instance['possible_activities'],
+        ), None)
+
+        print(attachment_activity)
+        #print(self.instance['possible_activities'])
+
+        if attachment_activity is None:
+            return
+        
+        # get files from db
+        antrag_files = File.query.filter_by(parent_id=self.id).all()
+        attachment_activity['fields'] = [
+            {
+                "fieldType": 2 if file.processed else 1,
+                "name": f'attachment_{index}',
+                "brief": file.filename,
+                "fieldDataType": "File",
+                "details": json.loads(file.details),
+                "endpoint": file.id,
+            } for index, file in enumerate(antrag_files)
+        ] 
+
+
+
+
+    
 
     def updateFields(self, data):
         #
         # updates antrag fields based on data
         #
 
-        print('\n*** UPDATE FIELDS')
-        import json
-        print(json.dumps(data, indent=2))
+        #print('\n*** UPDATE FIELDS')
+        #import json
+        #print(json.dumps(data, indent=2))
 
         booleans = {
             True: "True",
@@ -111,8 +151,9 @@ class SampleAntrag(Antrag):
                     for sub_field in field['relatedFields']:
                         sub_field['valueChosenOrEntered'] = data['values'].get(sub_field['name'])
 
-
         self.update_auto_brands()
+        self.update_attachments()
+
 
     def executeActivity(self, data):
         #

+ 16 - 0
pms/data/antrag_activities.json

@@ -20,6 +20,22 @@
       "icon": "pdf.svg",
       "postExecution": "link",
       "fields": []
+    },
+    {
+      "name": "Attachments",
+      "description": "Manage Attachments",
+      "icon": "calculate.svg",
+      "fields": [],
+      "actions": [
+        {
+          "name": "upload",
+          "caption": "Add File"
+        },
+        {
+          "name": "close",
+          "caption": "Close"
+        }
+      ]
     }
   ]
 }