3
[fI                 @   sZ   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
Z
G dd	 d	ejZdS )
    )	ModelForm   )IdentityRegister)forms)ValidationError)ImageNc                   sR   e Zd ZG dd dZ fddZdd Zdd Zd	d
 Zdd Zdd Z	  Z
S )IdentityRegisterFormc               @   st   e Zd ZeZddddgZddddd	Zejd
didej	dddddej	dddddej	dddddd	Z
dS )zIdentityRegisterForm.MetaphonefrontbackselfiezPhone NumberzGambar Depan ICzGambar Belakang ICzGambar Swafoto)r	   r
   r   r   classzform-control form-control-lg)attrszform-control-filezimage/*Zcamera)r   acceptcapturezform-control-file N)__name__
__module____qualname__r   modelfieldslabelsr   	TextInput	FileInputwidgets r   r   "/var/www/html/kok/kck2021/forms.pyMeta
   s   r   c                s,   t  j|| x| jj D ]
}d|_qW d S )NT)super__init__r   valuesrequired)selfargskwargsfield)	__class__r   r   r      s    zIdentityRegisterForm.__init__c             C   s$   | j jd}tjd|s td|S )Nr	   z[\d\s\+\-\(\)]*$zPhone number invalid.)cleaned_datagetrematchr   )r!   r	   r   r   r   clean_phone   s    z IdentityRegisterForm.clean_phonec             C   s
   | j dS )Nr
   )clean_image_file)r!   r   r   r   clean_front$   s    z IdentityRegisterForm.clean_frontc             C   s
   | j dS )Nr   )r+   )r!   r   r   r   
clean_back'   s    zIdentityRegisterForm.clean_backc             C   s
   | j dS )Nr   )r+   )r!   r   r   r   clean_selfie*   s    z!IdentityRegisterForm.clean_selfiec             C   s>   | j j|}|r2d}|j|kr.td| d|S tdd S )N   i   zThe zC image file is too large ( > 5MB ). Please resize it and try again.zThis field is required.i   i  P )r&   r'   sizer   )r!   
field_nameZ
image_filemax_sizer   r   r   r+   -   s    
z%IdentityRegisterForm.clean_image_file)r   r   r   r   r   r*   r,   r-   r.   r+   __classcell__r   r   )r%   r   r      s   r   )Zdjango.formsr   modelsr   djangor   django.core.exceptionsr   PILr   r(   r   r   r   r   r   <module>   s   