o
    þÞh)i  ã                   @   s  d dl 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
 d dlmZ d dlmZ d d	lmZ d d
lmZmZ d dlmZmZ G dd„ dƒZG dd„ dƒZG dd„ dƒZG dd„ dƒZG dd„ dƒZG dd„ deeeƒZG dd„ deƒZG dd„ deeƒZG dd„ deeƒZ G dd„ dee ƒZ!G d d!„ d!eeeƒZ"G d"d#„ d#ee"ƒZ#G d$d%„ d%eeeƒZ$G d&d'„ d'ee$ƒZ%G d(d)„ d)eeeeƒZ&G d*d+„ d+ee&ƒZ'G d,d-„ d-e&ƒZ(G d.d/„ d/ee(ƒZ)G d0d1„ d1eeeeeƒZ*G d2d3„ d3ee*ƒZ+	5d<d6d7„Z,d8d9„ Z-d:d;„ Z.dS )=é    N)Úsettings)ÚImproperlyConfigured)Úmodels)ÚHttp404)Útimezone)Úcached_property)Úgettext)ÚView)ÚBaseDetailViewÚ!SingleObjectTemplateResponseMixin)ÚMultipleObjectMixinÚ#MultipleObjectTemplateResponseMixinc                   @   óH   e Zd ZdZdZdZdd„ Zdd„ Zdd	„ Zd
d„ Z	dd„ Z
dd„ ZdS )Ú	YearMixinz-Mixin for views manipulating year-based data.z%YNc                 C   ó   | j S )zv
        Get a year format string in strptime syntax to be used to parse the
        year from url variables.
        )Úyear_format©Úself© r   úZ/var/www/html/premium_crap/venv/lib/python3.10/site-packages/django/views/generic/dates.pyÚget_year_format   ó   zYearMixin.get_year_formatc                 C   ób   | j }|du r/z| jd }W |S  ty.   z
| jjd }W Y |S  ty-   ttdƒƒ‚w w |S )z8Return the year for which this view should display data.NÚyearzNo year specified)r   ÚkwargsÚKeyErrorÚrequestÚGETr   Ú_)r   r   r   r   r   Úget_year"   ó   ûþÿýzYearMixin.get_yearc                 C   ó   t | |ddd�S )zGet the next valid year.Fr   ©Úis_previousÚperiod©Ú_get_next_prev©r   Údater   r   r   Úget_next_year/   ó   zYearMixin.get_next_yearc                 C   r!   )zGet the previous valid year.Tr   r"   r%   r'   r   r   r   Úget_previous_year3   r*   zYearMixin.get_previous_yearc                 C   s4   z|j |jd ddd�W S  ty   ttdƒƒ‚w )úŒ
        Return the start date of the next interval.

        The interval is defined by start date <= item date < next start date.
        é   ©r   ÚmonthÚdayúDate out of range)Úreplacer   Ú
ValueErrorr   r   r'   r   r   r   Ú_get_next_year7   s
   ÿzYearMixin._get_next_yearc                 C   s   |j ddd�S )ú.Return the start date of the current interval.r-   ©r/   r0   ©r2   r'   r   r   r   Ú_get_current_yearB   s   zYearMixin._get_current_year)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r)   r+   r4   r8   r   r   r   r   r      s    r   c                   @   r   )Ú
MonthMixinz.Mixin for views manipulating month-based data.z%bNc                 C   r   )zx
        Get a month format string in strptime syntax to be used to parse the
        month from url variables.
        )Úmonth_formatr   r   r   r   Úget_month_formatM   r   zMonthMixin.get_month_formatc                 C   r   )z9Return the month for which this view should display data.Nr/   zNo month specified)r/   r   r   r   r   r   r   )r   r/   r   r   r   Ú	get_monthT   r    zMonthMixin.get_monthc                 C   r!   )zGet the next valid month.Fr/   r"   r%   r'   r   r   r   Úget_next_montha   r*   zMonthMixin.get_next_monthc                 C   r!   )zGet the previous valid month.Tr/   r"   r%   r'   r   r   r   Úget_previous_monthe   r*   zMonthMixin.get_previous_monthc                 C   sR   |j dkrz|j|jd ddd�W S  ty   ttdƒƒ‚w |j|j d dd�S )r,   é   r-   r.   r1   r6   )r/   r2   r   r3   r   r   r'   r   r   r   Ú_get_next_monthi   s   
