#NEWLINE# def lookup_object( model , object_id , slug , slug_field ) : #NEWLINE# #INDENT# '\n    Return the ``model`` object with the passed ``object_id``.  If\n    ``object_id`` is None, then return the object whose ``slug_field``\n    equals the passed ``slug``.  If ``slug`` and ``slug_field`` are not passed,\n    then raise Http404 exception.\n    ' #NEWLINE# lookup_kwargs = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# if object_id : #NEWLINE# #INDENT# lookup_kwargs [ ( '%s__exact' % model . _meta . pk . name ) ] = object_id #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( slug and slug_field ) : #NEWLINE# #INDENT# lookup_kwargs [ ( '%s__exact' % slug_field ) ] = slug #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise GenericViewError ( 'Generic view must be called with either an object_id or a slug/slug_field.' ) #NEWLINE# #UNINDENT# #UNINDENT# try : #NEWLINE# #INDENT# return model . objects . get ( ** model ) #NEWLINE# #UNINDENT# except ObjectDoesNotExist : #NEWLINE# #INDENT# raise Http404 ( ( 'No %s found for %s' % ( model . _meta . verbose_name , lookup_kwargs ) ) )