跳转到主要内容

Django应用,用于跟踪系统中的所有动作/事件。

项目描述

# Django History Actions

Django应用,用于跟踪系统中的动作/事件。

[![构建状态](https://travis-ci.org/marcosschroh/django-history-actions.svg?branch=master)](https://travis-ci.org/marcosschroh/django-history-actions)
[![codecov](https://codecov.io/gh/marcosschroh/django-history-actions/branch/master/graph/badge.svg)](https://codecov.io/gh/marcosschroh/django-history-actions)
[![GitHub许可证](https://img.shields.io/github/license/marcosschroh/django-history-actions.svg)](https://github.com/marcosschroh/django-history-actions/blob/master/LICENSE)
![PyPI - Python版本](https://img.shields.io/badge/python-3-blue.svg)


## **目录**

- [功能](#features)
- [模型描述](#model-description)
- [快速入门](#quickstart)
- [系统名称](#system-name)
- [信号](#signals)
- [运行测试](#running-tests)

### 功能

1. 保存您的django模型的历史记录。
2. 定义全局系统名称或按模型定义
3. 动作应用程序检查器。
4. 信号以跟踪已保存的模型。

### 模型描述

| 字段 | 描述 | 类型 | 必填 | 默认 |
|:-------------|:-----------------|:-----|:---------|:--------------------|
| author | 动作作者(用户名) | str | True | |
| action | 执行的动作 | str | True | |
| system | 系统名称 | str | True | 从设置或模型实例中获取 |
| actor | 参与动作的演员(用户名) | str | False | |
| created | 动作创建的日期时间 | Datetime | False | 自动生成 |
| content_type | 模型实例的内容类型 | str | False | 从模型实例自动生成 |
| object_pk | 对象pk | int | False | 从模型实例获取 |
| notes | 与动作相关的额外注释 | TextField | False | |
| 额外 | 额外字段用于存储可序列化对象。 | 文本字段 | False | |

### 快速入门

安装 Django History Actions

```bash
pip install django-history-events
```

将其添加到您的 `INSTALLED_APPS`

```python
INSTALLED_APPS = (
...
'history_actions',
...
)

# 定义您的系统名称
HISTORY_ACTIONS_SYSTEM = 'main'
```

在您的应用程序中定义 actions.py

```python
# actions.py

from django.utils.translation import ugettext_lazy as _

INFO_TRAINING_SAVE_ACTION = 'INFO_TRAINING_SAVE_ACTION'

ACTIONS = {
'INFO_TRAINING_SAVE_ACTION': _('info trainig save action')
}
```

现在您可以跟踪历史记录了

```python
from history_actions.manager import HistoryManager

# 记录一个事件
HistoryManager.create(
'an_author', 'INFO_TRAINING_SAVE_ACTION')

# 记录与模型相关联的事件
model_instance = ModelKlass.objects.first()
HistoryManager.create(
'an_author', 'INFO_TRAINING_SAVE_ACTION', model_instance=model_instance)

# 记录包含更多信息的与模型相关联的事件
username = User.ojects.first().username
HistoryActions.create(
'an_author', 'INFO_TRAINING_SAVE_ACTION', model_instance=model_instance, actor=username, notes='我的笔记')


# 记录与模型相关联并序列化模型的事件
username = User.ojects.first().username
model_instance_dict = model_instance.to_dict()
HistoryActions.create(
'an_author', 'INFO_TRAINING_SAVE_ACTION', model_instance=model_instance, actor=username, notes='我的笔记', extra=model_instace_dict)

# 使用不同的系统
HistoryActions.create(
'an_author', 'INFO_TRAINING_SAVE_ACTION', model_instance=model_instance, actor=username, notes='我的笔记', extra=model_instace_dict, system="custom")
```

如果您想为模型跟踪使用不同的系统,可以在以下位置定义它

```python
# models.py

class Chatdentity(MachuBaseModel)
HISTORY_ACTION_SYSTEM = 'chat'

user = models.OneToOneField(User)
user_two = models.OneToOneField(User, related_name='user_manager')
given_name = models.CharField(
'Given Name(s)', max_length=200, default='')
family_name = models.CharField(
'Family Name(s)', max_length=200, default='')
```

### 系统名称

系统名称来自以下内容

1. `create` 方法的 `kwargs`。
2. 来自 `settings.py` 中定义的 `HISTORY_ACTIONS_SYSTEM` 变量。
3. 在模型类中定义的 `HISTORY_ACTION_SYSTEM` 类变量。

### 信号

### 运行测试

```bash
source <YOURVIRTUALENV>/bin/activate
(myenv) $ pip install tox
(myenv) $ tox
```

项目详情


下载文件

下载适用于您的平台的文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。

源分布

django-history-actions-0.1.1.tar.gz (8.3 kB 查看哈希值)

上传时间

构建分布

django_history_actions-0.1.1-py2.py3-none-any.whl (7.6 kB 查看哈希值)

上传时间 Python 2 Python 3

由以下支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误记录 StatusPage StatusPage 状态页面