'Display the tag selector with specific categories and allowed values,
depending on the context.'

@XBlockAside.aside_for(AUTHOR_VIEW)
def student_view_aside(self, block, context):

    if isinstance(block, CapaModule):
        tags = []
        for tag in self.get_available_tags():
            tag_available_values = tag.get_values()
            tag_current_values = self.saved_tags.get(tag.name, [])
            if isinstance(tag_current_values, basestring):
                tag_current_values = [tag_current_values]
            tag_values_not_exists = [cur_val for cur_val in tag_current_values if (cur_val not in tag_available_values)]
            tag_values_available_to_choose = (tag_available_values + tag_values_not_exists)
            tag_values_available_to_choose.sort()
            tags.append({'key': tag.name, 'title': tag.title, 'values': tag_values_available_to_choose, 'current_values': tag_current_values})
        fragment = Fragment(render_to_string('structured_tags_block.html', {'tags': tags, 'tags_count': len(tags), 'block_location': block.location}))
        fragment.add_javascript_url(self._get_studio_resource_url('/js/xblock_asides/structured_tags.js'))
        fragment.initialize_js('StructuredTagsInit')
        return fragment
    else:
        return Fragment(u'')
