Cleaning some unnecessary whitespace, overall cleanup of various source codes.

This commit is contained in:
Griatch 2012-03-30 23:47:22 +02:00
parent d4c97d7df8
commit c0322c9eae
27 changed files with 1342 additions and 1318 deletions

View file

@ -1,7 +1,7 @@
"""
This implements the common managers that are used by the
abstract models in dbobjects.py (and which are thus shared by
all Attributes and TypedObjects).
all Attributes and TypedObjects).
"""
from functools import update_wrapper
from django.db import models
@ -9,15 +9,15 @@ from src.utils import idmapper
from src.utils.utils import make_iter
#from src.typeclasses import idmap
# Managers
# Managers
class AttributeManager(models.Manager):
"Manager for handling Attributes."
def attr_namesearch(self, searchstr, obj, exact_match=True):
"""
Searches the object's attributes for name matches.
Searches the object's attributes for name matches.
searchstr: (str) A string to search for.
"""
# Retrieve the list of attributes for this object.
@ -29,21 +29,21 @@ class AttributeManager(models.Manager):
db_key__icontains=searchstr)
#
# helper functions for the TypedObjectManager.
#
# helper functions for the TypedObjectManager.
#
def returns_typeclass_list(method):
"""
Decorator: Chantes return of the decorated method (which are
TypeClassed objects) into object_classes(s) instead. Will always
return a list (may be empty).
"""
"""
def func(self, *args, **kwargs):
"decorator. Returns a list."
"decorator. Returns a list."
self.__doc__ = method.__doc__
matches = method(self, *args, **kwargs)
matches = method(self, *args, **kwargs)
return [(hasattr(dbobj, "typeclass") and dbobj.typeclass) or dbobj for dbobj in make_iter(matches)]
return update_wrapper(func, method)
return update_wrapper(func, method)
def returns_typeclass(method):
"""
@ -55,8 +55,8 @@ def returns_typeclass(method):
rfunc = returns_typeclass_list(method)
try:
return rfunc(self, *args, **kwargs)[0]
except IndexError:
return None
except IndexError:
return None
return update_wrapper(func, method)
@ -64,20 +64,20 @@ def returns_typeclass(method):
#class TypedObjectManager(models.Manager):
class TypedObjectManager(idmapper.manager.SharedMemoryManager):
"""
Common ObjectManager for all dbobjects.
Common ObjectManager for all dbobjects.
"""
def dbref(self, dbref):
"""
Valid forms of dbref (database reference number)
are either a string '#N' or an integer N.
Output is the integer part.
Output is the integer part.
"""
if isinstance(dbref, basestring):
dbref = dbref.lstrip('#')
try:
if int(dbref) < 1:
return None
return None
except Exception:
return None
return dbref
@ -92,7 +92,7 @@ class TypedObjectManager(idmapper.manager.SharedMemoryManager):
"""
self.filter()
@returns_typeclass
def dbref_search(self, dbref):
"""
@ -131,25 +131,24 @@ class TypedObjectManager(idmapper.manager.SharedMemoryManager):
"""
Returns a dictionary with all the typeclasses active in-game
as well as the number of such objects defined (i.e. the number
of database object having that typeclass set on themselves).
of database object having that typeclass set on themselves).
"""
dbtotals = {}
typeclass_paths = set(self.values_list('db_typeclass_path', flat=True))
for typeclass_path in typeclass_paths:
for typeclass_path in typeclass_paths:
dbtotals[typeclass_path] = \
self.filter(db_typeclass_path=typeclass_path).count()
return dbtotals
return dbtotals
@returns_typeclass_list
def typeclass_search(self, typeclass):
"""
Searches through all objects returning those which has a certain
typeclass. If location is set, limit search to objects in
that location.
that location.
"""
if callable(typeclass):
cls = typeclass.__class__
typeclass = "%s.%s" % (cls.__module__, cls.__name__)
o_query = self.filter(db_typeclass_path__exact=typeclass)
o_query = self.filter(db_typeclass_path__exact=typeclass)
return o_query