î
ªÍ XÇ  ã               @   sô   d  d l  m Z d  d l m Z d  d l m Z m Z 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 Gd	 d
 „  d
 e ƒ Z Gd d „  d e e ƒ Z Gd d „  d e ƒ Z Gd d „  d e e ƒ Z d S)é    )Úunicode_literals)ÚImproperlyConfigured)ÚInvalidPageÚ	Paginator)ÚQuerySet)ÚHttp404)Úsix)Úugettext)ÚContextMixinÚTemplateResponseMixinÚViewc                   sÄ   e  Z d  Z d Z d Z d Z d Z d Z d Z d Z	 e
 Z d Z d Z d d „  Z d d	 „  Z d
 d „  Z d d „  Z d d d d „ Z d d „  Z d d „  Z d d „  Z ‡  f d d †  Z ‡  S)ÚMultipleObjectMixinz:
    A mixin for views manipulating multiple objects.
    TNr   Úpagec             C   sÀ   |  j  d k	 r9 |  j  } t | t ƒ rz | j ƒ  } qz nA |  j d k	 r] |  j j j ƒ  } n t d i |  j j d 6ƒ ‚ |  j	 ƒ  } | r¼ t | t
 j ƒ rª | f } n  | j | Œ  } n  | S)zÐ
        Return the list of items for this view.

        The return value must be an iterable and may be an instance of
        `QuerySet` in which case `QuerySet` specific behavior will be enabled.
        Nzj%(cls)s is missing a QuerySet. Define %(cls)s.model, %(cls)s.queryset, or override %(cls)s.get_queryset().Úcls)ÚquerysetÚ
isinstancer   ÚallÚmodelZ_default_managerr   Ú	__class__Ú__name__Úget_orderingr   Ústring_typesZorder_by)Úselfr   Úordering© r   úG/home/ubuntu/projects/ifolica/build/django/django/views/generic/list.pyÚget_queryset   s     	z MultipleObjectMixin.get_querysetc             C   s   |  j  S)zN
        Return the field or fields to use for ordering the queryset.
        )r   )r   r   r   r   r   7   s    z MultipleObjectMixin.get_orderingc             C   s1  |  j  | | d |  j ƒ  d |  j ƒ  ƒ} |  j } |  j j | ƒ p] |  j j j | ƒ p] d } y t | ƒ } Wn< t	 k
 r® | d k r˜ | j
 } n t t d ƒ ƒ ‚ Yn Xy, | j | ƒ } | | | j | j ƒ  f SWnO t k
 r,} z/ t t d ƒ i | d 6t | ƒ d 6ƒ ‚ WYd	 d	 } ~ Xn Xd	 S)
z3
        Paginate the queryset, if needed.
        ÚorphansÚallow_empty_first_pageé   Úlastz6Page is not 'last', nor can it be converted to an int.z+Invalid page (%(page_number)s): %(message)sÚpage_numberÚmessageN)Úget_paginatorÚget_paginate_orphansÚget_allow_emptyÚ
page_kwargÚkwargsÚgetÚrequestÚGETÚintÚ
ValueErrorZ	num_pagesr   Ú_r   Úobject_listZhas_other_pagesr   Ústr)r   r   Ú	page_sizeÚ	paginatorr&   r   r!   Úer   r   r   Úpaginate_queryset=   s$    	-z%MultipleObjectMixin.paginate_querysetc             C   s   |  j  S)zX
        Get the number of items to paginate by, or ``None`` for no pagination.
        )Úpaginate_by)r   r   r   r   r   Úget_paginate_byV   s    z#MultipleObjectMixin.get_paginate_byc             K   s   |  j  | | d | d | | S)zD
        Return an instance of the paginator for this view.
        r   r   )Úpaginator_class)r   r   Zper_pager   r   r'   r   r   r   r#   \   s    z!MultipleObjectMixin.get_paginatorc             C   s   |  j  S)zh
        Returns the maximum number of orphans extend the last page by when
        paginating.
        )Úpaginate_orphans)r   r   r   r   r$   e   s    z(MultipleObjectMixin.get_paginate_orphansc             C   s   |  j  S)zƒ
        Returns ``True`` if the view should display empty lists, and ``False``
        if a 404 should be raised instead.
        )Úallow_empty)r   r   r   r   r%   l   s    z#MultipleObjectMixin.get_allow_emptyc             C   s8   |  j  r |  j  St | d ƒ r0 d | j j j Sd Sd S)zE
        Get the name of the item to be used in the context.
        r   z%s_listN)Úcontext_object_nameÚhasattrr   Ú_metaÚ
