跳转到主要内容

django userproperty

项目描述

# Django Userproperty

[![Build Status](https://travis-ci.org/arteria/django-userproperty.svg?branch=master)](https://travis-ci.org/arteria/django-userproperty)
[![Coverage Status](https://coveralls.io/repos/arteria/django-userproperty/badge.svg?branch=master&service=github)](https://coveralls.io/github/arteria/django-userproperty?branch=master)
[![PyPI](https://img.shields.io/pypi/v/django-userproperty.svg)](https://pypi.python.org/pypi/django-userproperty)


django-userproperty是一个可重用的Django应用,用于管理每个用户和全局属性。此外,django-userproperty还提供了一些辅助函数来设置、获取、增加和减少这些属性。


## 安装

安装包

pip install django-userproperty

在settings.py中添加应用

INSTALLED_APPS = (
'userproperty',
)

更新你的root urls.py文件

...
url(r'^properties/', include('userproperty.urls')),
...


最后同步你的数据库

python manage.py syncdb


## 使用

### 异步使用的API

此应用旨在与JavaScript/jQuery和异步请求一起使用。它提供了一些基本的API接口来获取和设置属性

#### `get-uproperty`

> 需要登录用户

**name**: 用户属性的名称
default: 默认值,如果未找到用户属性,将返回此值

$.get("/get-uproperty/?name=<name>&default=<value>", function(data) {
alert(data);
});

response

{"status": "success", "number-of-items": "50"} // 或 100 如果找不到属性 number-of-items

#### `set-uproperty`

> 需要登录用户

**name**: 用户属性的名称
**value**: 要设置的属性值

$.get("/set-uproperty/?name=<name>&value=<value>", function(data) {
alert(data);
});

response

{"status": "success", "number-of-items": "100"}

#### `get-gproperty`

> 需要工作人员

**name**: 全局属性的名称
default: 默认值,如果未找到全局属性,将返回此值

$.get("/get-gproperty/?name=<name>&default=<value>", function(data) {
alert(data);
});

response

{"status": "success", "number-of-items": "50"}

#### `set-gproperty` - 需要工作人员

> 需要工作人员

**name**: 全局属性的名称
**value**: 要设置的属性值

$.get("/set-gproperty/?name=<name>&value=<value>", function(data) {
alert(data);
});

返回

{"status": "success", "number-of-items": "100"}


### 更多示例

在您的网站上创建账户后,用户需要完成一些任务,然后才能进入其个人资料。在此示例中,添加更多信息并同意条款和条件。

创建新用户时,您会创建一个新的属性

from userproperty.utils import addProperty

addProperty(request, tag='setup')
# 如果用户未保存在请求中,则添加:anUser=yourNewUser

在您的登录视图中,现在可以根据UserProperty有不同的结果

from userproperty.utils import getIntegerProperty, setIntegerProperty, removeProperty

# 在您的登录视图中

setupProperty = getIntegerProperty(request,'setup')

if setupProperty == 1
# 重定向,添加电话号码等表单
elif setupProperty == 2
# 重定向,接受条款和条件
elif setupProperty
removeProperty(request, tag='setup')

# 没有设置属性时的内容

剩下的只是将属性设置为新值,当执行相应的操作(表单在此情况下)时

from userproperty.utils import setIntegerProperty, removeProperty

# 在表单电话号码等的视图中
form.is_valid()
# 进行操作

setIntegerProperty(request, tag='setup', value=2)

# 重定向登录


# 在条款和条件的视图中
form.is_valid()
# 进行操作

removeProperty(request, tag='setup')

# 重定向登录

其他示例:设置旅游,保存用户特定属性(在js datatables中显示的数据条目数)等。

## PEP8

函数在pep8(单词之间用_分隔的小写)中可用

setIntegerProperty() ==> set_integer_property()

## 更新日志

### 06/Aug/2015

* 正确处理匿名用户。
* ``decUserProperty`` 和 ``incUserProperty`` 对于匿名用户或错误情况返回 ``False`` 而不是 ``True``。

项目详情


下载文件

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

源代码分发

django-userproperty-1.0.8.tar.gz (8.2 kB 查看散列)

上传时间 源代码

由以下组织支持

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