mirror of
https://github.com/evennia/evennia.git
synced 2026-03-19 22:36:31 +01:00
ev-API cleanups. ev can now be imported also from a non-django initiated python interpreter (it initiates itself). Gave some more info text and made sure wrapped db_ methods correctly forward their doc strings for introspection.
This commit is contained in:
parent
9409f835bc
commit
da51cb063f
3 changed files with 42 additions and 15 deletions
|
|
@ -3,6 +3,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).
|
||||
"""
|
||||
from functools import update_wrapper
|
||||
from django.db import models
|
||||
from src.utils import idmapper
|
||||
from src.utils.utils import make_iter
|
||||
|
|
@ -39,9 +40,10 @@ def returns_typeclass_list(method):
|
|||
"""
|
||||
def func(self, *args, **kwargs):
|
||||
"decorator. Returns a list."
|
||||
self.__doc__ = method.__doc__
|
||||
matches = method(self, *args, **kwargs)
|
||||
return [(hasattr(dbobj, "typeclass") and dbobj.typeclass) or dbobj for dbobj in make_iter(matches)]
|
||||
return func
|
||||
return update_wrapper(func, method)
|
||||
|
||||
def returns_typeclass(method):
|
||||
"""
|
||||
|
|
@ -49,12 +51,13 @@ def returns_typeclass(method):
|
|||
"""
|
||||
def func(self, *args, **kwargs):
|
||||
"decorator. Returns result or None."
|
||||
self.__doc__ = method.__doc__
|
||||
rfunc = returns_typeclass_list(method)
|
||||
try:
|
||||
return rfunc(self, *args, **kwargs)[0]
|
||||
except IndexError:
|
||||
return None
|
||||
return func
|
||||
return update_wrapper(func, method)
|
||||
|
||||
|
||||
#class TypedObjectManager(idmap.CachingManager):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue