<s> from biicode . common . exception import BiiStoreException <EOL> from biicode . server . model . permissions . element_permissions import ElementPermissions <EOL> from biicode . server . model . payment . user_subscription import UserSubscription , FREE_PLAN_ID <EOL> class GenericServerStore ( object ) : <EOL> '''<STR_LIT>''' <EOL> PUBLISHED_CELL_ST = '<STR_LIT>' <EOL> PUBLISHED_CONTENT_ST = '<STR_LIT>' <EOL> BLOCK_ST = '<STR_LIT>' <EOL> USER_ST = '<STR_LIT:user>' <EOL> COUNTERS_ST = '<STR_LIT>' <EOL> BLOCK_PERMISSIONS_ST = "<STR_LIT>" <EOL> USER_SUBSCRIPTION_ST = "<STR_LIT>" <EOL> def create_published_cells ( self , values ) : <EOL> '''<STR_LIT>''' <EOL> return self . create_multi ( values , GenericServerStore . PUBLISHED_CELL_ST ) <EOL> def create_published_contents ( self , value ) : <EOL> '''<STR_LIT>''' <EOL> return self . create_multi ( value , GenericServerStore . PUBLISHED_CONTENT_ST ) <EOL> def read_published_cells ( self , res_ids ) : <EOL> '''<STR_LIT>''' <EOL> return self . read_multi ( res_ids , GenericServerStore . PUBLISHED_CELL_ST ) <EOL> def read_published_contents ( self , content_ids ) : <EOL> '''<STR_LIT>''' <EOL> return self . read_multi ( content_ids , GenericServerStore . PUBLISHED_CONTENT_ST ) <EOL> def read_block ( self , brl ) : <EOL> '''<STR_LIT>''' <EOL> return self . read ( brl , GenericServerStore . BLOCK_ST ) <EOL> def create_block ( self , value , private = False ) : <EOL> '''<STR_LIT>''' <EOL> self . create ( ElementPermissions ( value . ID , private ) , GenericServerStore . BLOCK_PERMISSIONS_ST ) <EOL> return self . create ( value , GenericServerStore . BLOCK_ST ) <EOL> def read_user ( self , brl ) : <EOL> '''<STR_LIT>''' <EOL> return self . read ( brl , GenericServerStore . USER_ST ) <EOL> def update_block ( self , block ) : <EOL> '''<STR_LIT>''' <EOL> return self . update ( block , GenericServerStore . BLOCK_ST ) <EOL> def update_user ( self , user ) : <EOL> '''<STR_LIT>''' <EOL> return self . update ( user , GenericServerStore . USER_ST ) <EOL> def update_block_permissions ( self , permissions ) : <EOL> '''<STR_LIT>''' <EOL> return self . update ( permissions , GenericServerStore . BLOCK_PERMISSIONS_ST ) <EOL> def upsert_block_permissions ( self , permissions ) : <EOL> '''<STR_LIT>''' <EOL> return self . upsert ( permissions , GenericServerStore . BLOCK_PERMISSIONS_ST ) <EOL> def delete_block ( self , brl_block ) : <EOL> self . delete_block_permissions ( brl_block ) <EOL> return self . delete ( brl_block , GenericServerStore . BLOCK_ST ) <EOL> def delete_block_permissions ( self , brl_block ) : <EOL> return self . delete ( brl_block , GenericServerStore . BLOCK_PERMISSIONS_ST ) <EOL> def delete_published_cells ( self , ids ) : <EOL> '''<STR_LIT>''' <EOL> return self . delete_multi ( ids , GenericServerStore . PUBLISHED_CELL_ST ) <EOL> def delete_published_contents ( self , ids ) : <EOL> '''<STR_LIT>''' <EOL> return self . delete_multi ( ids , GenericServerStore . PUBLISHED_CONTENT_ST ) <EOL> def create_user ( self , user , numeric_id = None ) : <EOL> '''<STR_LIT>''' <EOL> if not numeric_id : <EOL> numeric_id = self . generate_user_id ( ) <EOL> user . numeric_id = numeric_id <EOL> id_or_error = self . create ( user , GenericServerStore . USER_ST , enable_update_if_current = True ) <EOL> if user . ID != id_or_error : <EOL> raise BiiStoreException ( '<STR_LIT>' % ( id_or_error , user . ID ) ) <EOL> user_subscription = UserSubscription ( user . ID ) <EOL> user_subscription . plan_id = FREE_PLAN_ID <EOL> self . create ( user_subscription , GenericServerStore . USER_SUBSCRIPTION_ST ) <EOL> def read_user_subscription ( self , brl_user ) : <EOL> """<STR_LIT>""" <EOL> return self . read ( brl_user , GenericServerStore . USER_SUBSCRIPTION_ST ) <EOL> def update_user_subscription ( self , user_subscription ) : <EOL> '''<STR_LIT>''' <EOL> return self . update ( user_subscription , GenericServerStore . USER_SUBSCRIPTION_ST ) <EOL> def read_block_permissions ( self , brl_block ) : <EOL> '''<STR_LIT>''' <EOL> ret = self . read ( brl_block , GenericServerStore . BLOCK_PERMISSIONS_ST ) <EOL> return ret <EOL> def block_count ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . count ( GenericServerStore . BLOCK_ST ) <EOL> def published_cell_count ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . count ( GenericServerStore . PUBLISHED_CELL_ST ) <EOL> def user_count ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . count ( GenericServerStore . USER_ST ) </s>
