Exemplo n.º 1
0
def zeropush_new_job(job):
    # Get sellers matching seller title
    sellers = Seller.objects.filter(titles=job.title).exclude(user=job.buyer).all()
    # Get sellers within distance
    suitable_sellers = []
    for seller in sellers:
        kwargs = {
            'lat1': float(job.geoposition.latitude),
            'long1': float(job.geoposition.longitude),
            'lat2': float(seller.geoposition.latitude),
            'long2': float(seller.geoposition.longitude),
        }
        if distance_in_kilometers(**kwargs) <= seller.distance:
            suitable_sellers.append(seller)
    # Get suitable user devices
    if len(suitable_sellers) > 0:
        devices = []
        for seller in suitable_sellers:
            devices += seller.user.pushdevice_set.all()
        # Notify devices
        if len(devices) > 0:
            if job.start_asap:
                alert = _(u"{title} ASAP").format(title=job.title.title)
            else:
                alert = _(u"{title} in {start_on}").format(title=job.title.title, start_on=timeuntil(job.start_on))
            print alert
            zeropush.notify_devices(devices, alert=alert)
Exemplo n.º 2
0
def zeropush_new_job(job):
    # Get sellers matching seller title
    sellers = Seller.objects.filter(titles=job.title).exclude(
        user=job.buyer).all()
    # Get sellers within distance
    suitable_sellers = []
    for seller in sellers:
        kwargs = {
            'lat1': float(job.geoposition.latitude),
            'long1': float(job.geoposition.longitude),
            'lat2': float(seller.geoposition.latitude),
            'long2': float(seller.geoposition.longitude),
        }
        if distance_in_kilometers(**kwargs) <= seller.distance:
            suitable_sellers.append(seller)
    # Get suitable user devices
    if len(suitable_sellers) > 0:
        devices = []
        for seller in suitable_sellers:
            devices += seller.user.pushdevice_set.all()
        # Notify devices
        if len(devices) > 0:
            if job.start_asap:
                alert = _(u"{title} ASAP").format(title=job.title.title)
            else:
                alert = _(u"{title} in {start_on}").format(
                    title=job.title.title, start_on=timeuntil(job.start_on))
            print alert
            zeropush.notify_devices(devices, alert=alert)
Exemplo n.º 3
0
 def obj_create(self, bundle, **kwargs):
     bundle = super(ImagePostResource, self).obj_create(bundle, user=bundle.request.user)
     #send push notifications
     user_ids = bundle.obj.event.users.filter(~models.Q(id=bundle.request.user.id)).values('id')
     devices = PushDevice.objects.filter(user_id__in=user_ids)
     alert = "%s uploaded a picture to '%s'" % (bundle.request.user.get_full_name(), bundle.obj.event.name)
     notify_devices(devices, alert=alert)
     return bundle
Exemplo n.º 4
0
 def obj_create(self, bundle, **kwargs):
     bundle = super(PlacePostResource, self).obj_create(bundle, user=bundle.request.user)
     # update the location of the event
     event = bundle.obj.event
     event.latitude = bundle.obj.latitude
     event.longitude = bundle.obj.longitude
     event.venue_id = bundle.obj.venue_id
     event.save()
     # send push notifications
     user_ids = bundle.obj.event.users.filter(~models.Q(id=bundle.request.user.id)).values('id')
     devices = PushDevice.objects.filter(user_id__in=user_ids)
     alert = "%s changed the location of '%s'" % (bundle.request.user.get_full_name(), bundle.obj.event.name)
     notify_devices(devices, alert=alert)
     return bundle
Exemplo n.º 5
0
 def obj_create(self, bundle, **kwargs):
     bundle = super(TextPostResource, self).obj_create(bundle, user=bundle.request.user)
     # send push notifications
     user_ids = bundle.obj.event.users.filter(~models.Q(id=bundle.request.user.id)).values('id')
     devices = PushDevice.objects.filter(user_id__in=user_ids)
     body = bundle.obj.body
     alert = "%s posted a message to '%s': '" % (bundle.request.user.get_full_name(), bundle.obj.event.name)
     
     if len(alert) + len(body) > 200:
         # Apple allows the push notification payload to be 256 bytes, so 200 is a safe under-estimate
         difference = 200 - len(alert)
         body = body[:difference] + '...'
     alert = alert + body + "'"
     notify_devices(devices, alert=alert)
     return bundle