Developers section

Inform API

There are 5 APIs implemented for data consulting for the following data models:
  • Objects (objectView)

  • Inform (informView)

  • Laboratory by organization (laboratoryOrgView)

  • Laboratory by user (laboratoryView)

  • Incident Report (incidentReportView)

  • Users in organization/laboratory (orgView)

    Advertencia

    • This API can process a parameter lab, that gets the users inside a specified laboratory if the organization can change it.

The data itself can be accessed using the http://host/derb/organization_id/api/modelViewToConsult.

Form.io Configuration for Basic Select Component

If the API is used in a select from Form.io, follow these steps:
  • Access the Data tab.

  • Change the Data Source Type to URL.

  • Change the Data Source URL to http://host/derb/organization_id/api/modelViewToConsult.

  • For consistency, disable the Lazy Load Data option, for the data to load correctly on edit.

  • Change the Storage Type to Number.

  • Change the ID Path to item.key.

  • Change the Value Property to key.

  • Change the Item Template to the following:

    <option value={{item.key}}>{{item.value}}</option>
    
  • Save the component.

Form.io Configuration for Custom Select Component

The Custom Select loads the configured APIs and automatically configures the select component, to load its data.

The APIs configured at this time are:
  • Users in Laboratory/Organization.

    Advertencia

    • Getting the users by laboratory requires inputting a laboratory pk in the Laboratory identifier field.

    • If the field is blank, the API will get users by organization.

  • Laboratory by Organization.

  • Laboratory by User.

  • Incident Report.

  • Inform.

Component settings:
  • The Value Property must be key.

  • The display, limit of results, multiple and other settings can be changed.

  • Save the component.

New API for Custom Select Component

Advertencia

It is recommended to create this API in derb application.

To create a new API follow these steps:
  • Configure a data serializer to return a key(pk) and value(text).

  • Configure a view that returns a response with the data ({key, value}).

  • Create a route that references this view.

  • Inside the CustomSelect.js file, in the Data component setting, create an option in the element with data.api key, with a descriptive label an the corresponding url_name as value.

    Advertencia

    • If the API needs extra data, a parameter for example, the corresponding fields must be implemented.

    • In the OnChange method, see if the url for the preview is being extracted correctly, if not, then implement the necessary extraction method.

    • If the data isn’t showing in the preview doesn’t mean that the url_name is wrong, test the functionality inside an inform instead.

  • If the url has any other parameter that isn’t organization, the get_components_url method that construct the url, must be modified.

  • This method can be found in the informs.py file inside the laboratory app.

Documentation from every view class

class derb.api.views.IncidentReportView(**kwargs)[fuente]

This view gets all laboratories associated to an organization and a specific user.

class derb.api.views.InformView(**kwargs)[fuente]

This view gets all informs associated to a user.

class derb.api.views.LaboratoryByOrgView(**kwargs)[fuente]

This view gets all laboratories associated to an organization.

class derb.api.views.LaboratoryByUserView(**kwargs)[fuente]

This view gets all laboratories associated to a user.

class derb.api.views.ObjectsView(**kwargs)[fuente]

This view gets all objects associated to an organization.

class derb.api.views.OrganizationUsersView(**kwargs)[fuente]

This view gets all users associated to an organization.

If lab parameter is included in the query, it gets all users that can access a lab

class derb.api.views.QueryPagination[fuente]

My Procedure API

There are 2 ModelViewSets implemented for the data management of Procedure Step Comments:

  • ProcedureStepCommentTableView: filters the information shown in the complete_my_procedure view’s datatable.

  • ProcedureStepCommentAPI: works as a CRUD for the comments through action decorators. Every method has a permissions checker for user.has_perms (depending on the requested action), user_is_allowed_on_organization and organization_can_change_laboratory through the _check_permission_on_laboratory method.

ProcedureStepCommentTableView functionality

This Model View Set filters the comments for the selected procedure step; in case that no procedure has been selected, the table shows all the comments associated to the My Procedure entity. The table has a button to add new comments which only allows to add a new comment if there is a selected step; if the isn’t a selected one, an alert is shown asking the user to select a step to proceed. The last datatable column has to <i></i> elements, one for comment edition and the other for comment deletion that are associated to the ProcedureStepCommentAPI methods. For edition or deletion it’s not necessary to select a step before.

