Example #1
0
    def createTimeEntryForProject(self,
                                  project_id,
                                  hours='',
                                  date=None,
                                  person_id=None,
                                  description=''):
        """Create entry (for a given project)
        
        REST: POST /projects/#{project_id}/time_entries.xml
        
        Creates a new time entry for the given todo item.
        
        XML Request:
            <time-entry>
                <person-id>#{person-id}</person-id>
                <date>#{date}</date>
                <hours>#{hours}</hours>
                <description>#{description}</description>
            </time-entry>

        Response:
            Returns HTTP status code 201 (Created) on success, with the
            Location header set to the URL of the new time entry. The
            integer ID of the entry may be extracted from that URL.
        """
        # ensure that we got numerical project id
        assert isinstance(project_id, int)

        path = '/projects/%d/time_entries.xml' % project_id
        # normalize all data for entry
        if date is None:
            # add current date
            date = time.strftime('%Y-%m-%d')
        # don't know how to get id of authenticated user
        if person_id is None:
            # add authenticated user
            person = self.getAuthenticatedPerson()
            if person is not None:
                person_id = person.id

        entry = TimeEntry(person_id=person_id,
                          project_id=project_id,
                          date=date,
                          hours=hours,
                          description=description)
        response = self.post(path, data=entry.serialize())

        # successfuly created entry
        if response.status == 201:
            entry.id = int(dict(response.headers)['location'].split('/')[-1])
            return entry
        return self.getErrors(response.contents)
Example #2
0
    def createTimeEntryForProject(self, project_id, hours='', date=None,
                                  person_id=None, description=''):
        """Create entry (for a given project)
        
        REST: POST /projects/#{project_id}/time_entries.xml
        
        Creates a new time entry for the given todo item.
        
        XML Request:
            <time-entry>
                <person-id>#{person-id}</person-id>
                <date>#{date}</date>
                <hours>#{hours}</hours>
                <description>#{description}</description>
            </time-entry>

        Response:
            Returns HTTP status code 201 (Created) on success, with the
            Location header set to the URL of the new time entry. The
            integer ID of the entry may be extracted from that URL.
        """
        # ensure that we got numerical project id
        assert isinstance(project_id, int)
        
        path = '/projects/%d/time_entries.xml' % project_id
        # normalize all data for entry
        if date is None:
            # add current date
            date = time.strftime('%Y-%m-%d')
        # don't know how to get id of authenticated user
        if person_id is None:
            # add authenticated user
            person = self.getAuthenticatedPerson()
            if person is not None:
                person_id = person.id
        
        entry = TimeEntry(person_id=person_id,
                          project_id=project_id,
                          date=date,
                          hours=hours,
                          description=description)
        response = self.post(path, data=entry.serialize())
        
        # successfuly created entry
        if response.status == 201:
            entry.id = int(dict(response.headers)['location'].split('/')[-1])
            return entry
        return self.getErrors(response.contents)
Example #3
0
    def getEntriesForTodoItem(self, todo_item_id):
        """Get all entries (for a todo item)
        
        REST: GET /todo_items/#{todo_item_id}/time_entries.xml
        
        Returns all time entries associated with the given todo item, in
        descending order by date. 
        
        Response:

            <time-entries type="array">
                <time-entry>
                    ...
                </time-entry>
                    ...
            </time-entries>
        """
        # ensure that we got numerical id
        assert isinstance(todo_item_id, int)
       
        path = '/todo_items/%d/time_entries.xml' % todo_item_id
        response = self.get(path)
        if response.status == 404:
            raise NotFoundError, 'Todo item with %d id is not found!' % \
                 todo_item_id
        
        rootElement = self.fromXML(response.contents)
        # TODO: use special Array attribute
        time_entries = []
        for data in rootElement.getElementsByTagName('time-entry'):
            time_entries.append(TimeEntry.load(data))
        return time_entries
Example #4
0
    def getEntriesForTodoItem(self, todo_item_id):
        """Get all entries (for a todo item)
        
        REST: GET /todo_items/#{todo_item_id}/time_entries.xml
        
        Returns all time entries associated with the given todo item, in
        descending order by date. 
        
        Response:

            <time-entries type="array">
                <time-entry>
                    ...
                </time-entry>
                    ...
            </time-entries>
        """
        # ensure that we got numerical id
        assert isinstance(todo_item_id, int)

        path = '/todo_items/%d/time_entries.xml' % todo_item_id
        response = self.get(path)
        if response.status == 404:
            raise NotFoundError, 'Todo item with %d id is not found!' % \
                 todo_item_id

        rootElement = self.fromXML(response.contents)
        # TODO: use special Array attribute
        time_entries = []
        for data in rootElement.getElementsByTagName('time-entry'):
            time_entries.append(TimeEntry.load(data))
        return time_entries
