'Add restricted Tag Browser views'

def upgrade_version_10(self):

    def create_tag_browser_view(table_name, column_name, view_column_name):
        script = '\n                                                                DROP    VIEW    IF    EXISTS    tag_browser_{tn};\n                                                                CREATE    VIEW    tag_browser_{tn}    AS    SELECT\n                                                                                id,\n                                                                                {vcn},\n                                                                                (SELECT    COUNT(id)    FROM    books_{tn}_link    WHERE    {cn}={tn}.id)    count\n                                                                FROM    {tn};\n                                                                DROP    VIEW    IF    EXISTS    tag_browser_filtered_{tn};\n                                                                CREATE    VIEW    tag_browser_filtered_{tn}    AS    SELECT\n                                                                                id,\n                                                                                {vcn},\n                                                                                (SELECT    COUNT(books_{tn}_link.id)    FROM    books_{tn}_link    WHERE\n                                                                                                {cn}={tn}.id    AND    books_list_filter(book))    count\n                                                                FROM    {tn};\n                                                                '.format(tn=table_name, cn=column_name, vcn=view_column_name)
        self.conn.executescript(script)
    for field in self.field_metadata.itervalues():
        if (field['is_category'] and (not field['is_custom']) and ('link_column' in field)):
            table = self.conn.get('SELECT    name    FROM    sqlite_master    WHERE    type="table"    AND    name=?', (('books_%s_link' % field['table']),), all=False)
            if (table is not None):
                create_tag_browser_view(field['table'], field['link_column'], field['column'])