There are 2 models related to this funcionality:

  • MyProcedure: entity that takes a Procedure object as its template and groups the users comments for each template’s Procedure Step.

  • CommentProcedureStep: has the information of its creator, the creation date, the referenced procedure step, the grouping My procedure and the comment.

class academic.api.views.MyProceduresAPI(**kwargs)[fuente]
dispatch(request, *args, **kwargs)

.dispatch() is pretty much the same as Django’s regular dispatch, but with extra hooks for startup, finalize, and exception handling.

get_queryset()[fuente]

Get the list of items for this view. This must be an iterable, and may be a queryset. Defaults to using self.queryset.

This method should always be used rather than accessing self.queryset directly, as self.queryset gets evaluated only once, and those results are cached for all subsequent requests.

You may want to override this if you need to provide different querysets depending on the incoming request.

(Eg. return a list of items that is specific to the user)

pagination_class

alias de LimitOffsetPagination

serializer_class

alias de MyProcedureDataTableSerializer

class academic.api.views.ProcedureStepCommentAPI(**kwargs)[fuente]
serializer_class

alias de ProcedureStepCommentSerializer

class academic.api.views.ProcedureStepCommentTableView(**kwargs)[fuente]
get_queryset()[fuente]

Get the list of items for this view. This must be an iterable, and may be a queryset. Defaults to using self.queryset.

This method should always be used rather than accessing self.queryset directly, as self.queryset gets evaluated only once, and those results are cached for all subsequent requests.

You may want to override this if you need to provide different querysets depending on the incoming request.

(Eg. return a list of items that is specific to the user)

pagination_class

alias de LimitOffsetPagination

serializer_class

alias de ProcedureStepCommentDatatableSerializer

Administrative Procedures API

ProcedureAPI is a generic view that filter the information about procedure templates

ProcedureAPI functionality

This Model ViewSet filters the procedures template for the organization and validate if the user relate to the organization is allow the table show all the procedures templates. Also the last datatable column has to <i></i> elements:

  • The first icon is to view the procedure template and the steps to do the procedure.

  • The second icon is to add procedure step this action is relation to the model ProcedureStep.

  • The third icon is to update the procedure template title and description.

  • The last icon is to remove or delete procedure templates.

These functionality is related to Procedure model.

class academic.api.views.ProcedureAPI(**kwargs)[fuente]
dispatch(request, *args, **kwargs)

.dispatch() is pretty much the same as Django’s regular dispatch, but with extra hooks for startup, finalize, and exception handling.

get_queryset()[fuente]

Get the list of items for this view. This must be an iterable, and may be a queryset. Defaults to using self.queryset.

This method should always be used rather than accessing self.queryset directly, as self.queryset gets evaluated only once, and those results are cached for all subsequent requests.

You may want to override this if you need to provide different querysets depending on the incoming request.

(Eg. return a list of items that is specific to the user)

pagination_class

alias de LimitOffsetPagination

serializer_class

alias de ProcedureDataTableSerializer

ShelfObject Management API on Laboratory View

class laboratory.api.shelfobject.ShelfObjectCreateMethods(context={})[fuente]
create_equipment(serializer, limits_serializer, equipment_serializer=None)[fuente]

Create equipment type Shelfobject .

Parámetros:
  • serializer – ShelfObjectSerializer to create equipment type shelfobject

  • limits_serializer – Serializer with the data to create ShelfObjectLimits

Devuelve:

equipment type shelfobject was created

create_material(serializer, limits_serializer)[fuente]

Create material type Shelfobject .

Parámetros:
  • serializer – ShelfObjectSerializer to create material type shelfobject

  • limits_serializer – Serializer with the data to create ShelfObjectLimits

Devuelve:

material type shelfobject was created

create_reactive(serializer, limits_serializer)[fuente]

Create reactive type Shelfobject. The container is moved to the right shelf (created one with quantity 1 and decrease quantity on the original -or delete it if quantity is 0 after-).

Parámetros:
  • serializer – ShelfObjectSerializer to create reactive type shelfobject

  • limits_serializer – Serializer with the data to create ShelfObjectLimits

Devuelve:

reactive type shelfobject was created

create_refuse_equipment(serializer, limits_serializer, equipment_serializer=None)[fuente]

