def unpurchase_item(self, item_id): ''' Mark the given item as not purchased if you were the one who purchased it ''' _ = lambda x: x.key().id() self._verify_owner() item = self.db.get_item(item_id) if not self._can_read_list(item.parent_list.owner.key().id()): raise PermissionDeniedError() oid = _(self.owner) if item.purchased_by is not None and _(item.purchased_by) != oid: self._item_already_taken('purchased', item.purchased_by) if item.reserved_by is not None and _(item.reserved_by) != oid: self._item_already_taken('reserved', item.reserved_by) l = None if item.is_surprise: l = item.parent_list self.db.delete(item) else: item.purchased_by = None l = item.put().parent_list return WishList.from_db(l)
def unpurchase_item(self, item_id): """ Mark the given item as not purchased if you were the one who purchased it """ _ = lambda x: x.key().id() self._verify_owner() item = self.db.get_item(item_id) if not self._can_read_list(item.parent_list.owner.key().id()): raise PermissionDeniedError() oid = _(self.owner) if item.purchased_by is not None and _(item.purchased_by) != oid: self._item_already_taken('purchased', item.purchased_by) if item.reserved_by is not None and _(item.reserved_by) != oid: self._item_already_taken('reserved', item.reserved_by) l = None if item.is_surprise: l = item.parent_list self.db.delete(item) else: item.purchased_by = None l = item.put().parent_list return WishList.from_db(l)
def remove_item(self, item_id): """ Remove the given item. If the item has been reserved/purchased, send an email notification to the the reserver/purchaser """ self._verify_owner() item = self.db.get_item(item_id) if not self._can_add_to_list(item.parent_list.owner.key().id()): raise PermissionDeniedError() if item.reserved_by is not None: to = item.reserved_by.email subject = 'Wish List Item Deleted' name, email = self.owner.nickname, self.owner.email template_tuple = ( item.reserved_by.nickname, name, email, item.name, item.parent_list.name, 'Reserved', name, email, ) body = self.ae.DELETED_ITEM_TEMPLATE % template_tuple self.ae.send_mail(to, subject, body) elif item.purchased_by is not None: to = item.purchased_by.email subject = 'Wish List Item Deleted' name, email = self.owner.nickname, self.owner.email template_tuple = ( item.purchased_by.nickname, name, email, item.name, item.parent_list.name, 'Purchased', name, email, ) body = self.ae.DELETED_ITEM_TEMPLATE % template_tuple self.ae.send_mail(to, subject, body) l = item.parent_list self.db.delete(item) return WishList.from_db(l)
def get_lists(self, owner_id): ''' Retrieve all the wish lists for the given owner ''' if not self._can_read_list(owner_id): raise PermissionDeniedError() oid = self.owner.key().id() own = oid == owner_id owner = self.db.get_owner(owner_id) return [WishList.from_db(l, own=own) for l in owner.lists]
def get_lists(self, owner_id): """ Retrieve all the wish lists for the given owner """ if not self._can_read_list(owner_id): raise PermissionDeniedError() oid = self.owner.key().id() own = oid == owner_id owner = self.db.get_owner(owner_id) return [WishList.from_db(l, own=own) for l in owner.lists]
def add_list(self, owner_id, name, desc): ''' Add a new wish list for the given owner, ensuring a unique name ''' if not self._can_add_to_list(owner_id): raise PermissionDeniedError() if not self.db.is_list_name_unique(owner_id, name): raise DuplicateNameError(WishList, name) l = self.db.add_list(owner_id, name, desc) return WishList.from_db(l)
def add_list(self, owner_id, name, desc): """ Add a new wish list for the given owner, ensuring a unique name """ if not self._can_add_to_list(owner_id): raise PermissionDeniedError() if not self.db.is_list_name_unique(owner_id, name): raise DuplicateNameError(WishList, name) l = self.db.add_list(owner_id, name, desc) return WishList.from_db(l)
def update_item(self, item_id, name, cat, desc, url): ''' Update the name, category, description and url of an existing item ''' item = self.db.get_item(item_id) if not self._can_add_to_list(item.parent_list.owner.key().id()): raise PermissionDeniedError() item.name = name item.category = cat item.description = desc item.url = url return WishList.from_db(item.put().parent_list)
def update_item(self, item_id, name, cat, desc, url): """ Update the name, category, description and url of an existing item """ item = self.db.get_item(item_id) if not self._can_add_to_list(item.parent_list.owner.key().id()): raise PermissionDeniedError() item.name = name item.category = cat item.description = desc item.url = url return WishList.from_db(item.put().parent_list)
def add_item(self, list_id, name, cat, desc, url, surprise): ''' Add an item to the given wish list ''' l = self.db.get_list(list_id) can_read = self._can_read_list(l.owner.key().id()) can_add = self._can_add_to_list(l.owner.key().id()) if not (can_add or (can_read and surprise)): raise PermissionDeniedError() item = self.db.add_list_item(list_id, name, cat, desc, url, surprise) if surprise: item.reserved_by = self.owner item.put() return WishList.from_db(self.db.get_list(list_id))
def add_item(self, list_id, name, cat, desc, url, surprise): """ Add an item to the given wish list """ l = self.db.get_list(list_id) can_read = self._can_read_list(l.owner.key().id()) can_add = self._can_add_to_list(l.owner.key().id()) if not (can_add or (can_read and surprise)): raise PermissionDeniedError() item = self.db.add_list_item(list_id, name, cat, desc, url, surprise) if surprise: item.reserved_by = self.owner item.put() return WishList.from_db(self.db.get_list(list_id))
def update_list(self, list_id, name, desc): ''' Update the name/description of an existing wish list for the given owner, ensuring a unique name ''' l = self.db.get_list(list_id) oid = l.owner.key().id() if not self._can_add_to_list(oid): raise PermissionDeniedError() if not self.db.is_list_name_unique(oid, name, l.key()): raise DuplicateNameError(WishList, name) l.name = name l.description = desc return WishList.from_db(l.put())
def update_list(self, list_id, name, desc): """ Update the name/description of an existing wish list for the given owner, ensuring a unique name """ l = self.db.get_list(list_id) oid = l.owner.key().id() if not self._can_add_to_list(oid): raise PermissionDeniedError() if not self.db.is_list_name_unique(oid, name, l.key()): raise DuplicateNameError(WishList, name) l.name = name l.description = desc return WishList.from_db(l.put())
def remove_item(self, item_id): ''' Remove the given item. If the item has been reserved/purchased, send an email notification to the the reserver/purchaser ''' self._verify_owner() item = self.db.get_item(item_id) if not self._can_add_to_list(item.parent_list.owner.key().id()): raise PermissionDeniedError() if item.reserved_by is not None: to = item.reserved_by.email subject = 'Wish List Item Deleted' name, email = self.owner.nickname, self.owner.email template_tuple = ( item.reserved_by.nickname, name, email, item.name, item.parent_list.name, 'Reserved', name, email, ) body = self.ae.DELETED_ITEM_TEMPLATE % template_tuple self.ae.send_mail(to, subject, body) elif item.purchased_by is not None: to = item.purchased_by.email subject = 'Wish List Item Deleted' name, email = self.owner.nickname, self.owner.email template_tuple = ( item.purchased_by.nickname, name, email, item.name, item.parent_list.name, 'Purchased', name, email, ) body = self.ae.DELETED_ITEM_TEMPLATE % template_tuple self.ae.send_mail(to, subject, body) l = item.parent_list self.db.delete(item) return WishList.from_db(l)
def unreserve_item(self, item_id): ''' Mark the given item as not reserved if you were the one who reserved it ''' _ = lambda x: x.key().id() self._verify_owner() item = self.db.get_item(item_id) if not self._can_read_list(item.parent_list.owner.key().id()): raise PermissionDeniedError() oid = _(self.owner) if item.purchased_by is not None and _(item.purchased_by) != oid: self._item_already_taken('purchased', item.purchased_by) if item.reserved_by is not None and _(item.reserved_by) != oid: self._item_already_taken('reserved', item.reserved_by) item.reserved_by = None return WishList.from_db(item.put().parent_list)
def purchase_item(self, item_id): ''' Mark the given item as purchased ''' _ = lambda x: x.key().id() self._verify_owner() item = self.db.get_item(item_id) if not self._can_read_list(item.parent_list.owner.key().id()): raise PermissionDeniedError() oid = _(self.owner) if item.purchased_by is not None and _(item.purchased_by) != oid: self._item_already_taken('purchased', item.purchased_by) if item.reserved_by is not None and _(item.reserved_by) != oid: self._item_already_taken('reserved', item.reserved_by) item.reserved_by = None item.purchased_by = self.owner return WishList.from_db(item.put().parent_list)