import jingrow


@jingrow.whitelist()
def create_custom_format(pagetype, name, based_on="Standard", beta=False):
	pg = jingrow.new_pg("Print Format")
	pg.pg_type = pagetype
	pg.name = name
	beta = jingrow.parse_json(beta)

	if beta:
		pg.print_format_builder_beta = 1
	else:
		pg.print_format_builder = 1
	pg.format_data = (
		jingrow.db.get_value("Print Format", based_on, "format_data") if based_on != "Standard" else None
	)
	pg.insert()
	return pg
