afex-audit-trail


Nameafex-audit-trail JSON
Version 0.2.6 PyPI version JSON
download
home_page
SummaryA Django app to create server logs and users' notification.
upload_time2023-08-24 10:54:22
maintainer
docs_urlNone
authorAFEX NIGERIA
requires_python>=3.7
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # AFEX Audit Trail

## Installation

### Install Dependencies

- **Python 3.8**
- **Django 4.0**

Install the package with pip and all the required libraries would be installed

```bash
pip install afex-audit-trail
```

## Setting up...

Add '**audit-trails**' to your installed apps:

```bash
INSTALLED_APPS = [
  ...
  'audit_trails',
  ....
]
```

Run 'python manage.py migrate' to add the schema

```bash
python manage.py migrate
```

## Generating Logs

To generate log for every request and response on the server, add the 'ActivityLoggingMiddleware' 
to your MIDDLEWARE list.

```bash
MIDDLEWARE = [
  ....
  'audit_trails.middleware.ActivityLoggingMiddleware',
]
```

The log can be stored in either database or file, file being the default storage. Set the LOG_STORAGE variable
in your settings.py file if you wish to use database for storage. 

```bash
LOG_STORAGE = 'database'
```

Log file can be found in activity.log in the project directory


## Generating Notifications

Notifications are generated manually by calling the appropriate method in your views or anywhere you'd like to 
generate notifications.

Notification has 4 levels namely; ```info, success, warning, error```. Each of the has a method for creating 
notification with their respective level.

To generate notification anywhere in your code, import notify from signals and call the method that matches your 
notification level with the right attribute.

The right syntax is:

```snippet
from audit_trails.signals import notify

notify.success(actor, recipients, action, action_object_type, action_object_id)
```

### Add notification urls to your conf
For webview projects, include ```audit_trails.urls``` and ```audit_trails.api.urls``` for api, in your  urlconf:

```angular2html
urlpatterns = [
    ...
    path('notifications/', include('audit_trails.api.urls')),
    ...
]
```

### Responses (View)

#### For api, '/notifications' returns a javascript object similar to the sample below:
```json
{
    "responseCode": 100,
    "data": [
        {
            "id": 1,
            "level": "success",
            "description": "You modified John Doe's profile",
            "timestamp": "2023-04-03T17:03:01.957252+01:00",
            "timesince": "15 minutes",
            "is_read": false
        },
        {
            "id": 5,
            "level": "success",
            "description": "John created Mary Doe's profile",
            "timestamp": "2023-03-03T10:05:18.361405+01:00",
            "timesince": "1 month",
            "is_read": false
        }
    ],
    "message": "Notification list retrieved successfully"
}
```

### For webview, '/notifications' returns a html page with list of notifications



### Arguments:
#### Required
- **actor**: A required object of a user instance
- **recipients**: A set of users to whom the notifications are sent
- **action**: A short description (preferably one or two word)
- **action_object_type**: Specifies the object type on whom the action was performed and it could be of nay type
- **action_object_id**: An integer of the action object id. together with the ```action_object_type```.
    The actual object is gotten.

#### Others
- **action_target_object_type**: Specifies the object type **to** which the action was performed and it could be of nay type
- **action_target_object_id**: An integer of the action object id. together with the ```action_target_object_type```.
- **detail**: An optional string field for more information about the notification. 

### Extra Information

Other notification level methods are: ```notify.info(), notify.warning(), notify.error()```, with the same 
arguments as ```notify.success()```


#### Queryset Methods
Queryset methods were added to make querying and manipulations easier. Some of the methods are :
```unread(), read(), mark_all_as_read(), mark_all_as_unread()```

e.g ```user.notifications.mark_all_as_read()``` would mark all notification as read for a particular user.


