Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def post(self):
"""Create a Campaign"""
args = story_post_parser.parse_args()
# Verify charity is supported
if args["charity_id"] not in [c["id"] for c in SUPPORTED_CHARITIES]:
abort(400, description="Unsupported charity: {}".format(args["charity_id"]))
# Create campaign id
while True:
u = uuid.uuid4()
s = shortuuid.encode(u)[:5]
if not self.table.get_item({"campaign_id": s}):
break
printable = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
name_str = filter(lambda x: x in printable, args["campaigner_name"].strip().lower())
name_str = name_str.replace(" ", "-")
args["campaign_id"] = "{}-{}".format(name_str, s)
args["campaigner_name"] = args["campaigner_name"].strip()
args["campaigner_email"] = args["campaigner_email"].strip()
args["campaign_status"] = "active"
args['notified_on'] = arrow.utcnow().isoformat()
args['created_on'] = arrow.utcnow().isoformat()
args['secret_id'] = shortuuid.uuid()
args['charity_id'] = args["charity_id"]
# Put the object