Custom PumpWood Views

class pumpwood_viewutils.views.PumpWoodDataBaseRestService(**kwargs)

This view extends PumpWoodRestService, including pivot function.

model_variables = []

Specify which model variables will be returned in pivot. Line index are the model_variables - columns (function pivot parameter) itens.

pivot(request, *args, **kwargs)

Pivot QuerySet data acording to columns selected, and filters passed.

Parameters:
  • request.data['filter_dict'] (dict) – Dictionary passed as objects.filter(**filter_dict)
  • request.data['exclude_dict'] (dict) – Dictionary passed as objects.exclude(**exclude_dict)
  • request.data['ordering_list'] (list) – List passed as objects.order_by(*ordering_list)
  • request.data['columns'] (str) – Variables to be used as pivot collumns
  • request.data['format'] – Format used in pandas.DataFrame().to_dict()
Returns:

Return database data pivoted acording to columns parameter

Rtyoe:

panas.Dataframe converted to disctionary

class pumpwood_viewutils.views.PumpWoodRestService(**kwargs)

Basic View-Set for pumpwood rest end-points

delete(request, *args, **kwargs)

Delete view, it is not implemented. Coder must do it.

Parameters:pk (int) – Object pk to be retrieve
Raises:PumpWoodForbidden – ‘Delete case has not been implemented’ if not implemented.
execute_action(request, *args, **kwargs)

Execute action over objects defined by the pk.

Parameters:
  • action (str) – The action that will be performed
  • pk (int) – Pk of the object that the action will be performed over. If it is a staic action, pk must be None
  • request.data (dict) – Parameters to used on the action
Returns:

A dictionary {‘result’: action result, ‘action’: action name, ‘parameters’: parameters used in the action, ‘obj’: the serialized object that was used in the action }

Return type:

dict

Raises:

PumpWoodForbidden – ‘There is no method {action} in rest actions for {class_name}’ if action not found

list(request, *args, **kwargs)

View function to list objects. number of objects are limited by settings.REST_FRAMEWORK[‘PAGINATE_BY’]. To get next page, use exclude_dict[‘pk__in’: [list of the received pks]] to get more objects.

Use to limit the query .query.filter_by_dict function.

Parameters:
  • request.data['filter_dict'] (dict) – Dictionary passed as objects.filter(**filter_dict)
  • request.data['exclude_dict'] (dict) – Dictionary passed as objects.exclude(**exclude_dict)
  • request.data['ordering_list'] (list) – List passed as objects.order_by(*ordering_list)
Returns:

A list of objects using list_serializer

list_actions(request, *args, **kwargs)

List model actions flaged with @rest_function wrapper. It returns the list of the actions and its descriptions.

Returns:A list of actions descriptions using .serializer.SerializerObjectActions
Return type:list of dictionaries
list_options(request, *args, **kwargs)

Return options for object update acording its partial data.

Parameters:request.data (dict) – Partial object data.
Returns:A dictionary with options for diferent objects values
Return type:dict

Note

Must be implemented

list_search_options(request, *args, **kwargs)

Return options to be used in list funciton.

Returns:Dictionary with options for list parameters
Return type:dict

Note

Must be implemented

list_without_pag(request, *args, **kwargs)

View function to list objects. Basicaley the same of list, but without limitation by settings.REST_FRAMEWORK[‘PAGINATE_BY’].

Parameters:
  • request.data['filter_dict'] (dict) – Dictionary passed as objects.filter(**filter_dict)
  • request.data['exclude_dict'] (dict) – Dictionary passed as objects.exclude(**exclude_dict)
  • request.data['ordering_list'] (list) – List passed as objects.order_by(*ordering_list)
Returns:

A list of objects using list_serializer

Note

Be careful with the number of the objects that will be retrieved

retrieve(request, *args, **kwargs)

Retrieve view, uses the retrive_serializer to return object with pk.

Parameters:pk (int) – Object pk to be retrieve
Returns:The representation of the object passed by self.retrive_serializer
Return type:dict
save(request, *args, **kwargs)

Saves and updates object acording to request.data. Object will be updated if request.data[‘pk’] is not None.

Parameters:request.data (dict) – Object representation as self.retrive_serializer
Raises:PumpWoodException – ‘Object model class diferent from {service_model} : {model_class}’ request.data[‘model_class’] not the same as self.service_model.__name__