<s> from django . core . paginator import Paginator <EOL> from hyperadmin . indexes import PrimaryIndex <EOL> from hyperadmin . resources . resources import BaseResource <EOL> from hyperadmin . resources . crud . hyperobjects import ListResourceItem <EOL> from hyperadmin . resources . crud . endpoints import ListEndpoint , CreateEndpoint , DetailEndpoint , DeleteEndpoint <EOL> class CRUDResource ( BaseResource ) : <EOL> resource_class = '<STR_LIT>' <EOL> ordering = None <EOL> list_display = ( '<STR_LIT>' , ) <EOL> list_resource_item_class = ListResourceItem <EOL> paginator_class = Paginator <EOL> actions = [ ] <EOL> form_class = None <EOL> list_endpoint = ( ListEndpoint , { } ) <EOL> create_endpoint = ( CreateEndpoint , { } ) <EOL> detail_endpoint = ( DetailEndpoint , { } ) <EOL> delete_endpoint = ( DeleteEndpoint , { } ) <EOL> def get_view_endpoints ( self ) : <EOL> endpoints = super ( CRUDResource , self ) . get_view_endpoints ( ) <EOL> endpoints . extend ( [ <EOL> self . list_endpoint , <EOL> self . create_endpoint , <EOL> self . delete_endpoint , <EOL> self . detail_endpoint , <EOL> ] ) <EOL> return endpoints <EOL> def get_absolute_url ( self ) : <EOL> return self . link_prototypes [ '<STR_LIT:list>' ] . get_url ( ) <EOL> def get_item_url ( self , item ) : <EOL> if self . has_update_permission ( item ) : <EOL> return self . link_prototypes [ '<STR_LIT>' ] . get_url ( item = item ) <EOL> return self . link_prototypes [ '<STR_LIT>' ] . get_url ( item = item ) <EOL> def get_item_link ( self , item , ** kwargs ) : <EOL> if self . has_update_permission ( item ) : <EOL> return self . link_prototypes [ '<STR_LIT>' ] . get_link ( item = item , ** kwargs ) <EOL> return self . link_prototypes [ '<STR_LIT>' ] . get_link ( item = item , ** kwargs ) <EOL> def has_permission ( self , perm , ** kwargs ) : <EOL> func_name = '<STR_LIT>' % perm <EOL> if hasattr ( self , func_name ) : <EOL> return getattr ( self , func_name ) ( ** kwargs ) <EOL> return False <EOL> def has_create_permission ( self ) : <EOL> return True <EOL> def has_update_permission ( self , item = None ) : <EOL> return True <EOL> def has_delete_permission ( self , item = None ) : <EOL> return True <EOL> def on_create_success ( self , item ) : <EOL> '''<STR_LIT>''' <EOL> self . emit_event ( event = '<STR_LIT>' , item_list = [ item ] ) <EOL> return None <EOL> def on_update_success ( self , item ) : <EOL> '''<STR_LIT>''' <EOL> self . emit_event ( event = '<STR_LIT>' , item_list = [ item ] ) <EOL> return None <EOL> def on_delete_success ( self , item ) : <EOL> '''<STR_LIT>''' <EOL> self . emit_event ( event = '<STR_LIT>' , item_list = [ item ] ) <EOL> return None <EOL> def get_indexes ( self ) : <EOL> return { '<STR_LIT>' : PrimaryIndex ( '<STR_LIT>' , self ) } <EOL> def get_index_query ( self , name ) : <EOL> return self . get_primary_query ( ) <EOL> def get_item_breadcrumb ( self , item ) : <EOL> return self . get_item_link ( item , rel = '<STR_LIT>' , link_factor = '<STR_LIT>' ) <EOL> def get_list_resource_item_class ( self ) : <EOL> return self . list_resource_item_class <EOL> def get_list_resource_item ( self , instance , ** kwargs ) : <EOL> kwargs . setdefault ( '<STR_LIT>' , self ) <EOL> return self . get_list_resource_item_class ( ) ( instance = instance , ** kwargs ) <EOL> def get_instances ( self ) : <EOL> '''<STR_LIT>''' <EOL> if '<STR_LIT>' in self . state : <EOL> return self . state [ '<STR_LIT>' ] . object_list <EOL> if self . state . has_view_class ( '<STR_LIT>' ) : <EOL> return [ ] <EOL> return self . get_primary_query ( ) <EOL> def get_resource_items ( self ) : <EOL> instances = self . get_instances ( ) <EOL> if self . state . has_view_class ( '<STR_LIT>' ) : <EOL> return [ self . get_list_resource_item ( instance ) for instance in instances ] <EOL> return [ self . get_resource_item ( instance ) for instance in instances ] <EOL> def get_primary_query ( self , ** kwargs ) : <EOL> return self . resource_adaptor . objects . all ( ) <EOL> def get_ordering ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . ordering or ( ) <EOL> def get_paginator_class ( self ) : <EOL> return self . paginator_class <EOL> def get_paginator_kwargs ( self ) : <EOL> return { '<STR_LIT>' : getattr ( self , '<STR_LIT>' , <NUM_LIT:50> ) , } <EOL> def get_paginator ( self , index , ** kwargs ) : <EOL> return self . get_paginator_class ( ) ( index , ** kwargs ) <EOL> def get_outbound_links ( self ) : <EOL> links = self . create_link_collection ( ) <EOL> links . add_link ( '<STR_LIT:list>' , link_factor = '<STR_LIT>' ) <EOL> links . add_link ( '<STR_LIT>' , link_factor = '<STR_LIT>' ) <EOL> return links <EOL> def get_actions ( self , request ) : <EOL> actions = self . site . get_actions ( request ) <EOL> for func in self . actions : <EOL> if isinstance ( func , basestring ) : <EOL> func = getattr ( self , func ) <EOL> assert callable ( func ) <EOL> name = func . __name__ <EOL> description = getattr ( func , '<STR_LIT>' , name . replace ( '<STR_LIT:_>' , '<STR_LIT:U+0020>' ) ) <EOL> actions [ name ] = ( func , name , description ) <EOL> return actions <EOL> def get_action ( self , request , action ) : <EOL> actions = self . get_actions ( request ) <EOL> return actions [ action ] <EOL> def __unicode__ ( self ) : <EOL> return u'<STR_LIT>' % ( self . app_name , self . resource_name ) <EOL> def get_form_kwargs ( self , ** kwargs ) : <EOL> '''<STR_LIT>''' <EOL> if self . state . item : <EOL> kwargs . setdefault ( '<STR_LIT>' , self . state . item . instance ) <EOL> return super ( CRUDResource , self ) . get_form_kwargs ( ** kwargs ) </s>
