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