Permalink
Browse files

Revert "Potential easier access of items"

This reverts commit 528079b.
  • Loading branch information...
1 parent 528079b commit 9a200780580592c3ea8e1028dc7bf84072c6b0da Ryan Showalter committed Oct 4, 2010
Showing with 13 additions and 16 deletions.
  1. +13 −16 pycheddar/__init__.py
View
@@ -324,12 +324,7 @@ def _load_data_from_xml(self, xml, clean = True):
# the XML underneath here constitutes the necessary
# XML to generate that object; call its XML function
- if child.tag == 'items':
- tmp_item = klass.from_xml(indiv_xml, parent=self)
- getattr(self, child.tag)[tmp_item.code] = tmp_item
- else:
- getattr(self, child.tag).append(klass.from_xml(indiv_xml, parent = self))
-
+ getattr(self, child.tag).append(klass.from_xml(indiv_xml, parent = self))
except AttributeError:
break
@@ -448,11 +443,12 @@ def get_item(self, item_code):
"""Retrieve an item by item code. If the item does not exist,
raise ValueError."""
- if item_code in self.items:
- return self.items[item_code]
- else:
- raise ValueError, 'Item not found.'
-
+ for item in self.items:
+ if item.code == item_code:
+ return item
+
+ raise ValueError, 'Item not found.'
+
class Customer(CheddarObject):
"""An object representing a CheddarGetter customer."""
@@ -580,11 +576,12 @@ def get_item(self, item_code):
"""Retrieve an item by item code. If the item does not exist,
raise ValueError."""
- if item_code in self.subscription.items:
- self.subscription.items[item_code].customer = self
- return self.subscription.items[item_code]
- else:
- raise ValueError, 'Item not found.'
+ for item in self.subscription.items:
+ if item.code == item_code:
+ item.customer = self
+ return item
+
+ raise ValueError, 'Item not found.'
def add_charge(self, charge_code, item_code, amount = 0.0, quantity = 1, description = None):

0 comments on commit 9a20078

Please sign in to comment.