ÿzMonthMixin._get_next_monthc                 C   s   |j dd�S )z/Return the start date of the previous interval.r-   )r0   r7   r'   r   r   r   Ú_get_current_monthw   s   zMonthMixin._get_current_month)r9   r:   r;   r<   r>   r/   r?   r@   rA   rB   rD   rE   r   r   r   r   r=   G   s    r=   c                   @   r   )ÚDayMixinz,Mixin for views manipulating day-based data.z%dNc                 C   r   )zt
        Get a day format string in strptime syntax to be used to parse the day
        from url variables.
        )Ú
day_formatr   r   r   r   Úget_day_format‚   r   zDayMixin.get_day_formatc                 C   r   )z7Return the day for which this view should display data.Nr0   zNo day specified)r0   r   r   r   r   r   r   )r   r0   r   r   r   Úget_day‰   r    zDayMixin.get_dayc                 C   r!   )zGet the next valid day.Fr0   r"   r%   r'   r   r   r   Úget_next_day–   r*   zDayMixin.get_next_dayc                 C   r!   )zGet the previous valid day.Tr0   r"   r%   r'   r   r   r   Úget_previous_dayš   r*   zDayMixin.get_previous_dayc                 C   s   |t jdd� S )r,   r-   ©Údays)ÚdatetimeÚ	timedeltar'   r   r   r   Ú_get_next_dayž   s   zDayMixin._get_next_dayc                 C   s   |S ©r5   r   r'   r   r   r   Ú_get_current_day¦   s   zDayMixin._get_current_day)r9   r:   r;   r<   rG   r0   rH   rI   rJ   rK   rP   rR   r   r   r   r   rF   |   s    rF   c                   @   sP   e Zd ZdZdZdZdd„ Zdd„ Zdd	„ Zd
d„ Z	dd„ Z
dd„ Zdd„ ZdS )Ú	WeekMixinz-Mixin for views manipulating week-based data.ú%UNc                 C   r   )zv
        Get a week format string in strptime syntax to be used to parse the
        week from url variables.
        )Úweek_formatr   r   r   r   Úget_week_format±   r   zWeekMixin.get_week_formatc                 C   r   )z8Return the week for which this view should display data.NÚweekzNo week specified)rW   r   r   r   r   r   r   )r   rW   r   r   r   Úget_week¸   r    zWeekMixin.get_weekc                 C   r!   )zGet the next valid week.FrW   r"   r%   r'   r   r   r   Úget_next_weekÅ   r*   zWeekMixin.get_next_weekc                 C   r!   )zGet the previous valid week.TrW   r"   r%   r'   r   r   r   Úget_previous_weekÉ   r*   zWeekMixin.get_previous_weekc                 C   s8   z|t jd|  |¡ d� W S  ty   ttdƒƒ‚w )r,   é   rL   r1   )rN   rO   Ú_get_weekdayÚOverflowErrorr   r   r'   r   r   r   Ú_get_next_weekÍ   s
   ÿzWeekMixin._get_next_weekc                 C   s   |t  |  |¡¡ S rQ   )rN   rO   r\   r'   r   r   r   Ú_get_current_weekØ   s   zWeekMixin._get_current_weekc                 C   s<   |   ¡ }|dv r| ¡ S |dkr| ¡ d d S td| ƒ‚)z†
        Return the weekday for a given date.

        The first day according to the week format is 0 and the last day is 6.
        >   ú%Vú%WrT   r-   r[   zunknown week format: %s)rV   Úweekdayr3   )r   r(   rU   r   r   r   r\   Ü   s   zWeekMixin._get_weekday)r9   r:   r;   r<   rU   rW   rV   rX   rY   rZ   r^   r_   r\   r   r   r   r   rS   «   s    rS   c                   @   sD   e Zd ZdZdZdZdd„ Zdd„ Zedd	„ ƒZ	d
d„ Z
dd„ ZdS )Ú	DateMixinz3Mixin class for views manipulating date-based data.NFc                 C   s    | j du rtd| jj ƒ‚| j S )z7Get the name of the date field to be used to filter by.Nz%s.date_field is required.)Ú
date_fieldr   Ú	__class__r9   r   r   r   r   Úget_date_fieldñ   s
   