model_name)r   r.   r   r   r   Úget_context_object_names   s
    	z+MultipleObjectMixin.get_context_object_namec       	         sÚ   | j  d |  j ƒ } |  j | ƒ } |  j | ƒ } | r| |  j | | ƒ \ } } } } i | d 6| d 6| d 6| d 6} n" i d d 6d d 6d d 6| d 6} | d k	 r· | | | <n  | j | ƒ t t |  ƒ j |   S)z0
        Get the context for this view.
        r.   r1   Zpage_objÚis_paginatedNF)	Úpopr.   r5   r=   r3   ÚupdateÚsuperr   Úget_context_data)	r   r'   r   r0   r9   r1   r   r>   Úcontext)r   r   r   rB   ~   s&    
z$MultipleObjectMixin.get_context_data)r   Ú
__module__Ú__qualname__Ú__doc__r8   r   r   r4   r7   r9   r   r6   r&   r   r   r   r3   r5   r#   r$   r%   r=   rB   r   r   )r   r   r      s(   r   c               @   s"   e  Z d  Z d Z d d „  Z d S)ÚBaseListViewz7
    A base view for displaying a list of objects.
    c             O   s»   |  j  ƒ  |  _ |  j ƒ  } | s¢ |  j |  j ƒ d  k	 r^ t |  j d ƒ r^ |  j j ƒ  } n t |  j ƒ d k } | r¢ t t d ƒ i |  j	 j
 d 6ƒ ‚ q¢ n  |  j ƒ  } |  j | ƒ S)NÚexistsr   z5Empty list and '%(class_name)s.allow_empty' is False.Ú
class_name)r   r.   r%   r5   r:   rH   Úlenr   r-   r   r   rB   Zrender_to_response)r   r)   Úargsr'   r8   Zis_emptyrC   r   r   r   r(   ž   s    *zBaseListView.getN)r   rD   rE   rF   r(   r   r   r   r   rG   š   s   rG   c                   s.   e  Z d  Z d Z d Z ‡  f d d †  Z ‡  S)Ú#MultipleObjectTemplateResponseMixinzC
    Mixin for responding with a template and list of objects.
    Z_listc                s   y t  t |  ƒ j ƒ  } Wn t k
 r3 g  } Yn Xt |  j d ƒ r{ |  j j j } | j d | j	 | j
 |  j f ƒ n  | S)z 
        Return a list of template names to be used for the request. Must return
        a list. May not be called if render_to_response is overridden.
        r   z%s/%s%s.html)rA   rL   Úget_template_namesr   r:   r.   r   r;   ÚappendZ	app_labelr<   Útemplate_name_suffix)r   ÚnamesÚopts)r   r   r   rM   ¸   s    &z6MultipleObjectTemplateResponseMixin.get_template_names)r   rD   rE   rF   rO   rM   r   r   )r   r   rL   ²   s   rL   c               @   s   e  Z d  Z d Z d S)ÚListViewzž
    Render some list of objects, set by `self.model` or `self.queryset`.
    `self.queryset` can actually be any iterable of items, not just a queryset.
    N)r   rD   rE   rF   r   r   r   r   rR   Ï   s   rR   N)Ú
__future__r   Zdjango.core.exceptionsr   Zdjango.core.paginatorr   r   Zdjango.db.models.queryr   Zdjango.httpr   Zdjango.utilsr   Zdjango.utils.translationr	   r-   Zdjango.views.generic.baser
   r   r   r   rG   rL   rR   r   r   r   r   Ú<module>   s   Ž