コード例 #1
0
 def test_fifteen(self):
     dt = datetime.timedelta(seconds=15*60)
     tc = list(time_chunks(dt, 2))
     self.assertSequenceEqual(tc,
                              [
                                  datetime.timedelta(seconds=7*60),
                                  datetime.timedelta(seconds=8*60)
                             ])
コード例 #2
0
ファイル: smartadd.py プロジェクト: getpenelope/por.dashboard
    def smartadd_submit(self):
        """
        Receives a line of smart-add and performs validation/insertion.
        """
        projects = dict(
                ('%s - %s' % (p.name, p.customer.name), p.id)
                for p in self.request.filter_viewables(DBSession.query(Project).filter(Project.active))
                )

        def ticket_provider(project_id):
            if project_id:
                project = DBSession.query(Project).get(project_id)
                return [
                        t['id']
                        for t in ticket_store.get_tickets_for_project(project=project,
                                                                      not_invoiced=True,
                                                                      request=self.request)
                        ]

        parser = SmartAddParser(unicode(self.request.body, 'utf8', 'ignore'),
                                projects=projects,
                                available_tickets=ticket_provider,
                                request=self.request)

        errors = parser.validation_errors()
        if errors:
            # XXX register appropriate exception handler
            return Response(' - '.join(errors), status_int=400)

        pte = parser.parsed_time_entry
        parsed_tickets = pte['tickets']
        ticket_summaries = []

        entry_durations = list(time_chunks(pte['hours'], len(parsed_tickets)))

        for parsed_ticket, duration in zip(parsed_tickets, entry_durations):
            date = pte.get('date') or datetime.date.today()

            te = TimeEntry(date = date,
                           start = pte['start'],
                           end = pte['start'],
                           description = pte['description'],
                           ticket = parsed_ticket,
                           project_id = pte['project_id'],
                           hours = duration,
                           )
            te.request = self.request #bind for user calculation
            DBSession.add(te)
            # retrieve ticket descriptions (another trip to the store..)
            ticket_summaries.append(
                    '#%s (%s)' % (te.ticket, ticket_store.get_ticket(self.request, te.project_id, te.ticket)[3]['summary'])
                )

        return Response(u'Added to ticket(s) %s' % ', '.join(ticket_summaries))
コード例 #3
0
 def test_pi(self):
     dt = datetime.timedelta(seconds=3.1415926*60*60)
     tc = list(time_chunks(dt, 7))
     self.assertSequenceEqual(tc,
                              [
                                  datetime.timedelta(seconds=26*60),
                                  datetime.timedelta(seconds=26*60),
                                  datetime.timedelta(seconds=26*60),
                                  datetime.timedelta(seconds=26*60),
                                  datetime.timedelta(seconds=26*60),
                                  datetime.timedelta(seconds=26*60),
                                  datetime.timedelta(0, 1949, 733360),
                             ])
コード例 #4
0
 def test_onepiece(self):
     dt = datetime.timedelta(seconds=7000)
     tc = list(time_chunks(dt, 1))
     self.assertSequenceEqual(tc, [datetime.timedelta(seconds=7000)])