コード例 #1
0
def get_station_assignments_history_data(request, station):
    page = int(request.GET.get("page", "1"))
    sort_by = request.GET.get("sort_by", "create_date")
    sort_dir = request.GET.get("sort_dir", "-")

    status_list = request.GET.get("status_list", None)
    if status_list:
        status_list = simplejson.loads(status_list)

    start_date = request.GET.get("start_date", None)
    end_date = request.GET.get("end_date", None)
    if start_date and end_date:
        form = DatePickerForm({'start_date': start_date, 'end_date': end_date})
        if form.is_valid():
            start_date = datetime.datetime.combine(form.cleaned_data["start_date"], datetime.time.min)
            end_date = datetime.datetime.combine(form.cleaned_data["end_date"], datetime.time.max)

    data = get_stations_assignments_history_data(station, page=page, sort_by=sort_by, sort_dir=sort_dir, start_date=start_date, end_date=end_date, status_list=status_list)
    return JSONResponse(data)
コード例 #2
0
def station_analytics(request, station):
    is_popup = True
    if request.META.has_key("HTTP_USER_AGENT"):
        workstation_agent = "adobeair" in request.META["HTTP_USER_AGENT"].lower()

    if request.POST: # date picker form submitted
        form = DatePickerForm(request.POST)
        if form.is_valid():
            start_date = datetime.datetime.combine(form.cleaned_data["start_date"], datetime.time.min)
            end_date = datetime.datetime.combine(form.cleaned_data["end_date"], datetime.time.max)
            assignments = OrderAssignment.objects.filter(station=station, create_date__gte=start_date, create_date__lte=end_date)
            pie_data, total_count = get_station_assignments_pie_data(assignments)
            return JSONResponse({'pie_data': pie_data, 'total_count': total_count})
        else:
            return JSONResponse({'error': 'error'})

    else:
        station_name = station.name
        form = DatePickerForm()
        accepted = models.ACCEPTED
        ignored = models.IGNORED
        not_taken = models.NOT_TAKEN
        rejected = models.REJECTED

        order_history_columns =  simplejson.dumps([unicode(s) for s in STATION_ASSIGNMENT_HISTORY_COLUMNS])
        order_history_column_names = simplejson.dumps([unicode(s) for s in STATION_ASSIGNMENT_HISTORY_COLUMN_NAMES])
        order_history_fields = simplejson.dumps([unicode(s) for s in STATION_ASSIGNMENT_HISTORY_FIELDS])

        end_date = datetime.datetime.combine(datetime.date.today(), datetime.time.max)
        start_date = datetime.datetime.combine(end_date - datetime.timedelta(weeks=1), datetime.time.min)
        assignments = OrderAssignment.objects.filter(station=station, create_date__gte=start_date, create_date__lte=end_date)
        pie_data, total_count = get_station_assignments_pie_data(assignments)
        pie_data = simplejson.dumps(pie_data)

        # stringify the dates to the format used in the page
        start_date, end_date = start_date.strftime("%d/%m/%Y"), end_date.strftime("%d/%m/%Y")
        return custom_render_to_response("station_analytics.html", locals(), context_instance=RequestContext(request))
コード例 #3
0
ファイル: util.py プロジェクト: WAYbetter/waybetter
        if res.status_code != 200:
            logging.error(u"safe_fetch returned %s: content=%s" % (res.status_code, res.content))
            if notify:
                notify_by_email(u"safe_fetch failed", u"safe_fetch returned %s for\nurl: %s\npayload: %s\n content:%s" %(res.status_code, url, payload, res.content))
            res = None

    return res

def base_datepicker_page(request, f_data, template_name, wrapper_locals, init_start_date=None, init_end_date=None, async=False):
    from common.forms import DatePickerForm
    from common.signals import async_computation_submitted_signal
    from common.tz_support import default_tz_now_max, default_tz_now_min, to_js_date

    if request.method == 'POST': # date picker form submitted
        form = DatePickerForm(request.POST)
        if form.is_valid():
            start_date = datetime.datetime.combine(form.cleaned_data["start_date"], datetime.time.min)
            end_date = datetime.datetime.combine(form.cleaned_data["end_date"], datetime.time.max)
            if async:
                assert wrapper_locals.get('channel_id')
                assert wrapper_locals.get('token')
                async_computation_submitted_signal.send(sender="base_datepicker_page", channel_id=wrapper_locals.get('channel_id'))
                deferred.defer(f_data, start_date, end_date, channel_id=wrapper_locals.get('channel_id'), token=wrapper_locals.get('token'))
                return JSONResponse({'status': 'submitted', 'token': wrapper_locals.get('token')})
            else:
                return JSONResponse({'data': f_data(start_date, end_date)})
        else:
            return JSONResponse({'error': 'error'})
    else:
        form = DatePickerForm()
コード例 #4
0
    return res


def base_datepicker_page(request,
                         f_data,
                         template_name,
                         wrapper_locals,
                         init_start_date=None,
                         init_end_date=None,
                         async=False):
    from common.forms import DatePickerForm
    from common.signals import async_computation_submitted_signal
    from common.tz_support import default_tz_now_max, default_tz_now_min, to_js_date

    if request.method == 'POST':  # date picker form submitted
        form = DatePickerForm(request.POST)
        if form.is_valid():
            start_date = datetime.datetime.combine(
                form.cleaned_data["start_date"], datetime.time.min)
            end_date = datetime.datetime.combine(form.cleaned_data["end_date"],
                                                 datetime.time.max)
            if async:
                assert wrapper_locals.get('channel_id')
                assert wrapper_locals.get('token')
                async_computation_submitted_signal.send(
                    sender="base_datepicker_page",
                    channel_id=wrapper_locals.get('channel_id'))
                deferred.defer(f_data,
                               start_date,
                               end_date,
                               channel_id=wrapper_locals.get('channel_id'),