#NEWLINE# def get_object_from_identifier( identifier , valid = None ) : #NEWLINE# #INDENT# ' Helper function to resolve an item identifier\n        into a model instance.\n\n        Raises StoreException if the identifier is invalid\n        or the requested Model could not be found\n\n        Raises <Model>.DoesNotExist if the object lookup fails\n\n        Arguments (optional):\n\n            valid\n                One or more Django model classes to compare the\n                returned model instance to.\n    ' #NEWLINE# try : #NEWLINE# #INDENT# ( model_str , pk ) = identifier . split ( '__' ) #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# raise StoreException ( 'Invalid identifier string' ) #NEWLINE# #UNINDENT# Model = get_model ( * model_str . split ( '.' ) ) #NEWLINE# if ( Model is None ) : #NEWLINE# #INDENT# raise StoreException ( ( 'Model from identifier string "%s" not found' % valid ) ) #NEWLINE# #UNINDENT# if ( valid is not None ) : #NEWLINE# #INDENT# if ( not isinstance ( valid , ( list , tuple ) ) ) : #NEWLINE# #INDENT# valid = ( valid , ) #NEWLINE# #UNINDENT# if ( Model not in valid ) : #NEWLINE# #INDENT# raise StoreException ( 'Model type mismatch' ) #NEWLINE# #UNINDENT# #UNINDENT# return Model . _default_manager . get ( pk = pk )