コード例 #1
0
def daily_pickup_notifications():
    stats_utils.periodic_task('pickups__daily_pickup_notifications')

    for group in Group.objects.all():
        with timezone.override(group.timezone):
            if timezone.localtime().hour is not 20:  # only at 8pm local time
                continue

            for data in fetch_pickup_notification_data_for_group(group):
                prepare_pickup_notification_email(**data).send()
                stats.pickup_notification_email(group=data['group'],
                                                **{
                                                    k: v.count()
                                                    for k, v in data.items()
                                                    if isinstance(v, QuerySet)
                                                })
コード例 #2
0
    def pickup_notification(self):
        user = random_user()

        pickup1 = PickupDate.objects.order_by('?').first()
        pickup2 = PickupDate.objects.order_by('?').first()
        pickup3 = PickupDate.objects.order_by('?').first()
        pickup4 = PickupDate.objects.order_by('?').first()

        localtime = timezone.localtime()

        return prepare_pickup_notification_email(
            user=user,
            group=user.groups.first(),
            tonight_date=localtime,
            tomorrow_date=localtime + relativedelta(days=1),
            tonight_user=[pickup1, pickup2],
            tonight_empty=[pickup3, pickup4],
            tonight_not_full=[pickup4],
            tomorrow_user=[pickup2],
            tomorrow_empty=[pickup3],
            tomorrow_not_full=[pickup4],
        )