Ejemplo n.º 1
0
    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)
Ejemplo n.º 2
0
    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)
Ejemplo n.º 3
0
    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)
Ejemplo n.º 4
0
    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]
Ejemplo n.º 5
0
    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]
Ejemplo n.º 6
0
    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)
Ejemplo n.º 7
0
    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)
Ejemplo n.º 8
0
    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)
Ejemplo n.º 9
0
    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)
Ejemplo n.º 10
0
    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))
Ejemplo n.º 11
0
    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))
Ejemplo n.º 12
0
    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())
Ejemplo n.º 13
0
    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())
Ejemplo n.º 14
0
    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)
Ejemplo n.º 15
0
    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)
Ejemplo n.º 16
0
    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)