o
    6]hH                     @   sv   d dl mZ d dlm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G dd dejZ	dS )    )models)timezonec                   @   sN   e Zd ZdZejdddZejddZejdddZ	G d	d
 d
Z
dd ZdS )NotificationCategoryz/Categories for different types of notificationsd   T
max_lengthuniqueblank   z#61b239)r   defaultc                   @   s   e Zd ZdZdgZdS )zNotificationCategory.MetazNotification CategoriesnameN)__name__
__module____qualname__verbose_name_pluralordering r   r   )/var/www/apihucms/notifications/models.pyMeta   s    
r   c                 C      | j S Nr   selfr   r   r   __str__      zNotificationCategory.__str__N)r   r   r   __doc__r   	CharFieldr   	TextFielddescription
color_coder   r   r   r   r   r   r      s    r   c                       s  e Zd ZdZg dZejddZejddZ	ejddZ
ejejd	Zejdd
ZejddZejeejddddZejdeddZejdd	ZejdddZejdddZejddddZejddddZejdddZG dd dZ  fddZ!dd  Z"e#d!d" Z$  Z%S )#NotificationzMain notification model))lowLow)mediumMedium)highHigh)urgentUrgent   r   Tr	   zFull notification content)	help_textr   )auto_now_add)auto_nownotifications)	on_deletenullr
   related_name
   r%   )r   choicesr   Fz%Show in featured/highlighted sections)r   r-   zExternal link for more details)r
   r-   znotifications/attachments/)	upload_tor
   r3   )r   r   r
      )r   r
   c                   @   sH   e Zd ZddgZejdgdejdgdejdgdejdgdgZdS )zNotification.Metaz-published_datez-created_at)fields	is_activeis_featuredcategoryN)r   r   r   r   r   Indexindexesr   r   r   r   r   9   s    r   c                    s|   | j s3ddlm} || j}|| _ d}tjj| j d r3| d| | _ |d7 }tjj| j d st j	|i | d S )Nr   )slugify   )slug-)
rA   django.utils.textr?   titler"   objectsfilterexistssupersave)r   argskwargsr?   	base_slugcounter	__class__r   r   rI   B   s   
zNotification.savec                 C   r   r   )rD   r   r   r   r   r   M   r   zNotification.__str__c                 C   s6   | j d| j d| j d| j d| j  dS )z#Returns formatted date for frontendz%dz%Bz%Yz%Y-%m-%d)daymonthyear	full_dateiso_date)published_datestrftime	isoformatr   r   r   r   formatted_dateP   s   



zNotification.formatted_date)&r   r   r   r   PRIORITY_CHOICESr   r   rD   r   r    contentDateTimeFieldr   nowrU   
created_at
updated_at
ForeignKeyr   SET_NULLr<   priorityBooleanFieldr:   r;   URLFieldexternal_link	FileField
attachment	SlugFieldrA   meta_descriptionr   rI   r   propertyrX   __classcell__r   r   rN   r   r"      s8    	r"   c                   @   s4   e Zd ZdZejdddZG dd dZdd Zd	S )
NotificationTagzTags for notifications2   Tr   c                   @   s   e Zd ZdgZdS )zNotificationTag.Metar   Nr   r   r   r   r   r   r   r   r   `   s    
r   c                 C   r   r   r   r   r   r   r   r   c   r   zNotificationTag.__str__N)	r   r   r   r   r   r   r   r   r   r   r   r   r   rk   \   s
    rk   c                   @   sJ   e Zd ZdZejeejddZeje	ejddZ
G dd dZdd Zd	S )
NotificationTagRelationz8Many-to-many relationship between notifications and tagsnotification_tags)r2   r4   tagged_notificationsc                   @      e Zd ZddgZdS )zNotificationTagRelation.MetanotificationtagN)r   r   r   unique_togetherr   r   r   r   r   l       r   c                 C   s   | j j d| jj S )Nz - )rr   rD   rs   r   r   r   r   r   r   o   s   zNotificationTagRelation.__str__N)r   r   r   r   r   r_   r"   CASCADErr   rk   rs   r   r   r   r   r   r   rn   g   s    rn   c                   @   sp   e Zd ZdZejdddZejddZe Z	ejdddd	Z
ejd
dZejddZG dd dZdd ZdS )SiteStatisticz,Statistics displayed alongside notificationsr   Tr      r,   rl   zIcon class or name)r   r
   r-   r   r.   c                   @   rq   )zSiteStatistic.Metaorderr   Nrm   r   r   r   r   r   |   ru   r   c                 C   s   | j  d| j S )Nz: )r   valuer   r   r   r   r      s   zSiteStatistic.__str__N)r   r   r   r   r   r   r   rz   r   r    iconPositiveIntegerFieldry   rb   r:   r   r   r   r   r   r   rw   s   s    rw   N)
	django.dbr   django.utilsr   Modelr   r"   rk   rn   rw   r   r   r   r   <module>   s    I