Browse Source

Document activity added

aguryev 3 years ago
parent
commit
b5ab8f1d34
3 changed files with 42 additions and 22 deletions
  1. 25 18
      antrag.py
  2. 13 4
      pms/data/antrag_activities.json
  3. 4 0
      pms/data/valuelists.json

+ 25 - 18
antrag.py

@@ -5,6 +5,7 @@
 from flask import url_for
 from polzybackend.mediators import Antrag
 from polzybackend.models import File
+from polzybackend.utils import date_format
 from pms.fast_offer import get_fast_offer, get_value_lists
 from functools import reduce
 from time import sleep
@@ -99,36 +100,42 @@ class SampleAntrag(Antrag):
 
         print('\n*** Update Attachments')
 
-        # get attachment activity
-        attachment_activity = next(filter(
-            lambda activity: activity.get('name') == "Attachments",
+        # get documents activity
+        document_activity = next(filter(
+            lambda activity: activity.get('name') == "Documents",
             self.instance['possible_activities'],
         ), None)
 
-        print(attachment_activity)
-        #print(self.instance['possible_activities'])
+        print('Document Activity:')
+        print(document_activity)
 
-        if attachment_activity is None:
-            return
+        if document_activity is None:
+            raise Exception('Document Activity not found')
+
+        # get attachment field
+        attachments = next(filter(
+            lambda field: field.get('name') == "Attachments",
+            document_activity['fields']
+        ))
+
+        print('Document Activity:')
+        print(document_activity)
+
+        if attachments is None:
+            raise Exception('Attachment Field not found')
         
         # get files from db
         antrag_files = File.query.filter_by(parent_id=self.id).all()
-        attachment_activity['fields'] = [
+        attachments['valueChosenOrEntered'] = [
             {
-                "fieldType": 2 if file.processed else 1,
-                "name": f'attachment_{index}',
-                "brief": file.filename,
-                "fieldDataType": "File",
-                "details": json.loads(file.details),
-                "endpoint": file.id,
+                "id": file.id,
+                "filename": file.filename,
+                "created": file.created.strftime(date_format),
+                "type": file.type,
             } for index, file in enumerate(antrag_files)
         ] 
 
 
-
-
-    
-
     def updateFields(self, data):
         #
         # updates antrag fields based on data

+ 13 - 4
pms/data/antrag_activities.json

@@ -22,10 +22,19 @@
       "fields": []
     },
     {
-      "name": "Attachments",
-      "description": "Manage Attachments",
-      "icon": "calculate.svg",
-      "fields": [],
+      "name": "Documents",
+      "description": "Documents",
+      "icon": "iconSaveRecommendation.svg",
+      "fields": [
+        {
+          "fieldType": 2,
+          "name": "Attachments",
+          "brief": "Attachments",
+          "tooltip": "Here you can manage the attached documents",
+          "fieldDataType": "Documents",
+          "valueChosenOrEntered": []
+        }
+      ],
       "actions": [
         {
           "name": "upload",

+ 4 - 0
pms/data/valuelists.json

@@ -1,4 +1,8 @@
 {
+  "fileType": [
+    "Identification",
+    "Passport"
+  ],
   "carBrand": [
     "Audi",
     "Bentley",