Important update: Fixed two crash bugs in attribute getting/setting. Less importantly, the money value shown in 'inventory' now pluralizes properly.

This commit is contained in:
Greg Taylor 2007-04-23 15:22:40 +00:00
parent 9335adc03a
commit 9e587bd4e3
4 changed files with 10 additions and 10 deletions

View file

@ -324,7 +324,7 @@ class Object(models.Model):
"""
if self.has_attribute(attribute):
# Attribute already exists, update it.
attrib_obj = Attribute.objects.filter(object=self).filter(name=attribute)
attrib_obj = Attribute.objects.filter(object=self).filter(name=attribute)[0]
attrib_obj.value = new_value
attrib_obj.save()
else:
@ -445,14 +445,14 @@ class Object(models.Model):
def get_attribute_value(self, attrib, default=False):
"""
Returns the value of an attribute on an object.
Returns the value of an attribute on an object. You may need to
type cast the returned value from this function!
attrib: (str) The attribute's name.
"""
if self.has_attribute(attrib):
attrib = Attribute.objects.filter(object=self).filter(name=attrib)
attrib_value = attrib[0].value
return attrib_value.value
return attrib[0].value
else:
if default:
return default

View file

@ -29,12 +29,12 @@ def cmd_inventory(cdat):
for item in pobject.get_contents():
session.msg(" %s" % (item.get_ansiname(),))
money = pobject.get_attribute_value("MONEY", default=0)
if money > 0:
money_name = functions_db.get_server_config("MONEY_NAME_PLURAL")
else:
money = int(pobject.get_attribute_value("MONEY", default=0))
if money == 1:
money_name = functions_db.get_server_config("MONEY_NAME_SINGULAR")
else:
money_name = functions_db.get_server_config("MONEY_NAME_PLURAL")
session.msg("You have %d %s." % (money,money_name))
def cmd_look(cdat):

View file

@ -557,7 +557,7 @@ def cmd_set(cdat):
attrib_value = eq_args[1][splicenum:]
# In global_defines.py, see NOSET_ATTRIBS for protected attribute names.
if not functions_db.is_modifiable_attrib(attrib_name):
if not functions_db.is_modifiable_attrib(attrib_name) and not pobject.is_superuser():
session.msg("You can't modify that attribute.")
return

Binary file not shown.