o
    @h                     @   s   d dl mZ d dlmZ d dlmZ d dlZd dlZd dlZdddZ	G dd	 d	ej
ZG d
d dej
ZG dd dej
ZG dd dej
ZdS )    )models)timezone)MinValueValidatorN   c                    s<   t j 	 d fddt| D }tjj|d s|S q)z7Generate a unique registration code of specified lengthT c                 3   s    | ]}t  V  qd S N)randomchoice).0_
characters 2/var/www/html/smartRegister/registration/models.py	<genexpr>   s    z'generate_unique_code.<locals>.<genexpr>)registration_code)stringdigitsjoinrangeRegistrationobjectsfilterexists)lengthcoder   r   r   generate_unique_code	   s   r   c                   @   sZ   e Zd ZdZejdddZejdddZej	ddZ
ej	ddZdd	 ZG d
d dZdS )	EventTypezMModel to define different types of events (Training, Seminar, Workshop, etc.)d   T)
max_lengthuniqueblanknullauto_now_addauto_nowc                 C      | j S r   nameselfr   r   r   __str__      zEventType.__str__c                   @   s   e Zd ZdZdZdS )zEventType.Metaz
Event TypezEvent TypesN)__name__
__module____qualname__verbose_nameverbose_name_pluralr   r   r   r   Meta   s    r4   N)r/   r0   r1   __doc__r   	CharFieldr*   	TextFielddescriptionDateTimeField
created_at
updated_atr-   r4   r   r   r   r   r      s    r   c                       s   e Zd ZdZejddZejeej	ddZ
e Ze Ze ZejddZejddZejdd	ed
gdddZejddZejdddZejddZejddZdd Z fddZG dd dZ  ZS )EventzJModel to define events with details like name, type, dates, location, etc.   r   events	on_deleterelated_nameFdefault
      r   T)
max_digitsdecimal_places
validatorsr#   r"   z;Archived events are hidden from feedback dashboard dropdown)rD   	help_textr$   r&   c                 C   r(   r   r)   r+   r   r   r   r-   0   r.   zEvent.__str__c                    s(   | j r	| js	d| _t j|i | d S )Ng        )is_paidamountsupersaver,   argskwargs	__class__r   r   rN   3   s   z
Event.savec                   @   s   e Zd ZdgZdS )z
Event.Metaz-start_dateN)r/   r0   r1   orderingr   r   r   r   r4   9   s    
r4   )r/   r0   r1   r5   r   r6   r*   
ForeignKeyr   CASCADE
event_typer7   r8   r9   
start_dateend_datelocationBooleanFieldrK   DecimalFieldr   rL   	is_activeis_archivedr:   r;   r-   rN   r4   __classcell__r   r   rR   r   r<   !   s"    r<   c                       s   e Zd ZdZdZdZejdej	ddZ
ejddedZejd	d
Ze Zejd	ddddZejeejddZejdeddZejdeddZejddZejddZejddZejdddZdd Z fddZG dd dZ   Z!S )r   z,Model to track user registrations for events)pendingPendingapprovedApprovedrejectedRejected))not_requiredzNot Requiredr`   rc   rf   TF)primary_keyrD   editablerE   )r   r    rD   r=   r>   r   zOrganisation name)r   r"   rD   rJ   registrationsr@   2   ra   )r   choicesrD   ri   r$   r&   rC   )r#   r"   c                 C   s   | j  d| jj d| j dS )Nz - z ())	full_nameeventr*   r   r+   r   r   r   r-   Y   s   zRegistration.__str__c                    s8   | j s| jjrd| _nd| _d| _t j|i | d S )Nra   ri   rd   )pkrq   rK   payment_statusstatusrM   rN   rO   rR   r   r   rN   \   s   zRegistration.savec                   @   s   e Zd ZddgZdgZdS )zRegistration.Metaemailrq   z-registered_atN)r/   r0   r1   unique_togetherrT   r   r   r   r   r4   g   s    
r4   )"r/   r0   r1   r5   STATUS_CHOICESPAYMENT_STATUS_CHOICESr   	UUIDFielduuiduuid4idr6   r   r   rp   
EmailFieldru   organisationrU   r<   rV   rq   rt   rs   r9   registered_atr;   r[   has_attendedattendance_timestampr-   rN   r4   r_   r   r   rR   r   r   =   s&    r   c                   @   sP   e Zd ZdZejeejddZej	ddZ
ejddZejdddZd	d
 ZdS )PaymentProofz$Model to store payment proof uploadspayment_proofr@   zpayment_proofs/)	upload_toTr$   r!   c                 C   s   d| j  S )NzPayment proof for )registrationr+   r   r   r   r-   s   s   zPaymentProof.__str__N)r/   r0   r1   r5   r   OneToOneFieldr   rV   r   	FileFieldfiler9   uploaded_atr7   notesr-   r   r   r   r   r   l   s    r   )r   )	django.dbr   django.utilsr   django.core.validatorsr   rz   r   r   r   Modelr   r<   r   r   r   r   r   r   <module>   s    
	/