def require_user(self, userid): # Initialize user, return 404 if it doesn't exist in db unescaped_userid = urllib.unquote_plus(userid) user = User(unescaped_userid) if not user.exists_in_db(): abort(404) return user
def post(self): logger.logger.debug("POSTING") args = self.parse_args() user = User(args) try: if user.insert(): return "{0} inserted".format(user.userid) except PrimaryKeyException as e: abort(403) except: abort(400)
def put(self, group_name=None): # TODO: create generic parser users = request.json if users is None: abort(400) group = self.require_group(group_name) filtered_users = [ userid for userid in users if User(userid).exists_in_db() ] group.update(filtered_users) return "{0} updated".format(group_name)