
    &Pg@                         d dl mZ d dlmZ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 d dlmZ d d	lZd
 Zd Zd Zd Zd Zd Zy	)    )HttpResponseRedirect)r2rcourse_defaults)
CourseSiteSecureCourseFile)
SearchFormLoadScheduleForm)
is_faculty)Epoch)settings)PathNc                     t        |       }d|d<   | j                  dk(  rCt        | j                        }|j	                         r(|j
                  d   }t        |      |d<   n
t               }||d<   t        | d|      S )N searchresultsPOSTterms
searchformzcourses/p064pages.html)class_defaultsmethodr   r   is_validcleaned_datalook_forr   )requestdicr   r   s       %/var/www/djphys/courses/p064/views.pypagesr      s{    

!CC~~-
 ++G4E#+E?C \
"Cw0#66    c                    d|d<   t         j                  |d<   | j                  dk(  rt        | j                        }|j                         r_|j                  d   }t        |      }t               }|D ]0  }|j                  d      \  }}||vr|||<   !||xx   d|z   z  cc<   2 ||d<   n
t               }||d	<   t        | d
|      S )Nr   r   URLGETr   ,;buttonsr   zcourses/p064search.html)r   P064URLr   r   r    r   r   r   dictsplitr   )	r   r   r   r   hitscountsentryfileterms	            r   searchr,   )   s    C!!CJ~~,
 ++G4EE?DVF /"[[-
dv%#'F4L4LC$J.L/ $C	N#J&Lw1377r   c                 2    t        |       }t        | d|      S )Nzcourses/p064project.html)r   r   )r   r   s     r   projectr.   B   s    
'
"Cw2C88r   c                 ,   t        t        j                        }t               }g }d| v r|  }t	        j
                  d|      D ]d  }|j                  t	        j                  |j                  d      t        j                               | j                  |j                         d      } f | j                         j                  d      D ]R  }t        |      s|j                  t	        j                  |t        j                  t        j                  z               T t        |j!                  d            D ]  }	 t#        |d      j%                         j'                  d      }|D ]d  }
	 t-        d
j/                  d            }|
j1                  |d	       }|s6|j3                  |j4                  dz   |j                         z          f  |S # t(        $ r}	t+        |	       Y d	}	~	d	}	~	ww xY w# t(        $ r}	t+        |	       d
}Y d	}	~	d	}	~	ww xY w)z
    Perform a search through the .html files in
    the directory specified in the settings field P064FILES.
    To get the search terms noticed, when will need to install them
    in an in-document javascript variable.
    "z"(.*?)"   r    *.htmlrbutf8Nr   z<!-- menu-end -->r!   )r   r   	P064FILESsetrefinditerappendcompilegroupMreplacestripr&   lenIsortedglobopenreaddecode	Exceptionprintmaxfindr,   addname)r   dirr'   patternscopymtr*   txteepspns               r   r   r   G   s    x!!
"C5DH
e|Z. 	1AOOBJJqwwqz24489MM!'')R0E	1 [[]  % 8q6OOBJJq"$$+678 sxx)* 6	tT"'')008C  		6A388$789 QR!AS177945		66& K  	$KK	  ds0   <)G+G3	G0G++G03	H<HHc                  z    t        t        j                        } | j                  d      D ]  }t	        |d        y )Nr3   r   )r   r   r6   rC   rewrite)rM   r*   s     r   clear_searchrX   r   s4    
x!!
"C" br   c                     d| d}t        j                  dd| dt        | d      j                         t         j                  t         j
                  z        }t        | d      j                  |       y )Nzvar search_terms = "z";z"<script id="search">(.*)?</script>z<script id="search">z	</script>rw)r8   subrD   rE   r=   DOTALLwrite)r*   search_termsssrR   s       r   rW   rW   x   sd    ~R	0B
&&6't95dC%%'		)9;C 	sO#r   )django.httpr   courses.viewsr   r   courses.modelsr   r   courses.formsr   r	   people.funcsr
   djphys.epochr   django.confr   pathlibr   r8   r   r,   r.   r   rX   rW    r   r   <module>rj      sA    - . 7 6 #     	7829
(Vr   