ÿzDateMixin.get_date_fieldc                 C   r   )zi
        Return `True` if the view should be allowed to display objects from
        the future.
        )Úallow_futurer   r   r   r   Úget_allow_futureù   r   zDateMixin.get_allow_futurec                 C   s6   | j du r
|  ¡ j n| j }|j |  ¡ ¡}t|tjƒS )zq
        Return `True` if the date field is a `DateTimeField` and `False`
        if it's a `DateField`.
        N)ÚmodelÚget_querysetÚ_metaÚ	get_fieldrf   Ú
isinstancer   ÚDateTimeField)r   ri   Úfieldr   r   r   Úuses_datetime_field  s   zDateMixin.uses_datetime_fieldc                 C   s,   | j rtj |tjj¡}tjrt |¡}|S )zó
        Convert a date into a datetime when the date field is a DateTimeField.

        When time zone support is enabled, `date` is assumed to be in the
        current time zone, so that displayed items are consistent with the URL.
        )	rp   rN   ÚcombineÚtimeÚminr   ÚUSE_TZr   Ú
make_aware)r   Úvaluer   r   r   Ú_make_date_lookup_arg  s
   
zDateMixin._make_date_lookup_argc                 C   sJ   |   ¡ }| jr!|  |¡}|  |tjdd� ¡}d| |d| |iS ||iS )z×
        Get the lookup kwargs for filtering on a single date.

        If the date field is a DateTimeField, we can't just filter on
        date_field=date because that doesn't take the time into account.
        r-   rL   ú%s__gteú%s__lt)rf   rp   rw   rN   rO   )r   r(   rd   ÚsinceÚuntilr   r   r   Ú_make_single_date_lookup  s   
þz"DateMixin._make_single_date_lookup)r9   r:   r;   r<   rd   rg   rf   rh   r   rp   rw   r|   r   r   r   r   rc   ë   s    

	rc   c                   @   sJ   e Zd ZdZdZdZdd„ Zdd„ Zdd	„ Zd
d„ Z	dd„ Z
ddd„ZdS )ÚBaseDateListViewzƒ
    Base class for date-based views displaying a list of objects.

    This requires subclassing to provide a response mixin.
    Fr   c                 O   s6   |   ¡ \| _| _}| jd| j| jdœ|¤Ž}|  |¡S )N)Úobject_listÚ	date_listr   )Úget_dated_itemsr   r~   Úget_context_dataÚrender_to_response)r   r   Úargsr   Úextra_contextÚcontextr   r   r   Úget8  s   ÿÿ
zBaseDateListView.getc                 C   s   t dƒ‚)z#Obtain the list of dates and items.z>A DateView must provide an implementation of get_dated_items())ÚNotImplementedErrorr   r   r   r   r€   ?  s   ÿz BaseDateListView.get_dated_itemsc                 C   s   | j du rd|  ¡  S | j S )zu
        Return the field or fields to use for ordering the queryset; use the
        date field by default.
        Nú-%s)Úorderingrf   r   r   r   r   Úget_orderingE  s   zBaseDateListView.get_orderingc           	      K   s¤   |   ¡ jdi |¤Ž}|  ¡ }|  ¡ }|  ¡ }|  |¡}|s3| jr$t ¡ nt	ƒ }|jdi d| |i¤Ž}|sP|du r<| n| 
¡  }|rPttdƒd|jjji ƒ‚|S )zs
        Get a queryset properly filtered according to `allow_future` and any
        extra lookup kwargs.
        ú%s__lteNú$No %(verbose_name_plural)s availableÚverbose_name_pluralr   )rj   Úfilterrf   rh   Úget_allow_emptyÚget_paginate_byrp   r   ÚnowÚtimezone_todayÚexistsr   r   ri   rk   r�   )	r   ÚlookupÚqsrd   rg   Úallow_emptyÚpaginate_byr‘   Úis_emptyr   r   r   Úget_dated_querysetL  s$   

