ó
£dYc           @   sO  d  d l  m Z m Z d  d l m Z 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 d  d l m Z m Z m Z d  d l m Z d  d	 l 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  Td  d l! Td  d l" Td  d l# Td „  Z$ d „  Z% d „  Z& d „  Z' d „  Z( d S(   iÿÿÿÿ(   t   render_to_responset   get_object_or_404(   t   RequestContextt   loadert   Context(   t   login_requiredt   permission_required(   t   Q(   t   Site(   t   settings(   t   HttpResponseRedirectt   Http404t   HttpResponse(   t   reverse(   t   Usert   Group(   t   messages(   t   slugify(   t   datetimet   datet   time(   t   *c   
      C   sé   |  j  d k r t St j j d |  d t ƒ j d ƒ } g  } x¥ | D] } | j j } | j j	 } t
 j | j d ƒ } t } x' | D] } | d | k r„ t } q„ q„ W| rD i  }	 | |	 d <| |	 d <| |	 d <| j |	 ƒ qD qD W| S(	   Nt   newst   sectiont	   publisheds   -createds   %B %Yt
   monthtitlet   montht   year(   t   typet   Falset   MediaArticlet   objectst   filtert   Truet   order_byt   createdR   R   R   t   strftimet   append(
   R   t   articlest   monthst   articlet	   art_montht   art_yearR   t   add_to_arrayR   t
   montharray(    (    s7   /var/www/svtgbi.org/svtgbi/modules/mediacentre/views.pyt   get_month_list   s&    $


c         C   s/   t  j j ƒ  } t d i | d 6d t |  ƒ ƒS(   Ns$   public/mediacentre/media_centre.htmlt   sectionst   context_instance(   t   MediaSectionR   t   allR    R   (   t   requestR.   (    (    s7   /var/www/svtgbi.org/svtgbi/modules/mediacentre/views.pyt   media_centre5   s    c         C   sÒ  t  j j ƒ  } t t  d | ƒ} t | ƒ } t j ƒ  } | j d k r¥ t j j	 d | d t
 d | ƒ j | j ƒ } t j j	 d | d t
 d | ƒ j | j ƒ } ny t j j	 d | d t
 ƒ j | j ƒ } | j	 t d | ƒ t d t
 ƒ Bƒ } t j j	 d | d t
 d | ƒ j | j ƒ } g  } g  }	 x3 | D]+ }
 |
 j |  ƒ d	 k r1| j |
 ƒ q1q1Wx3 | D]+ }
 |
 j |  ƒ d	 k rg|	 j |
 ƒ qgqgWt d
 i | d 6| d 6| d 6| d 6|	 d 6d t |  ƒ ƒS(   Nt   slugt   eventsR   R   t   event_date_end__gtt   archive_date__gtt   archive_date__isnullt   archive_date__ltt   alloweds%   public/mediacentre/media_section.htmlR.   R'   R&   t   archived_articlesR/   (   R0   R   R1   R   R-   R   t   nowR   R   R    R!   R"   t   orderR   t   get_permissionR%   R    R   (   R2   t   section_slugR.   R   R'   t   todayR&   R;   t   final_articlest   final_archived_articlesR(   (    (    s7   /var/www/svtgbi.org/svtgbi/modules/mediacentre/views.pyt   media_section<   s&    -0'%-c      	   C   s4  t  j j ƒ  } t t  d | d d ƒ} t | ƒ } t j ƒ  } t | ƒ } t | ƒ } t | | d ƒ } t j	 | d ƒ }	 t
 j j d | d t d | d	 | ƒ j | j ƒ }
 g  } x3 |
 D]+ } | j |  ƒ d
 k r» | j | ƒ q» q» Wt d i | d 6| d 6| d 6| d 6| d 6|	 d 6| d 6d t |  ƒ ƒS(   NR4   R   R   i   s   %B %YR   R   t   created__yeart   created__monthR:   s-   public/mediacentre/media_section_archive.htmlR.   R&   R   R   t	   monthnameR'   R/   (   R0   R   R1   R   R-   R   R<   t   intR   R$   R   R    R!   R"   R=   R>   R%   R    R   (   R2   R?   R   R   R.   R   R'   R@   t   current_monthRF   R&   RA   R(   (    (    s7   /var/www/svtgbi.org/svtgbi/modules/mediacentre/views.pyt   media_section_month[   s    3c         C   se  t  t d | ƒ} t | ƒ } t  t d | d | d t ƒ} t } t } | j |  ƒ } | d k rŒ t ƒ  }	 t d i |	 d 6d t	 |  ƒ ƒS| d k r± t d	 i  d t	 |  ƒ ƒS| d
 k rÝ t
 j |  d ƒ t t d ƒ ƒ S|  j j ƒ  r"yØ t j j d |  j d d ƒ }
 |
 j r‰t |
 j k rLt j j d | d t ƒ j d ƒ } qÃt j j t d t ƒ t d |
 j ƒ Bd | ƒj d ƒ } n: t j j t d t ƒ t d |
 j ƒ Bd | ƒj d ƒ } WqF|  j j r÷t j j d | ƒ j d ƒ } qt j j d | d t ƒ j d ƒ } qFXn$ t j j d | d t ƒ j d ƒ } g  } xá | D]Ù } | j j j ƒ  r|  j j ƒ  r,yy t j j d |  j d d ƒ }
 t } x8 | j j j ƒ  D]$ } |
 | j j ƒ  k r´t } q´q´W| rò| j | ƒ n  Wq|  j j r| j | ƒ qqXq,qS| j | ƒ qSWt d i | d 6| d 6| d 6| d 6d t	 |  ƒ ƒS(   NR4   t   section__slugR   t   denieds   public/login/access-denied.htmlt
   login_formR/   s   permission-denieds#   public/login/permission-denied.htmlt   lapsedsk   Sorry your membership has lapsed, you will need to renew your membership to be able to access this article.t   account_renewt   usert   member_statust   currentR(   t'   resource__limit_to_member_types__isnullR=   t   resource__limit_to_member_typess%   public/mediacentre/media_article.htmlR   R'   t   article_resources(    R   R0   R-   R   R!   R   R>   t	   LoginFormR    R   R   t   warningR
   R   RO   t   is_authenticatedt   MemberR   t   gett   expiry_dateR@   t   MediaArticleResourceR    R"   R   t   member_typet   is_superusert   resourcet   limit_to_member_groupsR1   t   membersR%   (   R2   R?   t   article_slugR   R'   R(   RK   t   permission_deniedt
   permissionRL   t   memberRT   t   final_resourcesR^   t	   in_groupst   group(    (    s7   /var/www/svtgbi.org/svtgbi/modules/mediacentre/views.pyt   media_articlet   sX    	 	'=>!+$N()   t   django.shortcutsR    R   t   django.templateR   R   R   t   django.contrib.auth.decoratorsR   R   t   django.db.modelsR   t   django.contrib.sites.modelsR   t   django.confR	   t   django.httpR
   R   R   t   django.core.urlresolversR   t   django.contrib.auth.modelsR   R   t   django.contribR   t   django.template.defaultfiltersR   R   R   R   t   formst   modules.core.formst   modelst   modules.members.modelsR-   R3   RC   RI   Rh   (    (    (    s7   /var/www/svtgbi.org/svtgbi/modules/mediacentre/views.pyt   <module>   s(   



				