a
    tf	                    @   s  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 d dlT d dlT 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 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(d dl)m*Z* d dl+m,Z,m-Z-m.Z. d dl+m/Z/ d dl0m1Z1 d dl2m3Z3 d dl4m5Z5 d dl mZm6Z6 d dl7m8Z8 d dl9Z9d dl:Z:d dl;Z;d dl<Z<d dl=Z=d dl>m?Z? d dl@mAZA d d lBmCZC d dlDZDd dlmZ d dlmZ G d!d" d"eZEe(Fd#ZGG d$d% d%e
ZHd&d' ZId(d) ZJG d*d+ d+e
ZKG d,d- d-e
ZLG d.d/ d/e
ZMG d0d1 d1e
ZNG d2d3 d3e
ZOG d4d5 d5e
ZPG d6d7 d7e
ZQG d8d9 d9e
ZRG d:d; d;e
ZSdS )<    )HttpResponseJsonResponse)reverse)PageNumberPagination)Response)APIView)api_viewpermission_classes)*N)response)	Paginator)r   )defunct_hash_message)settings)Web3)&construct_sign_and_send_raw_middleware)Account)encode_defunct)LocalAccount)renderr   )Mnemonic)signing)IsAuthenticated)genericspermissionsserializersstatus)openapi)swagger_auto_schema)CategorySerializer)r   HttpResponseRedirect)authenticate)ContentFile)
SignupForm)timezonec                   @   s   e Zd ZdZdZdZdS )CustomPagination
   	page_sized   N)__name__
__module____qualname__r'   page_size_query_parammax_page_size r.   r.   /Users/christophesurbier/Dropbox/Mon Mac (MacBook-Air-de-christophe.local)/Documents/Programmation/SellTix/tixsellbackend/api_partner/views_events.pyr%   ,   s   r%   djangoc                   @   s4   e Zd ZedddddZedddddZdS )	signupNauto_schemac                 C   s   t  }t|dd|iS )Nzsignup.htmlform)r#   r   )selfrequestformatr4   r.   r.   r/   get5   s    z
signup.getc              
   C   sB  z t d t |j |jd}|jd}|r|rt d t d t|||d}t d t | |d urtjj|d }|r|j	rt
d	 nhd
t|j d }dt|j d }t d|  t d|  tjj|j||dd}	|	d }
t
|
W S nt }||_tjj|jdddiddidd}t d t | |d |_t||_|  dt|j d }d
t|j d }t d|  t d|  tjj|d ||dd}	t |	 |	d }t
|W S ntddW S ntddW S W n: ty< } z t | tddW  Y d }~S d }~0 0 d S )Nztry to signup post methodusernamepasswordzform is validzTry to authenticate user)r9   r:   zUser authenticated)user+https://api.selltix.live/redoc_partner_api/3https://api.selltix.live/partner_api/striperefresh//2https://api.selltix.live/partner_api/stripereturn/zReturn url %szrefresh_url url %saccount_onboardingaccountrefresh_url
return_urltypeurlexpress	requestedT)card_payments	transfers)countryrE   capabilities===On recoit de stripe id  r     )loggerinfoPOSTr8   r!   Sellerobjectsfilterfirststripe_charges_enabledr    strrN   stripeAccountLinkcreatestripe_user_idr;   r   rK   jsondumpsstripe_account_jsonsaver   	Exceptionerror)r5   r6   r7   emailr:   r;   sellerrC   rD   accountLinklinkseller_profilerB   urlToRedirecter.   r.   r/   post:   st    











zsignup.post)N)N)r)   r*   r+   r   r8   rk   r.   r.   r.   r/   r1   4   s   r1   c              
   C   sr   z<t j}| dd }d| }dd| i}tj||d}W dS  tyl } zt| W Y d }~dS d }~0 0 d S )	Nr>   z'https://api.pinata.cloud/pinning/unpin/AuthorizationBearer )headersTF)r   PINATA_API_KEYsplitrequestsdeleterb   rQ   rc   )imagepinata_api_keycidrF   ro   r   rj   r.   r.   r/   unpin_image   s    
rw   c              
   C   s  t d t |  zBt| trRd| v rR| d\}}|dd }t|} n0d}t| drp| jdd }t| dr| 	 } t
