<s> import re <EOL> from postgres . orm import Model <EOL> name_pattern = re . compile ( r'<STR_LIT>' ) <EOL> def slugize ( slug ) : <EOL> """<STR_LIT>""" <EOL> assert name_pattern . match ( slug ) is not None <EOL> slug = slug . lower ( ) <EOL> for c in ( '<STR_LIT:U+0020>' , '<STR_LIT:U+002C>' , '<STR_LIT:.>' , '<STR_LIT:_>' ) : <EOL> slug = slug . replace ( c , '<STR_LIT:->' ) <EOL> while '<STR_LIT>' in slug : <EOL> slug = slug . replace ( '<STR_LIT>' , '<STR_LIT:->' ) <EOL> slug = slug . strip ( '<STR_LIT:->' ) <EOL> return slug <EOL> def get_list_for ( db , participant_id ) : <EOL> """<STR_LIT>""" <EOL> if participant_id is None : <EOL> return db . all ( """<STR_LIT>""" ) <EOL> else : <EOL> return db . all ( """<STR_LIT>""" , ( participant_id , ) ) <EOL> class Community ( Model ) : <EOL> """<STR_LIT>""" <EOL> typname = "<STR_LIT>" <EOL> @ classmethod <EOL> def from_slug ( cls , slug ) : <EOL> return cls . db . one ( """<STR_LIT>""" , ( slug , ) ) <EOL> def get_members ( self , limit = None , offset = None ) : <EOL> return self . db . all ( """<STR_LIT>""" , ( self . slug , limit , offset ) ) <EOL> def check_membership ( self , participant ) : <EOL> return self . db . one ( """<STR_LIT>""" , ( self . slug , participant . id ) ) </s>