Create refuse equipment type Shelfobject .

Parámetros:
  • serializer – ShelfObjectSerializer to create refuse equipment type shelfobject

  • limits_serializer – Serializer with the data to create ShelfObjectLimits

Devuelve:

refuse equipment type shelfobject was created

create_refuse_material(serializer, limits_serializer)[fuente]

Create refuse material type Shelfobject .

Parámetros:
  • serializer – ShelfObjectSerializer to create refuse material type shelfobject

  • limits_serializer – Serializer with the data to create ShelfObjectLimits

Devuelve:

refuse material type shelfobject was created

create_refuse_reactive(serializer, limits_serializer, equiment_serializer=None)[fuente]

Create refuse reactive type Shelfobject. The container is moved to the right shelf (created one with quantity 1 and decrease quantity on the original -or delete it if quantity is 0 after-).

Parámetros:
  • serializer – ShelfObjectSerializer to create reactive type shelfobject

  • limits_serializer – Serializer with the data to create ShelfObjectLimits

Devuelve:

Refuse reactive type shelfobject was created

class laboratory.api.shelfobject.ShelfObjectViewSet(**kwargs)[fuente]
create_comments(request, org_pk, lab_pk, pk, **kwargs)[fuente]

Creates a new observation for a specific shelf object

Parámetros:
  • request – http request

  • org_pk – pk of the organization

  • lab_pk – pk of the laboratory from which the shelf object is located

  • pk – pk of the shelf object that the comment will be added to

  • kwargs – other extra params

Devuelve:

JsonResponse with the status of the creating

create_shelfobject(request, org_pk, lab_pk, **kwargs)[fuente]

This action allows the creates shelfobjects into the shelves, also user needs to have required access permission to do this action,futhermore the serializer validate that the quantity adding is less or equal than the shelfs quantity,the only moment permit a shelfobject quantity greater than shelf quantity is when the shelf is quantity unlimited, also the serializer validates shelfobject measurement unit need to be similar than shelf measurement unit, the only form to add a shelfobjects with different unit is when the shelf don’t have measurement unit

Parámetros:
  • request – http request

  • org_pk – organization related user permissions

  • lab_pk – laboratory related to shelfobject and user permissions

  • kwargs – extra params

Devuelve:

increase shelf object quantity, return success o error message

create_status(request, org_pk, lab_pk, **kwargs)[fuente]

Creates new status for shelfobjects

Parámetros:
  • request – http request

  • org_pk – organization related to reserved product and user permissions

  • lab_pk – laboratory related to reserved product and user permissions

  • kwargs – extra params

Devuelve:

save a status in it catalog, return success o error message

delete(request, org_pk, lab_pk, **kwargs)[fuente]

Deletes a specific shelf object from a shelf

Parámetros:
  • request – http request

  • org_pk – pk of the organization

  • lab_pk – pk of the laboratory from which the shelf object is located

  • kwargs – other extra params

Devuelve:

JsonResponse with the status of the DELETE request

details(request, org_pk, lab_pk, pk, **kwargs)[fuente]

Returns all the data from the specified Shelf Object including the Relations Fields

Parámetros:
  • request – http request

  • org_pk – pk of the organization

  • lab_pk – pk of the laboratory from which the shelf object is located

  • pk – pk of the shelf object that the data must be extracted from

  • kwargs – other extra params

Devuelve:

JsonResponse with a modal containing the details from the shelf object

fill_decrease_shelfobject(request, org_pk, lab_pk, **kwargs)[fuente]

This action allows the shelf object decrease by following data: required quantity and optional description validate through serializer, also user needs to have required access permission to do this action related to this specific organization and laboratory.

Parámetros:
  • request – http request

  • org_pk – organization related user permissions

  • lab_pk – laboratory related to shelf object and user permissions

  • kwargs – extra params

Devuelve:

decrease shelf object quantity, return success o error message

fill_increase_shelfobject(request, org_pk, lab_pk, **kwargs)[fuente]

This action allows the shelf object increase by following data: required quantity and optional provider and bill validate through serializer, also user needs to have required access permission to do this action related to this specific organization and laboratory.

Parámetros:
  • request – http request

  • org_pk – organization related user permissions

  • lab_pk – laboratory related to shelf object and user permissions

  • kwargs – extra params

