diff --git a/ConsoleSnippets.py b/ConsoleSnippets.py index 12a9dc8..965a169 100644 --- a/ConsoleSnippets.py +++ b/ConsoleSnippets.py @@ -50,7 +50,7 @@ def main(): return if command == 'getrecordbyid': - PrintGetRecordById(onspring, 195, 5) + PrintGetRecordById(onspring, 195, 3,dataFormat=DataFormat.Raw.name) return if command == 'deleterecord': @@ -71,8 +71,8 @@ def main(): if command == 'addrecord': fields = [ - RecordFieldValue(6983, 'A New Test Task'), - RecordFieldValue(6984, 'This is a test task.') + StringFieldValue(6983, 'A New Test Task'), + StringFieldValue(6984, 'This is a test task.') ] PrintAddOrUpdateRecord(onspring, 195, fields) @@ -81,8 +81,8 @@ def main(): if command == 'updaterecord': fields = [ - RecordFieldValue(6983, 'Updated'), - RecordFieldValue(6984, 'Updated') + StringFieldValue(6983, 'Updated'), + StringFieldValue(6984, 'Updated') ] PrintAddOrUpdateRecord(onspring, 195, fields, 60) diff --git a/Enums.py b/Enums.py index 780947f..c1ff1d4 100644 --- a/Enums.py +++ b/Enums.py @@ -19,13 +19,13 @@ class ResultValueType(Enum): FileList = 11 class Increment(Enum): - Seconds = 0 - Minutes = 1 - Hours = 2 - Days = 3 - Weeks = 4 - Months = 5 - Years = 6 + Seconds = "Second(s)" + Minutes = "Minute(s)" + Hours = "Hour(s)" + Days = "Day(s)" + Weeks = "Week(s)" + Months = "Month(s)" + Years = "Year(s)" class Recurrence(Enum): Empty = "None" diff --git a/Models.py b/Models.py index 2da649c..aaf760d 100644 --- a/Models.py +++ b/Models.py @@ -1,3 +1,4 @@ +from dataclasses import field import datetime import uuid @@ -132,89 +133,7 @@ class AddOrUpdateListItemResponse: def __init__(self, id: uuid): self.id = id -# field types -class StringFieldValue: - def __init__(self, value: str, fieldId: int): - self.fieldId = fieldId - self.value = value - -class IntegerFieldValue: - def __init__(self, value: int, fieldId: int): - self.value = value - self.fieldId = fieldId - -class DecimalFieldValue: - def __init__(self, value: Decimal, fieldId: int): - self.value = value - self.fieldId = fieldId - -class DateFieldValue: - def __init__(self, value: datetime, fieldId: int): - self.value = value - self.fieldId = fieldId - -class GuidFieldValue: - def __init__(self, value: uuid.UUID, fieldId: int): - self.value = value - self.fieldId = fieldId - -class TimeSpanData: - def __init__(self, quantity: Decimal, increment: str, recurrence: str=None, endByDate: datetime=None, endAfterOccurrences: int=None): - self.quantity = quantity - self.increment = increment - self.recurrence = recurrence - self.endByDate = endByDate - self.endAfterOccurrences = endAfterOccurrences - -class TimeSpanValue: - def __init__(self, value: TimeSpanData, fieldId: int): - self.value = value - self.fieldId = fieldId - -class StringListValue: - def __init__(self, value: list[str], fieldId: int): - self.value = value - self.fieldId = fieldId - -class IntegerListValue: - def __init__(self, value: list[int], fieldId: int): - self.value = value - self.fieldId = fieldId - -class GuidListValue: - def __init__(self, value: list[uuid.UUID], fieldId: int): - self.value = value - self.fieldId = fieldId - -class Attachment: - def __init__(self, fileId: int, fileName: str, notes: str, storageLocation: str): - self.fileId = fileId - self.fileName = fileName - self.notes = notes - self.storageLocation = storageLocation - -class AttachmentListValue: - def __init__(self, value: list[Attachment], fieldId: int): - self.value = value - self.fieldId = fieldId - -class FileListValue: - def __init__(self, value: list[int], fieldId: int): - self.value = value - self.fieldId = fieldId - -class ScoringGroup: - def __init__(self, listValueId: uuid.UUID, name: str, score: Decimal, maximumScore: Decimal): - self.listValueId = listValueId - self.name = name - self.score = score - self.maximumScore = maximumScore - -class ScoringGroupListValue: - def __init__(self, value: list[ScoringGroup], fieldId: int): - self.value = value - self.fieldId = fieldId # record specific @@ -229,7 +148,7 @@ class RecordFieldValue: if self.type != ResultValueType.String.name: return None - return StringFieldValue(self.value, self.fieldId).value + return StringFieldValue(self.fieldId, self.value).value def AsInteger(self): @@ -441,4 +360,108 @@ class GetBatchRecordsResponse: class AddOrUpdateRecordResponse: def __init__(self, id: int, warnings: list[str]=[]): self.id = id - self.warnings = warnings \ No newline at end of file + self.warnings = warnings + +# field types + +class StringFieldValue(RecordFieldValue): + def __init__(self, fieldId: int, value): + 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 + self.type = ResultValueType.Integer.name + +class DecimalFieldValue: + def __init__(self, value: Decimal, fieldId: int): + self.value = value + self.fieldId = fieldId + self.type = ResultValueType.Decimal.name + +class DateFieldValue: + def __init__(self, value: datetime, fieldId: int): + self.value = value + self.fieldId = fieldId + self.type = ResultValueType.Date.name + +class GuidFieldValue: + def __init__(self, value: uuid.UUID, fieldId: int): + self.value = value + self.fieldId = fieldId + self.type = ResultValueType.Guid.name + +class TimeSpanData: + def __init__(self, quantity: Decimal, increment: Increment, recurrence: Recurrence=None, endByDate: datetime=None, endAfterOccurrences: int=None): + self.quantity = quantity + self.increment = increment + self.recurrence = recurrence + self.endByDate = endByDate + self.endAfterOccurrences = endAfterOccurrences + + def AsString(self): + if self.endByDate != None: + formattedDate = self.endByDate.strftime("%m/%d/%Y %I:%M %p") + return f'Every {self.quantity} {self.increment} End By {formattedDate}' + elif self.endAfterOccurrences != None: + return f'Every {self.quantity} {self.increment} End After {self.endAfterOccurrences}' + else: + return f'{self.quantity} {self.increment}' + +class TimeSpanValue: + def __init__(self, value: TimeSpanData, fieldId: int): + self.value = value + self.fieldId = fieldId + self.type = ResultValueType.TimeSpan.name + +class StringListValue: + def __init__(self, value: list[str], fieldId: int): + self.value = value + self.fieldId = fieldId + self.type = ResultValueType.StringList.name + +class IntegerListValue: + def __init__(self, value: list[int], fieldId: int): + self.value = value + self.fieldId = fieldId + self.type = ResultValueType.IntegerList.name + +class GuidListValue: + def __init__(self, value: list[uuid.UUID], fieldId: int): + self.value = value + self.fieldId = fieldId + self.type = ResultValueType.GuidList.name + +class Attachment: + def __init__(self, fileId: int, fileName: str, notes: str, storageLocation: str): + self.fileId = fileId + self.fileName = fileName + self.notes = notes + self.storageLocation = storageLocation + +class AttachmentListValue: + def __init__(self, value: list[Attachment], fieldId: int): + self.value = value + self.fieldId = fieldId + self.type = ResultValueType.AttachmentList.name + +class FileListValue: + def __init__(self, value: list[int], fieldId: int): + self.value = value + self.fieldId = fieldId + self.type = ResultValueType.FileList.name + +class ScoringGroup: + def __init__(self, listValueId: uuid.UUID, name: str, score: Decimal, maximumScore: Decimal): + self.listValueId = listValueId + self.name = name + self.score = score + self.maximumScore = maximumScore + +class ScoringGroupListValue: + def __init__(self, value: list[ScoringGroup], fieldId: int): + self.value = value + self.fieldId = fieldId + self.type = ResultValueType.ScoringGroupList.name \ No newline at end of file diff --git a/OnspringClient.py b/OnspringClient.py index f705d22..f0965ff 100644 --- a/OnspringClient.py +++ b/OnspringClient.py @@ -1,4 +1,3 @@ -from urllib import response import requests import json import re @@ -1134,14 +1133,12 @@ class OnspringClient: self.headers['Content-Type'] = 'application/json' - dictFields = [] + fieldsDict = {} for field in record.fields: - field = field.__dict__ - del field['type'] - dictFields.append(field) + fieldsDict[field.fieldId] = field.value - record.fields = dictFields + record.fields = fieldsDict requestData = json.dumps(record.__dict__)