Пример #1
0
    def get(self, request, *args, **kwargs):
        self.get_params()
        calc = StaffCapacityCalculator(
            UserProfile.objects.filter(status='active', grp=False),
            self.interval_start, self.interval_end)
        data = calc.calc()

        start_str = self.interval_start.strftime('%Y%m%d')
        end_str = self.interval_end.strftime('%Y%m%d')
        filename = "staff-capacity-%s-%s" % (start_str, end_str)

        column_names = [
            'Staff Member', 'Group', 'Capacity', 'Booked', '% Booked',
            'Available', '% Available'
        ]

        rows = [[
            x['user'].fullname,
            self.user_group(x['user']), x['capacity'], x['booked'],
            x['percent_booked'], x['available'], x['percent_available']
        ] for x in data]

        generator = ReportFileGenerator()
        return generator.generate(column_names, rows, filename,
                                  self.request.GET.get('format'))
Пример #2
0
    def get(self, request, *args, **kwargs):
        self.get_params()
        calc = StaffCapacityCalculator(
            UserProfile.objects.filter(status='active', grp=False),
            self.interval_start, self.interval_end)
        data = calc.calc()

        start_str = self.interval_start.strftime('%Y%m%d')
        end_str = self.interval_end.strftime('%Y%m%d')
        filename = "staff-capacity-%s-%s" % (start_str, end_str)

        column_names = ['Staff Member', 'Group', 'Capacity', 'Booked',
                        '% Booked', 'Available', '% Available']

        rows = [
            [x['user'].fullname,
             self.user_group(x['user']),
             x['capacity'],
             x['booked'],
             x['percent_booked'],
             x['available'],
             x['percent_available']]
            for x in data]

        generator = ReportFileGenerator()
        return generator.generate(
            column_names, rows, filename, self.request.GET.get('format'))
Пример #3
0
    def get(self, request, *args, **kwargs):
        self.get_params()

        calc = ActiveProjectsCalculator()
        data = calc.calc(self.interval_start, self.interval_end)

        # Find dates for displaying to the user
        start_str = self.interval_start.strftime('%Y%m%d')
        end_str = self.interval_end.strftime('%Y%m%d')
        filename = "active-projects-%s-%s" % (start_str, end_str)

        column_names = [
            'ID', 'Name', 'Project Number', 'Last worked on', 'Project Status',
            'Caretaker', 'Hours logged'
        ]

        rows = [[
            x.pid, x.name, x.projnum, x.last_worked_on, x.status,
            x.caretaker_user,
            interval_to_hours(x.hours_logged)
        ] for x in data['projects']]

        generator = ReportFileGenerator()
        return generator.generate(column_names, rows, filename,
                                  self.request.GET.get('format'))
Пример #4
0
    def get(self, request, *args, **kwargs):
        calc = TimeSpentByProjectCalculator()
        data = calc.calc()

        now = timezone.now()
        filename = 'time-spent-by-project-{}'.format(now.strftime('%Y-%m-%d'))

        column_names = ['Project Name', 'Status', 'Estimated Time',
                        'Time Spent', 'Due Date', 'Caretaker']

        generator = ReportFileGenerator()
        return generator.generate(column_names, data, filename, 'csv')
Пример #5
0
class ReportFileGeneratorTests(TestCase):
    def setUp(self):
        self.generator = ReportFileGenerator()
        self.test_column_names = ['ID', 'username']
        self.test_rows = [[2, 'abc'], [4, 'test_user']]

    def test_generate_empty_csv(self):
        self.generator.generate([], [], 'test', 'csv')

    def test_generate_csv(self):
        self.generator.generate(
            self.test_column_names,
            self.test_rows,
            'test',
            'csv')

    def test_generate_empty_excel(self):
        self.generator.generate([], [], 'test', 'xlsx')

    def test_generate_excel(self):
        self.generator.generate(
            self.test_column_names,
            self.test_rows,
            'test',
            'excel')
