api ¤
The api
app exposes the API endpoints for the application.
It uses the rest_framework
package to provide the API endpoints.
admin ¤
APITokenAdmin ¤
Bases: TokenAdmin
Custom Admin for DRF Token. Add supports for custom permissions.
formfield_for_foreignkey ¤
formfield_for_foreignkey(db_field: ForeignKey[Any, Any], request: HttpRequest, **kwargs: Any) -> ModelChoiceField
Show all or only current user depending on permissions.
Source code in src/firefighter/api/admin.py
get_form ¤
get_form(request: HttpRequest, obj: APITokenProxy | None = None, change: bool = False, **kwargs: Any) -> type[ModelForm[APITokenProxy]]
Prefill the form with the current user.
Source code in src/firefighter/api/admin.py
get_queryset ¤
Show all or only own tokens depending on permissions.
Source code in src/firefighter/api/admin.py
get_sortable_by ¤
Hack to send a message depending on the status of the user.
Source code in src/firefighter/api/admin.py
authentication ¤
BearerTokenAuthentication ¤
Bases: TokenAuthentication
To use Authorization: Bearer <token>
instead of Authorization: Token <token>
.
models ¤
APITokenProxy ¤
Bases: APIToken
Proxy mapping pk to user pk for use in admin.
Overrides default permissions.
permissions ¤
StrictDjangoModelPermissions ¤
Bases: DjangoModelPermissions
Custom class to restrict GET requests.
renderer ¤
CSVRenderer ¤
Bases: CSVRenderer
Renderer which serializes to CSV Override the default CSV Renderer to allow hiding header fields. Hide head by setting labels to "hidden".
tablize ¤
tablize(data: Any, header: Any | None = None, labels: Any | None = None) -> Generator[list[Any], None, None]
Convert a list of data into a table.
If there is a header provided to tablize it will efficiently yield each
row as needed. If no header is provided, tablize will need to process
each row in the data in order to construct a complete header. Thus, if
you have a lot of data and want to stream it, you should probably
provide a header to the renderer (using the header
attribute, or via
the renderer_context
).
Source code in src/firefighter/api/renderer.py
TSVRenderer ¤
Bases: CSVRenderer
Renderer which serializes to TSV.
tablize ¤
tablize(data: Any, header: Any | None = None, labels: Any | None = None) -> Generator[list[Any], None, None]
Convert a list of data into a table.
If there is a header provided to tablize it will efficiently yield each
row as needed. If no header is provided, tablize will need to process
each row in the data in order to construct a complete header. Thus, if
you have a lot of data and want to stream it, you should probably
provide a header to the renderer (using the header
attribute, or via
the renderer_context
).
Source code in src/firefighter/api/renderer.py
serializers ¤
CreatableSlugRelatedField ¤
Bases: SlugRelatedField[T]
, Generic[T]
Like SlugRelatedField, but allows to create an object that is not present in DB.
run_validation ¤
Override the default validation to perform the validation before trying to create the object.
Source code in src/firefighter/api/serializers.py
GroupedModelSerializer ¤
GroupedModelSerializer(
child_serializer: type[serializers.ModelSerializer[T]], key_getter: Callable[[T], str] = lambda: str(x.pk), **kwargs: Any
)
Bases: RelatedField[T, Any, Any]
, Generic[T]
Generic implementation for a model with a One2Many, where instead of a list we want the items grouped by a field, like costs or metrics.
Source code in src/firefighter/api/serializers.py
urls ¤
views ¤
components ¤
incident_cost_types ¤
incident_costs ¤
incidents ¤
CreateIncidentViewSet ¤
Bases: CreateModelMixin
, GenericViewSet[Incident]
create ¤
Allow to create an incident. Requires a valid Bearer token, that you can create in the back-office if you have the right permissions.
Source code in src/firefighter/api/views/incidents.py
IncidentViewSet ¤
Bases: RetrieveModelMixin
, ListModelMixin
, AdvancedGenericViewSet[Incident]
labels
class-attribute
instance-attribute
¤
Dict mapping attributes/properties to a more friendly string to be shown in the header row for CSV/TSV renders.
E.g. labels = {"slack_channel_name": "Slack Channel"}
list ¤
List all incidents. Allows to show or hide tags which is DB intensive, with the show_tags parameters.
status
and _status__*
uses an enum:
Source code in src/firefighter/api/views/incidents.py
ProcessAfterResponse ¤
Bases: Response
Custom DRF Response, to trigger the Slack workflow after creating the incident and returning HTTP 201.