<s> import sys <EOL> import types <EOL> from google . appengine . ext import db <EOL> from django import VERSION <EOL> from django . core . exceptions import ObjectDoesNotExist <EOL> from django . db . models . fields import Field <EOL> from django . db . models . options import Options <EOL> from django . db . models . loading import register_models , get_model <EOL> class ModelManager ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , owner ) : <EOL> self . owner = owner <EOL> def __getattr__ ( self , name ) : <EOL> """<STR_LIT>""" <EOL> return getattr ( self . owner , name ) <EOL> class ModelOptions ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , cls ) : <EOL> self . object_name = cls . __name__ <EOL> self . module_name = self . object_name . lower ( ) <EOL> model_module = sys . modules [ cls . __module__ ] <EOL> self . app_label = model_module . __name__ . split ( '<STR_LIT:.>' ) [ - <NUM_LIT:2> ] <EOL> self . abstract = False <EOL> class pk : <EOL> """<STR_LIT>""" <EOL> name = "<STR_LIT>" <EOL> def __str__ ( self ) : <EOL> return "<STR_LIT>" % ( self . app_label , self . module_name ) <EOL> @ property <EOL> def many_to_many ( self ) : <EOL> """<STR_LIT>""" <EOL> return [ ] <EOL> class Relation ( object ) : <EOL> def __init__ ( self , to ) : <EOL> self . field_name = "<STR_LIT>" <EOL> def PropertyWrapper ( prop ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( prop , db . Reference ) : <EOL> prop . rel = Relation ( prop . reference_class ) <EOL> else : <EOL> prop . rel = None <EOL> prop . serialize = True <EOL> return prop <EOL> class PropertiedClassWithDjango ( db . PropertiedClass ) : <EOL> """<STR_LIT>""" <EOL> def __new__ ( cls , name , bases , attrs ) : <EOL> """<STR_LIT>""" <EOL> if name == '<STR_LIT>' : <EOL> return super ( PropertiedClassWithDjango , cls ) . __new__ ( cls , name , <EOL> bases , attrs ) <EOL> new_class = super ( PropertiedClassWithDjango , cls ) . __new__ ( cls , name , <EOL> bases , attrs ) <EOL> new_class . _meta = ModelOptions ( new_class ) <EOL> new_class . objects = ModelManager ( new_class ) <EOL> new_class . _default_manager = new_class . objects <EOL> new_class . DoesNotExist = types . ClassType ( '<STR_LIT>' , <EOL> ( ObjectDoesNotExist , ) , { } ) <EOL> m = get_model ( new_class . _meta . app_label , name , False ) <EOL> if m : <EOL> return m <EOL> register_models ( new_class . _meta . app_label , new_class ) <EOL> return get_model ( new_class . _meta . app_label , name , False ) <EOL> def __init__ ( cls , name , bases , attrs ) : <EOL> """<STR_LIT>""" <EOL> super ( PropertiedClassWithDjango , cls ) . __init__ ( name , bases , attrs ) <EOL> if name == '<STR_LIT>' : <EOL> return <EOL> fields = [ PropertyWrapper ( p ) for p in cls . _properties . values ( ) ] <EOL> cls . _meta . local_fields = fields <EOL> class BaseModel ( db . Model ) : <EOL> """<STR_LIT>""" <EOL> __metaclass__ = PropertiedClassWithDjango <EOL> def __eq__ ( self , other ) : <EOL> if not isinstance ( other , self . __class__ ) : <EOL> return False <EOL> return self . _get_pk_val ( ) == other . _get_pk_val ( ) <EOL> def __ne__ ( self , other ) : <EOL> return not self . __eq__ ( other ) <EOL> def _get_pk_val ( self ) : <EOL> """<STR_LIT>""" <EOL> return unicode ( self . key ( ) ) <EOL> def __repr__ ( self ) : <EOL> """<STR_LIT>""" <EOL> def _MakeReprTuple ( prop_name ) : <EOL> prop = getattr ( self . __class__ , prop_name ) <EOL> return ( prop_name , prop . get_value_for_datastore ( self ) ) <EOL> d = dict ( [ _MakeReprTuple ( prop_name ) for prop_name in self . properties ( ) ] ) <EOL> return "<STR_LIT>" % ( self . __class__ . __name__ , repr ( d ) ) <EOL> class RegistrationTestModel ( BaseModel ) : <EOL> """<STR_LIT>""" <EOL> pass </s>