jd| d	d
 }||  |j}W d    n1 s0    Y  d}dd| i}t|dX}	d|	i}
t d tj||
|d}t |  t |j | d }W d    n1 s@0    Y  t| |W S  ty } zt | W Y d }~d S d }~0 0 d S )Nu   ===On envoi à pinata z;base64,r>   rl   Zjpgname.readF)suffixrs   z.https://api.pinata.cloud/pinning/pinFileToIPFSrm   rn   rbfilez===Envoi a pinata ====)filesro   ZIpfsHash)rQ   rR   
isinstancerY   rq   base64	b64decodehasattrrx   rz   tempfileNamedTemporaryFilewriteopenrr   rk   r^   status_codeosunlinkrb   rc   )Z
image_dataru   r7   Zimgstrext	temp_fileZtemp_file_pathrF   ro   r}   r~   r   	ipfs_hashrj   r.   r.   r/   send_image_to_pinata   s:    




$
,

r   c                   @   s  e Zd ZegZed ddgeejdej	ej
ej	ejddej	ejddej	ejddej	ejddej	ejd	dej	ejd
dej	ejddej	ejddej	ejddej	ejddej	ejddej	ejddej	ejddej	ejddej	ejddej	ejddej	ejddej	ejdddddddddddd d!d!d!d!d"d#d$d%d&d'd(id)ejd*ej	ej
ej	ejd+dej	ejd,dd-ddd.d/d-d.d0d-d.d1d-d.d2d-d3id)ejd4dd5d6d7d8d9d:gd;id<d=d>dBd@dAZd?S )Cregistera  Register an organizer or update information if already exists.
        <br>On first registration (call), you will need to provide a <b>pin code</b>, that will be used to create your wallet.
        <br>SellTix will manage your wallet transactions in your behalf, and this is required to be able to create tickets on the blockchain.
        <br><br><b>Note:</b>
        <br><br>When registering, or publishing an event, we need to create blockchain transactions. Because these transactions can be slow,
        we have implemented an asynchronous process. We will use the <b>webhookUrl</b> (if provided) to notified you when transaction is done.
        <br><br>To do that, we will send a POST request with a payload in the body of the request:<br>
        <pre>
        <code>
        data = {
            "id": "uuid64",
            "event": "uuid64",
            "type": "string",
            "message": "string"
        }
        </code>
        </pre>
       zAccount informationzOrganizer updated successfullyzOrganizer IDrE   descriptionzOrganizer's email addresszOrganizer's first namezOrganizer's last namezDate Organizer joinedzOrganizer's phone numberz&Organizer's wallet address, if createdz)Whether Organizer accepts crypto paymentszOrganizer's company namezOrganizer's company websitezOrganizer's webhook URLz(Whether Organizer accepts MATIC paymentsz'Whether Organizer accepts USDT paymentsz'Whether Organizer accepts USDC paymentsz%Whether Organizer accepts CB paymentszOrganizer's descriptionzOrganizer's countryzOrganizer's timezone)rN   rd   
first_name	last_namedate_joinedphoneNumberwalletAddresscryptoAcceptedorganizerCompanyorganizeWebsite
webhookUrlmaticAcceptedusdtAcceptedusdcAccepted
cbAcceptedr   rK   r$   rE   
propertiesapplication/jsonZyour_idZ
your_emailZyour_first_nameZyour_last_namez2024-07-25T12:40:48.198571Zyour_phone_numberZyour_wallet_addressFTZyour_descriptionZyour_contract_addressZyour_company_nameZyour_websiteZyour_webhook_url)rN   rd   r   r   r   r   r   r   r   r   r   r   r   organizerContractr   r   r   r   schemaexamplesBad requestStatus of the operation KO message of the failure exceptionr   reasonKOPin code is requiredPin code must be 4 digitsPin code can't be changedzthe error message)zPin code requiredzInvalid pin codezPin code already setzAny other reasonUnauthorized(Given token not valid for any token typetoken_not_validAccessTokenaccessToken is invalid or expiredtoken_class
token_typemessagedetailcodemessagesr   r        rO   operation_idoperation_descriptiontagsrequest_body	responsesNc              
   C   s  t jj|jjd}t||jd}td z|	 rt|j
 |jrnd|j
