mirror of
https://github.com/evennia/evennia.git
synced 2026-03-23 00:06:30 +01:00
Moved permissions into a the tag system as a separate handler. Permissions still don't work quite right yet.
This commit is contained in:
parent
2acff2d1ab
commit
06e858b3f6
21 changed files with 1003 additions and 389 deletions
|
|
@ -508,10 +508,10 @@ class CmdPerm(MuxCommand):
|
|||
return
|
||||
|
||||
string = "Permissions on {w%s{n: " % obj.key
|
||||
if not obj.permissions:
|
||||
if not obj.permissions.all():
|
||||
string += "<None>"
|
||||
else:
|
||||
string += ", ".join(obj.permissions)
|
||||
string += ", ".join(obj.permissions.all())
|
||||
if hasattr(obj, 'player') and hasattr(obj.player, 'is_superuser') and obj.player.is_superuser:
|
||||
string += "\n(... but this object is currently controlled by a SUPERUSER! "
|
||||
string += "All access checks are passed automatically.)"
|
||||
|
|
@ -528,20 +528,12 @@ class CmdPerm(MuxCommand):
|
|||
tstring = ""
|
||||
if 'del' in switches:
|
||||
# delete the given permission(s) from object.
|
||||
for perm in self.rhslist:
|
||||
try:
|
||||
index = obj.permissions.index(perm)
|
||||
except ValueError:
|
||||
cstring += "\nPermission '%s' was not defined on %s." % (perm, obj.name)
|
||||
continue
|
||||
permissions = obj.permissions
|
||||
del permissions[index]
|
||||
obj.permissions = permissions
|
||||
cstring += "\nPermission '%s' was removed from %s." % (perm, obj.name)
|
||||
tstring += "\n%s revokes the permission '%s' from you." % (caller.name, perm)
|
||||
obj.permission.remove(self.rhslist)
|
||||
cstring += "\nPermission(s) %s removed from %s (if they existed)." % (", ".join(self.rhslist), obj.name)
|
||||
tstring += "\n%s revokes the permission(s) %s from you." % (caller.name, ", ".join(self.rhslist))
|
||||
else:
|
||||
# add a new permission
|
||||
permissions = obj.permissions
|
||||
permissions = obj.permissions.all()
|
||||
|
||||
for perm in self.rhslist:
|
||||
|
||||
|
|
@ -554,8 +546,7 @@ class CmdPerm(MuxCommand):
|
|||
if perm in permissions:
|
||||
cstring += "\nPermission '%s' is already defined on %s." % (rhs, obj.name)
|
||||
else:
|
||||
permissions.append(perm)
|
||||
obj.permissions = permissions
|
||||
obj.permissions.add(perm)
|
||||
cstring += "\nPermission '%s' given to %s." % (rhs, obj.name)
|
||||
tstring += "\n%s gives you the permission '%s'." % (caller.name, rhs)
|
||||
caller.msg(cstring.strip())
|
||||
|
|
|
|||
|
|
@ -1576,7 +1576,7 @@ class CmdExamine(ObjManipCommand):
|
|||
string += "\n{wsession(s){n: %s" % (", ".join(str(sess.sessid) for sess in obj.sessions))
|
||||
if hasattr(obj, "has_player") and obj.has_player:
|
||||
string += "\n{wPlayer{n: {c%s{n" % obj.player.name
|
||||
perms = obj.player.permissions
|
||||
perms = obj.player.permissions.all()
|
||||
if obj.player.is_superuser:
|
||||
perms = ["<Superuser>"]
|
||||
elif not perms:
|
||||
|
|
@ -1591,7 +1591,7 @@ class CmdExamine(ObjManipCommand):
|
|||
string += "\n{wDestination{n: %s" % obj.destination
|
||||
if obj.destination:
|
||||
string += " (#%s)" % obj.destination.id
|
||||
perms = obj.permissions
|
||||
perms = obj.permissions.all()
|
||||
if perms:
|
||||
perms_string = (", ".join(perms))
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -433,8 +433,8 @@ class CmdAccess(MuxCommand):
|
|||
cperms = "<Superuser>"
|
||||
pperms = "<Superuser>"
|
||||
else:
|
||||
cperms = ", ".join(caller.permissions)
|
||||
pperms = ", ".join(caller.player.permissions)
|
||||
cperms = ", ".join(caller.permissions.all())
|
||||
pperms = ", ".join(caller.player.permissions.all())
|
||||
|
||||
string += "\n{wYour access{n:"
|
||||
string += "\nCharacter {c%s{n: %s" % (caller.key, cperms)
|
||||
|
|
|
|||
|
|
@ -110,12 +110,12 @@ class CmdOOCLook(MuxPlayerCommand):
|
|||
sess = player.get_session(csessid)
|
||||
sid = sess in sessions and sessions.index(sess) + 1
|
||||
if sess and sid:
|
||||
string += "\n - {G%s{n [%s] (played by you in session %i)" % (char.key, ", ".join(char.permissions), sid)
|
||||
string += "\n - {G%s{n [%s] (played by you in session %i)" % (char.key, ", ".join(char.permissions.all()), sid)
|
||||
else:
|
||||
string += "\n - {R%s{n [%s] (played by someone else)" % (char.key, ", ".join(char.permissions))
|
||||
string += "\n - {R%s{n [%s] (played by someone else)" % (char.key, ", ".join(char.permissions.all()))
|
||||
else:
|
||||
# character is "free to puppet"
|
||||
string += "\n - %s [%s]" % (char.key, ", ".join(char.permissions))
|
||||
string += "\n - %s [%s]" % (char.key, ", ".join(char.permissions.all()))
|
||||
string = ("-" * 68) + "\n" + string + "\n" + ("-" * 68)
|
||||
self.msg(string)
|
||||
|
||||
|
|
@ -620,7 +620,7 @@ class CmdQuell(MuxPlayerCommand):
|
|||
def func(self):
|
||||
"Perform the command"
|
||||
player = self.caller
|
||||
permstr = player.is_superuser and " (superuser)" or " (%s)" % (", ".join(player.permissions))
|
||||
permstr = player.is_superuser and " (superuser)" or " (%s)" % (", ".join(player.permissions.all()))
|
||||
if self.cmdstring == '@unquell':
|
||||
if not player.get_attribute('_quell'):
|
||||
self.msg("Already using normal Player permissions%s." % permstr)
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ class CommandTest(TestCase):
|
|||
self.player = create.create_player("TestPlayer%i" % self.CID, "test@test.com", "testpassword", typeclass=TestPlayerClass)
|
||||
self.player2 = create.create_player("TestPlayer%ib" % self.CID, "test@test.com", "testpassword", typeclass=TestPlayerClass)
|
||||
|
||||
self.player.permissions = "Immortals"
|
||||
self.player.permissions.add("Immortals")
|
||||
self.char1.player = self.player
|
||||
self.char1.sessid = 1
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,54 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import datetime
|
||||
from south.db import db
|
||||
from south.v2 import SchemaMigration
|
||||
from django.db import models
|
||||
|
||||
|
||||
class Migration(SchemaMigration):
|
||||
|
||||
def forwards(self, orm):
|
||||
# Deleting field 'HelpEntry.db_permissions'
|
||||
db.delete_column(u'help_helpentry', 'db_permissions')
|
||||
|
||||
# Adding M2M table for field db_tags on 'HelpEntry'
|
||||
m2m_table_name = db.shorten_name(u'help_helpentry_db_tags')
|
||||
db.create_table(m2m_table_name, (
|
||||
('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
|
||||
('helpentry', models.ForeignKey(orm[u'help.helpentry'], null=False)),
|
||||
('tag', models.ForeignKey(orm[u'typeclasses.tag'], null=False))
|
||||
))
|
||||
db.create_unique(m2m_table_name, ['helpentry_id', 'tag_id'])
|
||||
|
||||
|
||||
def backwards(self, orm):
|
||||
# Adding field 'HelpEntry.db_permissions'
|
||||
db.add_column(u'help_helpentry', 'db_permissions',
|
||||
self.gf('django.db.models.fields.CharField')(default='', max_length=255, blank=True),
|
||||
keep_default=False)
|
||||
|
||||
# Removing M2M table for field db_tags on 'HelpEntry'
|
||||
db.delete_table(db.shorten_name(u'help_helpentry_db_tags'))
|
||||
|
||||
|
||||
models = {
|
||||
u'help.helpentry': {
|
||||
'Meta': {'object_name': 'HelpEntry'},
|
||||
'db_entrytext': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
|
||||
'db_help_category': ('django.db.models.fields.CharField', [], {'default': "'General'", 'max_length': '255'}),
|
||||
'db_key': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'}),
|
||||
'db_lock_storage': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
|
||||
'db_staff_only': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
|
||||
'db_tags': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['typeclasses.Tag']", 'null': 'True', 'symmetrical': 'False'}),
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
|
||||
},
|
||||
u'typeclasses.tag': {
|
||||
'Meta': {'unique_together': "(('db_key', 'db_category'),)", 'object_name': 'Tag', 'index_together': "(('db_key', 'db_category'),)"},
|
||||
'db_category': ('django.db.models.fields.CharField', [], {'max_length': '64', 'null': 'True', 'db_index': 'True'}),
|
||||
'db_data': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
|
||||
'db_key': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'db_index': 'True'}),
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
|
||||
}
|
||||
}
|
||||
|
||||
complete_apps = ['help']
|
||||
|
|
@ -13,6 +13,7 @@ from django.db import models
|
|||
from src.utils.idmapper.models import SharedMemoryModel
|
||||
from src.help.manager import HelpEntryManager
|
||||
from src.utils import ansi
|
||||
from src.typeclasses.models import Tag, TagHandler
|
||||
from src.locks.lockhandler import LockHandler
|
||||
from src.utils.utils import is_iter
|
||||
__all__ = ("HelpEntry",)
|
||||
|
|
@ -52,10 +53,11 @@ class HelpEntry(SharedMemoryModel):
|
|||
help_text='organizes help entries in lists')
|
||||
# the actual help entry text, in any formatting.
|
||||
db_entrytext = models.TextField('help entry', blank=True, help_text='the main body of help text')
|
||||
# a string of permissionstrings, separated by commas. Not used by help entries.
|
||||
db_permissions = models.CharField('permissions', max_length=255, blank=True)
|
||||
# lock string storage
|
||||
db_lock_storage = models.TextField('locks', blank=True, help_text='normally view:all().')
|
||||
# tags are primarily used for permissions
|
||||
db_tags = models.ManyToManyField(Tag, null=True,
|
||||
help_text='tags on this object. Tags are simple string markers to identify, group and alias objects.')
|
||||
# (deprecated, only here to allow MUX helpfile load (don't use otherwise)).
|
||||
# TODO: remove this when not needed anymore.
|
||||
db_staff_only = models.BooleanField(default=False)
|
||||
|
|
@ -66,6 +68,7 @@ class HelpEntry(SharedMemoryModel):
|
|||
def __init__(self, *args, **kwargs):
|
||||
SharedMemoryModel.__init__(self, *args, **kwargs)
|
||||
self.locks = LockHandler(self)
|
||||
self.tags = TagHandler(self)
|
||||
|
||||
class Meta:
|
||||
"Define Django meta options"
|
||||
|
|
@ -130,24 +133,24 @@ class HelpEntry(SharedMemoryModel):
|
|||
# self.save()
|
||||
#entrytext = property(__entrytext_get, __entrytext_set, __entrytext_del)
|
||||
|
||||
# permissions property
|
||||
#@property
|
||||
def __permissions_get(self):
|
||||
"Getter. Allows for value = self.permissions. Returns a list of permissions."
|
||||
return [perm.strip() for perm in self.db_permissions.split(',')]
|
||||
#@permissions.setter
|
||||
def __permissions_set(self, value):
|
||||
"Setter. Allows for self.permissions = value. Stores as a comma-separated string."
|
||||
if is_iter(value):
|
||||
value = ",".join([str(val).strip().lower() for val in value])
|
||||
self.db_permissions = value
|
||||
self.save()
|
||||
#@permissions.deleter
|
||||
def __permissions_del(self):
|
||||
"Deleter. Allows for del self.permissions"
|
||||
self.db_permissions = ""
|
||||
self.save()
|
||||
permissions = property(__permissions_get, __permissions_set, __permissions_del)
|
||||
## permissions property
|
||||
##@property
|
||||
#def __permissions_get(self):
|
||||
# "Getter. Allows for value = self.permissions. Returns a list of permissions."
|
||||
# return [perm.strip() for perm in self.db_permissions.split(',')]
|
||||
##@permissions.setter
|
||||
#def __permissions_set(self, value):
|
||||
# "Setter. Allows for self.permissions = value. Stores as a comma-separated string."
|
||||
# if is_iter(value):
|
||||
# value = ",".join([str(val).strip().lower() for val in value])
|
||||
# self.db_permissions = value
|
||||
# self.save()
|
||||
##@permissions.deleter
|
||||
#def __permissions_del(self):
|
||||
# "Deleter. Allows for del self.permissions"
|
||||
# self.db_permissions = ""
|
||||
# self.save()
|
||||
#permissions = property(__permissions_get, __permissions_set, __permissions_del)
|
||||
|
||||
# lock_storage property (wraps db_lock_storage)
|
||||
##@property
|
||||
|
|
|
|||
|
|
@ -146,13 +146,13 @@ def perm(accessing_obj, accessed_obj, *args, **kwargs):
|
|||
|
||||
try:
|
||||
perm = args[0].lower()
|
||||
perms_object = [p.lower() for p in accessing_obj.permissions]
|
||||
perms_object = [p.lower() for p in accessing_obj.permissions.all()]
|
||||
except (AttributeError, IndexError):
|
||||
return False
|
||||
|
||||
if utils.inherits_from(accessing_obj, "src.objects.objects.Object") and accessing_obj.player:
|
||||
player = accessing_obj.player
|
||||
perms_player = [p.lower() for p in player.permissions]
|
||||
perms_player = [p.lower() for p in player.permissions.all()]
|
||||
is_quell = player.get_attribute("_quell")
|
||||
|
||||
if perm in _PERMISSION_HIERARCHY:
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ Example:
|
|||
"Checking if the object has a particular, desired permission"
|
||||
if args:
|
||||
desired_perm = args[0]
|
||||
return desired_perm in accessing_obj.permissions
|
||||
return desired_perm in accessing_obj.permissions.all()
|
||||
return False
|
||||
|
||||
Lock functions should most often be pretty general and ideally possible to
|
||||
|
|
@ -429,7 +429,7 @@ def _test():
|
|||
|
||||
pdb.set_trace()
|
||||
obj1.locks = LockHandler(obj1)
|
||||
obj2.permissions = ["Immortals"]
|
||||
obj2.permissions.add("Immortals")
|
||||
obj2.id = 4
|
||||
|
||||
#obj1.locks.add("edit:attr(test)")
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ class TestLockCheck(LockTest):
|
|||
def testrun(self):
|
||||
dbref = self.obj2.dbref
|
||||
self.obj1.locks.add("owner:dbref(%s);edit:dbref(%s) or perm(Wizards);examine:perm(Builders) and id(%s);delete:perm(Wizards);get:all()" % (dbref, dbref, dbref))
|
||||
self.obj2.permissions = ['Wizards']
|
||||
self.obj2.permissions.add('Wizards')
|
||||
self.assertEquals(True, self.obj1.locks.check(self.obj2, 'owner'))
|
||||
self.assertEquals(True, self.obj1.locks.check(self.obj2, 'edit'))
|
||||
self.assertEquals(True, self.obj1.locks.check(self.obj2, 'examine'))
|
||||
|
|
@ -47,7 +47,7 @@ class TestLockCheck(LockTest):
|
|||
self.assertEquals(True, self.obj1.locks.check(self.obj2, 'not_exist', default=True))
|
||||
class TestLockfuncs(LockTest):
|
||||
def testrun(self):
|
||||
self.obj2.permissions = ['Wizards']
|
||||
self.obj2.permissions.add('Wizards')
|
||||
self.assertEquals(True, lockfuncs.true(self.obj2, self.obj1))
|
||||
self.assertEquals(False, lockfuncs.false(self.obj2, self.obj1))
|
||||
self.assertEquals(True, lockfuncs.perm(self.obj2, self.obj1, 'Wizards'))
|
||||
|
|
|
|||
|
|
@ -351,7 +351,7 @@ class ObjectManager(TypedObjectManager):
|
|||
if not new_locks:
|
||||
new_locks = original_object.db_lock_storage
|
||||
if not new_permissions:
|
||||
new_permissions = original_object.permissions
|
||||
new_permissions = original_object.permissions.all()
|
||||
if not new_destination:
|
||||
new_destination = original_object.destination
|
||||
|
||||
|
|
|
|||
108
src/objects/migrations/0024_move_permissions_to_handler.py
Normal file
108
src/objects/migrations/0024_move_permissions_to_handler.py
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import datetime
|
||||
from south.db import db
|
||||
from south.v2 import DataMigration
|
||||
from django.db import models
|
||||
|
||||
class Migration(DataMigration):
|
||||
|
||||
def forwards(self, orm):
|
||||
"Write your forwards methods here."
|
||||
# Note: Don't use "from appname.models import ModelName".
|
||||
# Use orm.ModelName to refer to models in this application,
|
||||
# and orm['appname.ModelName'] for models in other applications.
|
||||
|
||||
for obj in orm.ObjectDB.objects.all():
|
||||
if obj.db_permissions:
|
||||
for perm in [perm.strip() for perm in obj.db_permissions.split(",")]:
|
||||
tag = orm['typeclasses.Tag'].create(db_key=perm, db_category="permissions")
|
||||
tag.save()
|
||||
obj.db_tags.add(tag)
|
||||
|
||||
def backwards(self, orm):
|
||||
"Write your backwards methods here."
|
||||
|
||||
models = {
|
||||
u'auth.group': {
|
||||
'Meta': {'object_name': 'Group'},
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
|
||||
'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
|
||||
},
|
||||
u'auth.permission': {
|
||||
'Meta': {'ordering': "(u'content_type__app_label', u'content_type__model', u'codename')", 'unique_together': "((u'content_type', u'codename'),)", 'object_name': 'Permission'},
|
||||
'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
|
||||
'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['contenttypes.ContentType']"}),
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
|
||||
},
|
||||
u'contenttypes.contenttype': {
|
||||
'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
|
||||
'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
|
||||
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
|
||||
},
|
||||
u'objects.objectdb': {
|
||||
'Meta': {'object_name': 'ObjectDB'},
|
||||
'db_attributes': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['typeclasses.Attribute']", 'null': 'True', 'symmetrical': 'False'}),
|
||||
'db_cmdset_storage': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
|
||||
'db_date_created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
|
||||
'db_destination': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'destinations_set'", 'null': 'True', 'to': u"orm['objects.ObjectDB']"}),
|
||||
'db_home': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'homes_set'", 'null': 'True', 'to': u"orm['objects.ObjectDB']"}),
|
||||
'db_key': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}),
|
||||
'db_location': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'locations_set'", 'null': 'True', 'to': u"orm['objects.ObjectDB']"}),
|
||||
'db_lock_storage': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
|
||||
'db_permissions': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
|
||||
'db_player': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['players.PlayerDB']", 'null': 'True', 'blank': 'True'}),
|
||||
'db_sessid': ('django.db.models.fields.IntegerField', [], {'null': 'True'}),
|
||||
'db_tags': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['typeclasses.Tag']", 'null': 'True', 'symmetrical': 'False'}),
|
||||
'db_typeclass_path': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True'}),
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
|
||||
},
|
||||
u'players.playerdb': {
|
||||
'Meta': {'object_name': 'PlayerDB'},
|
||||
'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
|
||||
'db_attributes': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['typeclasses.Attribute']", 'null': 'True', 'symmetrical': 'False'}),
|
||||
'db_cmdset_storage': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True'}),
|
||||
'db_date_created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
|
||||
'db_is_connected': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
|
||||
'db_key': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}),
|
||||
'db_lock_storage': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
|
||||
'db_permissions': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
|
||||
'db_tags': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['typeclasses.Tag']", 'null': 'True', 'symmetrical': 'False'}),
|
||||
'db_typeclass_path': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True'}),
|
||||
'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
|
||||
'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
|
||||
'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
|
||||
'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
|
||||
'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
|
||||
'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
|
||||
'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
|
||||
'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
|
||||
'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
|
||||
'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
|
||||
},
|
||||
u'typeclasses.attribute': {
|
||||
'Meta': {'object_name': 'Attribute'},
|
||||
'db_category': ('django.db.models.fields.CharField', [], {'db_index': 'True', 'max_length': '128', 'null': 'True', 'blank': 'True'}),
|
||||
'db_date_created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
|
||||
'db_key': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
|
||||
'db_lock_storage': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
|
||||
'db_strvalue': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
|
||||
'db_value': ('src.utils.picklefield.PickledObjectField', [], {'null': 'True'}),
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
|
||||
},
|
||||
u'typeclasses.tag': {
|
||||
'Meta': {'unique_together': "(('db_key', 'db_category'),)", 'object_name': 'Tag', 'index_together': "(('db_key', 'db_category'),)"},
|
||||
'db_category': ('django.db.models.fields.CharField', [], {'max_length': '64', 'null': 'True', 'db_index': 'True'}),
|
||||
'db_data': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
|
||||
'db_key': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'db_index': 'True'}),
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
|
||||
}
|
||||
}
|
||||
|
||||
complete_apps = ['objects']
|
||||
symmetrical = True
|
||||
|
|
@ -0,0 +1,102 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import datetime
|
||||
from south.db import db
|
||||
from south.v2 import SchemaMigration
|
||||
from django.db import models
|
||||
|
||||
|
||||
class Migration(SchemaMigration):
|
||||
|
||||
def forwards(self, orm):
|
||||
# Deleting field 'ObjectDB.db_permissions'
|
||||
db.delete_column(u'objects_objectdb', 'db_permissions')
|
||||
|
||||
|
||||
def backwards(self, orm):
|
||||
# Adding field 'ObjectDB.db_permissions'
|
||||
db.add_column(u'objects_objectdb', 'db_permissions',
|
||||
self.gf('django.db.models.fields.CharField')(default='', max_length=255, blank=True),
|
||||
keep_default=False)
|
||||
|
||||
|
||||
models = {
|
||||
u'auth.group': {
|
||||
'Meta': {'object_name': 'Group'},
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
|
||||
'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
|
||||
},
|
||||
u'auth.permission': {
|
||||
'Meta': {'ordering': "(u'content_type__app_label', u'content_type__model', u'codename')", 'unique_together': "((u'content_type', u'codename'),)", 'object_name': 'Permission'},
|
||||
'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
|
||||
'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['contenttypes.ContentType']"}),
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
|
||||
},
|
||||
u'contenttypes.contenttype': {
|
||||
'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
|
||||
'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
|
||||
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
|
||||
},
|
||||
u'objects.objectdb': {
|
||||
'Meta': {'object_name': 'ObjectDB'},
|
||||
'db_attributes': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['typeclasses.Attribute']", 'null': 'True', 'symmetrical': 'False'}),
|
||||
'db_cmdset_storage': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
|
||||
'db_date_created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
|
||||
'db_destination': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'destinations_set'", 'null': 'True', 'to': u"orm['objects.ObjectDB']"}),
|
||||
'db_home': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'homes_set'", 'null': 'True', 'to': u"orm['objects.ObjectDB']"}),
|
||||
'db_key': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}),
|
||||
'db_location': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'locations_set'", 'null': 'True', 'to': u"orm['objects.ObjectDB']"}),
|
||||
'db_lock_storage': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
|
||||
'db_player': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['players.PlayerDB']", 'null': 'True', 'blank': 'True'}),
|
||||
'db_sessid': ('django.db.models.fields.IntegerField', [], {'null': 'True'}),
|
||||
'db_tags': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['typeclasses.Tag']", 'null': 'True', 'symmetrical': 'False'}),
|
||||
'db_typeclass_path': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True'}),
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
|
||||
},
|
||||
u'players.playerdb': {
|
||||
'Meta': {'object_name': 'PlayerDB'},
|
||||
'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
|
||||
'db_attributes': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['typeclasses.Attribute']", 'null': 'True', 'symmetrical': 'False'}),
|
||||
'db_cmdset_storage': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True'}),
|
||||
'db_date_created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
|
||||
'db_is_connected': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
|
||||
'db_key': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}),
|
||||
'db_lock_storage': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
|
||||
'db_tags': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['typeclasses.Tag']", 'null': 'True', 'symmetrical': 'False'}),
|
||||
'db_typeclass_path': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True'}),
|
||||
'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
|
||||
'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
|
||||
'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
|
||||
'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
|
||||
'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
|
||||
'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
|
||||
'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
|
||||
'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
|
||||
'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
|
||||
'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
|
||||
},
|
||||
u'typeclasses.attribute': {
|
||||
'Meta': {'object_name': 'Attribute'},
|
||||
'db_category': ('django.db.models.fields.CharField', [], {'db_index': 'True', 'max_length': '128', 'null': 'True', 'blank': 'True'}),
|
||||
'db_date_created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
|
||||
'db_key': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}),
|
||||
'db_lock_storage': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
|
||||
'db_strvalue': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
|
||||
'db_value': ('src.utils.picklefield.PickledObjectField', [], {'null': 'True'}),
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
|
||||
},
|
||||
u'typeclasses.tag': {
|
||||
'Meta': {'unique_together': "(('db_key', 'db_category'),)", 'object_name': 'Tag', 'index_together': "(('db_key', 'db_category'),)"},
|
||||
'db_category': ('django.db.models.fields.CharField', [], {'max_length': '64', 'null': 'True', 'db_index': 'True'}),
|
||||
'db_data': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
|
||||
'db_key': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'db_index': 'True'}),
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
|
||||
}
|
||||
}
|
||||
|
||||
complete_apps = ['objects']
|
||||
90
src/players/migrations/0027_move_permissions_to_handler.py
Normal file
90
src/players/migrations/0027_move_permissions_to_handler.py
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import datetime
|
||||
from south.db import db
|
||||
from south.v2 import DataMigration
|
||||
from django.db import models
|
||||
|
||||
class Migration(DataMigration):
|
||||
|
||||
def forwards(self, orm):
|
||||
"Write your forwards methods here."
|
||||
# Note: Don't use "from appname.models import ModelName".
|
||||
# Use orm.ModelName to refer to models in this application,
|
||||
# and orm['appname.ModelName'] for models in other applications.
|
||||
for obj in orm.PlayerDB.objects.all():
|
||||
if obj.db_permissions:
|
||||
for perm in [perm.strip() for perm in obj.db_permissions.split(",")]:
|
||||
tag = orm['typeclasses.Tag'].create(db_key=perm, db_category="permissions")
|
||||
tag.save()
|
||||
obj.db_tags.add(tag)
|
||||
|
||||
def backwards(self, orm):
|
||||
"Write your backwards methods here."
|
||||
|
||||
models = {
|
||||
u'auth.group': {
|
||||
'Meta': {'object_name': 'Group'},
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
|
||||
'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
|
||||
},
|
||||
u'auth.permission': {
|
||||
'Meta': {'ordering': "(u'content_type__app_label', u'content_type__model', u'codename')", 'unique_together': "((u'content_type', u'codename'),)", 'object_name': 'Permission'},
|
||||
'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
|
||||
'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['contenttypes.ContentType']"}),
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
|
||||
},
|
||||
u'contenttypes.contenttype': {
|
||||
'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
|
||||
'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
|
||||
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
|
||||
},
|
||||
u'players.playerdb': {
|
||||
'Meta': {'object_name': 'PlayerDB'},
|
||||
'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
|
||||
'db_attributes': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['typeclasses.Attribute']", 'null': 'True', 'symmetrical': 'False'}),
|
||||
'db_cmdset_storage': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True'}),
|
||||
'db_date_created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
|
||||
'db_is_connected': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
|
||||
'db_key': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}),
|
||||
'db_lock_storage': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
|
||||
'db_permissions': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
|
||||
'db_tags': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['typeclasses.Tag']", 'null': 'True', 'symmetrical': 'False'}),
|
||||
'db_typeclass_path': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True'}),
|
||||
'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
|
||||
'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
|
||||
'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
|
||||
'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
|
||||
'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
|
||||
'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
|
||||
'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
|
||||
'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
|
||||
'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
|
||||
'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
|
||||
},
|
||||
u'typeclasses.attribute': {
|
||||
'Meta': {'object_name': 'Attribute'},
|
||||
'db_category': ('django.db.models.fields.CharField', [], {'db_index': 'True', 'max_length': '128', 'null': 'True', 'blank': 'True'}),
|
||||
'db_date_created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
|
||||
'db_key': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
|
||||
'db_lock_storage': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
|
||||
'db_strvalue': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
|
||||
'db_value': ('src.utils.picklefield.PickledObjectField', [], {'null': 'True'}),
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
|
||||
},
|
||||
u'typeclasses.tag': {
|
||||
'Meta': {'unique_together': "(('db_key', 'db_category'),)", 'object_name': 'Tag', 'index_together': "(('db_key', 'db_category'),)"},
|
||||
'db_category': ('django.db.models.fields.CharField', [], {'max_length': '64', 'null': 'True', 'db_index': 'True'}),
|
||||
'db_data': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
|
||||
'db_key': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'db_index': 'True'}),
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
|
||||
}
|
||||
}
|
||||
|
||||
complete_apps = ['players']
|
||||
symmetrical = True
|
||||
|
|
@ -0,0 +1,86 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import datetime
|
||||
from south.db import db
|
||||
from south.v2 import SchemaMigration
|
||||
from django.db import models
|
||||
|
||||
|
||||
class Migration(SchemaMigration):
|
||||
|
||||
def forwards(self, orm):
|
||||
# Deleting field 'PlayerDB.db_permissions'
|
||||
db.delete_column(u'players_playerdb', 'db_permissions')
|
||||
|
||||
|
||||
def backwards(self, orm):
|
||||
# Adding field 'PlayerDB.db_permissions'
|
||||
db.add_column(u'players_playerdb', 'db_permissions',
|
||||
self.gf('django.db.models.fields.CharField')(default='', max_length=255, blank=True),
|
||||
keep_default=False)
|
||||
|
||||
|
||||
models = {
|
||||
u'auth.group': {
|
||||
'Meta': {'object_name': 'Group'},
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
|
||||
'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
|
||||
},
|
||||
u'auth.permission': {
|
||||
'Meta': {'ordering': "(u'content_type__app_label', u'content_type__model', u'codename')", 'unique_together': "((u'content_type', u'codename'),)", 'object_name': 'Permission'},
|
||||
'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
|
||||
'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['contenttypes.ContentType']"}),
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
|
||||
},
|
||||
u'contenttypes.contenttype': {
|
||||
'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
|
||||
'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
|
||||
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
|
||||
},
|
||||
u'players.playerdb': {
|
||||
'Meta': {'object_name': 'PlayerDB'},
|
||||
'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
|
||||
'db_attributes': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['typeclasses.Attribute']", 'null': 'True', 'symmetrical': 'False'}),
|
||||
'db_cmdset_storage': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True'}),
|
||||
'db_date_created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
|
||||
'db_is_connected': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
|
||||
'db_key': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}),
|
||||
'db_lock_storage': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
|
||||
'db_tags': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['typeclasses.Tag']", 'null': 'True', 'symmetrical': 'False'}),
|
||||
'db_typeclass_path': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True'}),
|
||||
'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
|
||||
'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
|
||||
'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
|
||||
'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
|
||||
'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
|
||||
'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
|
||||
'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
|
||||
'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
|
||||
'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
|
||||
'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
|
||||
},
|
||||
u'typeclasses.attribute': {
|
||||
'Meta': {'object_name': 'Attribute'},
|
||||
'db_category': ('django.db.models.fields.CharField', [], {'db_index': 'True', 'max_length': '128', 'null': 'True', 'blank': 'True'}),
|
||||
'db_date_created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
|
||||
'db_key': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}),
|
||||
'db_lock_storage': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
|
||||
'db_strvalue': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
|
||||
'db_value': ('src.utils.picklefield.PickledObjectField', [], {'null': 'True'}),
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
|
||||
},
|
||||
u'typeclasses.tag': {
|
||||
'Meta': {'unique_together': "(('db_key', 'db_category'),)", 'object_name': 'Tag', 'index_together': "(('db_key', 'db_category'),)"},
|
||||
'db_category': ('django.db.models.fields.CharField', [], {'max_length': '64', 'null': 'True', 'db_index': 'True'}),
|
||||
'db_data': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
|
||||
'db_key': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'db_index': 'True'}),
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
|
||||
}
|
||||
}
|
||||
|
||||
complete_apps = ['players']
|
||||
125
src/scripts/migrations/0015_move_permissions_to_handler.py
Normal file
125
src/scripts/migrations/0015_move_permissions_to_handler.py
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import datetime
|
||||
from south.db import db
|
||||
from south.v2 import DataMigration
|
||||
from django.db import models
|
||||
|
||||
class Migration(DataMigration):
|
||||
|
||||
def forwards(self, orm):
|
||||
"Write your forwards methods here."
|
||||
# Note: Don't use "from appname.models import ModelName".
|
||||
# Use orm.ModelName to refer to models in this application,
|
||||
# and orm['appname.ModelName'] for models in other applications.
|
||||
for obj in orm.ScriptDB.objects.all():
|
||||
if obj.db_permissions:
|
||||
for perm in [perm.strip() for perm in obj.db_permissions.split(",")]:
|
||||
tag = orm['typeclasses.Tag'].create(db_key=perm, db_category="permissions")
|
||||
tag.save()
|
||||
obj.db_tags.add(tag)
|
||||
|
||||
def backwards(self, orm):
|
||||
"Write your backwards methods here."
|
||||
|
||||
models = {
|
||||
u'auth.group': {
|
||||
'Meta': {'object_name': 'Group'},
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
|
||||
'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
|
||||
},
|
||||
u'auth.permission': {
|
||||
'Meta': {'ordering': "(u'content_type__app_label', u'content_type__model', u'codename')", 'unique_together': "((u'content_type', u'codename'),)", 'object_name': 'Permission'},
|
||||
'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
|
||||
'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['contenttypes.ContentType']"}),
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
|
||||
},
|
||||
u'contenttypes.contenttype': {
|
||||
'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
|
||||
'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
|
||||
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
|
||||
},
|
||||
u'objects.objectdb': {
|
||||
'Meta': {'object_name': 'ObjectDB'},
|
||||
'db_attributes': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['typeclasses.Attribute']", 'null': 'True', 'symmetrical': 'False'}),
|
||||
'db_cmdset_storage': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
|
||||
'db_date_created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
|
||||
'db_destination': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'destinations_set'", 'null': 'True', 'to': u"orm['objects.ObjectDB']"}),
|
||||
'db_home': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'homes_set'", 'null': 'True', 'to': u"orm['objects.ObjectDB']"}),
|
||||
'db_key': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}),
|
||||
'db_location': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'locations_set'", 'null': 'True', 'to': u"orm['objects.ObjectDB']"}),
|
||||
'db_lock_storage': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
|
||||
'db_permissions': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
|
||||
'db_player': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['players.PlayerDB']", 'null': 'True', 'blank': 'True'}),
|
||||
'db_sessid': ('django.db.models.fields.IntegerField', [], {'null': 'True'}),
|
||||
'db_tags': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['typeclasses.Tag']", 'null': 'True', 'symmetrical': 'False'}),
|
||||
'db_typeclass_path': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True'}),
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
|
||||
},
|
||||
u'players.playerdb': {
|
||||
'Meta': {'object_name': 'PlayerDB'},
|
||||
'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
|
||||
'db_attributes': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['typeclasses.Attribute']", 'null': 'True', 'symmetrical': 'False'}),
|
||||
'db_cmdset_storage': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True'}),
|
||||
'db_date_created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
|
||||
'db_is_connected': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
|
||||
'db_key': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}),
|
||||
'db_lock_storage': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
|
||||
'db_permissions': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
|
||||
'db_tags': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['typeclasses.Tag']", 'null': 'True', 'symmetrical': 'False'}),
|
||||
'db_typeclass_path': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True'}),
|
||||
'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
|
||||
'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
|
||||
'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
|
||||
'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
|
||||
'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
|
||||
'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
|
||||
'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
|
||||
'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
|
||||
'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
|
||||
'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
|
||||
},
|
||||
u'scripts.scriptdb': {
|
||||
'Meta': {'object_name': 'ScriptDB'},
|
||||
'db_attributes': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['typeclasses.Attribute']", 'null': 'True', 'symmetrical': 'False'}),
|
||||
'db_date_created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
|
||||
'db_desc': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
|
||||
'db_interval': ('django.db.models.fields.IntegerField', [], {'default': '-1'}),
|
||||
'db_is_active': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
|
||||
'db_key': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}),
|
||||
'db_lock_storage': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
|
||||
'db_obj': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['objects.ObjectDB']", 'null': 'True', 'blank': 'True'}),
|
||||
'db_permissions': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
|
||||
'db_persistent': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
|
||||
'db_repeats': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
|
||||
'db_start_delay': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
|
||||
'db_tags': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['typeclasses.Tag']", 'null': 'True', 'symmetrical': 'False'}),
|
||||
'db_typeclass_path': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True'}),
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
|
||||
},
|
||||
u'typeclasses.attribute': {
|
||||
'Meta': {'object_name': 'Attribute'},
|
||||
'db_category': ('django.db.models.fields.CharField', [], {'db_index': 'True', 'max_length': '128', 'null': 'True', 'blank': 'True'}),
|
||||
'db_date_created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
|
||||
'db_key': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
|
||||
'db_lock_storage': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
|
||||
'db_strvalue': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
|
||||
'db_value': ('src.utils.picklefield.PickledObjectField', [], {'null': 'True'}),
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
|
||||
},
|
||||
u'typeclasses.tag': {
|
||||
'Meta': {'unique_together': "(('db_key', 'db_category'),)", 'object_name': 'Tag', 'index_together': "(('db_key', 'db_category'),)"},
|
||||
'db_category': ('django.db.models.fields.CharField', [], {'max_length': '64', 'null': 'True', 'db_index': 'True'}),
|
||||
'db_data': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
|
||||
'db_key': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'db_index': 'True'}),
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
|
||||
}
|
||||
}
|
||||
|
||||
complete_apps = ['scripts']
|
||||
symmetrical = True
|
||||
|
|
@ -0,0 +1,119 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import datetime
|
||||
from south.db import db
|
||||
from south.v2 import SchemaMigration
|
||||
from django.db import models
|
||||
|
||||
|
||||
class Migration(SchemaMigration):
|
||||
|
||||
def forwards(self, orm):
|
||||
# Deleting field 'ScriptDB.db_permissions'
|
||||
db.delete_column(u'scripts_scriptdb', 'db_permissions')
|
||||
|
||||
|
||||
def backwards(self, orm):
|
||||
# Adding field 'ScriptDB.db_permissions'
|
||||
db.add_column(u'scripts_scriptdb', 'db_permissions',
|
||||
self.gf('django.db.models.fields.CharField')(default='', max_length=255, blank=True),
|
||||
keep_default=False)
|
||||
|
||||
|
||||
models = {
|
||||
u'auth.group': {
|
||||
'Meta': {'object_name': 'Group'},
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
|
||||
'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
|
||||
},
|
||||
u'auth.permission': {
|
||||
'Meta': {'ordering': "(u'content_type__app_label', u'content_type__model', u'codename')", 'unique_together': "((u'content_type', u'codename'),)", 'object_name': 'Permission'},
|
||||
'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
|
||||
'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['contenttypes.ContentType']"}),
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
|
||||
},
|
||||
u'contenttypes.contenttype': {
|
||||
'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
|
||||
'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
|
||||
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
|
||||
},
|
||||
u'objects.objectdb': {
|
||||
'Meta': {'object_name': 'ObjectDB'},
|
||||
'db_attributes': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['typeclasses.Attribute']", 'null': 'True', 'symmetrical': 'False'}),
|
||||
'db_cmdset_storage': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
|
||||
'db_date_created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
|
||||
'db_destination': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'destinations_set'", 'null': 'True', 'to': u"orm['objects.ObjectDB']"}),
|
||||
'db_home': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'homes_set'", 'null': 'True', 'to': u"orm['objects.ObjectDB']"}),
|
||||
'db_key': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}),
|
||||
'db_location': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'locations_set'", 'null': 'True', 'to': u"orm['objects.ObjectDB']"}),
|
||||
'db_lock_storage': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
|
||||
'db_player': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['players.PlayerDB']", 'null': 'True', 'blank': 'True'}),
|
||||
'db_sessid': ('django.db.models.fields.IntegerField', [], {'null': 'True'}),
|
||||
'db_tags': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['typeclasses.Tag']", 'null': 'True', 'symmetrical': 'False'}),
|
||||
'db_typeclass_path': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True'}),
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
|
||||
},
|
||||
u'players.playerdb': {
|
||||
'Meta': {'object_name': 'PlayerDB'},
|
||||
'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
|
||||
'db_attributes': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['typeclasses.Attribute']", 'null': 'True', 'symmetrical': 'False'}),
|
||||
'db_cmdset_storage': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True'}),
|
||||
'db_date_created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
|
||||
'db_is_connected': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
|
||||
'db_key': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}),
|
||||
'db_lock_storage': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
|
||||
'db_tags': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['typeclasses.Tag']", 'null': 'True', 'symmetrical': 'False'}),
|
||||
'db_typeclass_path': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True'}),
|
||||
'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
|
||||
'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
|
||||
'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
|
||||
'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
|
||||
'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
|
||||
'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
|
||||
'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
|
||||
'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
|
||||
'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
|
||||
'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
|
||||
},
|
||||
u'scripts.scriptdb': {
|
||||
'Meta': {'object_name': 'ScriptDB'},
|
||||
'db_attributes': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['typeclasses.Attribute']", 'null': 'True', 'symmetrical': 'False'}),
|
||||
'db_date_created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
|
||||
'db_desc': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
|
||||
'db_interval': ('django.db.models.fields.IntegerField', [], {'default': '-1'}),
|
||||
'db_is_active': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
|
||||
'db_key': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}),
|
||||
'db_lock_storage': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
|
||||
'db_obj': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['objects.ObjectDB']", 'null': 'True', 'blank': 'True'}),
|
||||
'db_persistent': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
|
||||
'db_repeats': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
|
||||
'db_start_delay': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
|
||||
'db_tags': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['typeclasses.Tag']", 'null': 'True', 'symmetrical': 'False'}),
|
||||
'db_typeclass_path': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True'}),
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
|
||||
},
|
||||
u'typeclasses.attribute': {
|
||||
'Meta': {'object_name': 'Attribute'},
|
||||
'db_category': ('django.db.models.fields.CharField', [], {'db_index': 'True', 'max_length': '128', 'null': 'True', 'blank': 'True'}),
|
||||
'db_date_created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
|
||||
'db_key': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}),
|
||||
'db_lock_storage': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
|
||||
'db_strvalue': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
|
||||
'db_value': ('src.utils.picklefield.PickledObjectField', [], {'null': 'True'}),
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
|
||||
},
|
||||
u'typeclasses.tag': {
|
||||
'Meta': {'unique_together': "(('db_key', 'db_category'),)", 'object_name': 'Tag', 'index_together': "(('db_key', 'db_category'),)"},
|
||||
'db_category': ('django.db.models.fields.CharField', [], {'max_length': '64', 'null': 'True', 'db_index': 'True'}),
|
||||
'db_data': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
|
||||
'db_key': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'db_index': 'True'}),
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
|
||||
}
|
||||
}
|
||||
|
||||
complete_apps = ['scripts']
|
||||
|
|
@ -69,7 +69,7 @@ def create_objects():
|
|||
god_character.id = 1
|
||||
god_character.db.desc = _('This is User #1.')
|
||||
god_character.locks.add("examine:perm(Immortals);edit:false();delete:false();boot:false();msg:all();puppet:false()")
|
||||
god_character.permissions = "Immortals"
|
||||
god_character.permissions.add("Immortals")
|
||||
|
||||
god_character.save()
|
||||
god_player.set_attribute("_first_login", True)
|
||||
|
|
|
|||
|
|
@ -99,7 +99,6 @@ class TagManager(models.Manager):
|
|||
"""
|
||||
Get all tags on obj, optionally limited by key and/or category
|
||||
"""
|
||||
print "Key: %s, Category: %s" % (key, category)
|
||||
tags = _GA(obj, "db_tags").all()
|
||||
if key:
|
||||
tags = tags.filter(db_key__iexact=key.lower().strip())
|
||||
|
|
@ -153,10 +152,10 @@ class TagManager(models.Manager):
|
|||
tag.save()
|
||||
elif not tag:
|
||||
tag = self.create(db_key=key.lower().strip() if key!=None else None,
|
||||
db_category=category.lower().strip() if key!=None else None,
|
||||
db_category=category.lower().strip() if category and key!=None else None,
|
||||
db_data=str(data) if data!=None else None)
|
||||
tag.save()
|
||||
return tag
|
||||
return make_iter(tag)[0]
|
||||
|
||||
#
|
||||
# helper functions for the TypedObjectManager.
|
||||
|
|
|
|||
|
|
@ -101,7 +101,7 @@ class Attribute(SharedMemoryModel):
|
|||
#
|
||||
# These database fields are all set using their corresponding properties,
|
||||
# named same as the field, but withtout the db_* prefix.
|
||||
db_key = models.CharField('key', max_length=255)
|
||||
db_key = models.CharField('key', max_length=255, db_index=True)
|
||||
# access through the value property
|
||||
db_value = PickledObjectField('value', null=True)
|
||||
# string-specific storage for quick look-up
|
||||
|
|
@ -499,13 +499,15 @@ class TagHandler(object):
|
|||
|
||||
def add(self, tag, category=None, data=None):
|
||||
"Add a new tag to the handler. Tag is a string or a list of strings."
|
||||
for tag in make_iter(tag):
|
||||
tag = tag.strip().lower() if tag!=None else None
|
||||
for tagstr in make_iter(tag):
|
||||
tagstr = tagstr.strip().lower() if tagstr!=None else None
|
||||
category = "%s%s" % (self.prefix, category.strip().lower()) if category!=None else None
|
||||
data = str(data) if data!=None else None
|
||||
# this will only create tag if no matches existed beforehand (it will overload
|
||||
# data on an existing tag since that is not considered part of making the tag unique)
|
||||
tagobj = Tag.objects.create_tag(key=tag, category=category, data=data)
|
||||
tagobj = Tag.objects.create_tag(key=tagstr, category=category, data=data)
|
||||
print tagstr
|
||||
print tagobj
|
||||
_GA(self.obj, self._m2m_fieldname).add(tagobj)
|
||||
|
||||
def get(self, key, category="", return_obj=False):
|
||||
|
|
@ -591,8 +593,8 @@ class TypedObject(SharedMemoryModel):
|
|||
# Creation date. This is not changed once the object is created.
|
||||
db_date_created = models.DateTimeField('creation date', editable=False, auto_now_add=True)
|
||||
# Permissions (access these through the 'permissions' property)
|
||||
db_permissions = models.CharField('permissions', max_length=255, blank=True,
|
||||
help_text="a comma-separated list of text strings checked by in-game locks. They are often used for hierarchies, such as letting a Player have permission 'Wizards', 'Builders' etc. Character objects use 'Players' by default. Most other objects don't have any permissions.")
|
||||
#db_permissions = models.CharField('permissions', max_length=255, blank=True,
|
||||
# help_text="a comma-separated list of text strings checked by in-game locks. They are often used for hierarchies, such as letting a Player have permission 'Wizards', 'Builders' etc. Character objects use 'Players' by default. Most other objects don't have any permissions.")
|
||||
# Lock storage
|
||||
db_lock_storage = models.TextField('locks', blank=True,
|
||||
help_text="locks limit access to an entity. A lock is defined as a 'lock string' on the form 'type:lockfunctions', defining what functionality is locked and how to determine access. Not defining a lock means no access is granted.")
|
||||
|
|
@ -615,6 +617,7 @@ class TypedObject(SharedMemoryModel):
|
|||
#SharedMemoryModel.__init__(self, *args, **kwargs)
|
||||
_SA(self, "dbobj", self) # this allows for self-reference
|
||||
_SA(self, "locks", LockHandler(self))
|
||||
_SA(self, "permissions", PermissionHandler(self))
|
||||
|
||||
class Meta:
|
||||
"""
|
||||
|
|
@ -690,24 +693,24 @@ class TypedObject(SharedMemoryModel):
|
|||
|
||||
# permissions property
|
||||
#@property
|
||||
def __permissions_get(self):
|
||||
"Getter. Allows for value = self.name. Returns a list of permissions."
|
||||
perms = get_field_cache(self, "permissions")
|
||||
if perms:
|
||||
return [perm.strip() for perm in perms.split(',')]
|
||||
return []
|
||||
#@permissions.setter
|
||||
def __permissions_set(self, value):
|
||||
"Setter. Allows for self.name = value. Stores as a comma-separated string."
|
||||
value = ",".join([utils.to_unicode(val).strip() for val in make_iter(value)])
|
||||
set_field_cache(self, "permissions", value)
|
||||
#@permissions.deleter
|
||||
def __permissions_del(self):
|
||||
"Deleter. Allows for del self.name"
|
||||
self.db_permissions = ""
|
||||
self.save()
|
||||
del_field_cache(self, "permissions")
|
||||
permissions = property(__permissions_get, __permissions_set, __permissions_del)
|
||||
#def __permissions_get(self):
|
||||
# "Getter. Allows for value = self.name. Returns a list of permissions."
|
||||
# perms = get_field_cache(self, "permissions")
|
||||
# if perms:
|
||||
# return [perm.strip() for perm in perms.split(',')]
|
||||
# return []
|
||||
##@permissions.setter
|
||||
#def __permissions_set(self, value):
|
||||
# "Setter. Allows for self.name = value. Stores as a comma-separated string."
|
||||
# value = ",".join([utils.to_unicode(val).strip() for val in make_iter(value)])
|
||||
# set_field_cache(self, "permissions", value)
|
||||
##@permissions.deleter
|
||||
#def __permissions_del(self):
|
||||
# "Deleter. Allows for del self.name"
|
||||
# self.db_permissions = ""
|
||||
# self.save()
|
||||
# del_field_cache(self, "permissions")
|
||||
#permissions = property(__permissions_get, __permissions_set, __permissions_del)
|
||||
|
||||
# lock_storage property (wraps db_lock_storage)
|
||||
#@property
|
||||
|
|
@ -1083,293 +1086,56 @@ class TypedObject(SharedMemoryModel):
|
|||
return True
|
||||
|
||||
#
|
||||
# Attribute handler methods
|
||||
# Lock / permission methods
|
||||
#
|
||||
|
||||
#
|
||||
# Fully attr_obj attributes. You usually access these
|
||||
# through the obj.db.attrname method.
|
||||
|
||||
# Helper methods for attr_obj attributes
|
||||
|
||||
def has_attribute(self, attribute_name):
|
||||
def access(self, accessing_obj, access_type='read', default=False):
|
||||
"""
|
||||
See if we have an attribute set on the object.
|
||||
|
||||
attribute_name: (str) The attribute's name.
|
||||
Determines if another object has permission to access.
|
||||
accessing_obj - object trying to access this one
|
||||
access_type - type of access sought
|
||||
default - what to return if no lock of access_type was found
|
||||
"""
|
||||
return _GA(self, "attributes").has(attribute_name)
|
||||
return self.locks.check(accessing_obj, access_type=access_type, default=default)
|
||||
|
||||
#if not get_attr_cache(self, attribute_name):
|
||||
# attr_obj = _GA(self, "db_attributes").filter(db_key__iexact=attribute_name)
|
||||
# if attr_obj:
|
||||
# set_attr_cache(self, attribute_name, attr_obj[0])
|
||||
# else:
|
||||
# return False
|
||||
#return True
|
||||
|
||||
def set_attribute(self, attribute_name, new_value=None, lockstring=""):
|
||||
def check_permstring(self, permstring):
|
||||
"""
|
||||
Sets an attribute on an object. Creates the attribute if need
|
||||
be.
|
||||
|
||||
attribute_name: (str) The attribute's name.
|
||||
new_value: (python obj) The value to set the attribute to. If this is not
|
||||
a str, the object will be stored as a pickle.
|
||||
lockstring - this sets an access restriction on the attribute object. Note that
|
||||
this is normally NOT checked - use the secureattr() access method
|
||||
below to perform access-checked modification of attributes. Lock
|
||||
types checked by secureattr are 'attrread','attredit','attrcreate'.
|
||||
This explicitly checks if we hold particular permission without involving
|
||||
any locks.
|
||||
"""
|
||||
_GA(self, "attributes").add(attribute_name, new_value, lockstring=lockstring)
|
||||
#
|
||||
|
||||
#attr_obj = get_attr_cache(self, attribute_name)
|
||||
#if not attr_obj:
|
||||
# # check if attribute already exists
|
||||
# attr_obj = _GA(self, "db_attributes").filter(db_key__iexact=attribute_name)
|
||||
# if attr_obj:
|
||||
# # re-use old attribute object
|
||||
# attr_obj = attr_obj[0]
|
||||
# set_attr_cache(self, attribute_name, attr_obj) # renew cache
|
||||
# else:
|
||||
# # no old attr available; create new (caches automatically)
|
||||
# attr_obj = Attribute(db_key=attribute_name)
|
||||
# attr_obj.save() # important
|
||||
# _GA(self, "db_attributes").add(attr_obj)
|
||||
#if lockstring:
|
||||
# attr_obj.locks.add(lockstring)
|
||||
## we shouldn't need to fear stale objects, the signalling should catch all cases
|
||||
#attr_obj.value = new_value
|
||||
|
||||
def get_attribute_obj(self, attribute_name, default=None):
|
||||
"""
|
||||
Get the actual attribute object named attribute_name
|
||||
"""
|
||||
return _GA(self, "attributes").get(attribute_name, default=default, return_obj=True)
|
||||
#attr_obj = get_attr_cache(self, attribute_name)
|
||||
#if not attr_obj:
|
||||
# attr_obj = _GA(self, "db_attributes").filter(db_key__iexact=attribute_name)
|
||||
# if not attr_obj:
|
||||
# return default
|
||||
# attr_obj = attr_obj[0] # query evaluated here
|
||||
# set_attr_cache(self, attribute_name, attr_obj)
|
||||
#return attr_obj
|
||||
|
||||
def get_attribute(self, attribute_name, default=None, raise_exception=False):
|
||||
"""
|
||||
Returns the value of an attribute on an object. You may need to
|
||||
type cast the returned value from this function since the attribute
|
||||
can be of any type. Returns default if no match is found.
|
||||
|
||||
attribute_name: (str) The attribute's name.
|
||||
default: What to return if no attribute is found
|
||||
raise_exception (bool) - raise an exception if no object exists instead of returning default.
|
||||
"""
|
||||
return _GA(self, "attributes").get(attribute_name, default=default, raise_exception=raise_exception)
|
||||
#attr_obj = get_attr_cache(self, attribute_name)
|
||||
#if not attr_obj:
|
||||
# attr_obj = _GA(self, "db_attributes").filter(db_key__iexact=attribute_name)
|
||||
# if not attr_obj:
|
||||
# if raise_exception:
|
||||
# raise AttributeError
|
||||
# return default
|
||||
# attr_obj = attr_obj[0] # query is evaluated here
|
||||
# set_attr_cache(self, attribute_name, attr_obj)
|
||||
#return attr_obj.value
|
||||
|
||||
def del_attribute(self, attribute_name, raise_exception=False):
|
||||
"""
|
||||
Removes an attribute entirely.
|
||||
|
||||
attribute_name: (str) The attribute's name.
|
||||
raise_exception (bool) - raise exception if attribute to delete
|
||||
could not be found
|
||||
"""
|
||||
_GA(self, "attributes").remove(attribute_name, raise_exception=raise_exception)
|
||||
#attr_obj = get_attr_cache(self, attribute_name)
|
||||
#if not attr_obj:
|
||||
# attr_obj = _GA(self, "db_attributes").filter(db_key__iexact=attribute_name)
|
||||
# attr_obj = attr_obj[0] if attr_obj else None
|
||||
#if not attr_obj:
|
||||
# if raise_exception:
|
||||
# raise AttributeError
|
||||
# return
|
||||
## the post-remove cache signal will auto-delete the attribute as well,
|
||||
## don't call attr_obj.delete() after this.
|
||||
#self.db_attributes.remove(attr_obj)
|
||||
|
||||
def get_all_attributes(self):
|
||||
"""
|
||||
Returns all attributes defined on the object.
|
||||
"""
|
||||
return _GA(self, "attributes").all()
|
||||
#return list(_GA(self, "db_attributes").all())
|
||||
|
||||
def attr(self, attribute_name=None, value=None, delete=False):
|
||||
"""
|
||||
This is a convenient wrapper for
|
||||
get_attribute, set_attribute, del_attribute
|
||||
and get_all_attributes.
|
||||
If value is None, attr will act like
|
||||
a getter, otherwise as a setter.
|
||||
set delete=True to delete the named attribute.
|
||||
|
||||
Note that you cannot set the attribute
|
||||
value to None using this method. Use set_attribute.
|
||||
"""
|
||||
if attribute_name == None:
|
||||
# act as a list method
|
||||
return self.get_all_attributes()
|
||||
elif delete == True:
|
||||
self.del_attribute(attribute_name)
|
||||
elif value == None:
|
||||
# act as a getter.
|
||||
return self.get_attribute(attribute_name)
|
||||
if hasattr(self, "player"):
|
||||
if self.player and self.player.is_superuser: return True
|
||||
else:
|
||||
# act as a setter
|
||||
self.set_attribute(attribute_name, value)
|
||||
if self.is_superuser: return True
|
||||
|
||||
def secure_attr(self, accessing_object, attribute_name=None, value=None, delete=False,
|
||||
default_access_read=True, default_access_edit=True, default_access_create=True):
|
||||
if not permstring:
|
||||
return False
|
||||
perm = permstring.lower()
|
||||
perms = [p.lower() for p in self.permissions.all()]
|
||||
if perm in perms:
|
||||
# simplest case - we have a direct match
|
||||
return True
|
||||
if perm in _PERMISSION_HIERARCHY:
|
||||
# check if we have a higher hierarchy position
|
||||
ppos = _PERMISSION_HIERARCHY.index(perm)
|
||||
return any(True for hpos, hperm in enumerate(_PERMISSION_HIERARCHY)
|
||||
if hperm in perms and hpos > ppos)
|
||||
return False
|
||||
|
||||
|
||||
def flush_from_cache(self):
|
||||
"""
|
||||
This is a version of attr that requires the accessing object
|
||||
as input and will use that to check eventual access locks on
|
||||
the Attribute before allowing any changes or reads.
|
||||
|
||||
In the cases when this method wouldn't return, it will return
|
||||
True for a successful operation, None otherwise.
|
||||
|
||||
locktypes checked on the Attribute itself:
|
||||
attrread - control access to reading the attribute value
|
||||
attredit - control edit/delete access
|
||||
locktype checked on the object on which the Attribute is/will be stored:
|
||||
attrcreate - control attribute create access (this is checked *on the object* not on the Attribute!)
|
||||
|
||||
default_access_* defines which access is assumed if no
|
||||
suitable lock is defined on the Atttribute.
|
||||
|
||||
Flush this object instance from cache, forcing an object reload. Note that this
|
||||
will kill all temporary attributes on this object since it will be recreated
|
||||
as a new Typeclass instance.
|
||||
"""
|
||||
if attribute_name == None:
|
||||
return _GA(self, "attributes").all(accessing_obj=accessing_object, default_access=default_access_read)
|
||||
# act as list method, but check access
|
||||
#return [attr for attr in self.get_all_attributes()
|
||||
# if attr.access(accessing_object, "attread", default=default_access_read)]
|
||||
elif delete == True:
|
||||
# act as deleter
|
||||
_GA(self, "attributes").remove(attribute_name, accessing_obj=accessing_object, default_access=default_access_edit)
|
||||
#attr = self.get_attribute_obj(attribute_name)
|
||||
#if attr and attr.access(accessing_object, "attredit", default=default_access_edit):
|
||||
# self.del_attribute(attribute_name)
|
||||
# return True
|
||||
elif value == None:
|
||||
# act as getter
|
||||
return _GA(self, "attributes").get(attribute_name, accessing_obj=accessing_object, default_access=default_access_read)
|
||||
#attr = self.get_attribute_obj(attribute_name)
|
||||
#if attr and attr.access(accessing_object, "attrread", default=default_access_read):
|
||||
# return attr.value
|
||||
else:
|
||||
# act as setter
|
||||
attr = self.get_attribute_obj(attribute_name)
|
||||
if attr:
|
||||
# attribute already exists
|
||||
_GA(self, "attributes").add(attribute_name, value, accessing_obj=accessing_object, default_access=default_access_edit)
|
||||
#if attr.access(accessing_object, "attredit", default=default_access_edit):
|
||||
# self.set_attribute(attribute_name, value)
|
||||
# return True
|
||||
else:
|
||||
# creating a new attribute - check access on storing object!
|
||||
_GA(self, "attributes").add(attribute_name, value, accessing_obj=accessing_object, default_access=default_access_create)
|
||||
#if self.access(accessing_object, "attrcreate", default=default_access_create):
|
||||
# self.set_attribute(attribute_name, value)
|
||||
# return True
|
||||
|
||||
#@property
|
||||
def __db_get(self):
|
||||
"""
|
||||
A second convenience wrapper for the the attribute methods. It
|
||||
allows for the syntax
|
||||
obj.db.attrname = value
|
||||
and
|
||||
value = obj.db.attrname
|
||||
and
|
||||
del obj.db.attrname
|
||||
and
|
||||
all_attr = obj.db.all (unless there is no attribute named 'all', in which
|
||||
case that will be returned instead).
|
||||
"""
|
||||
try:
|
||||
return self._db_holder
|
||||
except AttributeError:
|
||||
class DbHolder(object):
|
||||
"Holder for allowing property access of attributes"
|
||||
def __init__(self, obj):
|
||||
_SA(self, 'obj', obj)
|
||||
def __getattribute__(self, attrname):
|
||||
if attrname == 'all':
|
||||
# we allow to overload our default .all
|
||||
attr = _GA(_GA(self, "obj"), "attributes").get("all")
|
||||
#attr = _GA(self, 'obj').get_attribute("all")
|
||||
if attr:
|
||||
return attr
|
||||
return _GA(self, 'all')
|
||||
return _GA(_GA(self, "obj"), "attributes").get(attrname)
|
||||
#return _GA(self, 'obj').get_attribute(attrname)
|
||||
def __setattr__(self, attrname, value):
|
||||
_GA(_GA(self, "obj"), "attributes").add(attrname, value)
|
||||
# _GA(self, 'obj').set_attribute(attrname, value)
|
||||
def __delattr__(self, attrname):
|
||||
_GA(_GA(self, "obj"), "attributes").remove(attrname)
|
||||
# _GA(self, 'obj').del_attribute(attrname)
|
||||
def get_all(self):
|
||||
return _GA(_GA(self, "obj"), "attributes").all(attrname)
|
||||
#return _GA(self, 'obj').get_all_attributes()
|
||||
all = property(get_all)
|
||||
self._db_holder = DbHolder(self)
|
||||
return self._db_holder
|
||||
#@db.setter
|
||||
def __db_set(self, value):
|
||||
"Stop accidentally replacing the db object"
|
||||
string = "Cannot assign directly to db object! "
|
||||
string += "Use db.attr=value instead."
|
||||
raise Exception(string)
|
||||
#@db.deleter
|
||||
def __db_del(self):
|
||||
"Stop accidental deletion."
|
||||
raise Exception("Cannot delete the db object!")
|
||||
db = property(__db_get, __db_set, __db_del)
|
||||
|
||||
self.__class__.flush_cached_instance(self)
|
||||
|
||||
#
|
||||
# NON-attr_obj storage methods
|
||||
# Non-persistent (ndb) storage
|
||||
#
|
||||
|
||||
def nattr(self, attribute_name=None, value=None, delete=False):
|
||||
"""
|
||||
This is the equivalence of self.attr but for non-attr_obj
|
||||
stores. Will not raise error but return None.
|
||||
"""
|
||||
if attribute_name == None:
|
||||
# act as a list method
|
||||
if callable(self.ndb.all):
|
||||
return self.ndb.all()
|
||||
else:
|
||||
return [val for val in self.ndb.__dict__.keys()
|
||||
if not val.startswith['_']]
|
||||
elif delete == True:
|
||||
if hasattr(self.ndb, attribute_name):
|
||||
_DA(_GA(self, "db"), attribute_name)
|
||||
elif value == None:
|
||||
# act as a getter.
|
||||
if hasattr(self.ndb, attribute_name):
|
||||
_GA(_GA(self, "ndb"), attribute_name)
|
||||
else:
|
||||
return None
|
||||
else:
|
||||
# act as a setter
|
||||
_SA(self.ndb, attribute_name, value)
|
||||
|
||||
#@property
|
||||
#@property ndb
|
||||
def __ndb_get(self):
|
||||
"""
|
||||
A non-attr_obj store (ndb: NonDataBase). Everything stored
|
||||
|
|
@ -1410,50 +1176,221 @@ class TypedObject(SharedMemoryModel):
|
|||
raise Exception("Cannot delete the ndb object!")
|
||||
ndb = property(__ndb_get, __ndb_set, __ndb_del)
|
||||
|
||||
#def nattr(self, attribute_name=None, value=None, delete=False):
|
||||
# """
|
||||
# This allows for assigning non-persistent data on the object using
|
||||
# a method call. Will return None if trying to access a non-existing property.
|
||||
# """
|
||||
# if attribute_name == None:
|
||||
# # act as a list method
|
||||
# if callable(self.ndb.all):
|
||||
# return self.ndb.all()
|
||||
# else:
|
||||
# return [val for val in self.ndb.__dict__.keys()
|
||||
# if not val.startswith['_']]
|
||||
# elif delete == True:
|
||||
# if hasattr(self.ndb, attribute_name):
|
||||
# _DA(_GA(self, "ndb"), attribute_name)
|
||||
# elif value == None:
|
||||
# # act as a getter.
|
||||
# if hasattr(self.ndb, attribute_name):
|
||||
# _GA(_GA(self, "ndb"), attribute_name)
|
||||
# else:
|
||||
# return None
|
||||
# else:
|
||||
# # act as a setter
|
||||
# _SA(self.ndb, attribute_name, value)
|
||||
|
||||
|
||||
|
||||
#
|
||||
# Lock / permission methods
|
||||
# Attribute handler methods - DEPRECATED!
|
||||
#
|
||||
|
||||
def access(self, accessing_obj, access_type='read', default=False):
|
||||
"""
|
||||
Determines if another object has permission to access.
|
||||
accessing_obj - object trying to access this one
|
||||
access_type - type of access sought
|
||||
default - what to return if no lock of access_type was found
|
||||
"""
|
||||
return self.locks.check(accessing_obj, access_type=access_type, default=default)
|
||||
#
|
||||
# Fully attr_obj attributes. You usually access these
|
||||
# through the obj.db.attrname method.
|
||||
|
||||
def check_permstring(self, permstring):
|
||||
# Helper methods for attr_obj attributes
|
||||
|
||||
def has_attribute(self, attribute_name):
|
||||
"""
|
||||
This explicitly checks if we hold particular permission without involving
|
||||
any locks.
|
||||
See if we have an attribute set on the object.
|
||||
|
||||
attribute_name: (str) The attribute's name.
|
||||
"""
|
||||
if hasattr(self, "player"):
|
||||
if self.player and self.player.is_superuser: return True
|
||||
logger.log_depmsg("obj.has_attribute() is deprecated. Use obj.attributes.has().")
|
||||
return _GA(self, "attributes").has(attribute_name)
|
||||
|
||||
def set_attribute(self, attribute_name, new_value=None, lockstring=""):
|
||||
"""
|
||||
Sets an attribute on an object. Creates the attribute if need
|
||||
be.
|
||||
|
||||
attribute_name: (str) The attribute's name.
|
||||
new_value: (python obj) The value to set the attribute to. If this is not
|
||||
a str, the object will be stored as a pickle.
|
||||
lockstring - this sets an access restriction on the attribute object. Note that
|
||||
this is normally NOT checked - use the secureattr() access method
|
||||
below to perform access-checked modification of attributes. Lock
|
||||
types checked by secureattr are 'attrread','attredit','attrcreate'.
|
||||
"""
|
||||
logger.log_depmsg("obj.set_attribute() is deprecated. Use obj.db.attr=value or obj.attributes.add().")
|
||||
_GA(self, "attributes").add(attribute_name, new_value, lockstring=lockstring)
|
||||
|
||||
def get_attribute_obj(self, attribute_name, default=None):
|
||||
"""
|
||||
Get the actual attribute object named attribute_name
|
||||
"""
|
||||
logger.log_depmsg("obj.get_attribute_obj() is deprecated. Use obj.attributes.get(..., return_obj=True)")
|
||||
return _GA(self, "attributes").get(attribute_name, default=default, return_obj=True)
|
||||
|
||||
def get_attribute(self, attribute_name, default=None, raise_exception=False):
|
||||
"""
|
||||
Returns the value of an attribute on an object. You may need to
|
||||
type cast the returned value from this function since the attribute
|
||||
can be of any type. Returns default if no match is found.
|
||||
|
||||
attribute_name: (str) The attribute's name.
|
||||
default: What to return if no attribute is found
|
||||
raise_exception (bool) - raise an exception if no object exists instead of returning default.
|
||||
"""
|
||||
logger.log_depmsg("obj.get_attribute() is deprecated. Use obj.db.attr or obj.attributes.get().")
|
||||
return _GA(self, "attributes").get(attribute_name, default=default, raise_exception=raise_exception)
|
||||
|
||||
def del_attribute(self, attribute_name, raise_exception=False):
|
||||
"""
|
||||
Removes an attribute entirely.
|
||||
|
||||
attribute_name: (str) The attribute's name.
|
||||
raise_exception (bool) - raise exception if attribute to delete
|
||||
could not be found
|
||||
"""
|
||||
logger.log_depmsg("obj.del_attribute() is deprecated. Use del obj.db.attr or obj.attributes.remove().")
|
||||
_GA(self, "attributes").remove(attribute_name, raise_exception=raise_exception)
|
||||
|
||||
def get_all_attributes(self):
|
||||
"""
|
||||
Returns all attributes defined on the object.
|
||||
"""
|
||||
logger.log_depmsg("obj.get_all_attributes() is deprecated. Use obj.db.all() or obj.attributes.all().")
|
||||
return _GA(self, "attributes").all()
|
||||
|
||||
def attr(self, attribute_name=None, value=None, delete=False):
|
||||
"""
|
||||
This is a convenient wrapper for
|
||||
get_attribute, set_attribute, del_attribute
|
||||
and get_all_attributes.
|
||||
If value is None, attr will act like
|
||||
a getter, otherwise as a setter.
|
||||
set delete=True to delete the named attribute.
|
||||
|
||||
Note that you cannot set the attribute
|
||||
value to None using this method. Use set_attribute.
|
||||
"""
|
||||
logger.log_depmsg("obj.attr() is deprecated. Use handlers obj.db or obj.attributes.")
|
||||
if attribute_name == None:
|
||||
# act as a list method
|
||||
return self.get_all_attributes()
|
||||
elif delete == True:
|
||||
self.del_attribute(attribute_name)
|
||||
elif value == None:
|
||||
# act as a getter.
|
||||
return self.get_attribute(attribute_name)
|
||||
else:
|
||||
if self.is_superuser: return True
|
||||
# act as a setter
|
||||
self.set_attribute(attribute_name, value)
|
||||
|
||||
if not permstring:
|
||||
return False
|
||||
perm = permstring.lower()
|
||||
if perm in [p.lower() for p in self.permissions]:
|
||||
# simplest case - we have a direct match
|
||||
return True
|
||||
if perm in _PERMISSION_HIERARCHY:
|
||||
# check if we have a higher hierarchy position
|
||||
ppos = _PERMISSION_HIERARCHY.index(perm)
|
||||
return any(True for hpos, hperm in enumerate(_PERMISSION_HIERARCHY)
|
||||
if hperm in [p.lower() for p in self.permissions] and hpos > ppos)
|
||||
return False
|
||||
|
||||
|
||||
def flush_from_cache(self):
|
||||
def secure_attr(self, accessing_object, attribute_name=None, value=None, delete=False,
|
||||
default_access_read=True, default_access_edit=True, default_access_create=True):
|
||||
"""
|
||||
Flush this object instance from cache, forcing an object reload. Note that this
|
||||
will kill all temporary attributes on this object since it will be recreated
|
||||
as a new Typeclass instance.
|
||||
This is a version of attr that requires the accessing object
|
||||
as input and will use that to check eventual access locks on
|
||||
the Attribute before allowing any changes or reads.
|
||||
|
||||
In the cases when this method wouldn't return, it will return
|
||||
True for a successful operation, None otherwise.
|
||||
|
||||
locktypes checked on the Attribute itself:
|
||||
attrread - control access to reading the attribute value
|
||||
attredit - control edit/delete access
|
||||
locktype checked on the object on which the Attribute is/will be stored:
|
||||
attrcreate - control attribute create access (this is checked *on the object* not on the Attribute!)
|
||||
|
||||
default_access_* defines which access is assumed if no
|
||||
suitable lock is defined on the Atttribute.
|
||||
|
||||
"""
|
||||
self.__class__.flush_cached_instance(self)
|
||||
logger.log_depmsg("obj.secure_attr() is deprecated. Use obj.attributes methods, giving accessing_obj keyword.")
|
||||
if attribute_name == None:
|
||||
return _GA(self, "attributes").all(accessing_obj=accessing_object, default_access=default_access_read)
|
||||
elif delete == True:
|
||||
# act as deleter
|
||||
_GA(self, "attributes").remove(attribute_name, accessing_obj=accessing_object, default_access=default_access_edit)
|
||||
elif value == None:
|
||||
# act as getter
|
||||
return _GA(self, "attributes").get(attribute_name, accessing_obj=accessing_object, default_access=default_access_read)
|
||||
else:
|
||||
# act as setter
|
||||
attr = self.get_attribute_obj(attribute_name)
|
||||
if attr:
|
||||
# attribute already exists
|
||||
_GA(self, "attributes").add(attribute_name, value, accessing_obj=accessing_object, default_access=default_access_edit)
|
||||
else:
|
||||
# creating a new attribute - check access on storing object!
|
||||
_GA(self, "attributes").add(attribute_name, value, accessing_obj=accessing_object, default_access=default_access_create)
|
||||
|
||||
#@property
|
||||
def __db_get(self):
|
||||
"""
|
||||
A second convenience wrapper for the the attribute methods. It
|
||||
allows for the syntax
|
||||
obj.db.attrname = value
|
||||
and
|
||||
value = obj.db.attrname
|
||||
and
|
||||
del obj.db.attrname
|
||||
and
|
||||
all_attr = obj.db.all (unless there is no attribute named 'all', in which
|
||||
case that will be returned instead).
|
||||
"""
|
||||
try:
|
||||
return self._db_holder
|
||||
except AttributeError:
|
||||
class DbHolder(object):
|
||||
"Holder for allowing property access of attributes"
|
||||
def __init__(self, obj):
|
||||
_SA(self, 'obj', obj)
|
||||
_SA(self, "attrhandler", _GA(_GA(self, "obj"), "attributes"))
|
||||
def __getattribute__(self, attrname):
|
||||
if attrname == 'all':
|
||||
# we allow to overload our default .all
|
||||
attr = _GA(self, "attrhandler").get("all")
|
||||
if attr:
|
||||
return attr
|
||||
return _GA(self, 'all')
|
||||
return _GA(self, "attrhandler").get(attrname)
|
||||
def __setattr__(self, attrname, value):
|
||||
_GA(self, "attrhandler").add(attrname, value)
|
||||
def __delattr__(self, attrname):
|
||||
_GA(self, "attrhandler").remove(attrname)
|
||||
def get_all(self):
|
||||
return _GA(self, "attrhandler").all()
|
||||
all = property(get_all)
|
||||
self._db_holder = DbHolder(self)
|
||||
return self._db_holder
|
||||
#@db.setter
|
||||
def __db_set(self, value):
|
||||
"Stop accidentally replacing the db object"
|
||||
string = "Cannot assign directly to db object! "
|
||||
string += "Use db.attr=value instead."
|
||||
raise Exception(string)
|
||||
#@db.deleter
|
||||
def __db_del(self):
|
||||
"Stop accidental deletion."
|
||||
raise Exception("Cannot delete the db object!")
|
||||
db = property(__db_get, __db_set, __db_del)
|
||||
|
||||
|
||||
|
||||
# connect to attribute cache signal
|
||||
|
|
|
|||
|
|
@ -125,7 +125,7 @@ def create_object(typeclass, key=None, location=None,
|
|||
|
||||
# custom-given perms/locks overwrite hooks
|
||||
if permissions:
|
||||
new_object.permissions = permissions
|
||||
new_object.permissions.add(permissions)
|
||||
if locks:
|
||||
new_object.locks.add(locks)
|
||||
if aliases:
|
||||
|
|
@ -463,9 +463,9 @@ def create_player(key, email, password,
|
|||
|
||||
# custom given arguments potentially overrides the hook
|
||||
if permissions:
|
||||
new_player.permissions = permissions
|
||||
new_player.permissions.add(permissions)
|
||||
elif not new_player.permissions:
|
||||
new_player.permissions = settings.PERMISSION_PLAYER_DEFAULT
|
||||
new_player.permissions.add(settings.PERMISSION_PLAYER_DEFAULT)
|
||||
if locks:
|
||||
new_player.locks.add(locks)
|
||||
return new_player
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue