Utilities

‘This’-object

‘This’-object is the shortcut for …

this.method this.property this.method.sub_method

def _this_owner(self, task):
   def get_owner():
      return None
   return partial(property(get_owner), self)

@viewprop decorator

@property-like decorator to define class instance properties, that could be overridden

class Viewset(object):
    def __init__(self, **initkwargs):
        for key, value in initkwargs.items():
            if not key.startswith('_') and hasattr(self.__class__, key):
                setattr(self, key, value)

    @viewprop
    def login_view(self):
        return LoginView(**self.get_login_view_kwargs())

viewset = Viewset(login_view=my_login_view)
assert viewset.login_view == my_login_view  # True