SHOW:
|
|
- or go back to the newest paste.
| 1 | class ItemValidator(object): | |
| 2 | ||
| 3 | - | def __init__(self, items): |
| 3 | + | def __init__(self, items, item=None): |
| 4 | self.items = items | |
| 5 | self.item = item | |
| 6 | ||
| 7 | - | if Item("Green") in items:
|
| 7 | + | |
| 8 | - | raise MyGreenValidationError |
| 8 | + | if self.item: |
| 9 | if self.item.color = "Green" and Item("Red") in self.items: # or something like that
| |
| 10 | raise MyGreenValidationError | |
| 11 | return True | |
| 12 | ||
| 13 | - | >>> f.items.add(item) |
| 13 | + | |
| 14 | - | >>> i = ItemValidator(items) |
| 14 | + | |
| 15 | >>> i = ItemValidator(f.items, item=item) | |
| 16 | - | >>> f.items.save() # or something |
| 16 | + | |
| 17 | >>> f.items.add(item) |