def must_have_addon(addon_name, model):
 def wrapper(func):
  @functools.wraps(func)
  @collect_auth
  def wrapped(*args, **kwargs):
   if (model == 'node'):
    _inject_nodes(kwargs)
    owner = kwargs['node']
   elif (model == 'user'):
    auth = kwargs.get('auth')
    owner = (auth.user if auth else None)
    if (owner is None):
     raise HTTPError(http.UNAUTHORIZED)
   else:
    raise HTTPError(http.BAD_REQUEST)
   addon = owner.get_addon(addon_name)
   if (addon is None):
    raise HTTPError(http.BAD_REQUEST)
   kwargs['{0}_addon'.format(model)] = addon
   return func(*args, **kwargs)
  return wrapped
 return wrapper

def must_have_addon ( addon_name , model ) : def wrapper ( func ) : @ functools . wraps ( func ) @ collect_auth def wrapped ( * args , ** kwargs ) : if ( model == 'node' ) : _inject_nodes ( kwargs ) owner = kwargs [ 'node' ] elif ( model == 'user' ) : auth = kwargs . get ( 'auth' ) owner = ( auth . user if auth else None ) if ( owner is None ) : raise HTTPError ( http . UNAUTHORIZED ) else : raise HTTPError ( http . BAD_REQUEST ) addon = owner . get_addon ( addon_name ) if ( addon is None ) : raise HTTPError ( http . BAD_REQUEST ) kwargs [ '{0}_addon' . format ( model ) ] = addon return func ( * args , ** kwargs ) return wrapped return wrapper
decorator factory that ensures that a given addon has been added to the target node .