Changeset View
Changeset View
Standalone View
Standalone View
swh/web/common/models.py
# Copyright (C) 2018-2019 The Software Heritage developers | # Copyright (C) 2018-2021 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU Affero General Public License version 3, or any later version | # License: GNU Affero General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
from typing import Dict | |||||
from django.db import models | from django.db import models | ||||
class SaveAuthorizedOrigin(models.Model): | class SaveAuthorizedOrigin(models.Model): | ||||
""" | """ | ||||
Model table holding origin urls authorized to be loaded into the archive. | Model table holding origin urls authorized to be loaded into the archive. | ||||
""" | """ | ||||
▲ Show 20 Lines • Show All 86 Lines • ▼ Show 20 Lines | class SaveOriginRequest(models.Model): | ||||
) | ) | ||||
class Meta: | class Meta: | ||||
app_label = "swh_web_common" | app_label = "swh_web_common" | ||||
db_table = "save_origin_request" | db_table = "save_origin_request" | ||||
ordering = ["-id"] | ordering = ["-id"] | ||||
indexes = [models.Index(fields=["origin_url", "status"])] | indexes = [models.Index(fields=["origin_url", "status"])] | ||||
def __str__(self): | def to_dict(self) -> Dict: | ||||
return str( | return { | ||||
{ | |||||
"id": self.id, | "id": self.id, | ||||
"request_date": self.request_date, | |||||
"visit_type": self.visit_type, | |||||
"visit_status": self.visit_status, | |||||
"origin_url": self.origin_url, | "origin_url": self.origin_url, | ||||
"visit_type": self.visit_type, | |||||
"request_date": self.request_date, | |||||
"status": self.status, | "status": self.status, | ||||
"loading_task_id": self.loading_task_id, | "loading_task_id": self.loading_task_id, | ||||
"loading_task_status": self.loading_task_status, | |||||
"visit_status": self.visit_status, | |||||
"visit_date": self.visit_date, | "visit_date": self.visit_date, | ||||
} | } | ||||
) | |||||
def __str__(self) -> str: | |||||
return str(self.to_dict()) | |||||
ardumont: I could probably revert this. My initial intent was to use it in the conversion code
below. | |||||
anlambertUnsubmitted Done Inline ActionsI agree with you, the dict conversion should be handled directly in the model. anlambert: I agree with you, the dict conversion should be handled directly in the model. |
I could probably revert this. My initial intent was to use it in the conversion code
below. Then as i moved towards the SaveOiriginRequestInfo typed dict, i stopped using
it.
I also wondered whether to have a to_dict method which would return directly the
SaveOriginRequestInfo dict. I don't realize if this is reasonable or not (that would
allow to avoid an intermediary function for one which sounds good to me).
@anlambert any thoughts on those matters?