#### Model Methods and Properties
- timesince: Property returning the difference between the current date and the date the notification was created.
- description: Property returning string sentence of the actor, action and object of the notification
- mark_as_read(): toggles the ```is_read``` field of a notification object to ```True```
- mark_as_unread(): toggles the ```is_read``` field of a notification object to ```False``
            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "afex-audit-trail",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "",
    "author": "AFEX NIGERIA",
    "author_email": "it@afexnigeria.com",
    "download_url": "https://files.pythonhosted.org/packages/0d/45/b089a66fc93d393ca1641d177fa6b4176087c675996860feab19a1300469/afex-audit-trail-0.2.6.tar.gz",
    "platform": null,
    "description": "# AFEX Audit Trail\n\n## Installation\n\n### Install Dependencies\n\n- **Python 3.8**\n- **Django 4.0**\n\nInstall the package with pip and all the required libraries would be installed\n\n```bash\npip install afex-audit-trail\n```\n\n## Setting up...\n\nAdd '**audit-trails**' to your installed apps:\n\n```bash\nINSTALLED_APPS = [\n  ...\n  'audit_trails',\n  ....\n]\n```\n\nRun 'python manage.py migrate' to add the schema\n\n```bash\npython manage.py migrate\n```\n\n## Generating Logs\n\nTo generate log for every request and response on the server, add the 'ActivityLoggingMiddleware' \nto your MIDDLEWARE list.\n\n```bash\nMIDDLEWARE = [\n  ....\n  'audit_trails.middleware.ActivityLoggingMiddleware',\n]\n```\n\nThe log can be stored in either database or file, file being the default storage. Set the LOG_STORAGE variable\nin your settings.py file if you wish to use database for storage. \n\n```bash\nLOG_STORAGE = 'database'\n```\n\nLog file can be found in activity.log in the project directory\n\n\n## Generating Notifications\n\nNotifications are generated manually by calling the appropriate method in your views or anywhere you'd like to \ngenerate notifications.\n\nNotification has 4 levels namely; ```info, success, warning, error```. Each of the has a method for creating \nnotification with their respective level.\n\nTo generate notification anywhere in your code, import notify from signals and call the method that matches your \nnotification level with the right attribute.\n\nThe right syntax is:\n\n```snippet\nfrom audit_trails.signals import notify\n\nnotify.success(actor, recipients, action, action_object_type, action_object_id)\n```\n\n### Add notification urls to your conf\nFor webview projects, include ```audit_trails.urls``` and ```audit_trails.api.urls``` for api, in your  urlconf:\n\n```angular2html\nurlpatterns = [\n    ...\n    path('notifications/', include('audit_trails.api.urls')),\n    ...\n]\n```\n\n### Responses (View)\n\n#### For api, '/notifications' returns a javascript object similar to the sample below:\n```json\n{\n    \"responseCode\": 100,\n    \"data\": [\n        {\n            \"id\": 1,\n            \"level\": \"success\",\n            \"description\": \"You modified John Doe's profile\",\n            \"timestamp\": \"2023-04-03T17:03:01.957252+01:00\",\n            \"timesince\": \"15 minutes\",\n            \"is_read\": false\n        },\n        {\n            \"id\": 5,\n            \"level\": \"success\",\n            \"description\": \"John created Mary Doe's profile\",\n            \"timestamp\": \"2023-03-03T10:05:18.361405+01:00\",\n            \"timesince\": \"1 month\",\n            \"is_read\": false\n        }\n    ],\n    \"message\": \"Notification list retrieved successfully\"\n}\n```\n\n### For webview, '/notifications' returns a html page with list of notifications\n\n\n\n### Arguments:\n#### Required\n- **actor**: A required object of a user instance\n- **recipients**: A set of users to whom the notifications are sent\n- **action**: A short description (preferably one or two word)\n- **action_object_type**: Specifies the object type on whom the action was performed and it could be of nay type\n- **action_object_id**: An integer of the action object id. together with the ```action_object_type```.\n    The actual object is gotten.\n\n#### Others\n- **action_target_object_type**: Specifies the object type **to** which the action was performed and it could be of nay type\n- **action_target_object_id**: An integer of the action object id. together with the ```action_target_object_type```.\n- **detail**: An optional string field for more information about the notification. \n\n### Extra Information\n\nOther notification level methods are: ```notify.info(), notify.warning(), notify.error()```, with the same \narguments as ```notify.success()```\n\n\n#### Queryset Methods\nQueryset methods were added to make querying and manipulations easier. Some of the methods are :\n```unread(), read(), mark_all_as_read(), mark_all_as_unread()```\n\ne.g ```user.notifications.mark_all_as_read()``` would mark all notification as read for a particular user.\n\n\n#### Model Methods and Properties\n- timesince: Property returning the difference between the current date and the date the notification was created.\n- description: Property returning string sentence of the actor, action and object of the notification\n- mark_as_read(): toggles the ```is_read``` field of a notification object to ```True```\n- mark_as_unread(): toggles the ```is_read``` field of a notification object to ```False``",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A Django app to create server logs and users' notification.",
    "version": "0.2.6",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4280a1c9533356d54597e502232f3083eb8075a8f7616344fc7d5e0e38898d1c",
                "md5": "e32dae722ea00cbd333aee97fea6d950",
                "sha256": "3ec9c23623e72d2c8ee5c58289f035b892a1e3438d755fada0a84be4e8c50ccd"
            },
            "downloads": -1,
            "filename": "afex_audit_trail-0.2.6-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e32dae722ea00cbd333aee97fea6d950",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 14106,
            "upload_time": "2023-08-24T10:54:41",
            "upload_time_iso_8601": "2023-08-24T10:54:41.562683Z",
            "url": "https://files.pythonhosted.org/packages/42/80/a1c9533356d54597e502232f3083eb8075a8f7616344fc7d5e0e38898d1c/afex_audit_trail-0.2.6-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0d45b089a66fc93d393ca1641d177fa6b4176087c675996860feab19a1300469",
                "md5": "e25b78f38fb12e9d7cd9c9c9283eaaac",
                "sha256": "8fbcf47a1341866a5eddc17ad4b91a5d12786c2b7221b01a340bd68d83cca7e3"
            },
            "downloads": -1,
            "filename": "afex-audit-trail-0.2.6.tar.gz",
            "has_sig": false,
            "md5_digest": "e25b78f38fb12e9d7cd9c9c9283eaaac",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 10229,
            "upload_time": "2023-08-24T10:54:22",
            "upload_time_iso_8601": "2023-08-24T10:54:22.102916Z",
            "url": "https://files.pythonhosted.org/packages/0d/45/b089a66fc93d393ca1641d177fa6b4176087c675996860feab19a1300469/afex-audit-trail-0.2.6.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-08-24 10:54:22",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "afex-audit-trail"
}
        
Elapsed time: 0.10223s