Devuelve:

increase shelf object quantity, return success o error message

list_comments(request, org_pk, lab_pk, pk, **kwargs)[fuente]

Returns all the observations related to a specific shelf object

Parámetros:
  • request – http request

  • org_pk – pk of the organization

  • lab_pk – pk of the laboratory from which the shelf object is located

  • pk – pk of the shelf object that the data must be extracted from

  • kwargs – other extra params

Devuelve:

Response with the observations related to the shelf object and the number of records

move_shelfobject_to_shelf(request, org_pk, lab_pk, **kwargs)[fuente]

This action allows the shelf object movements to others shelves inside a same laboratory, also user needs to have required access permission to do this action and visualize only shelves related to this specific organization and laboratory.

Parámetros:
  • request – http request

  • org_pk – organization related to shelf object and user permissions

  • lab_pk – laboratory related to shelf object and user permissions

  • kwargs – extra params

Devuelve:

move shelf object to other shelf, return success o error message

reserve(request, org_pk, lab_pk, **kwargs)[fuente]

This action allows the reserved product creation by following data: required quantity, initial and final date validate through serializer, also user needs to have required access permission to do this action related to this specific organization and laboratory.

Parámetros:
  • request – http request

  • org_pk – organization related to reserved product and user permissions

  • lab_pk – laboratory related to reserved product and user permissions

  • kwargs – extra params

Devuelve:

save a reserved product instance, return success o error message

shelf_availability_information(request, org_pk, lab_pk, **kwargs)[fuente]

This action allows a shelf data request, also user needs to have required access permission to visualize shelf information related to this specific organization and laboratory. Moreover, it should be stressed that “shelf info” field return a render_to_string template with all necessary shelf information by structured html code.

Parámetros:
  • request – http request

  • org_pk – organization related to shelf object and user permissions

  • lab_pk – laboratory related to shelf object and user permissions

  • kwargs – extra params

Devuelve:

JsonResponse with shelf availability information which contains following fields: name, type, quantity, discard, measurement_unit, quantity_storage_status, percentage_storage_status and shelf_info.

tag(request, org_pk, lab_pk, **kwargs)[fuente]

Return a tag on SVG format .. note:: Not available right now

Parámetros:
  • request

  • args

  • kwargs

Devuelve:

transfer_available_list(request, org_pk, lab_pk, **kwargs)[fuente]

Returns the transfers that have the provided laboratory saved as laboratory_received, this for the ones that have not been approved yet.

Parámetros:
  • request – http request

  • org_pk – pk of the organization being queried

  • lab_pk – pk of the laboratory that can receive the transfer in

  • kwargs – other extra params

Devuelve:

JsonResponse with the transfer request information and the number of records

transfer_in_approve(request, org_pk, lab_pk, **kwargs)[fuente]

Approves a transfer in, which means it will be moved/added to the new laboratory and decrement/move it from the source laboratory

Parámetros:
  • request – http request

  • org_pk – pk of the organization being queried

  • lab_pk – pk of the laboratory that can receive the transfer in

  • kwargs – other extra params

Devuelve:

JsonResponse with result information (success or error info)

transfer_in_deny(request, org_pk, lab_pk, **kwargs)[fuente]

Denies a transfer in, which means it will be deleted from database and the change added to the log

Parámetros:
  • request – http request

  • org_pk – pk of the organization being queried

  • lab_pk – pk of the laboratory that can receive the transfer in

  • kwargs – other extra params

Devuelve:

JsonResponse with result information (success or error info)

transfer_out(request, org_pk, lab_pk, **kwargs)[fuente]

Creates the request to transfer a shelf object into a different laboratory

Parámetros:
  • request – http request

  • org_pk – pk of the organization being updated

  • lab_pk – pk of the laboratory from which the object will be transfer from

  • kwargs – other extra params

Devuelve:

JsonResponse with result information (success or errors)

update_status(request, org_pk, lab_pk, pk, **kwargs)[fuente]

This action allows the change of shelfobject status, also user needs to have required access permission to do this action to change the state. Changes the status for a specific shelf object

Parámetros:
  • org_pk – pk of the organization

  • lab_pk – pk of the laboratory from which the shelf object is located

  • kwargs – other extra params

  • pk – pk of the shelf object that is changing the status

