ó
O'^c           @   sŪ   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 e   Z d e j f d     YZ e j j e e  e j j e e  d	 S(
   iĸĸĸĸ(   t   admint   messages(   t   get_user_model(   t   ugettext_lazyi   (   t   GCMError(   t
   APNSDevicet	   GCMDevicet   get_expired_tokenst   DeviceAdminc           B   sĨ   e  Z d Z d d d e j f Z d Z d Z e d  Z	 d   Z
 e d  e
 _ d   Z e d  e _ d   Z e d  e _ d   Z e d  e _ d   Z RS(   t   __str__t	   device_idt   usert   activet   date_createdt   names   user__%st   send_messaget   send_bulk_messaget   prune_devicest   enablet   disablec   
      C   s*  g  } g  } d } x | D]z } yA | r: | j  d  } n | j  d  } | r_ | j |  n  Wn& t k
 r } | j t |   n X| r Pq q W| rĖ |  j | t d d j |   d t j n  | r&| sę d j |  } n  | rt d |  }	 n t d |  }	 |  j | |	  n  d	 S(
   sY   
		Provides error handling for DeviceAdmin send_message and send_bulk_message methods.
		t    s   Test bulk notifications   Test single notifications(   Some messages could not be processed: %rs   , t   levels   Some messages were sent: %ss   All messages were sent: %sN(	   R   t   appendR   t   strt   message_usert   _t   joinR   t   ERROR(
   t   selft   requestt   querysett   bulkt   rett   errorst   rt   devicet   et   msg(    (    s:   /tmp/pip-unpacked-wheel-MTFMX_/push_notifications/admin.pyt   send_messages   s.    /c         C   s   |  j  | |  d  S(   N(   R&   (   R   R   R   (    (    s:   /tmp/pip-unpacked-wheel-MTFMX_/push_notifications/admin.pyR   2   s    s   Send test messagec         C   s   |  j  | | t  d  S(   N(   R&   t   True(   R   R   R   (    (    s:   /tmp/pip-unpacked-wheel-MTFMX_/push_notifications/admin.pyR   6   s    s   Send test message in bulkc         C   s   | j  d t  d  S(   NR   (   t   updateR'   (   R   R   R   (    (    s:   /tmp/pip-unpacked-wheel-MTFMX_/push_notifications/admin.pyR   :   s    s   Enable selected devicesc         C   s   | j  d t  d  S(   NR   (   R(   t   False(   R   R   R   (    (    s:   /tmp/pip-unpacked-wheel-MTFMX_/push_notifications/admin.pyR   >   s    s   Disable selected devicesc         C   sC   t    } | j d |  } x! | D] } t | _ | j   q" Wd  S(   Nt   registration_id__in(   R   t   filterR)   R   t   save(   R   R   R   t   expiredt   devicest   d(    (    s:   /tmp/pip-unpacked-wheel-MTFMX_/push_notifications/admin.pyR   B   s
    		(   R	   R
   R   R   R   (   R   (   R   R   R   R   R   (   t   __name__t
   __module__t   list_displayt   Usert   USERNAME_FIELDt   search_fieldst   list_filtert   actionsR)   R&   R   R   t   short_descriptionR   R   R   R   (    (    (    s:   /tmp/pip-unpacked-wheel-MTFMX_/push_notifications/admin.pyR      s   !				N(   t   django.contribR    R   t   django.contrib.authR   t   django.utils.translationR   R   t   gcmR   t   modelsR   R   R   R3   t
   ModelAdminR   t   sitet   register(    (    (    s:   /tmp/pip-unpacked-wheel-MTFMX_/push_notifications/admin.pyt   <module>   s   	E