o
    þÞhn  ã                   @   sŒ   d dl mZ d dlmZ d dlmZ d dlmZ d dl	m
Z
mZmZ G dd„ de
ƒZG dd	„ d	eeƒZG d
d„ deƒZG dd„ deeƒZdS )é    )ÚImproperlyConfigured)Úmodels)ÚHttp404)Úgettext)ÚContextMixinÚTemplateResponseMixinÚViewc                       s^   e Zd ZdZdZdZdZdZdZdZ	dZ
ddd„Zdd	„ Zd
d„ Zdd„ Z‡ fdd„Z‡  ZS )ÚSingleObjectMixinzS
    Provide the ability to retrieve a single object for further manipulation.
    NÚslugÚpkFc                 C   sÎ   |du r|   ¡ }| j | j¡}| j | j¡}|dur |j|d�}|dur9|du s+| jr9|  ¡ }|jdi ||i¤Ž}|du rI|du rItd| j	j
 ƒ‚z| ¡ }W |S  |jjyf   ttdƒd|jjji ƒ‚w )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_querysetÚkwargsÚgetÚpk_url_kwargÚslug_url_kwargÚfilterÚquery_pk_and_slugÚget_slug_fieldÚAttributeErrorÚ	__class__Ú__name__ÚmodelÚDoesNotExistr   Ú_Ú_metar   )ÚselfÚquerysetr   r
   Ú
slug_fieldÚobjr   r   ú[/var/www/html/premium_crap/venv/lib/python3.10/site-packages/django/views/generic/detail.pyÚ
get_object   s2   	ÿÿ
ûÿÿÿzSingleObjectMixin.get_objectc                 C   s:   | j du r| jr| jj ¡ S tdd| jji ƒ‚| j  ¡ S )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)r   r   Ú_default_managerÚallr   r   r   ©r   r   r   r!   r   =   s   

þÿ
zSingleObjectMixin.get_querysetc                 C   s   | j S )z;Get the name of a slug field to be used to look up by slug.)r   r&   r   r   r!   r   O   s   z SingleObjectMixin.get_slug_fieldc                 C   s$   | j r| j S t|tjƒr|jjS dS )z#Get the name to use for the object.N)Úcontext_object_nameÚ
isinstancer   ÚModelr   Ú
model_name)r   r    r   r   r!   Úget_context_object_nameS   s
   z)SingleObjectMixin.get_context_object_namec                    sJ   i }| j r| j |d< |  | j ¡}|r| j ||< | |¡ tƒ jdi |¤ŽS )z/Insert the single object into the context dict.ÚobjectNr   )r,   r+   ÚupdateÚsuperÚget_context_data)r   r   Úcontextr'   ©r   r   r!   r/   \   s   


z"SingleObjectMixin.get_context_data)N)r   Ú
__module__Ú__qualname__Ú__doc__r   r   r   r'   r   r   r   r"   r   r   r+   r/   Ú__classcell__r   r   r1   r!   r	      s    
(	r	   c                   @   s   e Zd ZdZdd„ ZdS )ÚBaseDetailViewzo
    Base view for displaying a single object.

    This requires subclassing to provide a response mixin.
    c                 O   s"   |   ¡ | _| j| jd�}|  |¡S )N)r,   )r"   r,   r/   Úrender_to_response)r   ÚrequestÚargsr   r0   r   r   r!   r   o   s   

zBaseDetailView.getN)r   r2   r3   r4   r   r   r   r   r!   r6   h   s    r6   c                       s$   e Zd ZdZdZ‡ fdd„Z‡  ZS )Ú!SingleObjectTemplateResponseMixinNÚ_detailc              	      sÔ   zt ƒ  ¡ }W |S  tyi   g }| jr'| jr't| j| jdƒ}|r'| d|¡ t| jtj	ƒr@| jj
}| d|j|j| jf ¡ n t| ddƒdur`t| jtj	ƒr`| d| jj
j| jj
j| jf ¡ |sftdƒ‚Y |S w )aÓ  
        Return a list of template names to be used for the request. May not be
        called if render_to_response() is overridden. Return a list containing
        ``template_name``, if set on the value. Otherwise, return a list
        containing:

        * the contents of the ``template_name_field`` field on the
          object instance that the view is operating upon (if available)
        * ``<app_label>/<model_name><template_name_suffix>.html``
        Nr   z%s/%s%s.htmlr   zžSingleObjectTemplateResponseMixin requires a definition of 'template_name', 'template_name_field', or 'model'; or an implementation of 'get_template_names()'.)r.   Úget_template_namesr   r,   Útemplate_name_fieldÚgetattrÚinsertr(   r   r)   r   ÚappendÚ	app_labelr*   Útemplate_name_suffixÚ
issubclassr   )r   ÚnamesÚnameÚobject_metar1   r   r!   r<   y   sJ   /ÒýÿÿÿýÿÿÿÿÒz4SingleObjectTemplateResponseMixin.get_template_names)r   r2   r3   r=   rB   r<   r5   r   r   r1   r!   r:   u   s    r:   c                   @   s   e Zd ZdZdS )Ú
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)r   r2   r3   r4   r   r   r   r!   rG   ·   s    rG   N)Údjango.core.exceptionsr   Ú	django.dbr   Údjango.httpr   Údjango.utils.translationr   r   Údjango.views.generic.baser   r   r   r	   r6   r:   rG   r   r   r   r!   Ú<module>   s    `B