o
    dJcX                     @   s   d dl mZ d dlmZ d dlmZmZ d dlmZm	Z	 d dl
mZ d dlmZ d dlmZ edd	 Zed
d Ze	dd Zedd ZdS )    )F)HttpResponsePermanentRedirect)get_object_or_404render)require_GETrequire_POST)base62)Link)LinkSubmitFormc                 C   s2   t tt|d}tdd |_|  t|jS )zY
    View which gets the link for the given base62_id value
    and redirects to it.
    idusage_count   )	r   r	   r   
to_decimalr   r   saver   urlrequest	base62_idlink r   7/var/www/html/docker_usevoice/src/apps/shorter/views.pyfollow   s   
r   c                 C   s"   t tt|d}t| dd|iS )z;
    View which shows information on a particular link
    r   zshortener/link_info.htmlr   )r   r	   r   r   r   r   r   r   r   info   s   r   c                 C   st   t | j}| r2d|jd i}|jd }|r!|dt|i tjj	d	i |}t
| dd|iS t
| dd|iS )
z3
    View for submitting a URL to be shortened
    r   customr   zshortener/submit_success.htmlr   zshortener/submit_failed.html	link_formNr   )r
   POSTis_validcleaned_dataupdater   r   r	   objectscreater   )r   formkwargsr   r   r   r   r   submit    s   

r$   c                 C   sB   t  tj ddd tj ddd d}t| d|S )z
    View for main page
    z-date_submittedN   z-usage_count)r   recent_linksmost_popular_linkszshortener/index.html)r
   r	   r    allorder_byr   )r   valuesr   r   r   index2   s
   r+   N)django.db.modelsr   django.httpr   django.shortcutsr   r   django.views.decorators.httpr   r   apps.shorter.baseconvr   apps.shorter.modelsr	   apps.shorter.formsr
   r   r   r$   r+   r   r   r   r   <module>   s    


