<s> from django . conf . urls . defaults import patterns , url <EOL> from hyperadmin . clients . common import Client <EOL> class BaseDjangoViewsClient ( Client ) : <EOL> """<STR_LIT>""" <EOL> public = True <EOL> def __init__ ( self , api_endpoint , name = '<STR_LIT>' , app_name = '<STR_LIT>' ) : <EOL> super ( BaseDjangoViewsClient , self ) . __init__ ( api_endpoint , name = name , app_name = app_name ) <EOL> def get_view_kwargs ( self , ** kwargs ) : <EOL> params = { '<STR_LIT>' : self , } <EOL> params . update ( kwargs ) <EOL> return params <EOL> def get_view_endpoints ( self ) : <EOL> """<STR_LIT>""" <EOL> return [ ] <EOL> def get_urls ( self ) : <EOL> urlpatterns = patterns ( '<STR_LIT>' , ) <EOL> for endpoint in self . get_view_endpoints ( ) : <EOL> urlpatterns += patterns ( '<STR_LIT>' , <EOL> url ( endpoint [ '<STR_LIT:url>' ] , <EOL> endpoint [ '<STR_LIT>' ] , <EOL> name = endpoint [ '<STR_LIT:name>' ] , ) , <EOL> ) <EOL> return urlpatterns <EOL> def api_permission_check ( self , request ) : <EOL> if not self . public : <EOL> return self . api_endpoint . api_permission_check ( request ) <EOL> def get_related_resource_from_field ( self , field ) : <EOL> return self . api_endpoint . get_related_resource_from_field ( field ) <EOL> def get_html_type_from_field ( self , field ) : <EOL> return self . api_endpoint . get_html_type_from_field ( field ) <EOL> @ property <EOL> def state ( self ) : <EOL> return self . api_endpoint . state <EOL> @ property <EOL> def media_types ( self ) : <EOL> return self . api_endpoint . media_types <EOL> class DjangoViewsClient ( BaseDjangoViewsClient ) : <EOL> """<STR_LIT>""" <EOL> view_endpoint_defs = [ ] <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( DjangoViewsClient , self ) . __init__ ( * args , ** kwargs ) <EOL> self . view_endpoints = list ( ) <EOL> def register_view_endpoint ( self , url , view_class , resource , endpoint_name , name = None , options = { } ) : <EOL> view_kwargs = self . get_view_kwargs ( resource = resource , url_name = endpoint_name , ** options ) <EOL> self . view_endpoints . append ( { <EOL> '<STR_LIT:url>' : url , <EOL> '<STR_LIT>' : view_class . as_view ( ** view_kwargs ) , <EOL> '<STR_LIT:name>' : name or endpoint_name , <EOL> } ) <EOL> def get_view_endpoints ( self ) : <EOL> endpoints = super ( DjangoViewsClient , self ) . get_view_endpoints ( ) <EOL> for entry in self . view_endpoint_defs : <EOL> view_class = entry [ '<STR_LIT>' ] <EOL> view_kwargs = self . get_view_kwargs ( resource = entry [ '<STR_LIT>' ] , url_name = entry [ '<STR_LIT>' ] ) <EOL> endpoints . append ( { <EOL> '<STR_LIT:url>' : entry [ '<STR_LIT:url>' ] , <EOL> '<STR_LIT>' : view_class . as_view ( ** view_kwargs ) , <EOL> '<STR_LIT:name>' : entry . get ( '<STR_LIT:name>' , entry [ '<STR_LIT>' ] ) , <EOL> } ) <EOL> endpoints . extend ( self . view_endpoints ) <EOL> return endpoints </s>