ÿÿÿz#BaseDateListView.get_dated_querysetc                 C   r   )zf
        Get the aggregation period for the list of dates: 'year', 'month', or
        'day'.
        )Údate_list_periodr   r   r   r   Úget_date_list_periodi  r   z%BaseDateListView.get_date_list_periodNÚASCc                 C   sr   |   ¡ }|  ¡ }|du r|  ¡ }| jr| |||¡}n| |||¡}|dur7|s7|s7ttdƒd|jj	j
i ƒ‚|S )zŽ
        Get a date list by calling `queryset.dates/datetimes()`, checking
        along the way for empty lists that aren't allowed.
        NrŒ   r�   )rf   r�   r›   rp   Ú	datetimesÚdatesr   r   ri   rk   r�   )r   ÚquerysetÚ	date_typer‰   rd   r–   r   r   r   r   Úget_date_listp  s   
ÿÿÿzBaseDateListView.get_date_list)Nrœ   )r9   r:   r;   r<   r–   rš   r†   r€   rŠ   r™   r›   r¡   r   r   r   r   r}   .  s    r}   c                   @   ó   e Zd ZdZdZdd„ ZdS )ÚBaseArchiveIndexViewzq
    Base view for archives of date-based items.

    This requires subclassing to provide a response mixin.
    Úlatestc                 C   s,   |   ¡ }| j|dd�}|s| ¡ }||i fS )ú:Return (date_list, items, extra_context) for this request.ÚDESC)r‰   )r™   r¡   Únone)r   r•   r   r   r   r   r€   ’  s
   
z$BaseArchiveIndexView.get_dated_itemsN)r9   r:   r;   r<   Úcontext_object_namer€   r   r   r   r   r£   ‰  ó    r£   c                   @   ó   e Zd ZdZdZdS )ÚArchiveIndexViewz&Top-level archive of date-based items.Ú_archiveN©r9   r:   r;   r<   Útemplate_name_suffixr   r   r   r   r«   �  ó    r«   c                   @   s(   e Zd ZdZdZdZdd„ Zdd„ ZdS )	ÚBaseYearArchiveViewz€
    Base view for a list of objects published in a given year.

    This requires subclassing to provide a response mixin.
    r/   Fc           	      C   s”   |   ¡ }|  ¡ }t||  ¡ ƒ}|  |¡}|  |  |¡¡}d| |d| |i}| jdi |¤Ž}|  |¡}|  ¡ s;| 	¡ }||||  
|¡|  |¡dœfS )r¥   rx   ry   )r   Ú	next_yearÚprevious_yearNr   )r   rf   Ú_date_from_stringr   rw   r4   r™   r¡   Úget_make_object_listr§   r)   r+   )	r   r   rd   r(   rz   r{   Úlookup_kwargsr•   r   r   r   r   r€   ­  s&   
þ
ýýz#BaseYearArchiveView.get_dated_itemsc                 C   r   )zo
        Return `True` if this view should contain the full list of objects in
        the given year.
        )Úmake_object_listr   r   r   r   r´   Í  r   z(BaseYearArchiveView.get_make_object_listN)r9   r:   r;   r<   rš   r¶   r€   r´   r   r   r   r   r°   £  s     r°   c                   @   rª   )ÚYearArchiveViewz*List of objects published in a given year.Ú_archive_yearNr­   r   r   r   r   r·   Õ  r¯   r·   c                   @   r¢   )ÚBaseMonthArchiveViewz�
    Base view for a list of objects published in a given month.

    This requires subclassing to provide a response mixin.
    r0   c           
      C   s”   |   ¡ }|  ¡ }|  ¡ }t||  ¡ ||  ¡ ƒ}|  |¡}|  |  |¡¡}d| |d| |i}| jdi |¤Ž}|  	|¡}	|	|||  
|¡|  |¡dœfS )r¥   rx   ry   )r/   Ú
next_monthÚprevious_monthNr   )r   r@   rf   r³   r   r?   rw   rD   r™   r¡   rA   rB   )
r   r   r/   rd   r(   rz   r{   rµ   r•   r   r   r   r   r€   ä  s(   ÿ
þ
ýýz$BaseMonthArchiveView.get_dated_itemsN)r9   r:   r;   r<   rš   r€   r   r   r   r   r¹   Û  r©   r¹   c                   @   rª   )ÚMonthArchiveViewz+List of objects published in a given month.Ú_archive_monthNr­   r   r   r   r   r¼     r¯   r¼   c                   @   ó   e Zd ZdZdd„ ZdS )ÚBaseWeekArchiveViewz€
    Base view for a list of objects published in a given week.

    This requires subclassing to provide a response mixin.
    c              
   C   sø   |   ¡ }|  ¡ }|  ¡ }|  ¡ }ddddœ}z|| }W n ty0   td|d t|ƒ¡f ƒ‚w |  ¡ }|dkrE|dkrEtd||f ƒ‚t	|||d	||ƒ}|  
