
    ,df                         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lmZ d Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!d Z"	 	 dS )    )renderredirect)authenticateloginlogout)messages   )
SignUpFormAddRecordFormBDCform)*)
connection)JsonResponse)render_to_stringmodel_to_dict)get_user_agentc                    t                      }| j                            d          }| j                            d          }t          |           |dk    s|dk    rTt          j                            d||g          }d |D             }t          dd|i| 	          |d
<   t          |          S |dk    r^t          j                            d||||||||||||g          }d |D             }t          dd|i| 	          |d
<   t          |          S d S t          j                            d          }d |D             }t          dd|i| 	          |d
<   t          |          S )N	txtSearch	prefilter nameNSELECT * FROM tonal_app_record WHERE first_name RLIKE %s OR last_name RLIKE %sc                 ,    g | ]}t          |          S  r   .0ls     ^/Users/Home/Documents/Fywapp/Dev/web_app/django/projects/fyw/app/tonal/greg/app_files/views.py
<listcomp>z)article_filter_mobile.<locals>.<listcomp>         E E Eaq!1!1 E E E    zgrid_mobile.htmlavailable_lessonsrequest
html_table
everywhere  SELECT * FROM tonal_app_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                 ,    g | ]}t          |          S r   r   r   s     r   r    z)article_filter_mobile.<locals>.<listcomp>.   r!   r"   SELECT * FROM tonal_app_recordc                 ,    g | ]}t          |          S r   r   r   s     r   r    z)article_filter_mobile.<locals>.<listcomp>5        AAA!]1--AAAr"   	dictPOSTgetprintRecordobjectsrawr   r   r%   datasearchr   	locationsr#   s         r   article_filter_mobiler9      s   66D\k**F  --I	)R<<** ,> +1	: :I
 !F E9 E E E "22DGZ\mFn:A"C "C "CD%%%$$** ,@ ,26666SY[acikq+166+CD DI !F E9 E E E "22DGZ\mFnw~!!!D%%%' %$* N&&'GHH	AAyAAA-.@CVXiBj6=? ? ?\ D!!!r"   c                    t                      }| j                            d          }| j                            d          }t          |           |dk    s|dk    rTt          j                            d||g          }d |D             }t          dd|i| 	          |d
<   t          |          S |dk    r^t          j                            d||||||||||||g          }d |D             }t          dd|i| 	          |d
<   t          |          S d S t          j                            d          }d |D             }t          dd|i| 	          |d
<   t          |          S )Nr   r   r   r   r   c                 ,    g | ]}t          |          S r   r   r   s     r   r    z#article_filter2.<locals>.<listcomp>S   r!   r"   	grid.htmlr#   r$   r&   r'   r(   c                 ,    g | ]}t          |          S r   r   r   s     r   r    z#article_filter2.<locals>.<listcomp>h   r!   r"   r*   c                 ,    g | ]}t          |          S r   r   r   s     r   r    z#article_filter2.<locals>.<listcomp>o   r,   r"   r-   r5   s         r   article_filter2r?   F   s   66D\k**F  --I	)R<<** ,> +1	: :I
 !F E9 E E E "2+@SUf?g:A"C "C "CD%%%$$** ,@ ,26666SY[acikq+166+CD DI !F E9 E E E "2+@SUf?gpw!x!x!xD%%%' %$* N&&'GHH	AAyAAA-k<OQb;c6=? ? ?\ D!!!r"   c                 H   t          |           }|j        rt          j                                        }| j        dk    r| j        d         }| j        d         }t          | ||          }|4t          | |           t          j
        | d           t          d          S t          j
        | d           t          d          S t          | dd	|i          S |j        rt          j                                        }| j        dk    r| j        d         }| j        d         }t          | ||          }|4t          | |           t          j
        | d
           t          d          S t          j
        | d           t          d          S t          | dd	|i          S d S )Nr/   usernamepasswordrA   rB   zYou Have Been Logged In PC!homez2There Was An Error Logging In, Please Try Again...z	home.htmlrecordszYou Have Been Logged In MOBILE!test	test.html)r   is_pcr2   r3   allmethodr/   r   r   r   successr   r   	is_mobile)r%   
