Skip to main content
# 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 is a reusable Django app that manages per user and global properties. In addition, django-userproperty provides helper functions to set, get, incerement and decrement these properties.


## Installation

Install the package:

pip install django-userproperty

Add the app in you settings.py:

INSTALLED_APPS = (
'userproperty',
)

Update your root urls.py file:

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


And finally sync your db

python manage.py syncdb


## Usage

### API for asynchronous Usage

This app is designed to be used with JavaScript/jQuery and asynchronous requests. It provides so besic API interfaces to get and set Properties

#### `get-uproperty`

> logged-in user is required

**name**: name of the user-property
default: default value, will be retuned if user-property not found

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

response:

{"status": "success", "number-of-items": "50"} // or 100 if the property number-of-items was not found

#### `set-uproperty`

> logged-in user is required

**name**: name of the user-property
**value**: value of the user-property to set

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

response:

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

#### `get-gproperty`

> staff member is required

**name**: name of the global-property
default: default value, will be retuned if global-property not found

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

response:

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

#### `set-gproperty` - staff member is required

> staff member is required

**name**: name of the global-property
**value**: value of the global-property to set

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

returns

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


### More examples:

After creating an account on your website, the user needs to do some tasks before he can enter his profile. In this example adding more information and agreeing to the terms and conditions.

When creating the new user you create a new property:

from userproperty.utils import addProperty

addProperty(request, tag='setup')
# if the user is not saved in the request add: anUser=yourNewUser

In your login view you can now have different outcomes based on the UserProperty

from userproperty.utils import getIntegerProperty, setIntegerProperty, removeProperty

#in your login view

setupProperty = getIntegerProperty(request,'setup')

if setupProperty == 1:
#redirect, a form for adding phone number etc
elif setupProperty == 2:
#redirect, accepting the terms and conditions
elif setupProperty:
removeProperty(request, tag='setup')

# stuff when no property was set

The only thing left to do is setting the property to a new value when the respective actions(forms in this case) are done:

from userproperty.utils import setIntegerProperty, removeProperty

#in the view with the form for the phonenumer etc.
form.is_valid():
#do stuff

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

#redirect login


#in the view for terms and conditions
form.is_valid():
#do stuff

removeProperty(request, tag='setup')

#redirect login

Other examples: setup tour, saving user specific properties(number of data entries displayed in js datatables), etc.

## PEP8

The functions are available in pep8 (lowercase with _ as separator between words)

setIntegerProperty() ==> set_integer_property()

## Change Log

### 06/Aug/2015

* Propper anonymous users handling.
* ``decUserProperty`` and ``incUserProperty`` returns ``False`` instead of ``True`` for anonymous users or in case of errors.

Metadata

Release files for django-userproperty 1.0.8

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

Source distribution (sdist)

Source distribution for django-userproperty 1.0.8
File Size Uploaded
django-userproperty-1.0.8.tar.gz 8.2 kB Details

Release files / django-userproperty-1.0.8.tar.gz

Download URL django-userproperty-1.0.8.tar.gz
Size 8.2 kB
Tags Source
SHA-256 checksum
How to use checksums
e45dcd2ab77e418d5489a2ea8d1e3febbe8d1cf28b5097c1d50510cf154125f6
BLAKE2b-256 checksum
How to use checksums
f41a10c70f5c4a1863658f2cbbf43b94385f0c892f53088d9260962754f9273f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

1.0.8 This release

1 release file

1.0.5

1 release file

1.0.4

1 release file

1.0.3

1 release file

1.0.2

1 release file

1.0.1

1 release file

1.0.0

1 release file

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