Skip to main content

Build Status Coverage Status Maintainability Downloads Downloads Downloads PyPI version

DRF-HISTORY

drf-history is a simple django rest framework app to track actions performed in a django app and to also gets the current request. The actions being tracked are POST, DELETE, PUT and PATCH

Data being captured is

Data Description
user The current loggedin user making the request
request data(body) Data being sent (POST, PATCH and PUT)
response data response data after the request is complete
table_name name of the model the request is affecting
instance_id The id of the created, updated or deleted model instance
method The request method i.e POST, DELETE, PUT or PATCH
created_at Date time object for when the request is being carried out
path path the request is coming from

Quick start

  1. Add track_actions to your INSTALLED_APPS setting

     INSTALLED_APPS = [
         ...,
         'track_actions',
     ]
    
  2. Add track_actions.requestMiddleware.RequestMiddleware in settings under middlewares

     MIDDLEWARE = [
         ... ,
         'track_actions.requestMiddleware.RequestMiddleware',
     ]
    
  3. Run python manage.py migrate track_actions to create the History model.

     `python manage.py migrate track_actions`
    

After this every POST, UPDATE and DELETE action will be recorded in your database under the history model.

To prevent sensitive fields from being saved

For example passwords.

You will have to create a yaml file called drf_history.yaml on the root of your django project. In this file add the following.

fields_to_exclude: ["password","another key here"]

You can then add all sensitve fields in the list separated by commas. These fields will be removed from the saved request data. This will apply to all tables.

This is only for data sent in the request.

To get the current request

To get the current request in progress anywhere in the application.

  1. Import the relevant class.

     from track_actions.requestMiddleware import RequestMiddleware
    

2 Get the current request object.

    current_request = RequestMiddleware.get_request_data()[1]

To access the get history endpoint

  1. In your project's url file

     `import track_actions` 
    
  2. Register the url in the urlpattern

     `path('track_actions/', include('track_actions.urls'))`
    
  3. visit the url in the browser or on postman

     `http://127.0.0.1:8000/track_actions/history/`
    

you should be able to see all the recorded history if you have admin priveleges and you are authenticated.

Alternatively

You can create your own endpoint to view all history from the History model by importing it in your views or serializers.

    `from track_actions.models import History`

NOTE

This package will only work if you have a user in a request and a user model in your database.

Release files for drf-history 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for drf-history 1.0.1
File Size Uploaded
drf-history-1.0.1.tar.gz 6.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for drf-history 1.0.1
File Interpreter ABI Platform
drf_history-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 15.9 kB

Release files / drf-history-1.0.1.tar.gz

Download URL drf-history-1.0.1.tar.gz
Size 6.6 kB
Tags Source
SHA-256 checksum
How to use checksums
73d71b3cf3135f25bd3e7964324e41cc94039b1549f7f68fedcdbf5782d13937
BLAKE2b-256 checksum
How to use checksums
cc768d53fa707416f77e7c5b30ade158485a1c2be0205e11118b4e9e9fb89c64
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.5

Release files / drf_history-1.0.1-py3-none-any.whl

Download URL drf_history-1.0.1-py3-none-any.whl
Size 9.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6015167c1facc6fbf4123b7aa7681440cfb24de2e4a7f88f47ca956993b84140
BLAKE2b-256 checksum
How to use checksums
98fe2e294c0259190109c77485ac2bd685cdd53a996a5c2d0f34976341a2ceb8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.5

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

1.0.0

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page