Browse Source

move dicts from dbsynce to tickets and dedublicate code

blezz-tech 3 weeks ago
parent
commit
424e5f05e5
1 changed files with 47 additions and 28 deletions
  1. 47 28
      lib/tickets.py

+ 47 - 28
lib/tickets.py

@@ -1,3 +1,6 @@
+def reverse_obj( obj):
+    """Меняет местами ключ и значение"""
+    return {status_code: name for name, status_code in obj.items()}
 
 class Ticket:
     TICKET_TYPES = (
@@ -38,35 +41,51 @@ class Ticket:
         ])
     )
 
-    TICKET_STATUSES_NAMES = {
-        111: "NEW",
-        110: "REOPENED",
-        121: "ASSIGNED",
-        131: "IN PROCESS",
-        149: "WONTFIX",
-        141: "DONE",
-        159: "DUPLICATE",
-        151: "CLOSED",
-        210: "TEMPLATE",
-        211: "BOOKED",
-        212: "ASSIGNED",
-        221: "ACCEPTED",
-        220: "PENDING",
-        229: "DECLINED",
-        222: "PRE-START",
-        231: "PROCESS",
-        238: "PRE-FORCEMAJEUER",
-        239: "FORCEMAJEUER",
-        241: "DONE",
-        249: "CANCELLED",
-        251: "CLOSED",
-        320: "PENDING",
-        321: "ACCEPTED",
-        359: "DECLINED",
-        420: "PENDING",
-        421: "ACCEPTED",
-        459: "DECLINED"
+    request_type = {
+        "NEW": 111,
+        "REOPENED": 110,
+        "ASSIGNED": 121,
+        "IN_PROCESS": 131,
+        "WONTFIX": 149,
+        "DONE": 141,
+        "DUPLICATE": 159,
+        "CLOSED": 151
     }
 
+    service_request_type = {
+        "TEMPLATE": 210,
+        "BOOKED": 211,
+        "ASSIGNED": 212,
+        "ACCEPTED": 221,
+        "PENDING": 220,
+        "DECLINED": 229,
+        "PRE_START": 222,
+        "PROCESS": 231,
+        "PRE_FORCEMAJEUER": 238,
+        "FORCEMAJEUER": 239,
+        "DONE": 241,
+        "CANCELLED": 249,
+        "CLOSED": 251
+    }
+
+    access_request_type = {
+        "PENDING": 320,
+        "ACCEPTED": 321,
+        "DECLINED": 359
+    }
+
+    neg_request_type = {
+        "PENDING": 420,
+        "ACCEPTED": 421,
+        "DECLINED": 459
+    }
+
+    TICKET_STATUSES_NAMES = reverse_obj(request_type) | \
+        reverse_obj(service_request_type) | \
+        reverse_obj(access_request_type) | \
+        reverse_obj(neg_request_type)
+
+
     TICKET_TYPES_CHOICES = tuple((item[0], item[1]) for item in TICKET_TYPES)
     LIFE_CYCLE_DICT = dict((item[0], item[2]) for item in TICKET_TYPES)
+