Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Potential easier access of items

  • Loading branch information...
commit 528079bbd0ae362075e5f931c0f10c2dec9c905c 1 parent f1110de
Ryan Showalter authored
Showing with 16 additions and 13 deletions.
  1. +16 −13 pycheddar/__init__.py
View
29 pycheddar/__init__.py
@@ -324,7 +324,12 @@ 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
- getattr(self, child.tag).append(klass.from_xml(indiv_xml, parent = self))
+ 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))
+
except AttributeError:
break
@@ -443,12 +448,11 @@ def get_item(self, item_code):
"""Retrieve an item by item code. If the item does not exist,
raise ValueError."""
- for item in self.items:
- if item.code == item_code:
- return item
-
- raise ValueError, 'Item not found.'
-
+ if item_code in self.items:
+ return self.items[item_code]
+ else:
+ raise ValueError, 'Item not found.'
+
class Customer(CheddarObject):
"""An object representing a CheddarGetter customer."""
@@ -576,12 +580,11 @@ def get_item(self, item_code):
"""Retrieve an item by item code. If the item does not exist,
raise ValueError."""
- for item in self.subscription.items:
- if item.code == item_code:
- item.customer = self
- return item
-
- raise ValueError, 'Item not found.'
+ 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.'
def add_charge(self, charge_code, item_code, amount = 0.0, quantity = 1, description = None):
Please sign in to comment.
Something went wrong with that request. Please try again.