<s> import logging <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> from horizon import exceptions <EOL> from horizon import forms <EOL> from openstack_dashboard . api import sahara as saharaclient <EOL> import openstack_dashboard . dashboards . project . data_processing . utils . workflow_helpers as whelpers <EOL> LOG = logging . getLogger ( __name__ ) <EOL> def anti_affinity_field ( ) : <EOL> return forms . MultipleChoiceField ( <EOL> label = _ ( "<STR_LIT>" ) , <EOL> required = False , <EOL> help_text = _ ( "<STR_LIT>" ) , <EOL> widget = forms . CheckboxSelectMultiple ( ) <EOL> ) <EOL> def populate_anti_affinity_choices ( self , request , context ) : <EOL> try : <EOL> sahara = saharaclient . client ( request ) <EOL> plugin , version = whelpers . get_plugin_and_hadoop_version ( request ) <EOL> version_details = sahara . plugins . get_version_details ( plugin , version ) <EOL> process_choices = [ ] <EOL> for processes in version_details . node_processes . values ( ) : <EOL> for process in processes : <EOL> process_choices . append ( ( process , process ) ) <EOL> cluster_template_id = request . REQUEST . get ( "<STR_LIT>" , None ) <EOL> if cluster_template_id is None : <EOL> selected_processes = request . REQUEST . get ( "<STR_LIT>" , [ ] ) <EOL> else : <EOL> cluster_template = ( <EOL> sahara . cluster_templates . get ( cluster_template_id ) ) <EOL> selected_processes = cluster_template . anti_affinity <EOL> checked_dict = dict ( ) <EOL> for process in selected_processes : <EOL> checked_dict [ process ] = process <EOL> self . fields [ '<STR_LIT>' ] . initial = checked_dict <EOL> except Exception : <EOL> process_choices = [ ] <EOL> exceptions . handle ( request , <EOL> _ ( "<STR_LIT>" ) ) <EOL> return process_choices </s>