v rnddd}t|dd	d
W S |  |jd u r|j
d }|d u rddd}t|dd	d
W S t|dks| sddd}t|dd	d
W S td}|jdd}d }	d }
ztttj}|jj }||j}
|j}	d|_|	|_|	|_ddlm }m!} ||
|}||_"||||_#dt$| }|t%|t&'d|_|  t( }d|_)d|_*t+,t%|j|jd|_-|  W nD t.y
 } z*dt%|d}t|dd	d
W  Y d }~W S d }~0 0 |j/d u rtd t(jj0ddt%|jd1 }|std t( }d|_)d|_*t+,t%|j|jd|_-|  t2t3|jW S d|j4d}t|dd	d
W S W nL t.y } z2t5| dt%|d}t|dd	d
W  Y d }~S d }~0 0 d S )NrN   dataz;===On recoit la requete de mise a jour de l'organisateur===pinCoder   r   r   Fr   safer   r      r   english   )ZstrengthTr   )encryptdecrypti'  ZSECRET_PIN_KEYZcreateOrganizerContract)refOrganizerr   z1==== Pas de contrat organisateur, on le cree ====r   actionZmetadata__containsz+==== Pas de tache en cours, on la cree ====)6UserrU   r8   r;   rN   UserUpdateSerializerr   rQ   rR   is_validvalidated_datar   r   ra   r   lenisdigitr   generater   HTTPProviderr   CONTRACT_NODE_URLethrB   r\   to_hexkeyaddressgeneratedWallet	publicKeyZapi.contentr   r   
privateKeywordsintrY   r   getenvTasksr   r   r^   r_   metadatarb   r   rV   rW   r   ZUserReadSerializererrorsrc   )r5   r6   r7   	organizer
serializerjsonToReturnr   Zmnemor   
public_keyprivate_keyw3rB   r   r   ZencryptedPrivateKeyZtheCodetaskrj   existing_taskr.   r.   r/   patch   s    }




&




zregister.patch)N)r)   r*   r+   r   r	   r   r   r   r   SchemaTYPE_OBJECTTYPE_INTEGERTYPE_STRINGTYPE_BOOLEANr   r.   r.   r.   r/   r      s   0|r   c                   @   s   e Zd ZegZed ddgdejdejej	ejej
ejejddejejdddd	d
dedddddddddddddddgididdddZdS )getCategorieszRetrieve all categoriesEventsr   zList of categorieszCategory IDr   zCategory name)rN   rx   r   )rE   itemsr   $3ecd5e86-4984-441a-b4c8-5fd8e1a91bafZArtz2023-09-28T11:22:18.960977z2023-09-28T11:22:25.056422)rN   rx   	createdAt	updatedAtz$fa4e06be-83c7-4225-b969-76df8646f72eZBusinessz2023-09-28T11:22:45.627135z2023-09-28T11:22:45.627170z$b05db215-150d-47a9-aa90-132fd996d49dzCoaching ou Consultantz2023-09-28T11:23:13.352278z2023-09-28T11:23:13.352357r   r   r   r   r   Nc                 C   s    t j }t|dd}t|jS )NTmany)CategoryrU   allr   r   r   )r5   r6   r7   
categoriesr   r.   r.   r/   r8     s    +
zgetCategories.get)N)r)   r*   r+   r   r	   r   r   r   r   
TYPE_ARRAYr   r   r   tupler8   r.   r.   r.   r/   r     sL   *r   c                   @   s  e Zd ZegZed ddgejejejej	ej
ddejejddejejddejejddejejd	dejej	d
dejej	ddejej	ejddejej	ddejej	ddejejddejej	ddejej	ddejej	ejddejejddejejddejejddddddddddddddddd d!d"d#d$d%d&d'ejd(ejejejej	ej
d)dejej	ej
ddejejd*dejejd+dejejd,dejejd-dejej	d
dejej	ddejej	ejd.dejej	d/dejej	d0dejejddejej	ddejej	ddejej	d1dejejddejejddejej	d2dejejd3dd4d5d6d7dddddddddddd8ddd d!d"d#d$d%d9id:ejd;ejejejej	d<dejej	d=dd>d5d?ejd@d6dAdBdCdDdEdFgdGidHdIdJdNdLdMZdKS )OcreateEventa  Create an event on SellTix platform.
        <br><br>
        An Event must be associated to a category. So you need first to get all categories with the endpoint <a href="#tag/Events/operation/getCategories"><b>getCategories</b></a>
        and then pass the id of the category you want to associate to the event.
        <br><br>
        You will have 3 possibilities with our Platform:
        <br>
        <ul>
            <li>1. You are managing the streaming of the event yourself. In this case, you need to pass the URL of the event. The URL can be a google meet link, a zoom link, a youtube link or any other link. The URL will be accessible to participants with tickets once the event will start. 
            </li>
            <li>2. We are managing the streaming of the event.</li>
            <li>3. The Event is not live and you want to provide a pre-recorded video. <b><i>Not implemented in the API</i></b></li>
        </ul>
        <br>To manage each option, you need to pass the following parameters:
        <br>
        <ul>
            <li>1. <b>isConference</b>: True if you are managing the streaming of the event yourself. False otherwise.
            </li>
            <li>2. <b>streamWithSelltix</b>: True if we are managing the streaming of the event.  False otherwise.
            </li>
            <li>3. <b>recordedVideo</b>: True if you provide a video file.  False otherwise.
            </li>
        </ul>
        At least once of this parameters must be True.
        <br><br><b>Note:</b>
        Because the image needs to be uploaded on a decentralized server, it can take few seconds before receiving the api response.
        <br><br>
        r   Reference to the event categoryrE   r7   r   zeIf true, you are managing the streaming and need to pass the <b>onlineUrl</b> parameter for that url.r   zcIf true, ae are managing the streaming for you. isConference and recordedVideo must be set to Falsez<b>Not implemented in our API. Please use our web dashboard.</b>. If true, the event is not live and a video will be played during the event.  isConference and streamWithSellTix must be set to False PIf true, the organizer doesn't want SellTix to promote the event on his platform
