Example #1
0
def ajax_status_value(request):
    if request.method != "POST":
        return redirect('/reporting/report')
    post_data = request.POST
    user = request.user
    status = models.Status.objects.get(id=post_data['status_id'])
    req = models.Requisition.objects.get(id=post_data['req_id'])

    value = int(post_data['value'])

    report_range_type = getattr(ReportRangeType, post_data['report_type'])
    req_status_matrix = logic.get_matrix(ReportDataType.REC_STATUS, report_range_type, user__id__exact=user.id)
    initial_value = req_status_matrix[req][status]

    response = dict(value=initial_value)
    if value <= initial_value or report_range_type['resolution'] != Resolution.WEEKLY:
        return HttpResponse(initial_value)

    new_value = value - initial_value
    edit_date = datetime.strptime(post_data['edit_date'], "%Y-%m-%d").date()
    status_value = models.StatusValue(user=user, req=req, status=status, value=new_value, date=edit_date)
    status_value.save()

    response['value'] = new_value
    return HttpResponse(value)
Example #2
0
def report(request):
    user = request.user

    users = User.objects.all()
    reqs = user.get_profile().requisitions.all()
    statuses = models.Status.objects.all().order_by()

    default_report_type = 'THIS_WEEK'
    report_range_type = getattr(ReportRangeType, default_report_type)

    # I tried to avoid handling POSTs here, but it was late and I was tired
    if request.method == 'POST':
        report_type_form = ReportTypeForm(request.POST)
        if report_type_form.is_valid():
            report_range_type = report_type_form.cleaned_data['report_type']
    else:
        report_type_form = ReportTypeForm(dict(report_type=default_report_type))

    edit_date = timeutil.default_today()
    if report_range_type['resolution'] == Resolution.WEEKLY:
        start_date, end_date = logic.range_from_report_range_type(report_range_type)
        edit_date = logic.pick_day_from_week(start_date, end_date)

    user_status_matrix = logic.get_matrix(ReportDataType.USER_STATUS, report_range_type)
    req_status_matrix = logic.get_matrix(ReportDataType.REC_STATUS, report_range_type, user__id__exact=user.id)

    return render_to_response(
        'reporting/report.html',
        dict(
			user=user,
			users=users,
			reqs=reqs,
            statuses=statuses,

            user_status_matrix=user_status_matrix,
            req_status_matrix=req_status_matrix,

            edit_date=edit_date,
            report_type_form=report_type_form,
        ),
        context_instance=RequestContext(request)
    )