|¡}	|  
|  |¡¡}
d
| |	d| |
i}| jdi |¤Ž}d|||  |¡|  |¡dœfS )r¥   Ú1Ú0)ra   rT   r`   z'Unknown week format %r. Choices are: %sz, r`   z%GzeISO week directive '%s' is incompatible with the year directive '%s'. Use the ISO year '%%G' instead.z%wrx   ry   N)rW   Ú	next_weekÚprevious_weekr   )r   rX   rf   rV   r   r3   ÚjoinÚsortedr   r³   rw   r^   r™   rY   rZ   )r   r   rW   rd   rU   Úweek_choicesÚ
week_startr   r(   rz   r{   rµ   r•   r   r   r   r€     sN   þÿÿÿþþÿ
þýýz#BaseWeekArchiveView.get_dated_itemsN©r9   r:   r;   r<   r€   r   r   r   r   r¿   	  ó    r¿   c                   @   rª   )ÚWeekArchiveViewz*List of objects published in a given week.Ú_archive_weekNr­   r   r   r   r   rÊ   A  r¯   rÊ   c                   @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚBaseDayArchiveViewz
    Base view for a list of objects published on a given day.

    This requires subclassing to provide a response mixin.
    c                 C   s@   |   ¡ }|  ¡ }|  ¡ }t||  ¡ ||  ¡ ||  ¡ ƒ}|  |¡S ©r¥   )r   r@   rI   r³   r   r?   rH   Ú_get_dated_items)r   r   r/   r0   r(   r   r   r   r€   N  s   ú
	z"BaseDayArchiveView.get_dated_itemsc              	   C   sH   |   |¡}| jdi |¤Ž}d|||  |¡|  |¡|  |¡|  |¡dœfS )z•
        Do the actual heavy lifting of getting the dated items; this accepts a
        date object so that TodayArchiveView can be trivial.
        N)r0   Úprevious_dayÚnext_dayr»   rº   r   )r|   r™   rK   rJ   rB   rA   )r   r(   rµ   r•   r   r   r   rÎ   _  s   
ûýz#BaseDayArchiveView._get_dated_itemsN)r9   r:   r;   r<   r€   rÎ   r   r   r   r   rÌ   G  s    rÌ   c                   @   rª   )ÚDayArchiveViewz)List of objects published on a given day.Ú_archive_dayNr­   r   r   r   r   rÑ   t  r¯   rÑ   c                   @   r¾   )ÚBaseTodayArchiveViewzv
    Base view for a list of objects published today.

    This requires subclassing to provide a response mixin.
    c                 C   s   |   tj ¡ ¡S rÍ   )rÎ   rN   r(   Útodayr   r   r   r   r€   �  r*   z$BaseTodayArchiveView.get_dated_itemsNrÈ   r   r   r   r   rÓ   z  rÉ   rÓ   c                   @   rª   )ÚTodayArchiveViewz List of objects published today.rÒ   Nr­   r   r   r   r   rÕ   †  r¯   rÕ   c                       s"   e Zd ZdZd‡ fdd„	Z‡  ZS )ÚBaseDateDetailViewzÔ
    Base detail view for a single object on a single date; this differs from the
    standard DetailView by accepting a year/month/day in the URL.

    This requires subclassing to provide a response mixin.
    Nc                    s¨   |   ¡ }|  ¡ }|  ¡ }t||  ¡ ||  ¡ ||  ¡ ƒ}|du r#|  ¡ n|}|  ¡ s@|t	j
 ¡ kr@ttdƒ|jjj| jjdœ ƒ‚|  |¡}|jdi |¤Ž}tƒ j|d�S )z%Get the object this request displays.NzZFuture %(verbose_name_plural)s not available because %(class_name)s.allow_future is False.)r�   Ú
