a
    npdYU                     @   s   d dl mZmZ d dlmZmZmZ d dlmZ ddl	m
Z
mZmZ ddlT d dlmZ d dlmZ d d	lmZ d d
lmZ dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd ZdS )     )renderredirect)authenticateloginlogout)messages   )
SignUpFormAddRecordFormBDCform)*)
connection)JsonResponse)render_to_stringmodel_to_dictc                 C   s  t  }| jd}| jd}t| |dks|dkrttjd||g}dd |D }tdd	|i| d
|d< t|S |dkrtjd||||||||||||g}dd |D }tdd	|i| d
|d< t|S n8tjd}dd |D }tdd	|i| d
|d< t|S d S )NZ	txtSearch	prefilter namezLSELECT * FROM website_record WHERE first_name RLIKE %s OR last_name RLIKE %sc                 S   s   g | ]}t |qS  r   .0lr   r   @/Users/Home/Documents/Nicolas/Dev/CFYOU/tonal/tonal_app/views.py
<listcomp>       z#article_filter2.<locals>.<listcomp>	grid.htmlavailable_lessonsrequestZ
html_tableZ
everywherea  SELECT * FROM website_record WHERE id RLIKE %s OR created_at RLIKE %s OR first_name RLIKE %s OR last_name RLIKE %s OR email RLIKE %s OR phone RLIKE %s OR address RLIKE %s OR city RLIKE %s OR state RLIKE %s OR zipcode RLIKE %s OR regarde RLIKE %s OR testrever RLIKE %s c                 S   s   g | ]}t |qS r   r   r   r   r   r   r   .   r   zSELECT * FROM website_recordc                 S   s   g | ]}t |qS r   r   r   r   r   r   r   5   r   )	dictPOSTgetprintRecordobjectsrawr   r   )r   datasearchr   	locationsr   r   r   r   article_filter2   s:    




r*   c                 C   s   t j }| jdkrr| jd }| jd }t| ||d}|d ur\t| | t| d t	dS t| d t	dS nt
| dd	|iS d S )
Nr!   usernamepasswordr+   r,   zYou Have Been Logged In!homez2There Was An Error Logging In, Please Try Again...z	home.htmlrecords)r$   r%   allmethodr!   r   r   r   successr   r   )r   r/   r+   r,   userr   r   r   r.   G   s    





r.   c                 C   s   t |  t| d tdS )NzYou Have Been Logged Out...r.   )r   r   r2   r   r   r   r   r   logout_user[   s    r4   c                 C   s   | j dkrdt| j}| rz|  |jd }|jd }t||d}t| | t	| d t
dS nt }t| dd|iS t| dd|iS )	Nr!   r+   	password1r-   z*You Have Successfully Registered! Welcome!r.   zregister.htmlform)r1   r	   r!   is_validsavecleaned_datar   r   r   r2   r   r   )r   r6   r+   r,   r3   r   r   r   register_usera   s    





r:   c                 C   s>   | j jr&tjj|d}t| dd|iS t| d tdS d S )Nidzrecord.htmlcustomer_recordz*You Must Be Logged In To View That Page...r.   )	r3   is_authenticatedr$   r%   r"   r   r   r2   r   )r   pkr=   r   r   r   r=   t   s
    r=   c                 C   sJ   | j jr2tjj|d}|  t| d tdS t| d tdS d S )Nr;   zRecord Deleted Successfully...r.   z#You Must Be Logged In To Do That...)	r3   r>   r$   r%   r"   deleter   r2   r   )r   r?   Z	delete_itr   r   r   delete_record~   s    rA   c                 C   sl   t | jp
d }| jjrT| jdkrD| rD| }t| d t	dS t
| dd|iS t| d t	dS d S )Nr!   zRecord Added...r.   zadd_record.htmlr6   You Must Be Logged In...)r
   r!   r3   r>   r1   r7   r8   r   r2   r   r   )r   r6   
add_recordr   r   r   rC      s    
rC   c                 C   s   | j jrtjj|d}tjj|d}t| jp.d ||d}t| jpBd |d}|	 rv|
  |
  t| d tdS t| d||dS t| d tdS d S )	Nr;   )instancer?   )rD   zRecord Has Been Updated!r.   zupdate_record.html)r6   form2rB   )r3   r>   r$   r%   r"   TDCr
   r!   r   r7   r8   r   r2   r   r   )r   r?   Zcurrent_recordZcurrent_record2r6   rE   r   r   r   update_record   s    rG   c                 C   s
   t | dS )Nz	test.htmlr   r   r   r   r   test   s    rI   c                 C   s
   t | dS )Nr   rH   r   r   r   r   grid   s    rJ   N) Zdjango.shortcutsr   r   django.contrib.authr   r   r   django.contribr   formsr	   r
   r   models	django.dbr   django.httpr   django.template.loaderr   django.forms.modelsr   r*   r.   r4   r:   r=   rA   rC   rG   rI   rJ   r   r   r   r   <module>   s&   ;
S