o
    og                     @   s   d dl mZ d dlmZ d dlmZ ddlmZmZ G dd dej	Z
ejdd	d
d Zejdd	dd ZeeG dd dejZeeG dd dejZdS )    )admin)forms)ValidationError   )CategoryPublicationc                   @   s"   e Zd ZG dd dZdd ZdS )PublicationAdminFormc                   @   s   e Zd ZeZdZdS )zPublicationAdminForm.Meta__all__N)__name__
__module____qualname__r   modelfields r   r   '/var/www/html/gwz/publications/admin.pyMeta   s    r   c                 C   sP   | j d}|r&|jdd  }g d}||vr&tdd|  |S )Ndocument.)pdfdocdocxz+Invalid file type. Allowed file types are: z, )cleaned_datagetnamesplitlowerr   joinupper)selfr   file_extallowed_extensionsr   r   r   clean_document   s   z#PublicationAdminForm.clean_documentN)r
   r   r   r   r"   r   r   r   r   r      s    r   zArchive selected publications)descriptionc                 C      |j dd d S )Narchivedstatusupdate
modeladminrequestquerysetr   r   r   make_archived      r.   zUnarchive selected publicationsc                 C   r$   )Nactiver&   r(   r*   r   r   r   make_active   r/   r1   c                   @   s   e Zd ZdZddiZdZdS )CategoryAdmin)r   r#   
created_atslug)r   )r   r#   N)r
   r   r   list_displayprepopulated_fieldssearch_fieldsr   r   r   r   r2   !   s    r2   c                   @   s4   e Zd ZeZdZdZdZddiZdZ	dZ
eegZdS )	PublicationAdmin)titlecategoryr'   published_datedownload_count	file_size)r'   r:   r;   )r9   r#   r4   )r9   r;   )z-published_dateN)r
   r   r   r   formr5   list_filterr7   r6   date_hierarchyorderingr.   r1   actionsr   r   r   r   r8   '   s    r8   N)django.contribr   djangor   django.core.exceptionsr   modelsr   r   	ModelFormr   actionr.   r1   register
ModelAdminr2   r8   r   r   r   r   <module>   s    



