@@ -40,9 +40,8 @@ def spaces(self, extra_params=None):
4040
4141 def _get_json (self , model , space = None , rel_path = None , extra_params = None , get_all = None ):
4242 """
43- Base level method which does all the work of hitting the API
43+ Base level method for fetching data from the API
4444 """
45-
4645 # Only API.spaces and API.event should not provide
4746 # the `space argument
4847 if space is None and model not in (Space , Event ):
@@ -114,7 +113,7 @@ def _get_json(self, model, space=None, rel_path=None, extra_params=None, get_all
114113
115114 def _post_json (self , instance , space = None , rel_path = None , extra_params = None ):
116115 """
117- Base level method which does all the work of hitting the API
116+ Base level method for updating data via the API
118117 """
119118
120119 model = type (instance )
@@ -172,7 +171,7 @@ def _post_json(self, instance, space=None, rel_path=None, extra_params=None):
172171
173172 def _delete_json (self , instance , space = None , rel_path = None , extra_params = None ):
174173 """
175- Base level method which does all the work of hitting the API
174+ Base level method for removing data from the API
176175 """
177176
178177 model = type (instance )
@@ -225,7 +224,7 @@ def _delete_json(self, instance, space=None, rel_path=None, extra_params=None):
225224
226225 def _put_json (self , instance , space = None , rel_path = None , extra_params = None ):
227226 """
228- Base level method which does all the work of hitting the API
227+ Base level method for adding new data to the API
229228 """
230229
231230 model = type (instance )
@@ -298,8 +297,9 @@ def tickets(self, extra_params=None):
298297 # Default params
299298 params = {
300299 'per_page' : 1000 ,
301- 'report' : 0 # All tickets
300+ 'report' : 0 , # Report 0 is all tickets
302301 }
302+
303303 if extra_params :
304304 params .update (extra_params )
305305
@@ -361,6 +361,7 @@ def _build_rel_path(self, to_append=None):
361361class Component (AssemblaObject ):
362362 pass
363363
364+
364365class Milestone (AssemblaObject ):
365366 @assembla_filter
366367 def tickets (self , extra_params = None ):
@@ -380,10 +381,7 @@ def milestone(self, extra_params=None):
380381 The Milestone that the Ticket is a part of
381382 """
382383 if self .get ('milestone_id' , None ):
383- milestones = filter (
384- lambda milestone : milestone ['id' ] == self ['milestone_id' ],
385- self .space .milestones (extra_params = extra_params )
386- )
384+ milestones = self .space .milestones (id = self ['milestone_id' ], extra_params = extra_params )
387385 if milestones :
388386 return milestones [0 ]
389387
@@ -393,9 +391,9 @@ def user(self, extra_params=None):
393391 The User currently assigned to the Ticket
394392 """
395393 if self .get ('assigned_to_id' , None ):
396- users = filter (
397- lambda user : user [ 'id' ] == self ['assigned_to_id' ],
398- self . space . users ( extra_params = extra_params )
394+ users = self . space . users (
395+ id = self ['assigned_to_id' ],
396+ extra_params = extra_params
399397 )
400398 if users :
401399 return users [0 ]
@@ -406,44 +404,48 @@ def component(self, extra_params=None):
406404 The Component currently assigned to the Ticket
407405 """
408406 if self .get ('component_id' , None ):
409- components = filter (
410- lambda component : component ['id' ] == self ['component_id' ],
411- self .space .components (extra_params = extra_params )
412- )
407+ components = self .space .components (id = self ['component_id' ], extra_params = extra_params )
413408 if components :
414409 return components [0 ]
415410
416411 def write (self ):
417- try :
418- self .api = self .space .api
419- except AttributeError :
412+ """
413+ Create or update the Ticket on Assembla
414+ """
415+ if not hasattr (self , 'space' ):
420416 raise AttributeError ("A ticket must have a 'space' attribute before you can write it to Assembla." )
421417
422- if self .get ('number' ): #we are modifying an existing ticket
418+ self .api = self .space .api
419+
420+ if self .get ('number' ): # We are modifying an existing ticket
423421 return self .api ._put_json (
424422 self ,
425423 space = self .space ,
426424 rel_path = self .space ._build_rel_path ('tickets' ),
427425 )
428- else : #creating a new ticketi
426+ else : # Creating a new ticket
429427 return self .api ._post_json (
430428 self ,
431429 space = self .space ,
432430 rel_path = self .space ._build_rel_path ('tickets' ),
433431 )
434432
435433 def delete (self ):
436- try :
437- self .api = self .space .api
438- except AttributeError :
434+ """
435+ Remove the Ticket from Assembla
436+ """
437+ if not hasattr (self , 'space' ):
439438 raise AttributeError ("A ticket must have a 'space' attribute before you can write it to Assembla." )
440439
440+ self .api = self .space .api
441+
441442 return self .api ._delete_json (
442443 self ,
443444 space = self .space ,
444445 rel_path = self .space ._build_rel_path ('tickets' ),
445446 )
446447
448+
447449class User (AssemblaObject ):
448450 @assembla_filter
449451 def tickets (self , extra_params = None ):
0 commit comments