<s> from django . utils . translation import ugettext_lazy as _ <EOL> from horizon import exceptions <EOL> from horizon . templatetags import sizeformat <EOL> from openstack_dashboard . api import glance <EOL> def get_available_images ( request , project_id = None , images_cache = None ) : <EOL> """<STR_LIT>""" <EOL> if images_cache is None : <EOL> images_cache = { } <EOL> public_images = images_cache . get ( '<STR_LIT>' , [ ] ) <EOL> images_by_project = images_cache . get ( '<STR_LIT>' , { } ) <EOL> if '<STR_LIT>' not in images_cache : <EOL> public = { "<STR_LIT>" : True , <EOL> "<STR_LIT:status>" : "<STR_LIT>" } <EOL> try : <EOL> images , _more , _prev = glance . image_list_detailed ( <EOL> request , filters = public ) <EOL> [ public_images . append ( image ) for image in images ] <EOL> images_cache [ '<STR_LIT>' ] = public_images <EOL> except Exception : <EOL> exceptions . handle ( request , <EOL> _ ( "<STR_LIT>" ) ) <EOL> if project_id is None : <EOL> images_by_project [ project_id ] = [ ] <EOL> if project_id not in images_by_project : <EOL> owner = { "<STR_LIT>" : project_id , <EOL> "<STR_LIT:status>" : "<STR_LIT>" } <EOL> try : <EOL> owned_images , _more , _prev = glance . image_list_detailed ( <EOL> request , filters = owner ) <EOL> images_by_project [ project_id ] = owned_images <EOL> except Exception : <EOL> owned_images = [ ] <EOL> exceptions . handle ( request , <EOL> _ ( "<STR_LIT>" <EOL> "<STR_LIT>" ) ) <EOL> else : <EOL> owned_images = images_by_project [ project_id ] <EOL> if '<STR_LIT>' not in images_cache : <EOL> images_cache [ '<STR_LIT>' ] = images_by_project <EOL> images = owned_images + public_images <EOL> image_ids = [ ] <EOL> final_images = [ ] <EOL> for image in images : <EOL> if image . id not in image_ids : <EOL> image_ids . append ( image . id ) <EOL> final_images . append ( image ) <EOL> return [ image for image in final_images <EOL> if image . container_format not in ( '<STR_LIT>' , '<STR_LIT>' ) ] <EOL> def image_field_data ( request , include_empty_option = False ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> images = get_available_images ( request , request . user . project_id ) <EOL> except Exception : <EOL> exceptions . handle ( request , _ ( '<STR_LIT>' ) ) <EOL> images . sort ( key = lambda c : c . name ) <EOL> images_list = [ ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) ] <EOL> for image in images : <EOL> image_label = u"<STR_LIT>" . format ( image . name , <EOL> sizeformat . diskgbformat ( image . size ) ) <EOL> images_list . append ( ( image . id , image_label ) ) <EOL> if not images : <EOL> return [ ( "<STR_LIT>" , _ ( "<STR_LIT>" ) ) , ] <EOL> return images_list </s>
