def post(self, args, **_kwargs): position = from_shape(Point(args['lng'], args['lat']), srid=4326) new_shop = Shop(name=args['name'], address=args['address'], position=position, withdrawn=False) new_shop.tags = [ ShopTag(name=tag, shop=new_shop) for tag in unique_stripped(args['tags']) ] db.session.add(new_shop) try: db.session.commit() except IntegrityError as e: db.session.rollback() if "shop_pna_c" in e.orig: return custom_error('Address/Position/Name', ['Same address, position and name with existing shop']), \ ErrorCode.BAD_REQUEST else: return custom_error( 'tags', ['Duplicate tags' ]), ErrorCode.BAD_REQUEST # we should never get here return shop_schema.dump(new_shop).data