-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmodels.py
105 lines (85 loc) · 3.18 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
"""External Resources models"""
from bulk_update_or_create import BulkUpdateOrCreateQuerySet
from django.db import models
from mitol.common.models import TimestampedModel
from websites.models import WebsiteContent
class ExternalResourceState(TimestampedModel):
"""Data model for tracking the state of external resources"""
class Status(models.TextChoices):
"""Choices for External Resource Status"""
UNCHECKED = "unchecked", "Unchecked or pending check"
VALID = "valid", "External Resource URL is valid"
BROKEN = "broken", "External Resource URL is broken"
CHECK_FAILED = (
"check_failed",
"Last attempt to check the External Resource URL failed",
)
class WaybackStatus(models.TextChoices):
"""Choices for Wayback Machine Status"""
PENDING = "pending", "Pending"
SUCCESS = "success", "Success"
ERROR = "error", "Error"
objects = BulkUpdateOrCreateQuerySet.as_manager()
content = models.OneToOneField(
WebsiteContent,
on_delete=models.CASCADE,
related_name="external_resource_state",
)
status = models.CharField(
max_length=16,
choices=Status.choices,
default=Status.UNCHECKED,
help_text="Status of the external resource (valid, broken, etc.).",
)
last_checked = models.DateTimeField(
default=None,
null=True,
blank=True,
help_text="The last time when this resource was checked for breakages.",
)
external_url_response_code = models.IntegerField(
default=None,
null=True,
blank=True,
)
wayback_job_id = models.CharField(
max_length=255,
default="",
blank=True,
help_text="Last Job ID returned by Wayback Machine API when submitting URL for snapshot.", # noqa: E501
)
wayback_status = models.CharField(
max_length=16,
choices=WaybackStatus.choices,
default="",
blank=True,
help_text="The status of the Wayback Machine snapshot taken from the last archiving job.", # noqa: E501
)
wayback_status_ext = models.CharField(
max_length=128,
default="",
blank=True,
help_text="Extended status of the last Wayback Machine snapshot for detailed error tracking.", # noqa: E501
)
wayback_url = models.URLField(
max_length=800,
default="",
blank=True,
help_text="Last working Wayback Machine snapshot URL for the External Resource.", # noqa: E501
)
wayback_http_status = models.IntegerField(
default=None,
null=True,
blank=True,
help_text="HTTP status code received when accessing the last Wayback Machine snapshot.", # noqa: E501
)
wayback_last_successful_submission = models.DateTimeField(
default=None,
null=True,
blank=True,
help_text="The last time when the URL was successfully submitted to the Wayback Machine.", # noqa: E501
)
def __str__(self):
"""Return a string representation of the state"""
name = self.content.title if self.content else None
return f"State for external resource: {name}"