def _create(self, contact_id, params, add_func, return_obj): """Create sub object from param using add_func.""" contact = CoreContact.get(self.user, contact_id) created = getattr(contact, add_func)(params) log.debug('Created object {} for contact {}'.format( created.address_id, contact.contact_id)) return return_obj.build(created).serialize()
def contact(self): """User is a contact.""" if self.contact_id is None: return None try: return CoreContact.get(self, self.contact_id) except NotFound: log.warn("contact {} not found for user {}". format(self.contact_id, self.user_id)) return None
def contact(self): """User is a contact.""" if self.contact_id is None: return None try: return CoreContact.get(self, self.contact_id) except NotFound: log.warn("contact {} not found for user {}".format( self.contact_id, self.user_id)) return None
def collection_get(self): filter_params = {'limit': self.get_limit(), 'offset': self.get_offset()} log.debug('Filter parameters {}'.format(filter_params)) results = CoreContact._model_class.search(self.user, **filter_params) data = [] for item in results: try: c = ReturnContact.build( CoreContact.get(self.user, item.contact_id)). \ serialize() data.append(c) except Exception as exc: log.error("unable to serialize contact : {}".format(exc)) return {'contacts': data, 'total': results.hits.total}
def __init__(self, request): self.request = request self.user = request.authenticated_userid contact_id = self.request.matchdict.get('contact_id') self.contact = CoreContact.get(self.user, contact_id)
def _delete(self, relation_id, delete_func): """Delete sub object relation_id using delete_fund.""" contact_id = self.request.validated['contact_id'] contact = CoreContact.get(self.user, contact_id) return getattr(contact, delete_func)(relation_id)