def derive_model_url(model_class, urlname_prefix, object, kind):
 if (not (isinstance(object, model_class) or (inspect.isclass(object) and issubclass(object, model_class)))):
  return
 kind_to_urlnames = {u'detail': ((u'%s.detail' % urlname_prefix), (u'%s.edit' % urlname_prefix))}
 kwarg_sets = [{}]
 if getattr(object, u'pk', None):
  kwarg_sets.append({u'pk': object.pk})
 for urlname in kind_to_urlnames.get(kind, [(u'%s.%s' % (urlname_prefix, kind))]):
  for kwargs in kwarg_sets:
   try:
    return reverse(urlname, kwargs=kwargs)
   except NoReverseMatch:
    pass
 return None

def derive_model_url ( model_class , urlname_prefix , object , kind ) : if ( not ( isinstance ( object , model_class ) or ( inspect . isclass ( object ) and issubclass ( object , model_class ) ) ) ) : return kind_to_urlnames = { u'detail' : ( ( u'%s.detail' % urlname_prefix ) , ( u'%s.edit' % urlname_prefix ) ) } kwarg_sets = [ { } ] if getattr ( object , u'pk' , None ) : kwarg_sets . append ( { u'pk' : object . pk } ) for urlname in kind_to_urlnames . get ( kind , [ ( u'%s.%s' % ( urlname_prefix , kind ) ) ] ) : for kwargs in kwarg_sets : try : return reverse ( urlname , kwargs = kwargs ) except NoReverseMatch : pass return None
try to guess a model url for the given object and kind .