# HG changeset patch # User verrierj # Date 1315211947 -7200 # Node ID 4d3a3ea5225cc9a51cb9ba7e0be9eaee4791947f # Parent fe00e7302efe1db4f9b455fb305ed7d0b27ffb00 Add command to reindex project diff -r fe00e7302efe -r 4d3a3ea5225c src/ldt/ldt/management/commands/reindex.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/ldt/ldt/management/commands/reindex.py Mon Sep 05 10:39:07 2011 +0200 @@ -0,0 +1,44 @@ +from django.core.management.base import BaseCommand +import ldt.indexation +from ldt.ldt_utils.models import Content, Project +from ldt.ldt_utils.contentindexer import ContentIndexer, ProjectIndexer +from optparse import make_option + +class Command(BaseCommand): + help = 'Create a new index for all contents' + option_list = BaseCommand.option_list + ( + make_option("-p", "--projects", + dest="projects", + action="store_true", + help="Index projects in addition to contents"), + make_option("-c", "--content", + dest="content_id", + action="store", + type="string", + help="Index only the content specified by CONTENT_ID."), + ) + + def handle(self, *args, **options): + parser = self.create_parser("reindex", "") + options, _ = parser.parse_args() + + writer = ldt.indexation.get_writer(True) + + if options.content_id: + self.stdout.write('Creating index for %s\n' % options.content_id) + contentList = Content.objects.filter(iri_id=options.content_id) + indexer = ContentIndexer(contentList, writer) + indexer.index_all() + else: + self.stdout.write('Creating contents index...\n') + contentList = Content.objects.all() + indexer = ContentIndexer(contentList, writer) + indexer.index_all() + + if options.projects: + self.stdout.write('Creating projects index...\n') + projectList = Project.objects.filter(contents__in=contentList, state=2).distinct() + indexer = ProjectIndexer(projectList, writer) + indexer.index_all() + + writer.close()