Devuelve:

JsonResponse with the description and detail of the shelfobject status if is a success or only the detail when is an error

class laboratory.api.shelfobject.ShelfObjectTableViewSet(**kwargs)[fuente]

This API allows laboratory room table view.

filter_queryset(queryset)[fuente]

Given a queryset, filter it with whichever filter backend is in use.

You are unlikely to want to override this method, although you may need to call it either from a list view, or from a custom get_object method if you want to apply the configured filtering backend to the default queryset.

get_queryset()[fuente]

Get the list of items for this view. This must be an iterable, and may be a queryset. Defaults to using self.queryset.

This method should always be used rather than accessing self.queryset directly, as self.queryset gets evaluated only once, and those results are cached for all subsequent requests.

You may want to override this if you need to provide different querysets depending on the incoming request.

(Eg. return a list of items that is specific to the user)

pagination_class

alias de LimitOffsetPagination

serializer_class

alias de ShelfObjectTableSerializer

API Search Laboratory View

class laboratory.api.shelfobject.SearchLabView(**kwargs)[fuente]

This generic view set allows to find a specific element like a laboratory room, furniture, shelf, shelf object or object by filters tags, those are compounds by unique pk, value(join between pk and name), objtype and color. User access will be checking on view permissions, laboratory and organization.

Priority search level:

  1. Object

  2. Shelf Object

  3. Shelf

  4. Furniture

  5. Laboratory Room

Priority search level represents a value object on laboratory search elements. An example is multiple search tags like a laboratory room tag and an object tag, the second tag will modify laboratory room result as a first tag.

get(request, org_pk, lab_pk)[fuente]

Return an object with following structure

search_list = {
    'labroom': [pk laboratory rooms],
    'furniture': {'furniture': [], 'labroom': []},
    'shelf': {'shelf': [], 'furniture': [], 'labroom': []},
    'shelfobject': {'shelfobject': [], 'shelf': [], 'furniture': [], 'labroom': []},
    'object': {'object': [], 'shelf': {'shelf': [], 'furniture': [], 'labroom': []}}
}
Parámetros:
  • request – http request

  • org_pk – organization related user permissions

  • lab_pk – laboratory related to laboratory rooms, furniture, shelves, shelf objects and objects.

Devuelve:

an object with possible matches related to get param

Permissions and Authorization Management

class auth_and_perms.api.viewsets.RolAPI(**kwargs)[fuente]
serializer_class

alias de RolSerializer

class auth_and_perms.api.viewsets.UpdateRolOrganizationProfilePermission(**kwargs)[fuente]
serializer_class

alias de ProfilePermissionRolOrganizationSerializer

class auth_and_perms.api.viewsets.OrganizationAPI(**kwargs)[fuente]
get_queryset()[fuente]

Get the list of items for this view. This must be an iterable, and may be a queryset. Defaults to using self.queryset.

This method should always be used rather than accessing self.queryset directly, as self.queryset gets evaluated only once, and those results are cached for all subsequent requests.

You may want to override this if you need to provide different querysets depending on the incoming request.

(Eg. return a list of items that is specific to the user)

serializer_class

alias de OrganizationSerializer

class auth_and_perms.api.viewsets.UserLaboratoryOrganization(**kwargs)[fuente]
get_queryset()[fuente]

Get the list of items for this view. This must be an iterable, and may be a queryset. Defaults to using self.queryset.

This method should always be used rather than accessing self.queryset directly, as self.queryset gets evaluated only once, and those results are cached for all subsequent requests.

You may want to override this if you need to provide different querysets depending on the incoming request.

(Eg. return a list of items that is specific to the user)

pagination_class

alias de LimitOffsetPagination

serializer_class

alias de ProfileRolDataTableSerializer

class auth_and_perms.api.viewsets.UserInOrganization(**kwargs)[fuente]
get_queryset()[fuente]

Get the list of items for this view. This must be an iterable, and may be a queryset. Defaults to using self.queryset.

This method should always be used rather than accessing self.queryset directly, as self.queryset gets evaluated only once, and those results are cached for all subsequent requests.

You may want to override this if you need to provide different querysets depending on the incoming request.

(Eg. return a list of items that is specific to the user)

pagination_class

alias de LimitOffsetPagination

serializer_class

