diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..df2219c --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*pyc \ No newline at end of file diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/lighthouse.py b/lighthouse.py index e2bb70f..dcb0e29 100644 --- a/lighthouse.py +++ b/lighthouse.py @@ -265,13 +265,14 @@ def get_all_tickets(self, project): c = 30 page = 1 ticket_count = 0 - while c == 30: + while c >= 30: c = self.get_tickets(project, page) ticket_count += c page += 1 def get_tickets(self, project, page=1): - """Retrieves all the tickets in a project + """Retrieves all the tickets in a page of a project. + If no page is specified, the first is used. >>> lh = Lighthouse() >>> lh.url = 'http://ars.lighthouseapp.com' @@ -316,22 +317,31 @@ def get_tickets(self, project, page=1): if(ticket_list.get('children', None)): for ticket in ticket_list['children']: c += 1 - t_obj = Ticket() - for field in ticket['children']: - field_name, field_value, field_type = \ - self._parse_field(field) - py_field_name = field_name.replace('-', '_') - t_obj.__setattr__(py_field_name, field_value) - t_obj.fields.add(py_field_name) - project.tickets[t_obj.number] = t_obj + if( ticket.get('children', None) ): # Got the KeyError 'children', so check whether it exists + t_obj = Ticket() + for field in ticket['children']: + field_name, field_value, field_type = \ + self._parse_field(field) + py_field_name = field_name.replace('-', '_') + t_obj.__setattr__(py_field_name, field_value) + t_obj.fields.add(py_field_name) + project.tickets[t_obj.number] = t_obj return c + def get_new_tickets(self, project): + """Retrieves all the tickets in the first page of a project, + then returns a list with the new ones. + """ + old_tickets = project.tickets; + self.get_tickets(project) + return list(set(project.tickets).difference(set(old_tickets))) + def get_full_ticket(self, project, ticket): path = Ticket.endpoint_single % (project.id, ticket.number) ticket_data = self._get_data(path) + for field in ticket_data['children']: - field_name, field_value, field_type = \ - self._parse_field(field) + field_name, field_value, field_type = self._parse_field(field) py_field_name = field_name.replace('-', '_') ticket.__setattr__(py_field_name, field_value) ticket.fields.add(py_field_name) @@ -384,7 +394,7 @@ def __init__(self): def __repr__(self): if self.title: - return "Ticket: %s" % (self.title,) + return "Ticket: %s" % (self.title.encode('ascii', 'replace'),) else: return "Ticket: Unnamed" @@ -428,4 +438,4 @@ def __init__(self, arg): if __name__ == "__main__": import doctest - doctest.testmod(optionflags=doctest.IGNORE_EXCEPTION_DETAIL) \ No newline at end of file + doctest.testmod(optionflags=doctest.IGNORE_EXCEPTION_DETAIL)