Example #5
0
    def getEntriesReport(self,
                         _from,
                         _to,
                         subject_id=None,
                         todo_item_id=None,
                         filter_project_id=None,
                         filter_company_id=None):
        """Get time report

        REST: GET /time_entries/report.xml

        Returns the set of time entries that match the given criteria.

        This action accepts the following query parameters: from, to,
        subject_id, todo_item_id, filter_project_id, and filter_company_id. Both
        from and to should be dates in YYYYMMDD format, and can be used to
        restrict the result to a particular date range. (No more than 6 months'
        worth of entries may be returned in a single query, though). The
        subject_id parameter lets you constrain the result to a single person's
        time entries. todo_item_id restricts the result to only those entries
        relating to the given todo item. filter_project_id restricts the entries
        to those for the given project, and filter_company_id restricts the
        entries to those for the given company.

        Response:

            <time-entries type="array">
              <time-entry>
                ...
              </time-entry>
              ...
            </time-entries>
        """
        # ensure that we got numerical ids
        query = ['from=%s' % _from, 'to=%s' % _to]
        if subject_id:
            assert isinstance(subject_id, int)
            query.append('subject_id=%d' % subject_id)
        if todo_item_id:
            assert isinstance(todo_item_id, int)
            query.append('todo_item_id=%d' % todo_item_id)
        if filter_project_id:
            assert isinstance(filter_project_id, int)
            query.append('filter_project_id=%d' % filter_project_id)
        if filter_company_id:
            assert isinstance(filter_company_id, int)
            query.append('filter_company_id=%d' % filter_company_id)

        path = '/time_entries/report.xml?%s' % '&'.join(query)
        response = self.get(path)
        if response.status != 200:
            return self.getErrors(response.contents)

        rootElement = self.fromXML(response.contents)
        # TODO: use special Array attribute
        time_entries = []
        for data in rootElement.getElementsByTagName('time-entry'):
            time_entries.append(TimeEntry.load(data))
        return time_entries
Example #6
0
    def getEntriesReport(self, _from, _to, subject_id=None, todo_item_id=None,
                         filter_project_id=None, filter_company_id=None):
        """Get time report

        REST: GET /time_entries/report.xml

        Returns the set of time entries that match the given criteria.

        This action accepts the following query parameters: from, to,
        subject_id, todo_item_id, filter_project_id, and filter_company_id. Both
        from and to should be dates in YYYYMMDD format, and can be used to
        restrict the result to a particular date range. (No more than 6 months'
        worth of entries may be returned in a single query, though). The
        subject_id parameter lets you constrain the result to a single person's
        time entries. todo_item_id restricts the result to only those entries
        relating to the given todo item. filter_project_id restricts the entries
        to those for the given project, and filter_company_id restricts the
        entries to those for the given company.

        Response:

            <time-entries type="array">
              <time-entry>
                ...
              </time-entry>
              ...
            </time-entries>
        """
        # ensure that we got numerical ids
        query = ['from=%s' % _from, 'to=%s' % _to]
        if subject_id:
            assert isinstance(subject_id, int)
            query.append('subject_id=%d' % subject_id)
        if todo_item_id:
            assert isinstance(todo_item_id, int)
            query.append('todo_item_id=%d' % todo_item_id)
        if filter_project_id:
            assert isinstance(filter_project_id, int)
            query.append('filter_project_id=%d' % filter_project_id)
        if filter_company_id:
            assert isinstance(filter_company_id, int)
            query.append('filter_company_id=%d' % filter_company_id)

        path = '/time_entries/report.xml?%s' % '&'.join(query)
        response = self.get(path)
        if response.status != 200:
            return self.getErrors(response.contents)

        rootElement = self.fromXML(response.contents)
        # TODO: use special Array attribute
        time_entries = []
        for data in rootElement.getElementsByTagName('time-entry'):
            time_entries.append(TimeEntry.load(data))
        return time_entries