This change to set_script_parent() is also needed to get the previous @parent fixes to work, sorry for the omission.

This commit is contained in:
Griatch 2009-04-25 18:05:46 +00:00
parent 9d199032b0
commit a32840002c

View file

@ -585,10 +585,12 @@ class Object(models.Model):
attribute: (str) The attribute's name. attribute: (str) The attribute's name.
new_value: (str) The value to set the attribute to. new_value: (str) The value to set the attribute to.
""" """
new_value = str(new_value).strip()
if self.has_attribute(attribute): if self.has_attribute(attribute):
# Attribute already exists, update it. # Attribute already exists, update it.
attrib_obj = Attribute.objects.filter(attr_object=self).filter(attr_name__iexact=attribute)[0] attrib_obj = Attribute.objects.filter(attr_object=self).filter(attr_name__iexact=attribute)[0]
if new_value.strip() == '': if not new_value:
# If you do something like @set me=SOMEATTR:, destroy the attrib. # If you do something like @set me=SOMEATTR:, destroy the attrib.
attrib_obj.delete() attrib_obj.delete()
else: else:
@ -596,8 +598,8 @@ class Object(models.Model):
attrib_obj.attr_value = new_value attrib_obj.attr_value = new_value
attrib_obj.save() attrib_obj.save()
else: else:
if new_value.strip() != '': if not new_value:
# Attribute object doesn't exist, create it. # Attribute object and we have given a doesn't exist, create it.
new_attrib = Attribute() new_attrib = Attribute()
new_attrib.attr_name = attribute new_attrib.attr_name = attribute
new_attrib.attr_value = new_value new_attrib.attr_value = new_value
@ -782,10 +784,15 @@ class Object(models.Model):
self.script_parent = settings.SCRIPT_DEFAULT_PLAYER self.script_parent = settings.SCRIPT_DEFAULT_PLAYER
else: else:
self.script_parent = settings.SCRIPT_DEFAULT_OBJECT self.script_parent = settings.SCRIPT_DEFAULT_OBJECT
elif parent_str: elif parent_str:
#check if this is actually a reasonable script parent
#(storing with a non-valid parent path causes havoc!)
if not scripthandler.scriptlink(self, parent_str):
return False
self.script_parent = parent_str.strip() self.script_parent = parent_str.strip()
self.save() self.save()
return True
def get_attribute_value(self, attrib, default=None): def get_attribute_value(self, attrib, default=None):
""" """
Returns the value of an attribute on an object. You may need to Returns the value of an attribute on an object. You may need to
@ -971,4 +978,4 @@ class Object(models.Model):
return defines_global.OBJECT_TYPES[otype][1][0] return defines_global.OBJECT_TYPES[otype][1][0]
# Deferred imports are poopy. This will require some thought to fix. # Deferred imports are poopy. This will require some thought to fix.
from src import cmdhandler from src import cmdhandler