Пример #6
0
    def get(self, request, *args, **kwargs):
        calc = TimeSpentByProjectCalculator()
        data = calc.calc()

        now = timezone.now()
        filename = 'time-spent-by-project-{}'.format(now.strftime('%Y-%m-%d'))

        column_names = [
            'Project Name', 'Status', 'Estimated Time', 'Time Spent',
            'Due Date', 'Caretaker'
        ]

        generator = ReportFileGenerator()
        return generator.generate(column_names, data, filename, 'csv')
Пример #7
0
    def get(self, request, *args, **kwargs):
        calc = TimeSpentByUserCalculator()
        data = calc.calc()

        now = timezone.now()
        filename = 'time-spent-by-user-{}'.format(now.strftime('%Y-%m-%d'))

        column_names = [
            'Project Name', 'Milestone Name', 'Task Name', 'Task Status',
            'Assigned to', 'Project Status', 'Estimated Time', 'Time Spent',
            'Task Due Date', 'Task Modified Date', 'Project Due Date',
            'Caretaker', 'Task Description', 'Comment History'
        ]

        generator = ReportFileGenerator()
        return generator.generate(column_names, data, filename, 'csv')
Пример #8
0
    def get(self, request, *args, **kwargs):
        calc = TimeSpentByUserCalculator()
        data = calc.calc()

        now = timezone.now()
        filename = 'time-spent-by-user-{}'.format(now.strftime('%Y-%m-%d'))

        column_names = [
            'Project Name', 'Milestone Name', 'Task Name', 'Task Status',
            'Assigned to', 'Project Status', 'Estimated Time',
            'Time Spent', 'Task Due Date', 'Task Modified Date',
            'Project Due Date',
            'Caretaker', 'Task Description', 'Comment History'
        ]

        generator = ReportFileGenerator()
        return generator.generate(column_names, data, filename, 'csv')
Пример #9
0
    def get(self, request, *args, **kwargs):
        self.get_params()
        calc = StaffReportCalculator(
            UserProfile.objects.filter(status='active', grp=False))
        data = calc.calc(self.interval_start, self.interval_end)

        start_str = self.interval_start.strftime('%Y%m%d')
        end_str = self.interval_end.strftime('%Y%m%d')
        filename = "staff-report-%s-%s" % (start_str, end_str)

        column_names = ['Staff Member', 'Hours Logged']

        rows = [[x['user'].fullname,
                 interval_to_hours(x['user_time'])] for x in data]

        generator = ReportFileGenerator()
        return generator.generate(column_names, rows, filename,
                                  self.request.GET.get('format'))
Пример #10
0
    def get(self, request, *args, **kwargs):
        self.get_params()
        calc = StaffReportCalculator(
            UserProfile.objects.filter(status='active', grp=False))
        data = calc.calc(self.interval_start, self.interval_end)

        start_str = self.interval_start.strftime('%Y%m%d')
        end_str = self.interval_end.strftime('%Y%m%d')
        filename = "staff-report-%s-%s" % (start_str, end_str)

        column_names = ['Staff Member', 'Hours Logged']

        rows = [
            [x['user'].fullname, interval_to_hours(x['user_time'])]
            for x in data]

        generator = ReportFileGenerator()
        return generator.generate(
            column_names, rows, filename, self.request.GET.get('format'))
Пример #11
0
    def get(self, request, *args, **kwargs):
        self.get_params()

        calc = ActiveProjectsCalculator()
        data = calc.calc(self.interval_start, self.interval_end)

        # Find dates for displaying to the user
        start_str = self.interval_start.strftime('%Y%m%d')
        end_str = self.interval_end.strftime('%Y%m%d')
        filename = "active-projects-%s-%s" % (start_str, end_str)

        column_names = ['ID', 'Name', 'Project Number', 'Last worked on',
                        'Project Status', 'Caretaker', 'Hours logged']

        rows = [[x.pid, x.name, x.projnum, x.last_worked_on, x.status,
                 x.caretaker_user, interval_to_hours(x.hours_logged)]
                for x in data['projects']]

        generator = ReportFileGenerator()
        return generator.generate(
            column_names, rows, filename, self.request.GET.get('format'))
