• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

zestedesavoir / zds-site / 11039742153

25 Sep 2024 07:23PM UTC coverage: 88.938%. Remained the same
11039742153

push

github

web-flow
Correction de l'erreur 422 de Coveralls (#6646)

4738 of 5930 branches covered (79.9%)

16740 of 18822 relevant lines covered (88.94%)

1.89 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/zds/tutorialv2/management/commands/validate_content.py
1
import logging
×
2

3
from django.core.management import BaseCommand
×
4
from django.utils.translation import gettext as _
×
5

6
from zds.tutorialv2.models.database import PublishableContent, Validation
×
7
from zds.tutorialv2.publication_utils import (
×
8
    publish_content,
9
    FailureDuringPublication,
10
    notify_update,
11
    save_validation_state,
12
)
13

14

15
class Command(BaseCommand):
×
16
    help = "Publish one content by its id. This require the content to be in validation and reserved by someone"
×
17

18
    def add_arguments(self, parser):
×
19
        parser.add_argument("content", type=Command.id_validator)
×
20
        parser.add_argument("--major", dest="is_major", action="store_true")
×
21
        parser.add_argument("--source", dest="source", type=str, default="")
×
22

23
    @staticmethod
×
24
    def id_validator(content_pk):
×
25
        try:
×
26
            content_pk = int(content_pk)
×
27
        except ValueError:
×
28
            raise ValueError("Identifier should be integer")
×
29
        content = PublishableContent.objects.filter(pk=content_pk).first()
×
30
        if not content:
×
31
            raise ValueError("Content does not exist")
×
32

33
        if not Validation.objects.filter(content=content, status="PENDING_V").first():
×
34
            raise ValueError("Content is not being validated")
×
35

36
        return content
×
37

38
    def handle(self, *args, content: PublishableContent, is_major=False, **options):
×
39
        content.current_validation = Validation.objects.filter(content=content, status="PENDING_V").first()
×
40
        versioned = content.load_version(sha=content.current_validation.version)
×
41
        is_update = content.sha_public
×
42
        try:
×
43
            published = publish_content(content, versioned, is_major_update=is_major)
×
44
        except FailureDuringPublication as e:
×
45
            self.stdout.write("Publication failed")
×
46
            logging.getLogger(__name__).exception("Failure during publication", exc_info=e)
×
47
        else:
48
            save_validation_state(
×
49
                content,
50
                is_update,
51
                published,
52
                content.current_validation,
53
                versioned,
54
                options.get("source", ""),
55
                is_major,
56
                user=content.current_validation.validator,
57
                comment=_("Géré depuis la commande d'administration"),
58
            )
59
            notify_update(content, is_update, is_major)
×
60
            self.stdout.write(_("La contenu a été validé"))
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc