<s> from modules . model import Model <EOL> from modules . validations import is_required , is_string , is_one_of , has_min_length <EOL> from modules . util import json_prep <EOL> import rethinkdb as r <EOL> from framework . elasticsearch import es <EOL> class Topic ( Model ) : <EOL> """<STR_LIT>""" <EOL> tablename = '<STR_LIT>' <EOL> schema = dict ( Model . schema . copy ( ) , ** { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : ( is_required , is_string , ) <EOL> } , <EOL> '<STR_LIT:name>' : { <EOL> '<STR_LIT>' : ( is_required , is_string , ( has_min_length , <NUM_LIT:1> ) , ) <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : ( is_required , ) , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:id>' : { <EOL> '<STR_LIT>' : ( is_required , is_string , ) , <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : ( is_required , is_string , ( <EOL> is_one_of , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' <EOL> ) ) , <EOL> } <EOL> } <EOL> } <EOL> } ) <EOL> @ classmethod <EOL> def list_by_entity_id ( cls , db_conn , entity_id , limit = <NUM_LIT:10> , skip = <NUM_LIT:0> , ** params ) : <EOL> """<STR_LIT>""" <EOL> data_list = ( cls . table <EOL> . filter ( r . row [ '<STR_LIT>' ] [ '<STR_LIT:id>' ] == entity_id ) <EOL> . order_by ( r . desc ( '<STR_LIT>' ) ) <EOL> . limit ( limit ) <EOL> . skip ( skip ) <EOL> . run ( db_conn ) ) <EOL> documents = [ cls ( data ) for data in data_list ] <EOL> return documents <EOL> def save ( self , db_conn ) : <EOL> """<STR_LIT>""" <EOL> es . index ( <EOL> index = '<STR_LIT>' , <EOL> doc_type = '<STR_LIT>' , <EOL> body = json_prep ( self . deliver ( ) ) , <EOL> id = self [ '<STR_LIT:id>' ] , <EOL> ) <EOL> return super ( ) . save ( db_conn ) </s>
