ó
Ô¬ÄVc           @   sL  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 d  d
 l m Z d  d l Td  d l Td  d l Td  d l m Z m Z m  Z  m! Z! d d „ Z" e# d „  ƒ Z$ e	 d ƒ d „  ƒ Z% e# d „  ƒ Z& e	 d ƒ d „  ƒ Z' e# d „  ƒ Z( e# d „  ƒ Z) e# d „  ƒ Z* e# d „  ƒ Z+ e# d „  ƒ Z, e# d „  ƒ Z- e# d „  ƒ Z. e# d „  ƒ Z/ e# d „  ƒ Z0 e# d „  ƒ Z1 e# d „  ƒ Z2 e# d „  ƒ Z3 e# d  „  ƒ Z4 e# d! „  ƒ Z5 e# d" „  ƒ Z6 e# d# „  ƒ Z7 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   messages(   t   slugify(   t   *(   t   Paget   PageSectiont   PageResourcet   PageSectionResourcet   urlc         C   sx   d } t  |  ƒ } } x[ t rs | rC d j | t | ƒ g ƒ } n  | j j i | | 6  j ƒ  sf | S| d 7} q Wd  S(   Ni    t   -i   (   R   t   Truet   joint   strt   objectst   filtert   count(   t   valuet   modelt	   slugfieldt   suffixt	   potentialt   base(    (    s6   /var/www/svtgbi.org/svtgbi/modules/pages/adminviews.pyt   slugify_unique   s    	c         C   s>   t  j j d t ƒ j d ƒ } t d i | d 6d t |  ƒ ƒS(   Nt   parent__isnullt   titles   admin/pages/pages.htmlt   pagest   context_instance(   R   R   R   R   t   order_byR    R   (   t   requestR&   (    (    s6   /var/www/svtgbi.org/svtgbi/modules/pages/adminviews.pyt   admin_pages!   s    s   admin_users.can_access_pagesc         C   s´   t  ƒ  } |  j r” t  |  j |  j ƒ } | j ƒ  r” | j d t ƒ } t | j t d ƒ | _	 | j ƒ  | j
 ƒ  t j |  d ƒ t t d ƒ ƒ Sn  t d i | d 6d t |  ƒ ƒS(   Nt   commitR   s   Page CreatedR*   s   admin/pages/add_page.htmlt   formR'   (   t   PageFormt   POSTt   FILESt   is_validt   savet   FalseR#   R%   R   R   t   save_m2mR   t   successR
   R   R    R   (   R)   R,   t   page(    (    s6   /var/www/svtgbi.org/svtgbi/modules/pages/adminviews.pyt   admin_add_page(   s    		

c         C   sà   t  t d | ƒ} | j |  j ƒ sD t j |  d ƒ t t d ƒ ƒ S| j } t	 d | ƒ } |  j
 r¹ t	 |  j
 |  j d | ƒ} | j ƒ  r¹ | j ƒ  t j |  d ƒ t t d ƒ ƒ Sn  t d i | d 6| d 6d	 t |  ƒ ƒS(
   Nt   ids    Sorry, you cannot edit this pageR*   t   instances   Page Updateds   admin/pages/edit_page.htmlR,   R5   R'   (   R   R   t   can_editt   userR   t   errorR
   R   R%   t   PageEditFormR.   R/   R0   R1   R4   R    R   (   R)   R7   R5   t
   orig_titleR,   (    (    s6   /var/www/svtgbi.org/svtgbi/modules/pages/adminviews.pyt   admin_edit_page7   s    		
c         C   s<   t  t d | ƒ} | j ƒ  t j |  d ƒ t t d ƒ ƒ S(   NR7   s   Page DeletedR*   (   R   R   t   deleteR   R4   R
   R   (   R)   R7   R5   (    (    s6   /var/www/svtgbi.org/svtgbi/modules/pages/adminviews.pyt   admin_delete_pageL   s    
c         C   s‰   t  t d | ƒ} | j |  j ƒ sD t j |  d ƒ t t d ƒ ƒ St j	 j
 d | ƒ j d ƒ } t d i | d 6| d 6d t |  ƒ ƒS(	   NR7   s    Sorry, you cannot edit this pageR*   R5   t   orders   admin/pages/page_sections.htmlt   sectionsR'   (   R   R   R9   R:   R   R;   R
   R   R   R   R   R(   R    R   (   R)   R7   R5   RB   (    (    s6   /var/www/svtgbi.org/svtgbi/modules/pages/adminviews.pyt   admin_sections_pageU   s    c         C   sì   t  t d | ƒ} | j |  j ƒ sD t j |  d ƒ t t d ƒ ƒ St ƒ  } |  j	 rÅ t |  j	 ƒ } | j
 ƒ  rÅ | j d t ƒ } | | _ | j ƒ  t j |  d ƒ t t d d | j g ƒƒ Sn  t d i | d	 6| d
 6d t |  ƒ ƒS(   NR7   s    Sorry, you cannot edit this pageR*   R+   s   Section Createdt   admin_pages_sectionst   argss!   admin/pages/add_page_section.htmlR5   R,   R'   (   R   R   R9   R:   R   R;   R
   R   t   PageSectionFormR.   R0   R1   R2   R5   R4   R7   R    R   (   R)   R7   R5   R,   t   section(    (    s6   /var/www/svtgbi.org/svtgbi/modules/pages/adminviews.pyt   admin_add_section_pageb   s    			
c         C   sö   t  t d | ƒ} | j |  j ƒ sD t j |  d ƒ t t d ƒ ƒ St  t d | ƒ} t	 d | ƒ } |  j
 rÈ t	 |  j
 d | ƒ} | j ƒ  rÈ | j ƒ  t j |  d ƒ t t d d | j g ƒƒ Sn  t d i | d	 6| d
 6| d 6d t |  ƒ ƒS(   NR7   s    Sorry, you cannot edit this pageR*   R8   s   Section UpdatedRD   RE   s"   admin/pages/edit_page_section.htmlRG   R5   R,   R'   (   R   R   R9   R:   R   R;   R
   R   R   RF   R.   R0   R1   R4   R7   R    R   (   R)   R7   t	   sectionidR5   RG   R,   (    (    s6   /var/www/svtgbi.org/svtgbi/modules/pages/adminviews.pyt   admin_edit_section_pagew   s    	
c         C   s‰   t  t d | ƒ} | j |  j ƒ sD t j |  d ƒ t t d ƒ ƒ St  t d | ƒ} | j	 ƒ  t j
 |  d ƒ t t d d | g ƒƒ S(   NR7   s    Sorry, you cannot edit this pageR*   s   Section DeletedRD   RE   (   R   R   R9   R:   R   R;   R
   R   R   R?   R4   (   R)   R7   RI   R5   RG   (    (    s6   /var/www/svtgbi.org/svtgbi/modules/pages/adminviews.pyt   admin_delete_section_pageŒ   s    
c         C   s‰   t  t d | ƒ} | j |  j ƒ sD t j |  d ƒ t t d ƒ ƒ St j	 j
 d | ƒ j d ƒ } t d i | d 6| d 6d t |  ƒ ƒS(	   NR7   s    Sorry, you cannot edit this pageR*   R5   RA   s   admin/pages/page_resources.htmlt	   resourcesR'   (   R   R   R9   R:   R   R;   R
   R   R   R   R   R(   R    R   (   R)   R7   R5   RL   (    (    s6   /var/www/svtgbi.org/svtgbi/modules/pages/adminviews.pyt   admin_resources_page   s    c         C   s  t  t d | ƒ} | j |  j ƒ sD t j |  d ƒ t t d ƒ ƒ St ƒ  } |  j	 ræ t |  j	 ƒ } | j
 ƒ  ræ yU | j d t ƒ } | | _ | j ƒ  t j |  d ƒ t t d d | j g ƒƒ SWqã t j |  d ƒ qã Xqæ n  t d	 i | d
 6| d 6d t |  ƒ ƒS(   NR7   s    Sorry, you cannot edit this pageR*   R+   s   Resource Createdt   admin_pages_resourcesRE   s   Could not create resources"   admin/pages/add_page_resource.htmlR5   R,   R'   (   R   R   R9   R:   R   R;   R
   R   t   PageResourceFormR.   R0   R1   R2   R5   R4   R7   R    R   (   R)   R7   R5   R,   t   resource(    (    s6   /var/www/svtgbi.org/svtgbi/modules/pages/adminviews.pyt   admin_add_resource_pageª   s"    			
 c         C   s  t  t d | ƒ} | j |  j ƒ sD t j |  d ƒ t t d ƒ ƒ St  t d | ƒ} t	 d | ƒ } |  j
 ré t	 |  j
 d | ƒ} | j ƒ  ré y: | j ƒ  t j |  d ƒ t t d d | j g ƒƒ SWqæ t j |  d ƒ qæ Xqé n  t d	 i | d
 6| d 6| d 6d t |  ƒ ƒS(   NR7   s    Sorry, you cannot edit this pageR*   R8   s   Resource UpdatedRN   RE   s   Could not update resources#   admin/pages/edit_page_resource.htmlR5   RP   R,   R'   (   R   R   R9   R:   R   R;   R
   R   R   RO   R.   R0   R1   R4   R7   R    R   (   R)   R7   t
   resourceidR5   RP   R,   (    (    s6   /var/www/svtgbi.org/svtgbi/modules/pages/adminviews.pyt   admin_edit_resource_pageÃ   s     	
 c         C   sª   t  t d | ƒ} | j |  j ƒ sD t j |  d ƒ t t d ƒ ƒ St  t d | ƒ} y | j	 ƒ  t j
 |  d ƒ Wn t j |  d ƒ n Xt t d d | j g ƒƒ S(   NR7   s    Sorry, you cannot edit this pageR*   s   Resource Deleteds   Could not delete resourceRN   RE   (   R   R   R9   R:   R   R;   R
   R   R   R?   R4   R7   (   R)   R7   RR   R5   RP   (    (    s6   /var/www/svtgbi.org/svtgbi/modules/pages/adminviews.pyt   admin_delete_resource_pageÞ   s    
c         C   s‰   t  t d | ƒ} | j |  j ƒ sD t j |  d ƒ t t d ƒ ƒ St j	 j
 d | ƒ j d ƒ } t d i | d 6| d 6d t |  ƒ ƒS(	   NR7   s    Sorry, you cannot edit this pageR*   R5   RA   s   admin/pages/blocks/blocks.htmlt   blocksR'   (   R   R   R9   R:   R   R;   R
   R   t	   PageBlockR   R   R(   R    R   (   R)   R7   R5   RU   (    (    s6   /var/www/svtgbi.org/svtgbi/modules/pages/adminviews.pyRU   ò   s    c         C   s  t  t d | ƒ} | j |  j ƒ sD t j |  d ƒ t t d ƒ ƒ St ƒ  } |  j	 ræ t |  j	 ƒ } | j
 ƒ  ræ yU | j d t ƒ } | | _ | j ƒ  t j |  d ƒ t t d d | j g ƒƒ SWqã t j |  d ƒ qã Xqæ n  t d	 i | d
 6| d 6d t |  ƒ ƒS(   NR7   s    Sorry, you cannot edit this pageR*   R+   s   Block Createdt   admin_pages_blocksRE   s   Could not create blocks!   admin/pages/blocks/add_block.htmlR5   R,   R'   (   R   R   R9   R:   R   R;   R
   R   t   PageBlockFormR.   R0   R1   R2   R5   R4   R7   R    R   (   R)   R7   R5   R,   t   block(    (    s6   /var/www/svtgbi.org/svtgbi/modules/pages/adminviews.pyt	   add_blockÿ   s"    			
 c         C   s  t  t d | ƒ} | j |  j ƒ sD t j |  d ƒ t t d ƒ ƒ St  t d | ƒ} t	 d | ƒ } |  j
 ré t	 |  j
 d | ƒ} | j ƒ  ré y: | j ƒ  t j |  d ƒ t t d d | j g ƒƒ SWqæ t j |  d ƒ qæ Xqé n  t d	 i | d
 6| d 6| d 6d t |  ƒ ƒS(   NR7   s    Sorry, you cannot edit this pageR*   R8   s   Block UpdatedRW   RE   s   Could not update blocks"   admin/pages/blocks/edit_block.htmlR5   RY   R,   R'   (   R   R   R9   R:   R   R;   R
   R   RV   RX   R.   R0   R1   R4   R7   R    R   (   R)   R7   t   blockidR5   RY   R,   (    (    s6   /var/www/svtgbi.org/svtgbi/modules/pages/adminviews.pyt
   edit_block  s     	
 c         C   sª   t  t d | ƒ} | j |  j ƒ sD t j |  d ƒ t t d ƒ ƒ St  t d | ƒ} y | j	 ƒ  t j
 |  d ƒ Wn t j |  d ƒ n Xt t d d | j g ƒƒ S(   NR7   s    Sorry, you cannot edit this pageR*   s   Block Deleteds   Could not delete blockRW   RE   (   R   R   R9   R:   R   R;   R
   R   RV   R?   R4   R7   (   R)   R7   R[   R5   RY   (    (    s6   /var/www/svtgbi.org/svtgbi/modules/pages/adminviews.pyt   delete_block3  s    
c         C   s¢   t  t d | ƒ} | j |  j ƒ sD t j |  d ƒ t t d ƒ ƒ St  t d | ƒ} t	 j
 j d | ƒ j d ƒ } t d i | d 6| d 6| d 6d	 t |  ƒ ƒS(
   NR7   s    Sorry, you cannot edit this pageR*   RG   RA   s'   admin/pages/page_section_resources.htmlR5   RL   R'   (   R   R   R9   R:   R   R;   R
   R   R   R   R   R   R(   R    R   (   R)   R7   RI   R5   RG   RL   (    (    s6   /var/www/svtgbi.org/svtgbi/modules/pages/adminviews.pyt   admin_resources_page_sectionF  s    c         C   s,  t  t d | ƒ} | j |  j ƒ sD t j |  d ƒ t t d ƒ ƒ St  t d | ƒ} t	 ƒ  } |  j
 rþ t	 |  j
 ƒ } | j ƒ  rþ y[ | j d t ƒ } | | _ | j ƒ  t j |  d ƒ t t d d | j | j g ƒƒ SWqû t j |  d ƒ qû Xqþ n  t d	 i | d
 6| d 6| d 6d t |  ƒ ƒS(   NR7   s    Sorry, you cannot edit this pageR*   R+   s   Resource Createdt   admin_page_section_resourcesRE   s   Could not create resources*   admin/pages/add_page_section_resource.htmlR5   RG   R,   R'   (   R   R   R9   R:   R   R;   R
   R   R   t   PageSectionResourceFormR.   R0   R1   R2   RG   R4   R7   R    R   (   R)   R7   RI   R5   RG   R,   RP   (    (    s6   /var/www/svtgbi.org/svtgbi/modules/pages/adminviews.pyt   admin_add_resource_page_sectionT  s$    			
&c         C   s3  t  t d | ƒ} | j |  j ƒ sD t j |  d ƒ t t d ƒ ƒ St  t d | ƒ} t  t	 d | ƒ} t
 d | ƒ } |  j rþ t
 |  j d | ƒ} | j ƒ  rÜ y | j ƒ  t j |  d ƒ WqÜ t j |  d ƒ qÜ Xn  t t d d | j | j g ƒƒ St d	 i | d
 6| d 6| d 6| d 6d t |  ƒ ƒS(   NR7   s    Sorry, you cannot edit this pageR*   R8   s   Resource Updateds   Could not update resourceR_   RE   s+   admin/pages/edit_page_section_resource.htmlR5   RG   RP   R,   R'   (   R   R   R9   R:   R   R;   R
   R   R   R   R`   R.   R0   R1   R4   R7   R    R   (   R)   R7   RI   RR   R5   RG   RP   R,   (    (    s6   /var/www/svtgbi.org/svtgbi/modules/pages/adminviews.pyt    admin_edit_resource_page_sectionn  s"    	
"c         C   sÂ   t  t d | ƒ} | j |  j ƒ sD t j |  d ƒ t t d ƒ ƒ St  t d | ƒ} t  t	 d | ƒ} y | j
 ƒ  t j |  d ƒ Wn t j |  d ƒ n Xt t d d | j | j g ƒƒ S(   NR7   s    Sorry, you cannot edit this pageR*   s   Resource Deleteds   Could not delete resourceR_   RE   (   R   R   R9   R:   R   R;   R
   R   R   R   R?   R4   R7   (   R)   R7   RI   RR   R5   RG   RP   (    (    s6   /var/www/svtgbi.org/svtgbi/modules/pages/adminviews.pyt"   admin_delete_resource_page_sectionˆ  s    
N(8   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.contribR   t   django.template.defaultfiltersR   t
   decoratorst   modules.core.functionst   formst   modelsR   R   R   R   R#   t   pages_access_requiredR*   R6   R>   R@   RC   RH   RJ   RK   RM   RQ   RS   RT   RU   RZ   R\   R]   R^   Ra   Rb   Rc   (    (    (    s6   /var/www/svtgbi.org/svtgbi/modules/pages/adminviews.pyt   <module>   sD   


"	