Пример #12
0
    def get(self, request, *args, **kwargs):
        calc = ProjectStatusCalculator()
        data = calc.calc()

        now = timezone.now()
        filename = 'project-status-{}'.format(now.strftime('%Y-%m-%d'))

        column_names = [
            'Category',
            'Project Name',
            'Project Status',
            'Caretaker',
            'Project Due Date',
            '% of Tasks Open',
            '% of Tasks In-Progress',
            '% of Tasks Complete',
            'Original Estimate',
            'Time Spent',
        ]

        generator = ReportFileGenerator()
        return generator.generate(column_names, data, filename, 'csv')
Пример #13
0
    def get(self, request, *args, **kwargs):
        calc = ProjectStatusCalculator()
        data = calc.calc()

        now = timezone.now()
        filename = 'project-status-{}'.format(now.strftime('%Y-%m-%d'))

        column_names = [
            'Category',
            'Project Name',
            'Project Status',
            'Caretaker',
            'Project Due Date',
            '% of Tasks Open',
            '% of Tasks In-Progress',
            '% of Tasks Complete',
            'Original Estimate',
            'Time Spent',
        ]

        generator = ReportFileGenerator()
        return generator.generate(column_names, data, filename, 'csv')
Пример #14
0
    def get(self, request, pk):
        p = get_object_or_404(Project, pk=pk)

        if request.GET.get('interval_start') and \
           request.GET.get('interval_end'):
            interval_start = pytz.timezone(settings.TIME_ZONE).localize(
                datetime.combine(
                    parse_date(request.GET.get('interval_start')),
                    datetime.min.time()))
            interval_end = pytz.timezone(settings.TIME_ZONE).localize(
                datetime.combine(
                    parse_date(request.GET.get('interval_end')),
                    datetime.max.time()))
            actual_times = p.actual_times_between(interval_start, interval_end)
        else:
            actual_times = p.all_actual_times()

        filename = "project-hours-%d" % p.pid

        column_names = [
            'iid', 'item title', 'type', 'owner', 'assigned_to',
            'priority', 'target_date', 'estimated_time',
            'mid', 'milestone', 'user', 'hours', 'completed at']

        rows = [[a.item.iid, a.item.title, a.item.type,
                 a.item.owner_user.userprofile.username,
                 a.item.assigned_user.userprofile.username,
                 a.item.priority, a.item.target_date,
                 interval_to_hours(a.item.estimated_time),
                 a.item.milestone.mid, a.item.milestone.name,
                 a.user.userprofile.username, interval_to_hours(a.actual_time),
                 a.completed]
                for a in actual_times]

        generator = ReportFileGenerator()
        return generator.generate(
            column_names, rows, filename,
            self.request.GET.get('format', 'csv'))
Пример #15
0
    def get(self, request, pk):
        p = get_object_or_404(Project, pk=pk)

        if request.GET.get('interval_start') and \
           request.GET.get('interval_end'):
            interval_start = pytz.timezone(settings.TIME_ZONE).localize(
                datetime.combine(parse_date(request.GET.get('interval_start')),
                                 datetime.min.time()))
            interval_end = pytz.timezone(settings.TIME_ZONE).localize(
                datetime.combine(parse_date(request.GET.get('interval_end')),
                                 datetime.max.time()))
            actual_times = p.actual_times_between(interval_start, interval_end)
        else:
            actual_times = p.all_actual_times()

        filename = "project-hours-%d" % p.pid

        column_names = [
            'iid', 'item title', 'type', 'owner', 'assigned_to', 'priority',
            'target_date', 'estimated_time', 'mid', 'milestone', 'user',
            'hours', 'completed at'
        ]

        rows = [[
            a.item.iid, a.item.title, a.item.type,
            a.item.owner_user.userprofile.username,
            a.item.assigned_user.userprofile.username, a.item.priority,
            a.item.target_date,
            interval_to_hours(a.item.estimated_time), a.item.milestone.mid,
            a.item.milestone.name, a.user.userprofile.username,
            interval_to_hours(a.actual_time), a.completed
        ] for a in actual_times]

        generator = ReportFileGenerator()
        return generator.generate(column_names, rows, filename,
                                  self.request.GET.get('format', 'csv'))
Пример #16
0
 def setUp(self):
     self.generator = ReportFileGenerator()
     self.test_column_names = ['ID', 'username']
     self.test_rows = [[2, 'abc'], [4, 'test_user']]