Exemple #1
0
def assistant_orders_by_uuid(request, assistant_uuid):
    if request.user.is_authenticated():
        try:
            assistant = Assistant.objects.filter(ASSISTANT_FILTER).get(
                uuid=uuid.UUID(assistant_uuid))
            aUser = AssistantUser.objects.filter(
                Q(user=request.user)).get(assistant=assistant)
            if aUser is None:
                raise PermissionDenied("illegal access.")
            if request.method == 'POST':
                appoints = AssistantAppointment.objects.filter(
                    Q(assistant=assistant)).filter(
                        Q(state=2) | Q(state=4) | Q(state=32)
                        | Q(state=256)).order_by("-createdDate")
                return HttpResponse(
                    tojson2(
                        appoints, AssistantOrdersJSONSerializer(),
                        assistant_appointment_fields + (
                            'user',
                            'transaction',
                        )))
            else:
                return render_to_response(
                    TEMPLATE_ROOT + 'escort/asorder.html', {'as': assistant},
                    context_instance=RequestContext(request))
        except Assistant.DoesNotExist:
            raise Http404("illegal access.")
        except AssistantUser.DoesNotExist:
            raise PermissionDenied("illegal access.")
    if isWechatBrowser(request.META['HTTP_USER_AGENT']):
        return forceLogin(request, 'wechat')
    url = set_query_parameter(
        reverse('login_3rd_page'), 'from',
        request.build_absolute_uri(request.get_full_path()))
    return HttpResponseRedirect(url)
Exemple #2
0
def assistant_by_uuid(request, assistant_uuid):
    if request.method == 'GET':
        assistant = get_object_or_404(Assistant,
                                      uuid=uuid.UUID(assistant_uuid))
        if request.mobile:
            return redirect('{}#/detail/{}'.format(reverse('assistant'),
                                                   assistant_uuid))
        return render_to_response(TEMPLATE_ROOT + 'escort/detail.html',
                                  {'as': assistant},
                                  context_instance=RequestContext(request))
    elif request.method == 'POST':
        try:
            assistant = Assistant.objects.get(uuid=uuid.UUID(assistant_uuid))
            assistantobj = simplejson.loads(
                tojson2(assistant, AssistantJSONSerializer(),
                        assistant_fields))
            assistantobj[0]['images'] = simplejson.loads(
                tojson2(
                    AssistantImage.objects.filter(
                        assistant=assistant).filter(ASSISTANT_IMAGE_FILTER),
                    AssistantJSONSerializer(), assistantimage_fields))
            return HttpResponse(simplejson.dumps(assistantobj))
        except Assistant.DoesNotExist:
            return HttpResponse("{'error': 'not found', 'code': 0}")
Exemple #3
0
def getOffers(assistant_uuid):
    offers = {}
    weekday = datetime.datetime.today().weekday()
    weekdays = [(weekday + i) % 7 for i in range(3)]
    for idx, weekday in enumerate(weekdays):
        assistantsOffers = AssistantOffer.objects.filter(
            ASSISTANT_OFFER_FILTER).filter(
                assistant=Assistant.objects.filter(ASSISTANT_FILTER).get(
                    uuid=uuid.UUID(assistant_uuid))).filter(
                        day=getattr(AssistantOffer.day,
                                    AssistantOffer.day._flags[weekday]))
        offers[idx] = simplejson.loads(
            tojson2(assistantsOffers, AssistantJSONSerializer(),
                    assistantoffer_fields_2))
    return offers
Exemple #4
0
def order_detail(request, order_id):
    if request.user.is_authenticated():
        try:
            appoint = AssistantAppointment.objects.get(
                transaction=int(order_id), user=request.user)
            updateAppointmentState(appoint)
            return HttpResponse(
                tojson2(
                    appoint, AssistantJSONSerializer(),
                    assistant_appointment_fields + (
                        'transaction',
                        'chargeCode',
                    )))
        except AssistantAppointment.DoesNotExist:
            raise Http404('illegal request.')
    raise PermissionDenied('login firstly')
Exemple #5
0
def user_assistant_order(request):
    if request.user.is_authenticated():
        if request.method == 'POST':
            appoints = AssistantAppointment.objects.filter(
                user=request.user).order_by("-createdDate")
            try:
                payload = simplejson.loads(request.body)
                if payload['page'] is not None:
                    paginator = Paginator(appoints, 5)
                    try:
                        appoints = paginator.page(payload['page'])
                    except PageNotAnInteger:
                        # If page is not an integer, deliver first page.
                        appoints = paginator.page(1)
                    except EmptyPage:
                        # If page is out of range (e.g. 9999), deliver last page of results.
                        appoints = []
            except (ValueError, KeyError):
                pass
            for appoint in appoints:
                updateAppointmentState(appoint)
            return HttpResponse(
                tojson2(
                    appoints, AssistantJSONSerializer(),
                    assistant_appointment_fields + (
                        'transaction',
                        'chargeCode',
                    )))
        else:
            if request.mobile:
                return redirect('{}#/order/all'.format(reverse('assistant')))
            return render_to_response(TEMPLATE_ROOT + 'escort/order.html',
                                      context_instance=RequestContext(request))
    if isWechatBrowser(request.META['HTTP_USER_AGENT']):
        return forceLogin(request, 'wechat')
    url = set_query_parameter(
        reverse('login_3rd_page'), 'from',
        request.build_absolute_uri(request.get_full_path()))
    return HttpResponseRedirect(url)