minor formatting and fixes
Some checks are pending
CodeQL / Analyze (python) (push) Waiting to run
Build Debian package / build (push) Waiting to run
Build Docker image / buildx (push) Waiting to run
Build Homebrew package / build (push) Waiting to run
Build GitHub Pages website / build (push) Waiting to run
Build GitHub Pages website / deploy (push) Blocked by required conditions
Run linters / lint (push) Waiting to run
Build Pip package / build (push) Waiting to run
Run tests / python_tests (ubuntu-22.04, 3.11) (push) Waiting to run
Run tests / docker_tests (push) Waiting to run

This commit is contained in:
Nick Sweeting 2024-09-05 04:39:46 -07:00
parent d50aed9185
commit ba6c1fd69b
No known key found for this signature in database
5 changed files with 9 additions and 11 deletions

View file

@ -127,10 +127,11 @@ class ABIDModel(models.Model):
) )
change_error = ValidationError({ change_error = ValidationError({
NON_FIELD_ERRORS: ValidationError(full_summary),
**{ **{
# url: ValidationError('Cannot update self.url= https://example.com/old -> https://example.com/new ...') # url: ValidationError('Cannot update self.url= https://example.com/old -> https://example.com/new ...')
diff['abid_src'].replace('self.', '') if diff['old_val'] != diff['new_val'] else NON_FIELD_ERRORS diff['abid_src'].replace('self.', '')
if (diff['old_val'] != diff['new_val']) and hasattr(self, diff['abid_src'].replace('self.', ''))
else NON_FIELD_ERRORS
: ValidationError( : ValidationError(
'Cannot update %(abid_src)s= "%(old_val)s" -> "%(new_val)s" (would alter %(model)s.ABID.%(key)s=%(old_hash)s to %(new_hash)s)', 'Cannot update %(abid_src)s= "%(old_val)s" -> "%(new_val)s" (would alter %(model)s.ABID.%(key)s=%(old_hash)s to %(new_hash)s)',
code='ABIDConflict', code='ABIDConflict',
@ -138,6 +139,7 @@ class ABIDModel(models.Model):
) )
for diff in abid_diffs.values() for diff in abid_diffs.values()
}, },
NON_FIELD_ERRORS: ValidationError(full_summary),
}) })
should_ovewrite_abid = self.abid_drift_allowed if (abid_drift_allowed is None) else abid_drift_allowed should_ovewrite_abid = self.abid_drift_allowed if (abid_drift_allowed is None) else abid_drift_allowed

View file

@ -1,3 +1,4 @@
import os
import sys import sys
import inspect import inspect
from pathlib import Path from pathlib import Path

View file

@ -1,7 +1,6 @@
__package__ = 'archivebox.core' __package__ = 'archivebox.core'
import os import os
import json
from io import StringIO from io import StringIO
from pathlib import Path from pathlib import Path
@ -10,7 +9,6 @@ from datetime import datetime, timezone
from typing import Dict, Any from typing import Dict, Any
from django.contrib import admin from django.contrib import admin
from django.db.models import Count, Q, Prefetch
from django.urls import path, reverse, resolve from django.urls import path, reverse, resolve
from django.utils import timezone from django.utils import timezone
from django.utils.functional import cached_property from django.utils.functional import cached_property
@ -32,12 +30,10 @@ from signal_webhooks.utils import get_webhook_model
from ..util import htmldecode, urldecode, ansi_to_html from ..util import htmldecode, urldecode, ansi_to_html
from core.models import Snapshot, ArchiveResult, Tag, SnapshotTag from core.models import Snapshot, ArchiveResult, Tag
from core.forms import AddLinkForm from core.forms import AddLinkForm
from core.mixins import SearchResultsAdminMixin from core.mixins import SearchResultsAdminMixin
from api.models import APIToken from api.models import APIToken
from api.auth import get_or_create_api_token
from abid_utils.models import get_or_create_system_user_pk
from abid_utils.admin import ABIDModelAdmin from abid_utils.admin import ABIDModelAdmin
from index.html import snapshot_icons from index.html import snapshot_icons

View file

@ -1,9 +1,8 @@
__package__ = 'archivebox.plugantic' __package__ = 'archivebox.plugantic'
from typing import Optional, List, Literal from typing import List, Literal
from pathlib import Path from pydantic import ConfigDict
from pydantic import BaseModel, Field, ConfigDict, computed_field
from .base_hook import BaseHook, HookType from .base_hook import BaseHook, HookType

View file

@ -20,7 +20,7 @@ class BaseHook(BaseModel):
it modifies django.conf.settings in-place to add changes corresponding to its HookType. it modifies django.conf.settings in-place to add changes corresponding to its HookType.
e.g. for a HookType.CONFIG, the Hook.register() function places the hook in settings.CONFIG (and settings.HOOKS) e.g. for a HookType.CONFIG, the Hook.register() function places the hook in settings.CONFIG (and settings.HOOKS)
An example of an impure Hook would be a CHECK that modifies settings but also calls django.core.checks.register(check). An example of an impure Hook would be a CHECK that modifies settings but also calls django.core.checks.register(check).
In practice any object that subclasses BaseHook and provides a .register() function can behave as a Hook.
setup_django() -> imports all settings.INSTALLED_APPS... setup_django() -> imports all settings.INSTALLED_APPS...
# django imports AppConfig, models, migrations, admins, etc. for all installed apps # django imports AppConfig, models, migrations, admins, etc. for all installed apps