o ʎ_k@sddlmZddlmZddlmZddlmZddl m Z m Z m Z Gddde Z Gdd d e e ZGd d d e ZGd d d eeZdS))ImproperlyConfigured)models)Http404)gettext) ContextMixinTemplateResponseMixinViewcs^eZdZdZdZdZdZdZdZdZ dZ dddZ dd Z d d Z d d ZfddZZS)SingleObjectMixinzS Provide the ability to retrieve a single object for further manipulation. NslugpkFcCs|dur|}|j|j}|j|j}|dur |j|d}|dur9|dus+|jr9|}|jdi||i}|durI|durItd|j j z|}W|S|j j yft tdd|j jjiw)z Return the object the view is displaying. Require `self.queryset` and a `pk` or `slug` argument in the URLconf. Subclasses can override this to return any object. N)r zXGeneric detail view %s must be called with either an object pk or a slug in the URLconf.z,No %(verbose_name)s found matching the query verbose_name) get_querysetkwargsget pk_url_kwargslug_url_kwargfilterquery_pk_and_slugget_slug_fieldAttributeError __class____name__model DoesNotExistr__metar )selfquerysetr r slug_fieldobjr r =/usr/lib/python3/dist-packages/django/views/generic/detail.py get_objects.    zSingleObjectMixin.get_objectcCs:|jdur|jr|jjStdd|jji|jS)z Return the `QuerySet` that will be used to look up the object. This method is called by the default implementation of get_object() and may not be called if get_object() is overridden. Nzj%(cls)s is missing a QuerySet. Define %(cls)s.model, %(cls)s.queryset, or override %(cls)s.get_queryset().cls)rr_default_managerallrrrrr r r!r:s   zSingleObjectMixin.get_querysetcCs|jS)z;Get the name of a slug field to be used to look up by slug.)rr&r r r!rNsz SingleObjectMixin.get_slug_fieldcCs$|jr|jSt|tjr|jjSdS)z#Get the name to use for the object.N)context_object_name isinstancerModelr model_name)rr r r r!get_context_object_nameRs  z)SingleObjectMixin.get_context_object_namec sJi}|jr|j|d<||j}|r|j||<||tjdi|S)z/Insert the single object into the context dict.objectNr )r,r+updatesuperget_context_data)rrcontextr'rr r!r/[s    z"SingleObjectMixin.get_context_data)N)r __module__ __qualname____doc__rrrr'rrrr"rrr+r/ __classcell__r r r1r!r s & r c@seZdZdZddZdS)BaseDetailViewz+A base view for displaying a single object.cOs"||_|j|jd}||S)N)r,)r"r,r/render_to_response)rrequestargsrr0r r r!ris  zBaseDetailView.getN)rr2r3r4rr r r r!r6gs r6cs$eZdZdZdZfddZZS)!SingleObjectTemplateResponseMixinN_detailc szt}W|Styfg}|jr'|jr't|j|jd}|r'|d|t|jtj r@|jj }| d|j |j |jfn t|dddur`t|jtj r`| d|jj j |jj j |jf|scY|Sw)a Return a list of template names to be used for the request. May not be called if render_to_response() is overridden. Return the following list: * the value of ``template_name`` on the view (if provided) * the contents of the ``template_name_field`` field on the object instance that the view is operating upon (if available) * ``/.html`` Nrz %s/%s%s.htmlr)r.get_template_namesrr,template_name_fieldgetattrinsertr(rr)rappend app_labelr*template_name_suffix issubclassr)rnamesname object_metar1r r!r<ss6 #    z4SingleObjectTemplateResponseMixin.get_template_names)rr2r3r=rBr<r5r r r1r!r:osr:c@seZdZdZdS) DetailViewz Render a "detail" view of an object. By default this is a model instance looked up from `self.queryset`, but the view will support display of *any* object by overriding `self.get_object()`. N)rr2r3r4r r r r!rGsrGN)django.core.exceptionsr django.dbr django.httprdjango.utils.translationrrdjango.views.generic.baserrrr r6r:rGr r r r!s   _5