alias de ProfileRolDataTableSerializer

class auth_and_perms.api.viewsets.DeleteUserFromContenttypeViewSet(**kwargs)[fuente]
serializer_class

alias de DeleteUserFromContenttypeSerializer

class auth_and_perms.api.viewsets.ProfileToContenttypeObjectAPI(**kwargs)[fuente]
serializer_class

alias de ProfileAssociateOrganizationSerializer

class auth_and_perms.api.viewsets.UpdateGroupsByProfile(**kwargs)[fuente]

Laboratory API

class laboratory.api.views.ApiReservationCRUD(**kwargs)[fuente]
class laboratory.api.views.ApiReservedProductsCRUD(**kwargs)[fuente]
class laboratory.api.views.CommentAPI(**kwargs)[fuente]
serializer_class

alias de CommentsSerializer

class laboratory.api.views.EquipmentManagementViewset(**kwargs)[fuente]
filter_queryset(queryset)[fuente]

Given a queryset, filter it with whichever filter backend is in use.

You are unlikely to want to override this method, although you may need to call it either from a list view, or from a custom get_object method if you want to apply the configured filtering backend to the default queryset.

pagination_class

alias de LimitOffsetPagination

class laboratory.api.views.EquipmentTypeManagementViewset(**kwargs)[fuente]
pagination_class

alias de LimitOffsetPagination

class laboratory.api.views.InformViewSet(**kwargs)[fuente]
get_queryset()[fuente]

Get the list of items for this view. This must be an iterable, and may be a queryset. Defaults to using self.queryset.

This method should always be used rather than accessing self.queryset directly, as self.queryset gets evaluated only once, and those results are cached for all subsequent requests.

You may want to override this if you need to provide different querysets depending on the incoming request.

(Eg. return a list of items that is specific to the user)

pagination_class

alias de LimitOffsetPagination

serializer_class

alias de InformDataTableSerializer

class laboratory.api.views.InstrumentalFamilyManagementViewset(**kwargs)[fuente]
pagination_class

alias de LimitOffsetPagination

class laboratory.api.views.LogEntryViewSet(**kwargs)[fuente]
get_queryset()[fuente]

Get the list of items for this view. This must be an iterable, and may be a queryset. Defaults to using self.queryset.

This method should always be used rather than accessing self.queryset directly, as self.queryset gets evaluated only once, and those results are cached for all subsequent requests.

You may want to override this if you need to provide different querysets depending on the incoming request.

(Eg. return a list of items that is specific to the user)

pagination_class

alias de LimitOffsetPagination

serializer_class

alias de LogEntryDataTableSerializer

class laboratory.api.views.ProtocolViewSet(**kwargs)[fuente]
filter_queryset(queryset)[fuente]

Given a queryset, filter it with whichever filter backend is in use.

You are unlikely to want to override this method, although you may need to call it either from a list view, or from a custom get_object method if you want to apply the configured filtering backend to the default queryset.

pagination_class

alias de LimitOffsetPagination

serializer_class

alias de ProtocolDataTableSerializer

class laboratory.api.views.ShelfList(**kwargs)[fuente]
dispatch(request, *args, **kwargs)

.dispatch() is pretty much the same as Django’s regular dispatch, but with extra hooks for startup, finalize, and exception handling.

class laboratory.api.views.ShelfObjectAPI(**kwargs)[fuente]
class laboratory.api.views.ShelfObjectGraphicAPI(**kwargs)[fuente]
class laboratory.shelfobject_container.viewsets.ContainerManagementViewset(**kwargs)[fuente]
get_queryset()[fuente]

Get the list of items for this view. This must be an iterable, and may be a queryset. Defaults to using self.queryset.

This method should always be used rather than accessing self.queryset directly, as self.queryset gets evaluated only once, and those results are cached for all subsequent requests.

You may want to override this if you need to provide different querysets depending on the incoming request.

(Eg. return a list of items that is specific to the user)

pagination_class

alias de LimitOffsetPagination

SGA API

class sga.api.sga_components_viewsets.DangerIndicationAPI(**kwargs)[fuente]
serializer_class

alias de DangerIndicationSerializer

class sga.api.sga_components_viewsets.DangerIndicationTableView(**kwargs)[fuente]
pagination_class

alias de LimitOffsetPagination

