def find_one_by_search_id(self, search_id, deleted=False): """ Lazy-loads a single :class:`Search` by ID :param search_id: The search identifier :type search_id: :class:`int` :param deleted: Whether to find a deleted search :type deleted: :class:`bool` :rtype: :class:`Field` or :class:`None` Usage:: >>> from emma.model.account import Account >>> acct = Account(1234, "08192a3b4c5d6e7f", "f7e6d5c4b3a29180") >>> acct.searches.find_one_by_search_id(0) # does not exist raises <KeyError> >>> acct.searches.find_one_by_search_id(123) <Search> >>> acct.searches[123] <Search> """ search_id = int(search_id) path = '/searches/%s' % search_id params = {"deleted": True} if deleted else {} if search_id not in self._dict: search = emma.model.search raw = self.account.adapter.get(path, params) if raw: self._dict[search_id] = search.Search(self.account, raw) return (search_id in self._dict) and self._dict[search_id] or None
def fetch_all(self, deleted=False): """ Lazy-loads the full set of :class:`Search` objects :param deleted: Whether to include deleted fields :type deleted: :class:`bool` :rtype: :class:`dict` of :class:`Search` objects Usage:: >>> from emma.model.account import Account >>> acct = Account(1234, "08192a3b4c5d6e7f", "f7e6d5c4b3a29180") >>> acct.searches.fetch_all() {123: <Search>, 321: <Search>, ...} """ search = emma.model.search path = '/searches' params = {"deleted": True} if deleted else {} if not self._dict: self._dict = dict( (x['search_id'], search.Search(self.account, x)) for x in self.account.adapter.paginated_get(path, params)) return self._dict
def fetch_all(self): """ Lazy-loads the full set of :class:`Search` objects :rtype: :class:`dict` of :class:`Search` objects Usage:: >>> from emma.model.account import Account >>> acct = Account(1234, "08192a3b4c5d6e7f", "f7e6d5c4b3a29180") >>> mlng = acct.mailings[123] >>> mlng.searches.fetch_all() {123: <Search>, 321: <Search>, ...} """ if 'mailing_id' not in self.mailing: raise ex.NoMailingIdError() search = emma.model.search path = '/mailings/%s/searches' % self.mailing['mailing_id'] if not self._dict: self._dict = dict( (x['search_id'], search.Search(self.mailing.account, x)) for x in self.mailing.account.adapter.paginated_get(path)) return self._dict