@@ -0,0 +1,1734 @@
+import os%0A%0Afrom django.core.management.base import BaseCommand%0Afrom django.template.loader import get_template%0A%0Afrom django.conf import settings%0A%0Afrom flatblocks.templatetags.flatblock_tags import FlatBlockNode%0Afrom flatblocks.models import FlatBlock%0A%0A%0Aclass Command(BaseCommand):%0A    help = %22List unassigned flatblocks in the templates%22%0A%0A    def handle(self, *args, **options):%0A        save_nodes = (len(args) and args%5B0%5D == 'create')%0A        templ_list = %5B%5D%0A        flatblock_nodes = %5B%5D%0A        print_nodes = %5B%5D%0A%0A        #get list of templates%0A        for templ_dir in settings.TEMPLATE_DIRS:%0A            templ_list += %5Bos.path.join(dp, f) for dp, dn, fn in os.walk(os.path.expanduser(templ_dir)) for f in fn%5D%0A%0A        #load templates and get FlatBlockNode slugs%0A        for templ in templ_list:%0A            try:%0A                t = get_template(templ)%0A                flatblock_nodes += %5Bnode.slug for node in t.nodelist.get_nodes_by_type(FlatBlockNode)%5D%0A            except:%0A                pass%0A%0A        #distinct slugs%0A        flatblock_nodes = list(set(flatblock_nodes))%0A%0A        #check if flatblocks have entry in database%0A        for node in flatblock_nodes:%0A            if FlatBlock.objects.filter(slug=node).count() == 0:%0A                #if create argument was supplied, save empty nodes%0A                if save_nodes:%0A                    block = FlatBlock(header=%22%5B%7B0%7D%5D%22.format(node), content=%22Generated flatblock%22, slug=node)%0A                    block.save()%0A                print_nodes.append(node)%0A%0A        if len(print_nodes):%0A            if save_nodes:%0A                print %22Following nodes were created:%22%0A            print %22%5Cn%22.join(print_nodes)%0A        else:%0A            print %22All FlatBlock items are in database%22

Add command for checking & saving unassigned flatblocks in the database