k4ever/k4ever/main/models.py

70 lines
2.4 KiB
Python
Raw Normal View History

2010-10-13 02:57:59 +02:00
from django.db import models
from django.db.models.signals import post_save
2010-10-13 02:57:59 +02:00
from django.contrib.auth.models import User
from decimal import Decimal
2010-10-13 02:57:59 +02:00
class UserProfile(models.Model):
2011-10-06 18:09:35 +02:00
""" Contains data for a user, especially the account balance. """
2010-10-13 02:57:59 +02:00
user = models.ForeignKey(User, unique=True)
balance = models.DecimalField(max_digits=9, decimal_places=2, default=Decimal(0))
def __unicode__(self):
2010-10-16 17:33:18 +02:00
return "%s (Kontostand: %s)" % (self.user ,self.balance)
def createUserProfile(sender, instance, created, **kwargs):
""" Hook to create a new :class:`UserProfile` when the user is created. """
if created:
profile = UserProfile()
profile.user = instance
profile.save()
post_save.connect(createUserProfile, sender=User)
2011-09-30 01:24:41 +02:00
class Plugin(models.Model):
2011-10-06 18:09:35 +02:00
""" This Model contains a plugin and its configuration.
A Plugin consists of its own information (name, author, version
and description, which are displayed on the plugin
selection page), a configuration of what a plugin is allowed to do
2011-10-06 18:09:35 +02:00
and what not and an own user for authentication against the
API.
:attr:`uniqueAuthblob` is used if the :class:`Plugin` has to uniquely
identify a user by his/her :attr:`authblob <PluginPermission.authblob>`.
2011-10-06 18:09:35 +02:00
The other attributes are used for plugin/user read/write access to the
authblob.
"""
2011-09-30 17:22:26 +02:00
user = models.ForeignKey(User, unique=True)
2011-09-30 22:29:02 +02:00
# plugin info
name = models.CharField(max_length=40)
2011-09-30 17:22:26 +02:00
author = models.CharField(max_length=40)
version = models.CharField(max_length=40)
descr = models.TextField(default='')
2011-09-30 22:29:02 +02:00
# plugin config
2011-09-30 02:15:53 +02:00
uniqueAuthblob = models.BooleanField(default=False)
2011-09-30 22:29:02 +02:00
userCanWriteAuthblob = models.BooleanField(default=True)
# automatically set when write is allowed
userCanReadAuthblob = models.BooleanField(default=True)
pluginCanWriteAuthblob = models.BooleanField(default=False)
pluginCanReadAuthblob = models.BooleanField(default=False)
2011-09-30 17:22:26 +02:00
def __unicode__(self):
return self.name
2011-09-30 01:24:41 +02:00
2011-09-30 17:22:26 +02:00
class PluginPermission(models.Model):
2011-10-06 18:09:35 +02:00
""" States that a user allows access to his/her account to a :class:`Plugin`.
The :attr:`authblob` can be used by the Plugin to store
authentication data, e.g. a barcode or hashed password.
"""
2011-09-30 17:22:26 +02:00
user = models.ForeignKey(User)
plugin = models.ForeignKey('Plugin')
2011-10-06 18:09:35 +02:00
#: authblob which holds arbitrary authentication data.
2011-09-30 22:29:02 +02:00
authblob = models.TextField(default='')
2011-09-30 17:22:26 +02:00
def __unicode__(self):
return "%s allows %s" % (self.user, self.plugin)