コード例 #1
0
ファイル: views.py プロジェクト: foonnnnn/django-timetracker
def download_all_holiday_data(request, who=None):
    '''Endpoint which creates a CSV file for all holiday data for a
    single employee.

    :param who: The ID of the person the report should be generated for
    if the user is not in the span of control for the administrator then
    no report will be generated.'''
    if not who:
        raise Http404

    auth_user = Tbluser.objects.get(id=request.session.get("user_id"))
    try:
        target_user = auth_user.get_subordinates().get(id=who)
    except Tbluser.DoesNotExist:
        raise Http404

    buf = StringIO()
    buf.write("\xef\xbb\xbf")
    csvfile = UnicodeWriter(buf)
    csvfile.writerow(TrackingEntry.headings())

    for entry in TrackingEntry.objects.filter(user_id=who):
        csvfile.writerow(entry.display_as_csv())

    response = HttpResponse(buf.getvalue(), mimetype="text/csv")
    response['Content-Disposition'] = \
        'attachment;filename=AllHolidayData_%s.csv' % target_user.id
    return response
コード例 #2
0
def download_all_holiday_data(request, who=None): # pragma: no cover
    '''Endpoint which creates a CSV file for all holiday data for a
    single employee.

    :param who: The ID of the person the report should be generated for
    if the user is not in the span of control for the administrator then
    no report will be generated.'''
    if not who:
        raise Http404

    auth_user = Tbluser.objects.get(id=request.session.get("user_id"))
    try:
        target_user = auth_user.get_subordinates().get(id=who)
    except Tbluser.DoesNotExist:
        raise Http404

    buf = StringIO()
    buf.write("\xef\xbb\xbf")
    csvfile = UnicodeWriter(buf)
    csvfile.writerow(TrackingEntry.headings())

    for entry in TrackingEntry.objects.filter(user_id=who):
        csvfile.writerow(entry.display_as_csv())

    response = HttpResponse(buf.getvalue(), mimetype="text/csv")
    response['Content-Disposition'] = \
        'attachment;filename=AllHolidayData_%s.csv' % target_user.id
    return response
コード例 #3
0
def all_team(request, year=None, month=None, team=None): # pragma: no cover
    if not year or not month or not team:
        raise Http404

    buf = StringIO()
    buf.write("\xef\xbb\xbf")
    csvfile = UnicodeWriter(buf)
    csvfile.writerow(TrackingEntry.headings())
    for user in Tbluser.objects.filter(market=team):
        for entry in TrackingEntry.objects.filter(
            entry_date__year=year,
            entry_date__month=month,
            user_id=user.id):
            csvfile.writerow(entry.display_as_csv())
    response = HttpResponse(buf.getvalue(), mimetype="text/csv")
    response['Content-Disposition'] = \
        'attachment;filename=AllHolidayData_%s_%s_%s.csv' % (year, month, team)
    return response
コード例 #4
0
ファイル: views.py プロジェクト: foonnnnn/django-timetracker
def yearmonthhol(request, year=None, month=None):
    '''Endpoint which creates a CSV file for all holiday data within
    a specific month.

    :param year: The year for the report.
    :param month: The month for the report.

    :note: Both year and mont are required.'''
    auth_user = Tbluser.objects.get(id=request.session.get("user_id"))
    buf = StringIO()
    buf.write("\xef\xbb\xbf")
    csvfile = UnicodeWriter(buf)
    csvfile.writerow(TrackingEntry.headings())
    for user in auth_user.get_subordinates():
        for entry in TrackingEntry.objects.filter(
            entry_date__year=year,
            entry_date__month=month,
            user_id=user.id):
            csvfile.writerow(entry.display_as_csv())
    response = HttpResponse(buf.getvalue(), mimetype="text/csv")
    response['Content-Disposition'] = \
        'attachment;filename=HolidayData_%s_%s.csv' % (year, month)
    return response
コード例 #5
0
def yearmonthhol(request, year=None, month=None): # pragma: no cover
    '''Endpoint which creates a CSV file for all holiday data within
    a specific month.

    :param year: The year for the report.
    :param month: The month for the report.

    :note: Both year and mont are required.'''
    auth_user = Tbluser.objects.get(id=request.session.get("user_id"))
    buf = StringIO()
    buf.write("\xef\xbb\xbf")
    csvfile = UnicodeWriter(buf)
    csvfile.writerow(TrackingEntry.headings())
    for user in auth_user.get_subordinates():
        for entry in TrackingEntry.objects.filter(
            entry_date__year=year,
            entry_date__month=month,
            user_id=user.id):
            csvfile.writerow(entry.display_as_csv())
    response = HttpResponse(buf.getvalue(), mimetype="text/csv")
    response['Content-Disposition'] = \
        'attachment;filename=HolidayData_%s_%s.csv' % (year, month)
    return response