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
This commit is contained in:
Lance Edgar 2022-08-11 00:15:12 -05:00
parent 8d70107b5d
commit 4c29a667cb
2 changed files with 11 additions and 8 deletions

View file

@ -177,17 +177,14 @@ class APIMasterView(APIView):
""" """
return self.sortcol(order_by) 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 Return a simple ``SortColumn`` object which denotes the field and
optionally, the model, to be used when sorting. optionally, the model, to be used when sorting.
""" """
if len(args) == 1: if not model_name:
return SortColumn(args[0]) model_name = self.model_class.__name__
elif len(args) == 2: return SortColumn(field_name, model_name)
return SortColumn(args[1], args[0])
else:
raise ValueError("must pass 1 arg (field_name) or 2 args (model_name, field_name)")
def join_for_sort_spec(self, query, sort_spec): def join_for_sort_spec(self, query, sort_spec):
""" """

View file

@ -66,6 +66,12 @@ class WorkOrderView(APIMasterView):
'date_delivered': six.text_type(workorder.date_delivered or ''), '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): def update_object(self, workorder, data):
date_fields = [ date_fields = [
'date_submitted', 'date_submitted',
@ -79,7 +85,7 @@ class WorkOrderView(APIMasterView):
if field in data: if field in data:
if data[field] == '': if data[field] == '':
data[field] = None data[field] = None
else: elif not isinstance(data[field], datetime.date):
date = datetime.datetime.strptime(data[field], '%Y-%m-%d').date() date = datetime.datetime.strptime(data[field], '%Y-%m-%d').date()
data[field] = date data[field] = date