Explorar o código

minor formatting and fixes

Nick Sweeting hai 1 ano
pai
achega
ba6c1fd69b

+ 4 - 2
archivebox/abid_utils/models.py

@@ -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

+ 1 - 0
archivebox/builtin_plugins/pip/apps.py

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

+ 1 - 5
archivebox/core/admin.py

@@ -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

+ 2 - 3
archivebox/plugantic/base_configset.py

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

+ 1 - 1
archivebox/plugantic/base_hook.py

@@ -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