class_name)rŸ   r   )r   r@   rI   r³   r   r?   rH   rj   rh   rN   r(   rÔ   r   r   ri   rk   r�   re   r9   r|   rŽ   ÚsuperÚ
get_object)r   rŸ   r   r/   r0   r(   r•   rµ   ©re   r   r   rÙ   ”  s2   ú
ÿþüÿ
zBaseDateDetailView.get_object)N)r9   r:   r;   r<   rÙ   Ú__classcell__r   r   rÚ   r   rÖ   Œ  s    rÖ   c                   @   rª   )ÚDateDetailViewz’
    Detail view of a single object on a single date; this differs from the
    standard DetailView by accepting a year/month/day in the URL.
    Ú_detailNr­   r   r   r   r   rÜ   º  s    rÜ   Ú Ú__c           	      C   sn   || | | | }t | ƒ| t |ƒ | t |ƒ }z
tj ||¡ ¡ W S  ty6   ttdƒ||dœ ƒ‚w )z”
    Get a datetime.date object given a format string and a year, month, and day
    (only year is mandatory). Raise a 404 for an invalid date.
    uC   Invalid date string â€œ%(datestr)sâ€� given format â€œ%(format)sâ€�)ÚdatestrÚformat)ÚstrrN   Ústrptimer(   r3   r   r   )	r   r   r/   r>   r0   rG   Údelimrá   rà   r   r   r   r³   Ã  s    þÿÿÿr³   c                 C   sB  |   ¡ }|  ¡ }|  ¡ }t| d| ƒ}t| d| ƒ}||ƒ||ƒ}	}
|r?|r2||	tjdd� ƒ}n|
}|s;|tƒ kr=|S dS |rOd| |  |	¡i}d| }nd| |  |
¡i}|}|sm| jrdt	 
¡ }ntƒ }||d	| < |  ¡ jdi |¤Ž |¡}z	t|d
 |ƒ}W n
 ty�   Y dS w | jr�tjr™t	 |¡}| ¡ }||ƒS )aV  
    Get the next or the previous valid date. The idea is to allow links on
    month/day views to never be 404s by never providing a date that'll be
    invalid for the given view.

    This is a bit complicated since it handles different intervals of time,
    hence the coupling to generic_view.

    However in essence the logic comes down to:

        * If allow_empty and allow_future are both true, this is easy: just
          return the naive result (just the next/previous day/week/month,
          regardless of object existence.)

        * If allow_empty is true, allow_future is false, and the naive result
          isn't in the future, then return it; otherwise return None.

        * If allow_empty is false and allow_future is true, return the next
          date *that contains a valid object*, even if it's in the future. If
          there are no next objects, return None.

        * If allow_empty is false and allow_future is false, return the next
          date that contains a valid object. If that date is in the future, or
          if there are no next objects, return None.
    z_get_current_%sz_get_next_%sr-   rL   Nry   rˆ   rx   r‹   r   r   )rf   r�   rh   ÚgetattrrN   rO   r’   rw   rp   r   r‘   rj   rŽ   Úorder_byÚ
IndexErrorr   rt   Ú	localtimer(   )Úgeneric_viewr(   r#   r$   rd   r–   rg   Úget_currentÚget_nextÚstartÚendÚresultr”   r‰   r‘   r•   r   r   r   r&   Ø  sD   

ÿ
r&   c                   C   s   t jrt ¡ S tj ¡ S )z1Return the current date in the current time zone.)r   rt   r   Ú	localdaterN   r(   rÔ   r   r   r   r   r’   2  s   
r’   )rÞ   rÞ   rÞ   rÞ   rß   )/rN   Údjango.confr   Údjango.core.exceptionsr   Ú	django.dbr   Údjango.httpr   Údjango.utilsr   Údjango.utils.functionalr   Údjango.utils.translationr   r   Údjango.views.generic.baser	   Údjango.views.generic.detailr
   r   Údjango.views.generic.listr   r   r   r=   rF   rS   rc   r}   r£   r«   r°   r·   r¹   r¼   r¿   rÊ   rÌ   rÑ   rÓ   rÕ   rÖ   rÜ   r³   r&   r’   r   r   r   r   Ú<module>   sF    25/@C[2(8-.

ÿZ