From 4c29a667cb5d30cbb247988aea6f9c20ce37d7ca Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Thu, 11 Aug 2022 00:15:12 -0500 Subject: [PATCH] Couple of API tweaks for work orders made a change to sorting such that it assumes the primary model is being sorted, if caller does not specify --- tailbone/api/master.py | 11 ++++------- tailbone/api/workorders.py | 8 +++++++- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/tailbone/api/master.py b/tailbone/api/master.py index 27030f5b..7cb911be 100644 --- a/tailbone/api/master.py +++ b/tailbone/api/master.py @@ -177,17 +177,14 @@ class APIMasterView(APIView): """ return self.sortcol(order_by) - def sortcol(self, *args): + def sortcol(self, field_name, model_name=None): """ Return a simple ``SortColumn`` object which denotes the field and optionally, the model, to be used when sorting. """ - if len(args) == 1: - return SortColumn(args[0]) - elif len(args) == 2: - return SortColumn(args[1], args[0]) - else: - raise ValueError("must pass 1 arg (field_name) or 2 args (model_name, field_name)") + if not model_name: + model_name = self.model_class.__name__ + return SortColumn(field_name, model_name) def join_for_sort_spec(self, query, sort_spec): """ diff --git a/tailbone/api/workorders.py b/tailbone/api/workorders.py index 315a92bb..d559589d 100644 --- a/tailbone/api/workorders.py +++ b/tailbone/api/workorders.py @@ -66,6 +66,12 @@ class WorkOrderView(APIMasterView): 'date_delivered': six.text_type(workorder.date_delivered or ''), } + def create_object(self, data): + + # invoke the handler instead of normal API CRUD logic + workorder = self.workorder_handler.make_workorder(self.Session(), **data) + return workorder + def update_object(self, workorder, data): date_fields = [ 'date_submitted', @@ -79,7 +85,7 @@ class WorkOrderView(APIMasterView): if field in data: if data[field] == '': data[field] = None - else: + elif not isinstance(data[field], datetime.date): date = datetime.datetime.strptime(data[field], '%Y-%m-%d').date() data[field] = date