Conditions | 4 |
Total Lines | 22 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | from django.core.management.base import BaseCommand |
||
9 | def handle(self, *args, **kwargs): |
||
10 | if not models.Thread.objects.count(): |
||
11 | self.stdout.write( |
||
12 | self.style.WARNING("There are no threads to index.")) |
||
13 | |||
14 | backend = get_search_class()() |
||
15 | |||
16 | # clear out old index first |
||
17 | backend.wipe() |
||
18 | |||
19 | count = 0 |
||
20 | for thread in models.Thread.objects.all(): |
||
21 | backend.add(thread) |
||
22 | count += 1 |
||
23 | |||
24 | # SUCCESS style was introduced in django 1.9 |
||
25 | if hasattr(self.style, 'SUCCESS'): |
||
26 | out = self.style.SUCCESS("Updated %d thread(s)" % count) |
||
27 | else: |
||
28 | out = "Updated %d thread(s)" % count |
||
29 | |||
30 | self.stdout.write(out) |
||
31 |