serializer_class

alias de DangerIndicationDataTableSerializer

class sga.api.sga_components_viewsets.PrudenceAdviceAPI(**kwargs)[fuente]
serializer_class

alias de PrudenceAdviceSerializer

class sga.api.sga_components_viewsets.PrudenceAdviceTableView(**kwargs)[fuente]
pagination_class

alias de LimitOffsetPagination

serializer_class

alias de PrudenceAdviceDataTableSerializer

class sga.api.sga_components_viewsets.WarningWordAPI(**kwargs)[fuente]
serializer_class

alias de WarningWordSerializer

class sga.api.sga_components_viewsets.WarningWordTableView(**kwargs)[fuente]
pagination_class

alias de LimitOffsetPagination

serializer_class

alias de WarningWordDataTableSerializer

class sga.api.substance_viewset.SubstanceViewSet(**kwargs)[fuente]
get_queryset()[fuente]

Get the list of items for this view. This must be an iterable, and may be a queryset. Defaults to using self.queryset.

This method should always be used rather than accessing self.queryset directly, as self.queryset gets evaluated only once, and those results are cached for all subsequent requests.

You may want to override this if you need to provide different querysets depending on the incoming request.

(Eg. return a list of items that is specific to the user)

pagination_class

alias de LimitOffsetPagination

serializer_class

alias de SubstanceDataTableSerializer

class sga.api.review_flow_substance.ReviewSubstanceViewSet(**kwargs)[fuente]
filter_queryset(queryset)[fuente]

Given a queryset, filter it with whichever filter backend is in use.

You are unlikely to want to override this method, although you may need to call it either from a list view, or from a custom get_object method if you want to apply the configured filtering backend to the default queryset.

get_queryset()[fuente]

Get the list of items for this view. This must be an iterable, and may be a queryset. Defaults to using self.queryset.

This method should always be used rather than accessing self.queryset directly, as self.queryset gets evaluated only once, and those results are cached for all subsequent requests.

You may want to override this if you need to provide different querysets depending on the incoming request.

(Eg. return a list of items that is specific to the user)

pagination_class

alias de LimitOffsetPagination

serializer_class

alias de ReviewSubstanceDataTableSerializer

class sga.api.labels_viewset.DisplayLabelViewSet(**kwargs)[fuente]
filter_queryset(queryset)[fuente]

Given a queryset, filter it with whichever filter backend is in use.

You are unlikely to want to override this method, although you may need to call it either from a list view, or from a custom get_object method if you want to apply the configured filtering backend to the default queryset.

pagination_class

alias de LimitOffsetPagination

serializer_class

alias de DisplayLabelDataTableSerializer

class sga.api.recipients_viewset.RecipientSizeAPI(**kwargs)[fuente]
serializer_class

alias de RecipientSizeDataTableSerializer

Reports API

class report.api.views.ReportDataLogViewSet(**kwargs)[fuente]
get_queryset()[fuente]

Get the list of items for this view. This must be an iterable, and may be a queryset. Defaults to using self.queryset.

This method should always be used rather than accessing self.queryset directly, as self.queryset gets evaluated only once, and those results are cached for all subsequent requests.

You may want to override this if you need to provide different querysets depending on the incoming request.

(Eg. return a list of items that is specific to the user)

pagination_class

alias de LimitOffsetPagination

serializer_class

alias de ObjectChangeDataTableSerializer

class report.api.views.ReportDataViewSet(**kwargs)[fuente]
pagination_class

alias de LimitOffsetPagination

serializer_class

alias de ReportDataTableSerializer

Internationalization

The goal of internationalization and localization is to allow a single Web application to offer its content in languages and formats tailored to the audience.

Django has full support for translation of text, formatting of dates, times and numbers, and time zones.

Essentially, Django does two things:

  • It allows developers and template authors to specify which parts of their apps should be translated or formatted for local languages and cultures.

  • It uses these hooks to localize Web apps for particular users according to their preferences.

To specify which parts (specially string and unicode instances) must be translated to the local language where the web app is being deployed, Django offers the functions located in django.utils.translation.

Standard translation

To specify an standard translation, use the ugettext_lazy function:

  • In a view:

from django.utils.translation import ugettext_lazy as _
from django.http import HttpResponse

