Almagro, historia y patrimonio