user_agentrE   rA   rB   users         r   rD   rD      s   ((J  $F.$$&&>V##|J/H|J/H(XNNNDgt$$$ *GHHH''' *^___'''';70CDDD		 F.$$&&>V##|J/H|J/H(XNNNDgt$$$ *KLLL''' *^___'''';G0DEEE#F Fr"   c                 h    t          |            t          j        | d           t          d          S )NzYou Have Been Logged Out...rD   )r   r   rK   r   r$   s    r   logout_userrP      s/    
7OOOW;<<<Fr"   c                    | j         dk    rt          | j                  }|                                rs|                                 |j        d         }|j        d         }t          ||          }t          | |           t          j	        | d           t          d          S n!t                      }t          | dd|i          S t          | dd|i          S )	Nr/   rA   	password1rC   z*You Have Successfully Registered! Welcome!rD   zregister.htmlform)rJ   r
   r/   is_validsavecleaned_datar   r   r   rK   r   r   )r%   rS   rA   rB   rN   s        r   register_userrW      s    ~',''==?? 	$IIKKK(4H(5HHEEED'4   W&RSSSF###	$ ||g>>>'?VDM:::r"   c                     | j         j        r3t          j                            |          }t          | dd|i          S t          j        | d           t          d          S )Nidzrecord.htmlcustomer_recordz*You Must Be Logged In To View That Page...rD   )	rN   is_authenticatedr2   r3   r0   r   r   rK   r   )r%   pkr[   s      r   r[   r[      sa    |$   .,,,33g}/@.QRRR"NOOOr"   c                    | j         j        rXt          j                            |          }|                                 t          j        | d           t          d          S t          j        | d           t          d          S )NrY   zRecord Deleted Successfully...rD   z#You Must Be Logged In To Do That...)	rN   r\   r2   r3   r0   deleter   rK   r   )r%   r]   	delete_its      r   delete_recordra      s}    |$  N&&"&--	"BCCC"GHHHr"   c                 b   t          | j        pd           }| j        j        rj| j        dk    rL|                                r8|                                }t          j        | d           t          d          S t          | dd|i          S t          j        | d           t          d          S )Nr/   zRecord Added...rD   zadd_record.htmlrS   You Must Be Logged In...)r   r/   rN   r\   rJ   rT   rU   r   rK   r   r   )r%   rS   
add_records      r   rd   rd      s    -..D|$ 	 >V##}} (!YY[[
 *;<<<'''g06$-@@@"<===r"   c                 ,   | j         j        rt          j                            |          }t
          j                            |          }t          | j        pd ||          }t          | j        pd |          }|	                                rL|
                                 |
                                 t          j        | d           t          d          S t          | d||d          S t          j        | d           t          d          S )	NrY   )instancer]   )rf   zRecord Has Been Updated!rD   zupdate_record.html)rS   form2rc   )rN   r\   r2   r3   r0   TDCr   r/   r   rT   rU   r   rK   r   r   )r%   r]   current_recordcurrent_record2rS   rg   s         r   update_recordrk      s    |$  ++r+22+//R/00W\1TNrRRR,GGG==?? 	$IIKKKJJLLLW&@AAAF###g3T%5P5PQQQ"<===r"   c                 "    t          | d          S )NrG   r   r$   s    r   rF   rF          ';'''r"   c                 "    t          | d          S )Nr<   rm   r$   s    r   gridrp      rn   r"   N)#django.shortcutsr   r   django.contrib.authr   r   r   django.contribr   formsr
   r   r   models	django.dbr   django.httpr   django.template.loaderr   django.forms.modelsr   django_user_agents.utilsr   r9   r?   rD   rP   rW   r[   ra   rd   rk   rF   rp   r   r"   r   <module>r{      s   - - - - - - - - ; ; ; ; ; ; ; ; ; ; # # # # # # 5 5 5 5 5 5 5 5 5 5                 $ $ $ $ $ $ 3 3 3 3 3 3 - - - - - - 3 3 3 3 3 38" 8" 8"t8" 8" 8"v(F (F (FV  ; ; ;&                     ( ( (( ( (7r(~ ~r"   