Optimal Districting with Endogenous Party Platform