<s> from telegrambot . bot_views . generic . base import TemplateCommandView <EOL> from django . core . exceptions import ImproperlyConfigured , ObjectDoesNotExist , FieldError <EOL> class DetailCommandView ( TemplateCommandView ) : <EOL> model = None <EOL> queryset = None <EOL> context_object_name = None <EOL> slug_field = '<STR_LIT>' <EOL> def __init__ ( self , slug = None ) : <EOL> self . slug = slug <EOL> def get_slug_field ( self , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return self . slug_field <EOL> def get_queryset ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . queryset is None : <EOL> if self . model : <EOL> return self . model . _default_manager . all ( ) <EOL> else : <EOL> raise ImproperlyConfigured ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % { <EOL> '<STR_LIT>' : self . __class__ . __name__ <EOL> } <EOL> ) <EOL> return self . queryset . all ( ) <EOL> def get_slug ( self , ** kwargs ) : <EOL> return self . slug <EOL> def get_context ( self , bot , update , ** kwargs ) : <EOL> queryset = self . get_queryset ( ) <EOL> if not self . slug_field : <EOL> raise AttributeError ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> % self . __class__ . __name__ ) <EOL> slug_field = self . get_slug_field ( ** kwargs ) <EOL> slug = self . get_slug ( ** kwargs ) <EOL> if slug : <EOL> try : <EOL> object = queryset . get ( ** { slug_field : slug } ) <EOL> except FieldError : <EOL> raise FieldError ( "<STR_LIT>" % slug_field ) <EOL> except ObjectDoesNotExist : <EOL> object = None <EOL> else : <EOL> object = None <EOL> context = { '<STR_LIT>' : object } <EOL> if self . context_object_name : <EOL> context [ self . context_object_name ] = object <EOL> return context </s>
