|
| 1 | +# Copyright The IETF Trust 2019, All Rights Reserved |
| 2 | +# -*- coding: utf-8 -*- |
| 3 | +from __future__ import unicode_literals, print_function |
| 4 | + |
| 5 | + |
| 6 | +from django.core.management.base import BaseCommand |
| 7 | + |
| 8 | +import debug # pyflakes:ignore |
| 9 | + |
| 10 | +from ietf.community.models import SearchRule |
| 11 | +from ietf.community.utils import reset_name_contains_index_for_rule |
| 12 | + |
| 13 | +class Command(BaseCommand): |
| 14 | + help = (u""" |
| 15 | + Update the index tables for stored regex-based document search rules. |
| 16 | + """) |
| 17 | + |
| 18 | + def add_arguments(self, parser): |
| 19 | + parser.add_argument('-n', '--dry-run', action='store_true', default=False, |
| 20 | + help="Just show what would have been done") |
| 21 | + |
| 22 | + |
| 23 | + def handle(self, *args, **options): |
| 24 | + for rule in SearchRule.objects.filter(rule_type='name_contains'): |
| 25 | + count1 = rule.name_contains_index.count() |
| 26 | + if not options['dry_run']: |
| 27 | + reset_name_contains_index_for_rule(rule) |
| 28 | + count2 = rule.name_contains_index.count() |
| 29 | + if int(options['verbosity']) > 1: |
| 30 | + group = rule.group or rule.community_list.group |
| 31 | + person = rule.person |
| 32 | + if not person and not group: |
| 33 | + try: |
| 34 | + person = rule.community_list.user.person |
| 35 | + except: |
| 36 | + pass |
| 37 | + name = ((group and group.acronym) or (person and person.email_address())) or '?' |
| 38 | + self.stdout.write("%-24s %-24s %3d -->%3d\n" % (name[:24], rule.text[:24], count1, count2 )) |
| 39 | + |
0 commit comments