<s> from dockit import schema <EOL> from dockit . backends import get_document_backend <EOL> from django . db import models <EOL> from django . conf import settings <EOL> from django . contrib . auth . models import User <EOL> from copy import deepcopy <EOL> import datetime <EOL> class SchemaProxyDict ( dict ) : <EOL> def __getitem__ ( self , key ) : <EOL> val = dict . __getitem__ ( self , key ) <EOL> return TemporaryDocument . generate_document ( val ) <EOL> class TemporaryDocumentInfo ( schema . Schema ) : <EOL> user = schema . ModelReferenceField ( User , blank = True , null = True ) <EOL> created = schema . DateTimeField ( default = datetime . datetime . now ) <EOL> object_collection = schema . CharField ( ) <EOL> object_id = schema . CharField ( ) <EOL> number_of_changes = schema . IntegerField ( default = <NUM_LIT:0> ) <EOL> class TemporaryDocument ( schema . Document ) : <EOL> _tempinfo = schema . SchemaField ( TemporaryDocumentInfo ) <EOL> @ classmethod <EOL> def generate_document ( cls , document ) : <EOL> class GeneratedTempDocument ( cls ) : <EOL> class Meta : <EOL> proxy = True <EOL> fields = deepcopy ( document . _meta . fields ) <EOL> if document . _meta . typed_field : <EOL> GeneratedTempDocument . _meta . typed_field = document . _meta . typed_field <EOL> GeneratedTempDocument . _meta . typed_key = document . _meta . typed_key <EOL> t_field = fields [ document . _meta . typed_field ] <EOL> orignal_schemas = t_field . schemas <EOL> t_field . schemas = SchemaProxyDict ( orignal_schemas ) <EOL> GeneratedTempDocument . _meta . fields . update ( fields ) <EOL> GeneratedTempDocument . _meta . original_document = document <EOL> for name , value in GeneratedTempDocument . _meta . fields . iteritems ( ) : <EOL> if hasattr ( value , '<STR_LIT>' ) : <EOL> value . contribute_to_class ( GeneratedTempDocument , name ) <EOL> else : <EOL> setattr ( GeneratedTempDocument , name , value ) <EOL> return GeneratedTempDocument <EOL> def commit_changes ( self , doc_id = None ) : <EOL> document_cls = self . _meta . original_document <EOL> backend = get_document_backend ( ) <EOL> id_field = backend . get_id_field_name ( ) <EOL> data = self . to_primitive ( self ) <EOL> data [ id_field ] = doc_id <EOL> data . pop ( '<STR_LIT>' , None ) <EOL> instance = document_cls ( _primitive_data = data ) <EOL> instance . save ( ) <EOL> return instance <EOL> @ classmethod <EOL> def create_from_instance ( cls , instance ) : <EOL> backend = get_document_backend ( ) <EOL> data = instance . to_primitive ( instance ) <EOL> instance_id = data . pop ( backend . get_id_field_name ( ) , None ) <EOL> obj = cls . to_python ( data ) <EOL> obj . _original_id = instance_id <EOL> return obj <EOL> def create_temporary_document_class ( document_cls ) : <EOL> return TemporaryDocument . generate_document ( document_cls ) <EOL> class ActiveIndex ( schema . Document ) : <EOL> collection = schema . CharField ( ) <EOL> name = schema . CharField ( ) <EOL> backend = schema . CharField ( ) <EOL> backend_index_identifier = schema . CharField ( ) <EOL> creation_date = schema . DateTimeField ( default = datetime . datetime . now ) <EOL> class DockitPermission ( models . Model ) : <EOL> pass <EOL> if '<STR_LIT>' in settings . INSTALLED_APPS : <EOL> import dockit . auth </s>