def some_view(request):
    output = _('Hello World')
    return HttpResponse(output)
  • In a model:

from django.db import models
from django.utils.translation import ugettext_lazy as _

class Object(models.Model):
    REACTIVE = '0'
    MATERIAL = '1'
    EQUIPMENT = '2'
    TYPE_CHOICES = (
        (REACTIVE, _('Reactive')),
        (MATERIAL, _('Material')),
        (EQUIPMENT, _('Equipment'))
    )
    shelf = models.ForeignKey('Shelf')
    type = models.CharField(_('Type'), max_length=2, choices=TYPE_CHOICES)
    code = models.CharField(_('Code'), max_length=255)
    description = models.TextField(_('Description'))
    name = models.CharField(_('Name'), max_length=255)
    feature = models.ManyToManyField('ObjectFeatures')
  • In a template:

You need to put {% load i18n %} in the begining of the template, always after {% extends 'base.html' %}:

{% load i18n %}
<html>
        <head>
                <title> {% trans "This is the title." %} </title>
        </head>
        <body>
                <h1> {% trans "Hello World!!" %} </h1>
        </body>
</html>
  • In a template with CSS:

<html>
        <head>
                <title> {% trans "This is the title." %} </title>
                <style>
                        @page {
                                margin: 3cm 2cm; padding-left: 1.5cm;
                                @top-left {
                                        content: "{% trans "Organilab Report" %}";
                                }
                                @top-right {
                                        content: "{% trans "Date:" %} {{ datetime }}";
                                }
                                @bottom-right {
                                        content: "{% trans "Page" %} " counter(page)
                                        " {% trans "of" %} " counter(pages) ;
                                }
                                @bottom-left {
                                        content:  "{% trans "User:" %} {{ request.user }}";
                                        color: red;
                                }
                        }
                        body {
                                text-align: justify
                        }
                </style>
        </head>
        <body>
                <h1> {% trans "Hello World!!" %} </h1>
        </body>
</html>

Then, create a folder with the name of locale in your project (laboratory/locale), and execute the next command:

$ python manage.py makemessages  -l es

-l es : indicates the translation lenguage.

Edit the .po file.

PDF Generation with Weasyprint

Follow this steps for generation PDF files with weasyprint.

Dependencies

  • Update the file: requirements.txt.

$ pip install -r requirements.txt
  • Install packages: With a sudo session (or with any superuser privileges session) you must install your platform’s packages (Linux, Debian/Ubuntu).

$ sudo apt-get install python-dev python-pip python-lxml python-cffi libcairo2 libpango1.0-0 libgdk-pixbuf2.0-0 shared-mime-info
  • Install the next package: With a sudo session.

$ sudo apt-get install libxml2-dev libxslt1-dev libffi-dev
  • You need to upgrade the next files. In organilab virtualenv:

source ~/entornos/organilab/bin/activate
pip install --upgrade setuptools pip
  • Finally, you going to install Weasyprint.

pip install WeasyPrint

Code

  • You need to define a HTML view («example_pdf.html»). In this HTML view, you can define the top, the body and the bottom of the PDF file.

<html>
    <head>
        <style>
            @page {
                margin: 3cm 2cm; padding-left: 1.5cm;

                @top-left {
                    content: "Example Report";
                }
                @top-right {
                    content: "Date: {{ datetime }}";
                }
                @bottom-right {
                    content: "Page " counter(page) " of " counter(pages) ;
                }
                @bottom-left {
                    content:  "User: {{ request.user }}";
                    color: red;
                }
            }
            body {
                text-align: justify
            }
        </style>
    </head>
    <body>
        <h3>
            Hello, this is my report!!
        </h3>
    </body>
</html>
  • Define de PDF generator method.

def report_example(request):
    varModel = Model.objects.all()

    template = get_template('pdf/example_pdf.html')

    context = {
               'object_list': varModel,
               'datetime': timezone.now(),
               'request': request
               }

    html = template.render(Context(context)).encode("UTF-8")

    page = HTML(string=html, encoding='utf-8').write_pdf()

    response = HttpResponse(page, content_type='application/pdf')

    response[
              'Content-Disposition'] = 'attachment; filename="report_example.pdf"'
    return response
  • Create the URL.

url(r"^report/example$", views.report_example, name="report_example"),