
    Nh                         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 d d
lmZ d dlZ ej        e          Z G d dej                  Z G d de          Z G d de          ZdS )    )APIView)Responsestatus   )NotificationHistory)NotificationHistorySerializer)now)genericspermissions)IsAuthenticated)CustomPaginationNc                   "    e Zd ZegZeZeZd Z	dS )VendorNotificationAPIViewc                    |j         }t          j                            |                              d          }|                    d                                          }|                     |          }|                     |dd|i          }t          dd|| 	                    |j
                  j
        d	          S )
N)vendorz-sent_atFis_readTrequest)manycontextz*Buyer notifications retrieved successfully)r   messageunread_countdata)userr   objectsfilterorder_bycountpaginate_querysetget_serializerr   get_paginated_responser   )	selfr   argskwargsr   notifications_qsr   page
serializers	            3/var/www/html/e360mart/notification/views/vendor.pylistzVendorNotificationAPIView.list   s    |.6==T=JJSST^__'..u.==CCEE %%&677((D9gBV(WW
C(//
@@E	
 
   	    N)
__name__
__module____qualname__r   permission_classesr	   serializer_classr   pagination_classr*    r+   r)   r   r      s8        )*4'    r+   r   c                       e Zd ZegZd ZdS )!VendorMarkNotificationReadAPIViewc           	         	 |j         }t          j                            |d          }|                                }|dk    r@t
                              d|j                    t          dddt          j
                  S |                    d	           t
                              | d
|j                    t          d| ddt          j                  S # t          $ r_}t
                              d|j         j         dt          |                      t          dddt          j                  cY d }~S d }~ww xY w)NF)r   r   r   z$No unread notifications for vendor: z.No unread notifications found for this vendor.r   r   r   Tr   z* notifications marked as read for vendor: z notifications marked as read.z6Error in VendorMarkNotificationReadAPIView for vendor=z: Internal server error.)r   r   r   r   r   loggerinfoidr   r   HTTP_404_NOT_FOUNDupdateHTTP_200_OK	Exception	exceptionstrHTTP_500_INTERNAL_SERVER_ERROR)r#   r   r   	unread_qsr   es         r)   postz&VendorMarkNotificationReadAPIView.post)   s   	=<D+3::$PU:VVI$??,,Lq  L47LLMMM#O! ! !35 5 5 5
 T***KK<\\SWSZ\\]]]*JJJ  (* * * *
  	= 	= 	=qV]VbVeqqilmnioioqqrrr3  ;= = = = = = = = =	=s&   BC AC 
E)AE=EEN)r,   r-   r.   r   r/   rD   r2   r+   r)   r4   r4   &   s,        )*= = = = =r+   r4   c                       e Zd ZegZd ZdS )VendorDeleteNotificationAPIViewc                    |j                             d          }|st          ddddt          j                  S 	 t
          j                            ||j                  	                                }|r\|
                                 t                              d|j        j         d	|            t          d
ddt          j                  S t                              d|j        j         d|            t          ddddt          j                  S # t"          $ rR}t                              d| d|j        j                    t          dddt          j                  cY d }~S d }~ww xY w)Nnotification_idFznotification_id is required.z"Missing parameter: notification_id)r   r   errorr   )r:   r   zVendor z deleted notification ID Tz"Notification deleted successfully.r6   z= tried to delete nonexistent or unauthorized notification ID zNotification not found.z/Invalid notification ID or not owned by vendor.zError deleting notification ID z for vendor r7   )r   getr   r   HTTP_400_BAD_REQUESTr   r   r   r   firstdeleter8   r9   r:   r=   warningr;   r>   r?   rA   )r#   r   rH   historyrC   s        r)   rM   z&VendorDeleteNotificationAPIView.deleteK   s   !,**+<== 	39=  1	3 3 3 3	=)188OT[T`8aaggiiG 5   agloaaP_aabbb"C! ! !,. . . .
    I   I   I  xG   I   I  J  J  J#8N! ! !3	5 5 5 5  	= 	= 	=mmm\c\h\kmmnnn3  ;= = = = = = = = =	=s&   BD AD 
E8&AE3-E83E8N)r,   r-   r.   r   r/   rM   r2   r+   r)   rF   rF   G   s,        )*$= $= $= $= $=r+   rF   )rest_framework.viewsr   rest_framework.responser   rest_frameworkr   modelsr   serializersr	   django.utils.timezoner
   r   r   rest_framework.permissionsr   suscription.custom_paginationr   logging	getLoggerr,   r8   ListAPIViewr   r4   rF   r2   r+   r)   <module>r[      sT   ( ( ( ( ( ( , , , , , , ! ! ! ! ! ! ( ( ( ( ( ( 8 8 8 8 8 8 % % % % % % 0 0 0 0 0 0 0 0 6 6 6 6 6 6 : : : : : : 		8	$	$     4   0= = = = = = = =B(= (= (= (= (=g (= (= (= (= (=r+   