<s> import json <EOL> import uuid <EOL> from django . core . urlresolvers import reverse <EOL> from models import CrowdModelSpecification <EOL> class CrowdInterface ( object ) : <EOL> def __init__ ( self , crowd_name ) : <EOL> self . crowd_name = crowd_name <EOL> @ staticmethod <EOL> def validate_configuration ( configuration ) : <EOL> """<STR_LIT>""" <EOL> return True <EOL> @ staticmethod <EOL> def create_task ( configuration , content ) : <EOL> """<STR_LIT>""" <EOL> return uuid . uuid4 ( ) <EOL> @ staticmethod <EOL> def task_pre_save ( task_object ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> @ staticmethod <EOL> def group_pre_save ( group_object ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> @ staticmethod <EOL> def delete_tasks ( task_objects ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> @ staticmethod <EOL> def get_assignment_context ( request ) : <EOL> """<STR_LIT>""" <EOL> return { '<STR_LIT>' : request . GET . get ( '<STR_LIT>' , None ) , <EOL> '<STR_LIT>' : request . GET . get ( '<STR_LIT>' , None ) , <EOL> '<STR_LIT>' : request . GET . get ( '<STR_LIT>' , True ) } <EOL> @ staticmethod <EOL> def get_response_context ( request ) : <EOL> """<STR_LIT>""" <EOL> return { <EOL> '<STR_LIT>' : request . POST . get ( '<STR_LIT>' , None ) , <EOL> '<STR_LIT>' : request . POST . get ( '<STR_LIT>' , None ) , <EOL> '<STR_LIT>' : request . POST . get ( '<STR_LIT>' , None ) , <EOL> '<STR_LIT>' : request . POST . get ( '<STR_LIT>' , None ) <EOL> } <EOL> @ staticmethod <EOL> def worker_pre_save ( worker_object ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> @ staticmethod <EOL> def response_pre_save ( response_object ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def get_frontend_submit_url ( self , crowd_config ) : <EOL> """<STR_LIT>""" <EOL> return '<STR_LIT>' <EOL> def get_assignment_url ( self ) : <EOL> """<STR_LIT>""" <EOL> return reverse ( '<STR_LIT>' , args = [ self . crowd_name ] ) <EOL> def get_backend_submit_url ( self ) : <EOL> """<STR_LIT>""" <EOL> return reverse ( '<STR_LIT>' , args = [ self . crowd_name ] ) <EOL> @ staticmethod <EOL> def require_context ( context_dictionary , required_keys , exc ) : <EOL> if any ( [ context_dictionary . get ( k ) is None for k in required_keys ] ) : <EOL> raise exc <EOL> def validate_create_request ( self , request_json ) : <EOL> try : <EOL> json_dict = json . loads ( request_json ) <EOL> except ValueError : <EOL> return False <EOL> try : <EOL> self . require_context ( <EOL> json_dict , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:content>' ] , <EOL> ValueError ( ) ) <EOL> configuration = json_dict [ '<STR_LIT>' ] <EOL> self . require_context ( <EOL> configuration , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ] , <EOL> ValueError ( ) ) <EOL> except ValueError : <EOL> return False <EOL> content = json_dict [ '<STR_LIT:content>' ] <EOL> point_identifiers = content . keys ( ) <EOL> if len ( point_identifiers ) == <NUM_LIT:0> : <EOL> return False <EOL> crowd_config = configuration . get ( self . crowd_name , { } ) <EOL> return self . validate_configuration ( crowd_config ) <EOL> class CrowdRegistry ( object ) : <EOL> registered_crowds = { } <EOL> @ classmethod <EOL> def register_crowd ( cls , interface , ** model_classes ) : <EOL> name = interface . crowd_name <EOL> if name in cls . registered_crowds : <EOL> raise ValueError ( "<STR_LIT>" + name ) <EOL> model_spec = CrowdModelSpecification ( name , ** model_classes ) <EOL> model_spec . add_model_rels ( ) <EOL> cls . registered_crowds [ name ] = ( interface , model_spec ) <EOL> @ classmethod <EOL> def get_registry_entry ( cls , crowd_name ) : <EOL> interface , model_spec = cls . registered_crowds . get ( crowd_name , <EOL> ( None , None ) ) <EOL> if not interface and not model_spec : <EOL> raise ValueError ( "<STR_LIT>" + crowd_name ) <EOL> return interface , model_spec </s>
