Coverage for distro_tracker/core/management/commands/tracker_update_news_signatures.py: 91%
19 statements
« prev ^ index » next coverage.py v6.5.0, created at 2025-01-12 09:15 +0000
« prev ^ index » next coverage.py v6.5.0, created at 2025-01-12 09:15 +0000
1# Copyright 2013 The Distro Tracker Developers
2# See the COPYRIGHT file at the top-level directory of this distribution and
3# at https://deb.li/DTAuthors
4#
5# This file is part of Distro Tracker. It is subject to the license terms
6# in the LICENSE file found in the top-level directory of this
7# distribution and at https://deb.li/DTLicense. No part of Distro Tracker,
8# including this file, may be copied, modified, propagated, or distributed
9# except according to the terms contained in the LICENSE file.
10"""
11Implements a command which tries to update the signature information
12for :class:`News <distro_tracker.core.models.News>` instances which do not have
13any associated signatures.
14"""
15from django.core.management.base import BaseCommand
16from django.db import models
18from distro_tracker.core.models import EmailNews
21class Command(BaseCommand):
22 """
23 A Django management command which tries to update the signature information
24 for :class:`News <distro_tracker.core.models.News>` instances which do not
25 have any associated signatures.
26 """
27 help = ( # noqa
28 "Update the signature information related to News items which do not"
29 " have any related signatures yet."
30 )
32 def write(self, text):
33 if self.verbose: 33 ↛ 34line 33 didn't jump to line 34, because the condition on line 33 was never true
34 self.stdout.write(text)
36 def handle(self, *args, **kwargs):
37 self.verbose = int(kwargs['verbosity']) > 1
39 self.write("Retrieving list of news to update...")
40 no_signature_news = EmailNews.objects.annotate(
41 cnt=models.Count('signed_by'))
42 no_signature_news = no_signature_news.filter(cnt=0)
43 self.write("Processing news...")
44 self.write("{ID}: {TITLE}")
45 for news in no_signature_news:
46 self.write("{}: {}".format(news.id, news))
47 # Simply saving the instance directly triggers the signature
48 # verification.
49 news.save()