def setattribute(self, app, key): data = util.extract_data(self.handler, ['value']) principal = self.handler.get_current_user() storage = zca.getUtility(IPersonStorage) person = storage.get_person(principal) person.set_xattr(app, key, value) return Result()
def post_message(self, person_id): data = util.extract_data(self.handler, ['message']) if data['message'] is None: return Result(False, 101, 'empty message') pstorage = zca.getUtility(IPersonStorage) person = pstorage.get_person(person_id) if person is None: return Result(False, 102, 'user not found') storage = zca.getUtility(IActivityStorage) storage.add_activity(person_id, data) return Result()
def set_self(self): data = util.extract_data(self.handler, ['latitude', 'longitude', 'city', 'country']) has_param = False for key, value in data.items(): if value != None: has_param = True break if not has_param: return Result(False, 101, 'No parameter to update found') principal = self.handler.get_current_user() storage = zca.getUtility(IPersonStorage) person = storage.get_person(principal) person.set_properties(data) return result
def index(self, person_id): storage = zca.getUtility(IActivityStorage) data = util.extract_data(self.handler, ['page', 'pagesize']) limit = int(data['pagesize'] or 0) offset = int(limit * (data['page'] or 0)) activities = [ a.data() for a in storage.get_activities( person_id, limit, offset) ] result = Result() data = [] for activity in activities: data.append(Activity(**activity)) if data: result.data = data return result