Changeset View
Changeset View
Standalone View
Standalone View
swh/web/common/origin_save.py
# Copyright (C) 2018 The Software Heritage developers | # Copyright (C) 2018 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 bisect import bisect_right | from bisect import bisect_right | ||||
from datetime import datetime, timezone | from datetime import datetime, timezone | ||||
from django.core.exceptions import ObjectDoesNotExist | from django.core.exceptions import ObjectDoesNotExist | ||||
from django.core.exceptions import ValidationError | from django.core.exceptions import ValidationError | ||||
from django.core.validators import URLValidator | from django.core.validators import URLValidator | ||||
from django.utils.html import escape | |||||
from swh.web import config | from swh.web import config | ||||
from swh.web.common import service | from swh.web.common import service | ||||
from swh.web.common.exc import BadInputExc, ForbiddenExc, NotFoundExc | from swh.web.common.exc import BadInputExc, ForbiddenExc, NotFoundExc | ||||
from swh.web.common.models import ( | from swh.web.common.models import ( | ||||
SaveUnauthorizedOrigin, SaveAuthorizedOrigin, SaveOriginRequest, | SaveUnauthorizedOrigin, SaveAuthorizedOrigin, SaveOriginRequest, | ||||
SAVE_REQUEST_ACCEPTED, SAVE_REQUEST_REJECTED, SAVE_REQUEST_PENDING, | SAVE_REQUEST_ACCEPTED, SAVE_REQUEST_REJECTED, SAVE_REQUEST_PENDING, | ||||
SAVE_TASK_NOT_YET_SCHEDULED, SAVE_TASK_SCHEDULED, | SAVE_TASK_NOT_YET_SCHEDULED, SAVE_TASK_SCHEDULED, | ||||
▲ Show 20 Lines • Show All 102 Lines • ▼ Show 20 Lines | |||||
_validate_url = URLValidator(schemes=['http', 'https', 'svn', 'git']) | _validate_url = URLValidator(schemes=['http', 'https', 'svn', 'git']) | ||||
def _check_origin_url_valid(origin_url): | def _check_origin_url_valid(origin_url): | ||||
try: | try: | ||||
_validate_url(origin_url) | _validate_url(origin_url) | ||||
except ValidationError: | except ValidationError: | ||||
raise BadInputExc('The provided origin url (%s) is not valid!' % | raise BadInputExc('The provided origin url (%s) is not valid!' % | ||||
origin_url) | escape(origin_url)) | ||||
def _get_visit_info_for_save_request(save_request): | def _get_visit_info_for_save_request(save_request): | ||||
visit_date = None | visit_date = None | ||||
visit_status = None | visit_status = None | ||||
try: | try: | ||||
origin = {'type': save_request.origin_type, | origin = {'type': save_request.origin_type, | ||||
'url': save_request.origin_url} | 'url': save_request.origin_url} | ||||
▲ Show 20 Lines • Show All 262 Lines • Show Last 20 Lines |