Пример #1
0
    def post(self, request, **kwargs):
        generic_error_response = self.render_json_response({
            'status': 'error',
            'errors': {
                'non_field_errors': 'Invalid submission.'
            }
        })

        order_pk = request.POST.get('order')
        if order_pk is None:
            return generic_error_response

        try:
            order = Order.objects.get(pk=order_pk,
                                      accepted=True,
                                      completed=False,
                                      canceled=False)
        except Order.DoesNotExist:
            return generic_error_response

        order.completed = True
        order.time_completed = timezone.now()
        order.save()

        send_text('complete', unicode(order.customer.phone), {'order': order})

        return self.render_json_response({
            'status': 'success',
            'pk': order.pk,
            'customer_name': order.customer.full_name,
            'total': order.total,
            'time_taken': order.time_to_complete
        })
Пример #2
0
def send_tour_reminder_text(tour):
    to_person = tour.guide

    allow_texting = core_utils.get_setting('Allow Texting to Info Center')
    info_center_name = core_utils.get_setting('Info Center Director Name')
    info_center_phone = core_utils.get_setting('Info Center Phone Number')

    context = {'tour': tour, 'allow_texting': allow_texting, 'info_center_name': info_center_name, 'info_center_phone': info_center_phone}
    core_utils.send_text(unicode(to_person.phone), 'texts/tour_reminder.txt', context)
Пример #3
0
    def post(self, request):
        generic_error_response = self.render_json_response({
            'status': 'error',
            'errors': {
                'non_field_errors': 'Invalid submission.'
            }
        })

        order_pk = request.POST.get('order')
        if order_pk is None:
            return generic_error_response

        minutes_estimate = request.POST.get('minutes_estimate')
        try:
            minutes_estimate = int(minutes_estimate)
        except:
            return self.render_json_response({
                'status': 'error',
                'errors': {
                    'minutes_estimate': 'Invalid value.'
                }
            })

        if not minutes_estimate or minutes_estimate <= 0:
            return self.render_json_response({
                'status': 'error',
                'errors': {
                    'minutes_estimate': 'Invalid value.'
                }
            })

        try:
            order = Order.objects.get(pk=order_pk,
                                      accepted=False,
                                      completed=False,
                                      canceled=False)
        except Order.DoesNotExist:
            return generic_error_response

        order.accepted = True
        order.time_estimate = minutes_estimate
        order.time_accepted = timezone.now()
        order.save()

        send_text('accepted', unicode(order.customer.phone), {'order': order})

        return self.render_json_response({'status': 'success'})
Пример #4
0
    def post(self, request, **kwargs):
        generic_error_response = self.render_json_response({
            'status': 'error',
            'errors': {
                'non_field_errors': 'Invalid submission.'
            }
        })

        cancel_verb = kwargs.get('cancel_verb')

        order_pk = request.POST.get('order')
        if order_pk is None:
            return generic_error_response

        try:
            order = Order.objects.get(pk=order_pk,
                                      completed=False,
                                      canceled=False)
        except Order.DoesNotExist:
            return generic_error_response

        cancellation_reason_form = CancellationReasonForm(
            data={
                'cancellation_reason': request.POST.get('cancellation_reason')
            })

        if cancellation_reason_form.is_valid():
            cancellation_reason = cancellation_reason_form.cleaned_data.get(
                'cancellation_reason')
        else:
            cancellation_reason = None

        order.cancellation_reason = cancellation_reason
        order.canceled = True
        order.save()

        send_text('cancel', unicode(order.customer.phone), {
            'order': order,
            'verb': cancel_verb,
            'reason': cancellation_reason
        })

        return self.render_json_response({'status': 'success'})
Пример #5
0
def send_shift_reminder_text(shift):
    to_person = shift.person

    context = {'shift': shift}
    send_text(unicode(to_person.phone), 'texts/shift_reminder.txt', context)