more work;
This commit is contained in:
+8
-9
@@ -4,7 +4,6 @@ import sys
|
||||
|
||||
from OnspringClient import OnspringClient
|
||||
from configparser import ConfigParser
|
||||
from Helpers import GetResultValueString
|
||||
|
||||
from Models import *
|
||||
from Enums import *
|
||||
@@ -166,7 +165,7 @@ def PrintGetRecordsByAppId(client: OnspringClient, appId: int):
|
||||
for field in record.fields:
|
||||
print(f'Type: {field.type}')
|
||||
print(f'FieldId: {field.fieldId}')
|
||||
print(f'Value: {GetResultValueString(field)}')
|
||||
print(f'Value: {field.GetResultValueString()}')
|
||||
print('--')
|
||||
|
||||
print('----')
|
||||
@@ -190,7 +189,7 @@ def PrintGetRecordById(client: OnspringClient, appId: int, recordId: int, fieldI
|
||||
for field in response.data.fields:
|
||||
print(f'Type: {field.type}')
|
||||
print(f'FieldId: {field.fieldId}')
|
||||
print(f'Value: {GetResultValueString(field)}')
|
||||
print(f'Value: {field.GetResultValueString()}')
|
||||
print('--')
|
||||
|
||||
print('----')
|
||||
@@ -224,7 +223,7 @@ def PrintGetRecordsByIds(client: OnspringClient, appId: int, recordIds: list[int
|
||||
for field in record.fields:
|
||||
print(f'Type: {field.type}')
|
||||
print(f'FieldId: {field.fieldId}')
|
||||
print(f'Value: {GetResultValueString(field)}')
|
||||
print(f'Value: {field.GetResultValueString()}')
|
||||
print('--')
|
||||
|
||||
print('----')
|
||||
@@ -256,7 +255,7 @@ def PrintQueryRecords(client: OnspringClient, appId: int, filter: str, fieldIds:
|
||||
for field in record.fields:
|
||||
print(f'Type: {field.type}')
|
||||
print(f'FieldId: {field.fieldId}')
|
||||
print(f'Value: {GetResultValueString(field)}')
|
||||
print(f'Value: {field.GetResultValueString()}')
|
||||
print('--')
|
||||
|
||||
print('----')
|
||||
@@ -270,10 +269,10 @@ def PrintAddOrUpdateRecord(client: OnspringClient, appId: int, fields: list[Reco
|
||||
|
||||
response = client.AddOrUpdateRecord(record)
|
||||
|
||||
print(response.status_code)
|
||||
print(response.text)
|
||||
print(response.request.body)
|
||||
|
||||
print(f'Status Code: {response.statusCode}')
|
||||
print(f'Id: {response.data.id}')
|
||||
for warning in response.data.warnings:
|
||||
print(f'Warning: {warning}')
|
||||
|
||||
# files
|
||||
|
||||
|
||||
-59
@@ -11,62 +11,3 @@ def parseDate(date: str):
|
||||
return datetime.strptime(date, format)
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
def GetResultValueString(value):
|
||||
match value.type:
|
||||
case ResultValueType.String.name:
|
||||
return value.AsString()
|
||||
|
||||
case ResultValueType.Integer.name:
|
||||
return value.AsInteger()
|
||||
|
||||
case ResultValueType.Decimal.name:
|
||||
return value.AsDecimal()
|
||||
|
||||
case ResultValueType.Date.name:
|
||||
return value.AsDate()
|
||||
|
||||
case ResultValueType.TimeSpan.name:
|
||||
data = value.AsTimeSpan()
|
||||
return f'Quantity: {data.quantity}, Increment: {data.increment}, Recurrence: {data.recurrence}, EndByDate: {data.endByDate}, EndAfterOccurrences: {data.endAfterOccurrences}'
|
||||
|
||||
case ResultValueType.Guid.name:
|
||||
return value.AsGuid()
|
||||
|
||||
case ResultValueType.StringList.name:
|
||||
data = value.AsStringList()
|
||||
return f'{",".join(data)}'
|
||||
|
||||
case ResultValueType.IntegerList.name:
|
||||
data = value.AsIntegerList()
|
||||
return f'{",".join([str(i) for i in data])}'
|
||||
|
||||
case ResultValueType.GuidList.name:
|
||||
data = value.AsGuidList()
|
||||
return f'{",".join([str(guid) for guid in data])}'
|
||||
|
||||
case ResultValueType.AttachmentList.name:
|
||||
data = value.AsAttachmentList()
|
||||
|
||||
strings = []
|
||||
|
||||
for attachment in data:
|
||||
string = f'FileId: {attachment.fileId}, FileName: {attachment.fileName}, Notes: {attachment.notes}, StorageLocation: {attachment.storageLocation}'
|
||||
strings.append(string)
|
||||
|
||||
return f'{"; ".join(strings)}'
|
||||
|
||||
case ResultValueType.ScoringGroupList.name:
|
||||
data = value.AsScoringGroupList()
|
||||
|
||||
strings = []
|
||||
|
||||
for scoringGroup in data:
|
||||
string = f'ListValueId: {scoringGroup.listValueId}, Name: {scoringGroup.name}, Score: {scoringGroup.score}, Max Score: {scoringGroup.maximumScore}'
|
||||
strings.append(string)
|
||||
|
||||
return f'{"; ".join(strings)}'
|
||||
|
||||
case ResultValueType.FileList.name:
|
||||
data = value.AsFileList()
|
||||
return f'{",".join([str(i) for i in data])}'
|
||||
@@ -1,4 +1,3 @@
|
||||
from dataclasses import field
|
||||
import datetime
|
||||
import uuid
|
||||
|
||||
@@ -133,8 +132,6 @@ class AddOrUpdateListItemResponse:
|
||||
def __init__(self, id: uuid):
|
||||
self.id = id
|
||||
|
||||
|
||||
|
||||
# record specific
|
||||
|
||||
class RecordFieldValue:
|
||||
@@ -155,14 +152,14 @@ class RecordFieldValue:
|
||||
if self.type != ResultValueType.Integer.name:
|
||||
return None
|
||||
|
||||
return IntegerFieldValue(int(self.value), self.fieldId).value
|
||||
return IntegerFieldValue(self.fieldId, int(self.value)).value
|
||||
|
||||
def AsDecimal(self):
|
||||
|
||||
if self.type != ResultValueType.Decimal.name:
|
||||
return None
|
||||
|
||||
return DecimalFieldValue(Decimal(self.value), self.fieldId).value
|
||||
return DecimalFieldValue(self.fieldId, Decimal(self.value)).value
|
||||
|
||||
def AsDate(self):
|
||||
|
||||
@@ -171,14 +168,14 @@ class RecordFieldValue:
|
||||
|
||||
date = parseDate(self.value)
|
||||
|
||||
return DateFieldValue(date, self.fieldId).value
|
||||
return DateFieldValue(self.fieldId, date).value
|
||||
|
||||
def AsGuid(self):
|
||||
|
||||
if self.type != ResultValueType.Guid.name:
|
||||
return None
|
||||
|
||||
return GuidFieldValue(uuid.UUID(self.value), self.fieldId).value
|
||||
return GuidFieldValue(self.fieldId, uuid.UUID(self.value)).value
|
||||
|
||||
def AsTimeSpan(self):
|
||||
|
||||
@@ -202,21 +199,25 @@ class RecordFieldValue:
|
||||
endByDate,
|
||||
endAfterOccurrences)
|
||||
|
||||
return TimeSpanValue(data, self.fieldId).value
|
||||
return TimeSpanValue(self.fieldId, data).value
|
||||
|
||||
def AsStringList(self):
|
||||
|
||||
if self.type != ResultValueType.StringList.name:
|
||||
return None
|
||||
|
||||
return StringListValue(self.value, self.fieldId).value
|
||||
strings = [str(string) for string in self.value]
|
||||
|
||||
return StringListValue(self.fieldId, strings).value
|
||||
|
||||
def AsIntegerList(self):
|
||||
|
||||
if self.type != ResultValueType.IntegerList.name:
|
||||
return None
|
||||
|
||||
return IntegerListValue(self.value, self.fieldId).value
|
||||
integers = [int(integer) for integer in self.value]
|
||||
|
||||
return IntegerListValue(self.fieldId, integers).value
|
||||
|
||||
def AsGuidList(self):
|
||||
|
||||
@@ -228,7 +229,7 @@ class RecordFieldValue:
|
||||
for guid in self.value:
|
||||
guids.append(uuid.UUID(guid))
|
||||
|
||||
return GuidListValue(guids, self.fieldId).value
|
||||
return GuidListValue(self.fieldId, guids).value
|
||||
|
||||
def AsAttachmentList(self):
|
||||
|
||||
@@ -249,7 +250,7 @@ class RecordFieldValue:
|
||||
|
||||
attachments.append(attachment)
|
||||
|
||||
return AttachmentListValue(attachments, self.fieldId).value
|
||||
return AttachmentListValue(self.fieldId, attachments).value
|
||||
|
||||
def AsScoringGroupList(self):
|
||||
|
||||
@@ -270,14 +271,16 @@ class RecordFieldValue:
|
||||
|
||||
scoringGroups.append(scoringGroup)
|
||||
|
||||
return ScoringGroupListValue(scoringGroups, self.fieldId).value
|
||||
return ScoringGroupListValue(self.fieldId, scoringGroups).value
|
||||
|
||||
def AsFileList(self):
|
||||
|
||||
if self.type != ResultValueType.FileList.name:
|
||||
return None
|
||||
|
||||
return FileListValue(self.value, self.fieldId).value
|
||||
files = [int(file) for file in self.value]
|
||||
|
||||
return FileListValue(self.fieldId, files).value
|
||||
|
||||
def getValue(self):
|
||||
|
||||
@@ -308,6 +311,65 @@ class RecordFieldValue:
|
||||
else:
|
||||
return None
|
||||
|
||||
def GetResultValueString(self):
|
||||
match self.type:
|
||||
case ResultValueType.String.name:
|
||||
return self.AsString()
|
||||
|
||||
case ResultValueType.Integer.name:
|
||||
return self.AsInteger()
|
||||
|
||||
case ResultValueType.Decimal.name:
|
||||
return self.AsDecimal()
|
||||
|
||||
case ResultValueType.Date.name:
|
||||
return self.AsDate()
|
||||
|
||||
case ResultValueType.TimeSpan.name:
|
||||
data = self.AsTimeSpan()
|
||||
return f'Quantity: {data.quantity}, Increment: {data.increment}, Recurrence: {data.recurrence}, EndByDate: {data.endByDate}, EndAfterOccurrences: {data.endAfterOccurrences}'
|
||||
|
||||
case ResultValueType.Guid.name:
|
||||
return self.AsGuid()
|
||||
|
||||
case ResultValueType.StringList.name:
|
||||
data = self.AsStringList()
|
||||
return f'{",".join(data)}'
|
||||
|
||||
case ResultValueType.IntegerList.name:
|
||||
data = self.AsIntegerList()
|
||||
return f'{",".join([str(i) for i in data])}'
|
||||
|
||||
case ResultValueType.GuidList.name:
|
||||
data = self.AsGuidList()
|
||||
return f'{",".join([str(guid) for guid in data])}'
|
||||
|
||||
case ResultValueType.AttachmentList.name:
|
||||
data = self.AsAttachmentList()
|
||||
|
||||
strings = []
|
||||
|
||||
for attachment in data:
|
||||
string = f'FileId: {attachment.fileId}, FileName: {attachment.fileName}, Notes: {attachment.notes}, StorageLocation: {attachment.storageLocation}'
|
||||
strings.append(string)
|
||||
|
||||
return f'{"; ".join(strings)}'
|
||||
|
||||
case ResultValueType.ScoringGroupList.name:
|
||||
data = self.AsScoringGroupList()
|
||||
|
||||
strings = []
|
||||
|
||||
for scoringGroup in data:
|
||||
string = f'ListValueId: {scoringGroup.listValueId}, Name: {scoringGroup.name}, Score: {scoringGroup.score}, Max Score: {scoringGroup.maximumScore}'
|
||||
strings.append(string)
|
||||
|
||||
return f'{"; ".join(strings)}'
|
||||
|
||||
case ResultValueType.FileList.name:
|
||||
data = self.AsFileList()
|
||||
return f'{",".join([str(i) for i in data])}'
|
||||
|
||||
class Record:
|
||||
def __init__(self, appId: int, fields: list[RecordFieldValue], recordId: int=None):
|
||||
self.appId = appId
|
||||
@@ -362,6 +424,11 @@ class AddOrUpdateRecordResponse:
|
||||
self.id = id
|
||||
self.warnings = warnings
|
||||
|
||||
class DeleteBatchRecordsRequest:
|
||||
def __init__(self, appId: int, recordIds: list[int]):
|
||||
self.id = id
|
||||
self.recordIds = recordIds
|
||||
|
||||
# field types
|
||||
|
||||
class StringFieldValue(RecordFieldValue):
|
||||
@@ -369,29 +436,25 @@ class StringFieldValue(RecordFieldValue):
|
||||
self.type = ResultValueType.String.name
|
||||
RecordFieldValue.__init__(self, fieldId, value, self.type)
|
||||
|
||||
class IntegerFieldValue:
|
||||
def __init__(self, value: int, fieldId: int):
|
||||
self.value = value
|
||||
self.fieldId = fieldId
|
||||
class IntegerFieldValue(RecordFieldValue):
|
||||
def __init__(self, fieldId: int, value: int):
|
||||
self.type = ResultValueType.Integer.name
|
||||
RecordFieldValue.__init__(self, fieldId, value, self.type)
|
||||
|
||||
class DecimalFieldValue:
|
||||
def __init__(self, value: Decimal, fieldId: int):
|
||||
self.value = value
|
||||
self.fieldId = fieldId
|
||||
class DecimalFieldValue(RecordFieldValue):
|
||||
def __init__(self, fieldId: int, value: Decimal):
|
||||
self.type = ResultValueType.Decimal.name
|
||||
RecordFieldValue.__init__(self, fieldId, value, self.type)
|
||||
|
||||
class DateFieldValue:
|
||||
def __init__(self, value: datetime, fieldId: int):
|
||||
self.value = value
|
||||
self.fieldId = fieldId
|
||||
class DateFieldValue(RecordFieldValue):
|
||||
def __init__(self, fieldId: int, value: datetime):
|
||||
self.type = ResultValueType.Date.name
|
||||
RecordFieldValue.__init__(self, fieldId, value, self.type)
|
||||
|
||||
class GuidFieldValue:
|
||||
def __init__(self, value: uuid.UUID, fieldId: int):
|
||||
self.value = value
|
||||
self.fieldId = fieldId
|
||||
class GuidFieldValue(RecordFieldValue):
|
||||
def __init__(self, fieldId: int, value: uuid.UUID):
|
||||
self.type = ResultValueType.Guid.name
|
||||
RecordFieldValue.__init__(self, fieldId, value, self.type)
|
||||
|
||||
class TimeSpanData:
|
||||
def __init__(self, quantity: Decimal, increment: Increment, recurrence: Recurrence=None, endByDate: datetime=None, endAfterOccurrences: int=None):
|
||||
@@ -410,29 +473,25 @@ class TimeSpanData:
|
||||
else:
|
||||
return f'{self.quantity} {self.increment}'
|
||||
|
||||
class TimeSpanValue:
|
||||
def __init__(self, value: TimeSpanData, fieldId: int):
|
||||
self.value = value
|
||||
self.fieldId = fieldId
|
||||
class TimeSpanValue(RecordFieldValue):
|
||||
def __init__(self, fieldId: int, value: TimeSpanData):
|
||||
self.type = ResultValueType.TimeSpan.name
|
||||
RecordFieldValue.__init__(self, fieldId, value, self.type)
|
||||
|
||||
class StringListValue:
|
||||
def __init__(self, value: list[str], fieldId: int):
|
||||
self.value = value
|
||||
self.fieldId = fieldId
|
||||
class StringListValue(RecordFieldValue):
|
||||
def __init__(self, fieldId: int, value: list[str]):
|
||||
self.type = ResultValueType.StringList.name
|
||||
RecordFieldValue.__init__(self, fieldId, value, self.type)
|
||||
|
||||
class IntegerListValue:
|
||||
def __init__(self, value: list[int], fieldId: int):
|
||||
self.value = value
|
||||
self.fieldId = fieldId
|
||||
class IntegerListValue(RecordFieldValue):
|
||||
def __init__(self, fieldId: int, value: list[int]):
|
||||
self.type = ResultValueType.IntegerList.name
|
||||
RecordFieldValue.__init__(self, fieldId, value, self.type)
|
||||
|
||||
class GuidListValue:
|
||||
def __init__(self, value: list[uuid.UUID], fieldId: int):
|
||||
self.value = value
|
||||
self.fieldId = fieldId
|
||||
class GuidListValue(RecordFieldValue):
|
||||
def __init__(self, fieldId: int, value: list[uuid.UUID]):
|
||||
self.type = ResultValueType.GuidList.name
|
||||
RecordFieldValue.__init__(self, fieldId, value, self.type)
|
||||
|
||||
class Attachment:
|
||||
def __init__(self, fileId: int, fileName: str, notes: str, storageLocation: str):
|
||||
@@ -441,17 +500,15 @@ class Attachment:
|
||||
self.notes = notes
|
||||
self.storageLocation = storageLocation
|
||||
|
||||
class AttachmentListValue:
|
||||
def __init__(self, value: list[Attachment], fieldId: int):
|
||||
self.value = value
|
||||
self.fieldId = fieldId
|
||||
class AttachmentListValue(RecordFieldValue):
|
||||
def __init__(self, fieldId: int, value: list[Attachment]):
|
||||
self.type = ResultValueType.AttachmentList.name
|
||||
RecordFieldValue.__init__(self, fieldId, value, self.type)
|
||||
|
||||
class FileListValue:
|
||||
def __init__(self, value: list[int], fieldId: int):
|
||||
self.value = value
|
||||
self.fieldId = fieldId
|
||||
class FileListValue(RecordFieldValue):
|
||||
def __init__(self, fieldId: int, value: list[int]):
|
||||
self.type = ResultValueType.FileList.name
|
||||
RecordFieldValue.__init__(self, fieldId, value, self.type)
|
||||
|
||||
class ScoringGroup:
|
||||
def __init__(self, listValueId: uuid.UUID, name: str, score: Decimal, maximumScore: Decimal):
|
||||
@@ -460,8 +517,7 @@ class ScoringGroup:
|
||||
self.score = score
|
||||
self.maximumScore = maximumScore
|
||||
|
||||
class ScoringGroupListValue:
|
||||
def __init__(self, value: list[ScoringGroup], fieldId: int):
|
||||
self.value = value
|
||||
self.fieldId = fieldId
|
||||
class ScoringGroupListValue(RecordFieldValue):
|
||||
def __init__(self, fieldId: int, value: list[ScoringGroup]):
|
||||
self.type = ResultValueType.ScoringGroupList.name
|
||||
RecordFieldValue.__init__(self, fieldId, value, self.type)
|
||||
+46
-3
@@ -1120,8 +1120,7 @@ class OnspringClient:
|
||||
return ApiResponse(
|
||||
response.status_code,
|
||||
data,
|
||||
headers=response.headers,
|
||||
responseText=response.text)
|
||||
raw=response)
|
||||
|
||||
return ApiResponse(
|
||||
response.status_code,
|
||||
@@ -1148,7 +1147,51 @@ class OnspringClient:
|
||||
headers=self.headers,
|
||||
data=requestData)
|
||||
|
||||
return response
|
||||
if response.status_code == 400:
|
||||
|
||||
return ApiResponse(
|
||||
response.status_code,
|
||||
message='Request is data is invalid',
|
||||
raw=response)
|
||||
|
||||
if response.status_code == 401:
|
||||
|
||||
return ApiResponse(
|
||||
response.status_code,
|
||||
message='Unauthorized request',
|
||||
raw=response)
|
||||
|
||||
if response.status_code in [403, 404]:
|
||||
|
||||
jsonResponse = dict(response.json())
|
||||
|
||||
return ApiResponse(
|
||||
response.status_code,
|
||||
message=jsonResponse.get('message'),
|
||||
raw=response)
|
||||
|
||||
if response.status_code in [200, 201]:
|
||||
|
||||
jsonResponse = dict(response.json())
|
||||
|
||||
data = AddOrUpdateRecordResponse(
|
||||
jsonResponse.get('id'),
|
||||
jsonResponse.get('warnings'))
|
||||
|
||||
if response.status_code == 200:
|
||||
message = 'Record updated successfully'
|
||||
else:
|
||||
message = 'Record created successfully'
|
||||
|
||||
return ApiResponse(
|
||||
response.status_code,
|
||||
data,
|
||||
message=message,
|
||||
raw=response)
|
||||
|
||||
return ApiResponse(
|
||||
response.status_code,
|
||||
raw=response)
|
||||
|
||||
def DeleteRecordsByIds(self):
|
||||
|
||||
|
||||
Reference in New Issue
Block a user