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:
parent
8d70107b5d
commit
4c29a667cb
|
@ -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):
|
||||
"""
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue