U X^@sddlZddlZddlmZddlmZmZmZmZm Z m Z ddl m Z m Z mZddlmZmZmZmZddlmZmZddlmZmZmZmZe de d d d Ze d d dZe jdddgdddZe jdddgdddZ e dddZ!ddZ"e jdddgdeddZ#e jd dgdd!d"Z$e jd#ddgded$d%Z%e d&d'd(Z&e jd)ddgded*d+Z'e jd,dgded-d.Z(dS)/N)Image)render_templateurl_forflashredirectrequestabort)appdbbcrypt)RegistrationForm LoginFormUpdateAccountFormPostForm)UserPost) login_user current_user logout_userlogin_required/z/homecCstj}td|dS)Nz home.htmlZposts)rqueryallrrrVc:\Users\thekj\Desktop\Testesana\simple-project\project\Flask_Blog\flaskblog\routes.pyhome s rz/aboutcCs tdddS)Nz about.htmlZAbout)title)rrrrraboutsrz /registerGETPOST)methodscCstjrttdSt}|rvt|jj  d}t |j j |j j |d}tj|tjtddttdStdd|d S) Nrzutf-8)usernameemailpasswordz.Your account has been registered successfully!successloginz register.htmlZRegisterrform)ris_authenticatedrrr validate_on_submitr generate_password_hashr$datadecoderr"r#r sessionaddcommitrr)r(hashed_passworduserrrrregisters     r3z/logincCstjrttdSt}|rtjj|j j d }|rt |j|jj rt||jj dtjd}|rtt|SttdStddtdd|d S) Nr)r#)remembernextzs    rIz/accountcCst}|r\|jjr(t|jj}|t_|jjt_|jjt_t j t ddt tdStjdkrztj|j_tj|j_tddtjd}tdd ||td S) Nz+Your account has been updated successfully!r%accountrstatic profile_pics/rB account.htmlAccount)r image_filer(r2)rr*Zpicturer,rIrrPr"r#r r.r0rrrrmethodr)r(Z picture_filerPrrrrJNs         rJz/account/cCsPtjj|d}|r@|tkr@tdd|jd}tdd||dSttdSd S) N)r"rKrLrMrNrO)rrPr2rJzThis user doesn't exist!) rrr6r7rrrPrr)Z user_namer2rPrrr accountViewds   rRz /post/newcCs`t}|rPt|jj|jjtd}tj |tj t ddt t dStddd|dS)N)rcontentauthorz(Your post has been created successfully!r%rcreate_post.htmlzNew Postrlegendr()rr*rrr,rSrr r.r/r0rrrr)r(postrrrnew_postos    rYz/post/cCstj|}td|j|dS)Nz post.html)rrX)rr get_or_404rrpost_idrXrrrrXs rXz/post//updatecCstj|}|jtkrtdt}|rf|jj |_|j j |_ t j tddttd|jdStjdkr|j|j_ |j |j _ tddd|d S) Nz(Your post has been updated successfully!r%rX)r\rrUz Update PostrV)rrrZrTrrrr*rr,rSr r.r0rrridrrQr)r\rXr(rrr update_posts"         r_z/post//deletecCsJtj|}|jtkrtdtj|tj t ddt t dS)Nr]z(Your post has been deleted successfully!r%r) rrrZrTrrr r.deleter0rrrr[rrr delete_posts     ra))r>r?ZPILrflaskrrrrrr flaskblogr r r Zflaskblog.formsr r rrZflaskblog.modelsrr flask_loginrrrrrouterrr3r&r;rIrJrRrYrXr_rarrrrsD