Exemplo n.º 1
0
    def dispatch(self):
        sprint = self.v['sprint']
        bugs = self._fetch_bugs(sprint)
        sw = SprintWrapper(sprint, bugs, self.request)

        client = self.request.user.get_client()
        form = ProjectTimeForm(self.request.GET, client=client)

        if not self.request.GET.get('submited'):
            # ugly hack
            form.group_by_bugs.data = True
            form.group_by_user.data = True

        if not form.validate():
            return dict(form=form, sprint=sprint)

        group_by = True, True, form.group_by_bugs.data, form.group_by_user.data
        bigger_than = form.bigger_than.data
        ticket_choice = form.ticket_choice.data

        uber_query = self._prepare_uber_query_for_sprint(
            sprint, bugs, ticket_choice
        )
        entries = uber_query.all()

        if self.request.GET.get('excel'):
            from intranet3.lib.times import dump_entries_to_excel
            file, response = dump_entries_to_excel(
                entries, group_by, bigger_than
            )
            return response

        participation_of_workers = self._get_participation_of_workers(entries)

        tickets_id = ','.join([str(e[2]) for e in entries])
        trackers_id = ','.join([str(e[4].id) for e in entries])

        rows, entries_sum = HTMLRow.from_ordered_data(
            entries, group_by, bigger_than
        )

        return dict(
            rows=rows,
            entries_sum=entries_sum,
            form=form,
            info=sw.get_info(),
            participation_of_workers=participation_of_workers,
            participation_of_workers_sum=sum(
                [time[1] for time in participation_of_workers]
            ),
            trackers_id=trackers_id, tickets_id=tickets_id,
            sprint_tabs=sw.get_tabs()
        )
Exemplo n.º 2
0
    def get(self):
        client = self.request.user.get_client()
        form = ProjectsTimeForm(formdata=self.request.GET, client=client)
        if not form.validate():
            return render('time/tickets_report/projects_report.html', dict(form=form))

        query = DBSession.query
        start_date, end_date = form.date_range.data
        projects = form.projects.data
        users = form.users.data
        ticket_choice = form.ticket_choice.data
        group_by = (
            form.group_by_client.data,
            form.group_by_project.data,
            form.group_by_bugs.data,
            form.group_by_user.data
        )
        bigger_than = form.bigger_than.data

        LOG(u'Tickets report %r - %r - %r' % (start_date, end_date, projects))

        uber_query = query(Client, Project, TimeEntry.ticket_id, User, Tracker, TimeEntry.description, TimeEntry.date, TimeEntry.time)
        uber_query = uber_query.filter(TimeEntry.user_id==User.id)\
                               .filter(TimeEntry.project_id==Project.id)\
                               .filter(Project.tracker_id==Tracker.id)\
                               .filter(Project.client_id==Client.id)

        if projects:
            uber_query = uber_query.filter(TimeEntry.project_id.in_(projects))

        uber_query = uber_query.filter(TimeEntry.date>=start_date)\
                               .filter(TimeEntry.date<=end_date)\
                               .filter(TimeEntry.deleted==False)

        if ticket_choice == 'without_bug_only':
            uber_query = uber_query.filter(TimeEntry.ticket_id=='')
        elif ticket_choice == 'meetings_only':
            meeting_ids = [t['value'] for t in TimeEntryForm.PREDEFINED_TICKET_IDS]
            uber_query = uber_query.filter(TimeEntry.ticket_id.in_(meeting_ids))

        if users:
            uber_query = uber_query.filter(User.id.in_(users))

        uber_query = uber_query.order_by(Client.name, Project.name, TimeEntry.ticket_id, User.name)
        entries = uber_query.all()
        file, response = dump_entries_to_excel(entries, group_by, bigger_than)

        return response
Exemplo n.º 3
0
    def get(self):
        client = self.request.user.get_client()
        form = ProjectsTimeForm(formdata=self.request.GET, client=client)
        if not form.validate():
            return render("time/tickets_report/projects_report.html", dict(form=form))

        query = self.session.query
        start_date, end_date = form.date_range.data
        projects = form.projects.data
        users = form.users.data
        without_bug_only = form.without_bug_only.data

        LOG(u"Tickets report %r - %r - %r" % (start_date, end_date, projects))

        uber_query = query(
            Client, Project, TimeEntry.ticket_id, User, Tracker, TimeEntry.description, TimeEntry.date, TimeEntry.time
        )
        uber_query = (
            uber_query.filter(TimeEntry.user_id == User.id)
            .filter(TimeEntry.project_id == Project.id)
            .filter(Project.tracker_id == Tracker.id)
            .filter(Project.client_id == Client.id)
        )

        uber_query = (
            uber_query.filter(TimeEntry.project_id.in_(projects))
            .filter(TimeEntry.date >= start_date)
            .filter(TimeEntry.date <= end_date)
            .filter(TimeEntry.deleted == False)
        )
        if without_bug_only:
            uber_query = uber_query.filter(TimeEntry.ticket_id == None)

        if users:
            uber_query = uber_query.filter(User.id.in_(users))

        uber_query = uber_query.order_by(Client.name, Project.name, TimeEntry.ticket_id, User.name)
        entries = uber_query.all()
        file, response = dump_entries_to_excel(entries)

        return response