Event NameEvent descriptionoDate and time of the event. <b>Very important</b> should be in <strong>UTC format</strong> : %Y-%m-%dT%H:%M:%SZ3Timezone of the event. default will be Europe/Paris*Currency of the event. default will be EURDuration of the event3Conference URL i.e google meet, zoom, youtube, etc.Website of the eventgBase64 encoded image data. Example  'image':'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/......'zgRoyalty you will receive for each sell on marketplace. Please provide a percentage (between 0 and 100).$Whether crypto payments are accepted Whether CB payments are accepted)refCategoryisConferencestreamWithSelltixrecordedVideo	isPrivaterx   r   	eventDater$   currencyduration	onlineUrlwebsitert   royaltyr   r   z2024-09-01T10:00:00Z FTMusic conference)This conference is about music in generalx   $https://meet.google.com/jnt-qjpd-jnihttps://www.selltix.live2024-07-26T19:07:59.9072322024-07-26T19:07:59.940480r   Europe/ParisEURr&   )r  rt   r  r  r  r  rx   r   r  r  r  r   r   r   r   r  r$   r  r  rE   r   examplezEvent created successfullyUnique identifier for the eventz(If true, you are managing the streaming.z/If true, ae are managing the streaming for you.zKIf true, the event is not live and a video will be played during the event.;Whether the organizer wants SellTix to reference this eventDate and time of the event&Timezone of the event. ie Europe/Paris(Currency of the event. ie USD, EUR, etc.Image URL for the eventDSellTix event page URL where users would be able to purchase ticketsXRoyalty you will receive for each sell on marketplace. A percentage (between 0 and 100).)rN   r  r  r  r  r  rx   r   r  r$   r  r  r  r  rt   r   r   sellTixEventPager  r   r   $461e26f8-9e95-41ce-aa97-755c10e0d67c/https://www.selltix.live/event/music-conference)rN   r  rt   r  r  r  r  rx   r   r  r  r  r4  r   r   r   r   r  r$   r  r  r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )   r   rO   r   Nc                 C   sL  zt jj|jjd}t|jd}| r|jd}|t	j	
 k r`ddd}t|ddd	W S |jd
}|jd}|jd}	|dkr|dkr|	dkrddd}t|ddd	W S |dkr|dks|	dkrddd}t|ddd	W S |dkr |	dks|dkr ddd}t|ddd	W S |	dkrX|dks>|dkrXddd}t|ddd	W S |	rxddd}t|ddd	W S |jd}
|jd}|
r|
tjvrddd}t|ddd	W S |r|tjvrddd}t|ddd	W S |jd}|d u rddd}t|ddd	W S |dk s,|dkrFddd}t|ddd	W S |d }|jd}|d urtj}t||}|rd| }nd}nd}t|j |j|ddddd|j|j|d	}tt|jdd d	W S d|jd}t|ddd	W S W nX tyF } z>t| t|j dt|d}t|ddd	W  Y d }~S d }~0 0 d S )!Nr   r   r  r   z"Event date should be in the futurer   Fr   r   r  r  r  z[You need to select at least one option for isConference, streamWithSelltix or recordedVideoTzWYou can't create a conference and a streamWithSelltix or recordedVideo at the same timezWYou can't create a streamWithSelltix and recordedVideo or isConference at the same timezYYou can't create a isVideoRecorded and isConference or streamWithSelltix at the same timezSorry due to upload video file complexity, not available in our API. Please use our web interface to create your event and upload your videor  r$   Currency not supportedTimezone not supportedr  zPlease provide a royaltyr   r(   #Royalty should be between 0 and 100rt   8https://amber-large-nightingale-955.mypinata.cloud/ipfs/r   )	refOrganiser	eventTyper   	venueNamevenueAddressvenueGeolocr   r   rt   r8  )r   rU   r8   r;   rN   EventsForCreateCustomSerializerr   r   r   datetimenowr   r   
CURRENCIESpytzall_timezonesrp   r   rQ   rR   ra   r   r   EventsCustomSerializerr   rb   rc   rY   )r5   r6   r7   r   r   r  r   r  r  r  r  r$   r  rt   ru   	image_url	fullImageeventrj   r.   r.   r/   rk     s     '






zcreateEvent.post)N)r)   r*   r+   r   r	   r   r   r   r   r   FORMAT_UUIDr   FORMAT_DATETIMEr   FORMAT_BASE64r   rk   r.   r.   r.   r/   r    s   04
 %r  c                   @   s  e Zd ZegZed ddgejejejej	ddejej
ddejejddejejddejejejdd	ejejd
dejejddejej	ddejejddejejddejejejdd	ejej	ddejej
ddejej
ddddddddddddddddd d!d"d#ejd$ejejejejejd%d	ejej	ddejej
d&dejejddejejddejejejd'd	ejejd(dejejd)dejej	ddejejddejejddejejd*dejej
ddejej
ddejej
d+dejej	ddd,d-d.d/dddddddddddddd0id1ejd2ejejejejd3dejejd4dd5d-d6d7d5d6d8d5d9d1ejd:d.d;d<d=d>d?d@gdAidBdCdDdHdFdGZdES )IupdateEventzUpdate an event.
        <br><br><b>Note:</b>
        Because the image needs to be uploaded on a decentralized server, it can take few seconds before receiving the api response.
        <br><br>
        r   r  r   r	  r
  r  r  r  r  r  r  r  r  r  r3  r  r  )r  r  rx   r   r  r$   r  r  r  r  rt   r  r   r   z2024-12-24T10:00:00Zr   FzChristmas conferencez"This conference is about Christmasr#  r$  r%  Tr&  r'  r   r(  r)  )r  rt   r  rx   r   r  r  r  r   r   r   r   r  r$   r  r*  zEvent updated successfullyr,  r-  r.  r/  r0  r1  !Whether the event is a conference)rN   r  r  rx   r   r  r$   r  r  r  r  rt   r   r   r  r  r   r   r5  )rN   r  rt   r  rx   r   r  r  r  r   r   r   r   r  r   r   r   r   r   r   The reason of the failure;Event already published on blockchain. You cannot update it)r   Event already publishedr   r   r   r   r   r   r   r   r   r   r   Nc              
   C   s  zt jj||jd}|jdkr:ddd}t|dddW S t||jd	d
}| r|j	d}|j	d}|r|t
jvrddd}t|dddW S |r|tjvrddd}t|dddW S |j	d}	|	d urt|jdkrt|j t
j}
t|	|
}|rd| }nd}||j	d< |j	d}|rb|dk s@|dkrZddd}t|dddW S |d }| }tt|jdddW S td|jddddW S W np t jy   tdddddd Y S  ty
 } z.t| tdt|ddddW  Y d }~S d }~0 0 d S )NrN   r=  r   r   rR  r   Fr   r   T)r   partialr  r$   r9  r:  rt      r<  r   r  r(   r;  r   Event not found  )EventrU   r8   r;   r   r   rB  r   r   r   r   rE  rF  rG  r   rt   rw   rp   r   ra   rH  r   DoesNotExistrb   rQ   rc   rY   )r5   r6   pkr7   rK  r   r   r  r$   rt   ru   rI  rJ  r  Zupdated_eventrj   r.   r.   r/   r     sb     	








zupdateEvent.patch)NN)r)   r*   r+   r   r	   r   r   r   r   r   r   r   rM  rN  r   rL  r   r.   r.   r.   r/   rO    s   (*	 rO  c                   @   s   e Zd ZejgZedddgejddejdej	ej
ej	ejddej	ejd	dd
ddejddddddddgdiddddddZdS )DeleteEventZdeleteEventzzDelete an event.
        <br><br><b>Note:</b> If the event is started the delete operation will not be allowed.
          r   zEvent deleted successfully)r   r   r   r   r   r   r   r7  r   r   r   r   r   r   r   r   r   r   r   r   Nc              
   C   s   zt jj||jd}t|jdkr,t|j ddlm} ||rVt	ddddd	d
W S |j
dkrpd|_
|  n|  t	i ddd
W S  t jy   t	dddddd
 Y S  ty } z$t	dt|ddd	d
W  Y d }~S d }~0 0 d S )NrT  rV  r   )hasEventStartedr   zEvent is startedr   Fr   r         r   rW  rX  )rY  rU   r8   r;   r   rt   rw   backoffice.helpersr]  r   r   ra   rs   rZ  rb   rY   )r5   r6   r[  r7   rK  r]  rj   r.   r.   r/   rs     s     *


zDeleteEvent.delete)NN)r)   r*   r+   r   r   r	   r   r   r   r   r   r   rs   r.   r.   r.   r/   r\    sB   
)r\  c                   @   s  e Zd ZejgZedddgejdej	ej
ej	ejejddej	ejddej	ejd	dej	ejd
dej	ejddej	ejejddej	ejddej	ejddej	ejddej	ejddej	ejddej	ejddej	ejddej	ejddej	ejddej	ejddej	ejejddej	ejejddddddddddd d!d"d#d$d%d&d'd(d)d*d d+d,d-d.d/gd0id1ejd2ej	ej
ej	ejd3dej	ejd4dd5dd6ejd7dd8d9d:d;d<d=gd>id?d@dAdDdBdCZdS )EEventAPIListViewZ	getEventszGet all your event.
        r   zList of all organizer eventsr,  r  r  r   r-  r
  r  r.  r/  r0  r  r  r  r1  r  r  rP  r2  z#Date and time of the event creationz!Date and time of the event update)rN   r  r  rx   r   r  r$   r  r  r  r  rt   r   r   r  r4  r   r   r   r   r^  Nz$ade56c0f-8175-462d-b548-fac938fcab14r   Fr!  r"  r6  z2024-09-01T10:00:00r(  r)  r#  r$  r%  zfhttps://amber-large-nightingale-955.mypinata.cloud/ipfs/QmVSGSQjrprqiNcY9oNk3ac273o2C8uwYfqv6L3PQmKYGKTz2024-07-27T19:35:08.973445z2024-07-27T19:35:08.973457r   )rN   r   r  rx   r   r4  r  r$   r  r  r  r  rt   r   r   r   r   r  )countnextpreviousresultsr   r   r   r   r   r7  r   r   r   r   r   r   r   r   r   r   r   c              
   C   s   z<t jj|jd}t }|||}t|dd}||jW S  t	y } z.t
| tdt|ddddW  Y d }~S d }~0 0 d S )	N)r=  Tr   r   r   Fr   r   )rY  rU   rV   r;   r%   paginate_querysetZEventsForGetSerializerget_paginated_responser   rb   rQ   rc   r   rY   )r5   r6   r7   events	paginatorZpaginated_eventsr   rj   r.   r.   r/   r8     s    ]
zEventAPIListView.get)N)r)   r*   r+   r   r   r	   r   r   r   r   r   r   rL  r   r   rM  r8   r.   r.   r.   r/   ra    s   7
\ra  c                   @   s   e Zd ZejgZed ddgejdddddidejd	ej	ej
ej	ejd
dej	ejdddddddddddddddddddddejddddddddgdiddd d$d"d#Zd!S )%publishEventa  Publish an event.
        <br><br><b>Note:</b> Because this operation is asynchronous due to blockchain, it will return an Http 200 OK response and you will be notify 
        on your webhook url (if you provided one while registering) once the publication done.
        r   zEvent published successfullyr   OKPublication askedr   r   r   r   r   r   r   r   r   r   rQ  rW  rS  4Organizer contract not found. Please contact selltixNo Tickets found)r   rW  rS  zOrganizer contract not foundz
No Ticketsr   r   r   r   r   r   r   r   r   r   r   Nc                 C   s:  zt d tjj||jd}|jjd u rBtddddddW S |j	d	krbtdd
ddddW S t
jj|d }|dkrtddddddW S tjjddt|jd }|st d t }d|_	d|_tt|jt|jjd|_|  tddddddW S  tjy4   tdddddd Y S 0 d S )Nrj  rT  r   rn  r   FrX  r   r^  rS  )refEventr   ro  ZdeployEventContractr   zpublishEvent: Creating new task)rp  r=  rk  rl  rm  r   rW  )rQ   rR   rY  rU   r8   r;   r=  r   r   r   
TicketTyperV   rb  r   rY   rN   rW   r   r^   r_   r   ra   rZ  )r5   r6   r[  r7   rK  	nbTicketsr   r   r.   r.   r/   rk     s8    F





zpublishEvent.post)NN)r)   r*   r+   r   r   r	   r   r   r   r   r   r   rk   r.   r.   r.   r/   rj    sl   		 Erj  c                   @   s    e Zd ZedddddZdS )stripereturnNr2   c              
   C   s   zt jj|d}tj|j}td t| t	
||_|d rT|d rTd|_|  |jrltdW S d| d }t|W S W n8 ty } z t| td	d
W  Y d }~S d }~0 0 d S )Nuser__idrM   details_submittedcharges_enabledTr<   r=   r>   rP   r   )rT   rU   r8   rZ   r   retriever]   rQ   rR   r^   r_   r`   rX   ra   r    rb   rc   r   )r5   r6   r[  r7   merchantAccountrB   rC   rj   r.   r.   r/   r8     s     



zstripereturn.get)NNr)   r*   r+   r   r8   r.   r.   r.   r/   rs    s   rs  c                   @   s    e Zd ZedddddZdS )striperefreshNr2   c           	      C   sL   t jj|d}d| d }d| d }tjj|j||dd}|d }t|S )Nrt  r?   r>   r=   r@   rA   rF   )rT   rU   r8   rZ   r[   r\   r]   r    )	r5   r6   r[  r7   rh   rD   rC   rf   rg   r.   r.   r/   r8     s    zstriperefresh.get)NNrz  r.   r.   r.   r/   r{    s   r{  )Tdjango.httpr   r   django.urlsr   Zrest_framework.paginationr   rest_framework.responser   rest_framework.viewsr   Zrest_framework.decoratorsr   r	   Zapi_partner.serializersbackoffice.modelsrC  urllibr   django.core.paginatorr   eth_account.messagesr   tixsellr   web3r   web3.middlewarer   eth_accountr   r   eth_account.signers.localr   django.shortcutsr   mnemonicr   django.corer   loggingZrest_framework.permissionsr   rest_frameworkr   r   r   r   drf_yasgr   Zdrf_yasg.utilsr   Zapi.serializersr   r    django.contrib.authr!   r   r   r   rZ   r^   django.core.files.baser"   backoffice.forms.signupr#   django.utilsr$   rF  r%   	getLoggerrQ   r1   rw   r   r   r   r  rO  r\  ra  rj  rs  r{  r.   r.   r.   r/   <module>   sv   
U* m2  . FBki