ó
M<*Xc           @   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
 d  d l m Z d   Z d   Z d	   Z d
   Z d S(   iĸĸĸĸ(   t   datetime(   t   render_to_responset   rendert   redirect(   t   HttpResponse(   t   reverse(   t   LldevicePdlagAlarm(   t   user_get_languagec         C   sK  |  j  j   r7|  j j d  } t j j |  j j d  d  } t j j |  j j d  d  } t j j d | d | d |  } d } d } | d	 7} x | D]~ } | j	 d  k rė | d
 | j j |  d 7} | d | j d 7} qĄ | d
 | j j |  d 7} | d | j d 7} qĄ W| d 7} t |  St t d   Sd  S(   Nt	   device_idt   startDateInputs   %Y-%m-%d %H:%M:%St   endDateInputt   timestamp__gtet   timestamp__ltet   lldevicelistsO   <div style="margin-top: 50px;"><table class="table table-striped" id="tblGrid">s   <thead id="tblHead"><tr><th><font color="#444444">Timestamp</font></th><th><font color="#444444">Alarm</font></th></tr></thead><tbody>s   <tr><td><font color="#444444">s   </font></td>s   <td><font color="#444444">s   </font</td></tr>s   </tbody></table></div>t
   login_page(   t   usert   is_authenticatedt   GETt   getR    t   strptimeR   t   objectst   filtert   checkedt   Nonet	   timestampt   strftimet   alarmR   R   R   (   t   requestR   t
   start_datet   end_datet
   alarm_listt   fmtt   htmlR   (    (    sg   D:\SMTech Code\LeakLess Software\LeakLess Monitor\LeakLess Monitor\Applications\Measure\Alarms\views.pyt   alarm_return_device_alarms   s"    !!!


c         C   s   |  j  j   rk y9 t j j d |  j j d   j d d  t d  SWq{ t	 k
 rg } t | j
  SXn t t d   Sd  S(   Nt   idlldevicepdlag_alarmt   AlarmIDR   i   s   Alarm confirmedR   (   R   R   R   R   R   R   R   t   updateR   t	   Exceptiont   messageR   R   (   R   t   e(    (    sg   D:\SMTech Code\LeakLess Software\LeakLess Monitor\LeakLess Monitor\Applications\Measure\Alarms\views.pyt   alarm_confirm%   s    +c   	      C   s~  |  j  j   rjg  } |  j  j   } x( | D]  } | j | j d  d  q+ Wt j j d | d t  j	 d  } d } d } d } x | D] } | d	 k rĒ Pn  | d 7} | d
 t
 | j  d t
 | j  d | j j |  d t
 | j  d t j | j  j d d  d d 7} q W| d 7} | d k rVd t
 |  d | } n
 d | } t |  St t d   Sd  S(   Nt   .i   t   lldevicelist__int   checked__isnulls
   -timestamps   %Y-%m-%d %H:%M:%Si    sl   <ul id="notifDropDown" class="dropdown-menu scrollable-menu" style="background-color: #3399cc;" role="menu">i
   s   <li id="alarms    "><a><div><font color="#ffffff">s	   , &#160; s:   &#160; &#160; <button type="button" onclick="confirmAlarm(sC   )" class="btn btn-default">Confirm</button><br><div align="center">t   ,s   <br>s   </div>&#160;s   </font></div></a></li>s   </ul>sE   <span id="redNotifier" value="fire_Alarm" class="badge badge-notify">s   </span>s9   <span id="redNotifier" class="badge badge-notify"></span>R   (   R   R   t   get_all_permissionst   appendt   splitR   R   R   t   Truet   order_byt   strR"   R   R   R   t   cgit   escapeR   t   replaceR   R   R   (	   R   t	   permfieldt   permissionst   permt   AlarmsR   t   counterR    t   alarm1(    (    sg   D:\SMTech Code\LeakLess Software\LeakLess Monitor\LeakLess Monitor\Applications\Measure\Alarms\views.pyt    alarm_return_alarm_notifications0   s,    	
v


c         C   sĢ   |  j  j   r g  } |  j  j   } x( | D]  } | j | j d  d  q+ Wt j j d |  } t d i |  j  d 6| d 6t	 |   d 6 St
 t d   Sd  S(	   NR)   i   R*   s   alarms.htmlt   user_objectt   alarmst   langR   (   R   R   R-   R.   R/   R   R   R   R   R   R   R   (   R   R6   R7   R8   R   (    (    sg   D:\SMTech Code\LeakLess Software\LeakLess Monitor\LeakLess Monitor\Applications\Measure\Alarms\views.pyt   alarm_return_alarm_tableP   s    +N(   R    t   django.shortcutsR   R   R   t   django.httpR   t   django.core.urlresolversR   t   Applications.Measure.modelsR   t   Applications.Users.viewsR   R!   R(   R<   R@   (    (    (    sg   D:\SMTech Code\LeakLess Software\LeakLess Monitor\LeakLess Monitor\Applications\Measure\Alarms\views.pyt   <module>   s   			 