def with_addon(allow_missing=False):
 def wrapper(fn):
  @functools.wraps(fn)
  def inner(view, request, **kwargs):
   guid = kwargs.get('guid', None)
   try:
    if (guid is None):
     raise Addon.DoesNotExist('No GUID')
    addon = Addon.unfiltered.get(guid=guid)
   except Addon.DoesNotExist:
    if allow_missing:
     addon = None
    else:
     return Response({'error': _('Could not find add-on with id "{}".').format(guid)}, status=status.HTTP_404_NOT_FOUND)
   has_perm = ((addon is None) or (addon.has_author(request.user) or ((request.method == 'GET') and acl.action_allowed_user(request.user, 'Addons', 'Edit'))))
   if has_perm:
    return fn(view, request, addon=addon, **kwargs)
   else:
    return Response({'error': _('You do not own this addon.')}, status=status.HTTP_403_FORBIDDEN)
  return inner
 return wrapper

def with_addon ( allow_missing = False ) : def wrapper ( fn ) : @ functools . wraps ( fn ) def inner ( view , request , ** kwargs ) : guid = kwargs . get ( 'guid' , None ) try : if ( guid is None ) : raise Addon . DoesNotExist ( 'No GUID' ) addon = Addon . unfiltered . get ( guid = guid ) except Addon . DoesNotExist : if allow_missing : addon = None else : return Response ( { 'error' : _ ( 'Could not find add-on with id "{}".' ) . format ( guid ) } , status = status . HTTP_404_NOT_FOUND ) has_perm = ( ( addon is None ) or ( addon . has_author ( request . user ) or ( ( request . method == 'GET' ) and acl . action_allowed_user ( request . user , 'Addons' , 'Edit' ) ) ) ) if has_perm : return fn ( view , request , addon = addon , ** kwargs ) else : return Response ( { 'error' : _ ( 'You do not own this addon.' ) } , status = status . HTTP_403_FORBIDDEN ) return inner return wrapper
call the view function with an addon instead of a guid .