cablegates/oxdb/oxuser/models.py

36 lines
1.1 KiB
Python
Raw Normal View History

2009-10-09 13:58:38 +00:00
# -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4
from django.db import models
from django.contrib.auth.models import User
class Group(models.Model):
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)
name = models.CharField(blank=True, max_length=255, unique=True)
users = models.ManyToManyField(User, related_name='groups')
class Preference(models.Model):
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)
user = models.ForeignKey(User, related_name='preferences')
key = models.CharField(blank=True, max_length=255)
value = models.TextField(blank=True)
2010-01-25 09:20:21 +00:00
def getPreference(user, key, value=None):
q = Preference.objects.filter(user=user, key=key)
if q.count() > 0:
value = json.loads(q[0].value)
return value
def setPreference(user, key, value):
value = json.dumps(value)
q = Preference.objects.filter(user=user, key=key)
if q.count() > 0:
q[0].value = value
else:
p = Preference(user=user, key=key, value=value)
p.save()