o
    Pd                     @   s<  d dl m Z  d dlmZmZmZ d dlmZ d dl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mZ d
d Zdd Zdd ZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG d d! d!eZ d"d# Z!d$d% Z"d&d' Z#d(S ))    )datetime)
CreateView
UpdateView
DeleteView)reverse_lazy)Http404)renderredirectget_object_or_404)loader   )MoodActivityTag)MoodModelFormc                 C   s\   | j dd}| jjstdS tjj| jjd	dd | }t
d}d|i}t| d|S )Nepp
   loginuserz-momentzmain/index.html	mood_list)sessiongetr   is_authenticatedr	   r   objectsfilteridorder_byr   get_templater   )requestr   r   templatecontext r"   "/var/www/html/mymood/main/views.pyindex   s    
r$   c                 C   s   || j d< tdS )Nr   r$   )r   r	   )r   r   r"   r"   r#   set_epp   s   
r%   c                 C   s<   z	t jj|d}W n t jy   tdw t| dd|iS )NpkzMoment existiert nicht!zmain/detail.htmlmood)r   r   r   DoesNotExistr   r   )r   mood_idr(   r"   r"   r#   detail$   s   r+   c                       s0   e Zd ZeZddgZedZ fddZ  Z	S )	TagCreatenameicontag_listc                    s   | j j|j_tt| |S )N)r   r   instancesuperr,   
form_valid)selfform	__class__r"   r#   r2   1   s   zTagCreate.form_valid)
__name__
__module____qualname__r   modelfieldsr   success_urlr2   __classcell__r"   r"   r5   r#   r,   ,   s
    r,   c                   @      e Zd ZeZedZdS )	TagDeleter/   N)r7   r8   r9   r   r:   r   r<   r"   r"   r"   r#   r?   6       r?   c                   @       e Zd ZeZddgZedZdS )	TagUpdater-   r.   r/   N)r7   r8   r9   r   r:   r;   r   r<   r"   r"   r"   r#   rB   ;       rB   c                   @   rA   )ActivityCreater-   r.   activity_listNr7   r8   r9   r   r:   r;   r   r<   r"   r"   r"   r#   rD   A   rC   rD   c                   @   r>   )ActivityDeleterE   N)r7   r8   r9   r   r:   r   r<   r"   r"   r"   r#   rG   G   r@   rG   c                   @   rA   )ActivityUpdater-   r.   rE   NrF   r"   r"   r"   r#   rH   L   rC   rH   c                       s6   e Zd ZeZeZdejiZ	 fddZ
edZ  ZS )
MoodCreatemomentc                    s6   | j j}||j_t| j jd|j_tt| 	|S )Nr(   )
r   r   r0   intPOSTr   r(   r1   rI   r2   )r3   r4   r   r5   r"   r#   r2   W   s   zMoodCreate.form_validr$   )r7   r8   r9   r   r:   r   
form_classr   nowinitialr2   r   r<   r=   r"   r"   r5   r#   rI   R   s    
rI   c                   @   s(   e Zd ZdZeZeZedZ	g dZ
dS )
MoodUpdatez Update a mood entry  r$   )zfa-smile-beamzfa-smilezfa-mehzfa-frown-openzfa-frownN)r7   r8   r9   __doc__r   r:   r   rM   r   r<   fa_mood_iconsr"   r"   r"   r#   rP   `   s    rP   c                   @   s   e Zd ZdZeZedZdS )
MoodDeletez Delete a mood entry  r$   N)r7   r8   r9   rQ   r   r:   r   r<   r"   r"   r"   r#   rS   j   s    rS   c                 C   sr   t jj|d}t  }|j|_t |_|j|_|j|_|	  |j
|j
  |j|j  |	  tdS )a  
    Copy a mood entry.

    The user, comment and mood are copied, as well as tags and activities.

    The moment is set to the current time.
    :param request:
    :param mood_id: the id of the mood to be copied
    :return: redirects to the index view
    r&   r$   )r   r   r   user_idr   rN   rJ   commentr(   savetagssetall
activitiesr	   )r   r*   r(   new_moodr"   r"   r#   copymoodp   s   
r\   c                 C   s$   t j d}d|i}t| d|S )Nr-   rE   zmain/activity_list.html)r   r   rY   r   r   )r   rE   r!   r"   r"   r#   activitylist   s   r]   c                 C   s,   t jj| jjdd}d|i}t| d|S )Nr   r-   r/   zmain/tag_list.html)r   r   r   r   r   r   r   )r   r/   r!   r"   r"   r#   taglist   s   r^   N)$r   django.views.generic.editr   r   r   django.urlsr   django.httpr   django.shortcutsr   r	   r
   django.templater   modelsr   r   r   formsr   r$   r%   r+   r,   r?   rB   rD   rG   rH   rI   rP   rS   r\   r]   r^   r"   r"   r"   r#   <module>   s.    

	