
    1
h                     R   d dl mZ ddlmZ 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  G d
 dej                        Z ed      Z ej                   e       G d dej"                               Z G d dej"                        Zej(                  j!                  e	e       y)    )admin   )APILogN)timezone)JsonResponse)PendingOrder)get_pending_orders)HttpResponseRedirectc                        e Zd Z fdZ xZS )CustomAdminSitec                     t         |   |      }d }g }|D ]  }|d   dk(  r|}|j                  |         |r|j                  |       |S )Nnameskyplay_api)superget_app_listappend)selfrequestapp_listskyplay_api_app
other_appsapp	__class__s         -/var/www/skyplay_api_hub/skyplay_api/admin.pyr   zCustomAdminSite.get_app_list   se    7'0 
 	'C6{m+"%!!#&		' o.    )__name__
__module____qualname__r   __classcell__r   s   @r   r   r      s     r   r   custom_admin)r   c                   ,    e Zd ZdZdZdZd Zde_        y)APILogAdmin)	client_idendpointstatus_codetimestamp_ist)user__usernamer%   request_dataresponse_data)z
-timestampc                     t        j                  d      }|j                  j                  |      j	                  d      S )NAsia/Kolkata%Y-%m-%d %H:%M:%S)pytzr   	timestamp
astimezonestrftime)r   objists      r   r'   zAPILogAdmin.timestamp_ist(   s1    mmN+}}'',556IJJr   zTimestamp (IST)N)r   r   r   list_displaysearch_fieldsorderingr'   short_description r   r   r#   r#   "   s!    LLSMHK '8M#r   r#   c                   .     e Zd ZdZdZd Zd fd	Z xZS )PendingOrderAdmin)order_idr$   amountstatus
created_at
updated_atz.skyplay_api/admin/pendingorder_changelist.htmlc                     |Yt         j                  }t        j                  d      }|j                  |      }|j	                  |      }|j                  d      S |S )zE
        Convert UTC datetime to IST (Indian Standard Time).
        r,   )tzinfor-   )r.   utcr   replacer0   r1   )r   dtutc_zoneist_zonedt_ists        r   convert_to_istz PendingOrderAdmin.convert_to_ist2   sS     >xxH}}^4H8,B]]8,F??#677	r   c                    d|j                   v rt               }t        t        j                  j                  dd            }|D ]M  }|d   |vst        j                  j                  |d   |d   |d   |d   |d	   |d
   |d   |d   |d   	       O t        j                  j                  ddg      j                          | j                  |d       t        |j                        S |xs i }d|j                  v ret        j                  j                         }|D ]B  }| j                  |j                        |_        | j                  |j                        |_        D t         | E  ||      S )Ninsert_pendingr;   T)flatidr$   r<   r=   billing_cycle
invoice_idbilling_from_datebilling_to_dateinvoice_amount)	r;   r$   r<   r=   rM   rN   rO   rP   rQ   paid	cancelled)
status__inz#Pending orders synced successfully.pendingorder)extra_context)GETr	   setr   objectsvalues_listcreatefilterdeletemessage_userr
   pathallrH   r>   r?   r   changelist_view)r   r   rV   pending_ordersexisting_ordersorderr   s         r   ra   z!PendingOrderAdmin.changelist_view?   s   w{{*/1N!,"6"6"B"B:TX"B"YZO' ;o5 ((//!&t"'"4$X$X&+O&<#(#6*/0C*D(-.?(@',-='> 0 
   ''FK3H'IPPRg'LM'55 &+W\\))11557N' I#'#6#6u7G7G#H #'#6#6u7G7G#H I w&wm&LLr   )N)r   r   r   r4   change_list_templaterH   ra   r   r    s   @r   r:   r:   .   s    \LK"M "Mr   r:   )django.contribr   modelsr   r.   django.utilsr   django.httpr   r   utilsr	   r
   	AdminSiter   custom_admin_siteregister
ModelAdminr#   r:   siter8   r   r   <module>rp      s        ! $   % ,eoo * $8 8%"" 8 83M(( 3Mj 

  L"3 4r   