def retrieve_layers(self, *args, **options):
<EOL>queryset = Q()<EOL>if len(args) < <NUM_LIT:1>:<EOL><INDENT>all_layers = Layer.objects.published().external()<EOL>if options['<STR_LIT>']:<EOL><INDENT>exclude_list = options['<STR_LIT>'].replace('<STR_LIT:U+0020>', '<STR_LIT>').split('<STR_LIT:U+002C>')<EOL>return all_layers.exclude(slug__in=exclude_list)<EOL><DEDENT>else:<EOL><INDENT>self.verbose('<STR_LIT>')<EOL>return all_layers<EOL><DEDENT><DEDENT>for layer_slug in args:<EOL><INDENT>queryset = queryset | Q(slug=layer_slug)<EOL>try:<EOL><INDENT>layer = Layer.objects.get(slug=layer_slug)<EOL>if not layer.is_external:<EOL><INDENT>raise CommandError('<STR_LIT>' % layer_slug)<EOL><DEDENT>if not layer.is_published:<EOL><INDENT>raise CommandError('<STR_LIT>' % layer_slug)<EOL><DEDENT><DEDENT>except Layer.DoesNotExist:<EOL><INDENT>raise CommandError('<STR_LIT>' % layer_slug)<EOL><DEDENT><DEDENT>return Layer.objects.published().external().select_related().filter(queryset)<EOL>
Retrieve specified layers or all external layers if no layer specified.