-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Vendor django-automated-logging (#1794)
* Vendor django-automated-logging * Update requirements * Fix middleware module * Specify log for automated logging * Moved vendored package to _vendor folder * Missed updating flake8 * Ignore _vendor directory in check-manifest * Forgot __init__.py ... Issue: AAH-2388
- Loading branch information
1 parent
95cd3e5
commit 11b5926
Showing
66 changed files
with
6,604 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Vendor django-automated-logging to provide Django 4.x compatibility |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2020 Bilal Mahmoud | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
import sys | ||
from ._vendor import automated_logging | ||
|
||
sys.modules.setdefault("automated_logging", automated_logging) | ||
|
||
__version__ = "4.8.0dev" | ||
|
||
default_app_config = "galaxy_ng.app.PulpGalaxyPluginAppConfig" |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
""" | ||
Django Automated Logging makes logging easy. | ||
Django Automated Logging (DAL) is a package with the purpose of | ||
making logging in django automated and easy. | ||
""" | ||
default_app_config = 'automated_logging.apps.AutomatedloggingConfig' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
""" This is just a file that imports all admin interfaces defined in this package """ | ||
|
||
from automated_logging.admin.model_entry import * | ||
from automated_logging.admin.model_event import * | ||
from automated_logging.admin.model_mirror import * | ||
|
||
from automated_logging.admin.request_event import * | ||
|
||
from automated_logging.admin.unspecified_event import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
from django.contrib.admin.options import BaseModelAdmin, ModelAdmin, TabularInline | ||
from django.contrib.admin.templatetags.admin_urls import admin_urlname | ||
from django.shortcuts import resolve_url | ||
from django.utils.html import format_html | ||
from django.utils.safestring import SafeText | ||
|
||
from automated_logging.models import BaseModel | ||
|
||
|
||
class MixinBase(BaseModelAdmin): | ||
""" | ||
TabularInline and ModelAdmin readonly mixin have both the same methods and | ||
return the same, because of that fact we have a mixin base | ||
""" | ||
|
||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
|
||
self.readonly_fields = [f.name for f in self.model._meta.get_fields()] | ||
|
||
def get_actions(self, request): | ||
""" get_actions from ModelAdmin, but remove all write operations.""" | ||
actions = super().get_actions(request) | ||
actions.pop('delete_selected', None) | ||
|
||
return actions | ||
|
||
def has_add_permission(self, request, instance=None): | ||
""" no-one should have the ability to add something => r/o""" | ||
return False | ||
|
||
def has_delete_permission(self, request, instance=None): | ||
""" no-one should have the ability to delete something => r/o """ | ||
return False | ||
|
||
def has_change_permission(self, request, instance=None): | ||
""" no-one should have the ability to edit something => r/o """ | ||
return False | ||
|
||
def save_model(self, request, instance, form, change): | ||
""" disable saving by doing nothing """ | ||
pass | ||
|
||
def delete_model(self, request, instance): | ||
""" disable deleting by doing nothing """ | ||
pass | ||
|
||
def save_related(self, request, form, formsets, change): | ||
""" we don't need to save related, because save_model does nothing """ | ||
pass | ||
|
||
# helpers | ||
def model_admin_url(self, instance: BaseModel, name: str = None) -> str: | ||
""" Helper to return a URL to another object """ | ||
url = resolve_url( | ||
admin_urlname(instance._meta, SafeText("change")), instance.pk | ||
) | ||
return format_html('<a href="{}">{}</a>', url, name or str(instance)) | ||
|
||
|
||
class ReadOnlyAdminMixin(MixinBase, ModelAdmin): | ||
""" Disables all editing capabilities for the model admin """ | ||
|
||
change_form_template = "dal/admin/view.html" | ||
|
||
|
||
class ReadOnlyTabularInlineMixin(MixinBase, TabularInline): | ||
""" Disables all editing capabilities for inline """ | ||
|
||
model = None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
""" | ||
Everything related to the admin interface of ModelEntry is located in here | ||
""" | ||
|
||
from django.contrib.admin import register | ||
from django.shortcuts import redirect | ||
|
||
from automated_logging.admin.model_event import ModelEventAdmin | ||
from automated_logging.admin.base import ReadOnlyAdminMixin, ReadOnlyTabularInlineMixin | ||
from automated_logging.models import ModelEntry, ModelEvent | ||
|
||
|
||
class ModelEventInline(ReadOnlyTabularInlineMixin): | ||
""" inline for all attached events """ | ||
|
||
model = ModelEvent | ||
|
||
def __init__(self, *args, **kwargs): | ||
super(ModelEventInline, self).__init__(*args, **kwargs) | ||
|
||
self.readonly_fields = [*self.readonly_fields, 'get_uuid', 'get_modifications'] | ||
|
||
def get_uuid(self, instance): | ||
""" make the uuid small """ | ||
return self.model_admin_url(instance, str(instance.id).split('-')[0]) | ||
|
||
get_uuid.short_description = 'UUID' | ||
|
||
def get_modifications(self, instance): | ||
""" ModelEventAdmin already implements this functions, we just refer to it""" | ||
return ModelEventAdmin.get_modifications(self, instance) | ||
|
||
get_modifications.short_description = 'Modifications' | ||
|
||
fields = ('get_uuid', 'updated_at', 'user', 'get_modifications') | ||
|
||
ordering = ('-updated_at',) | ||
|
||
verbose_name = 'Event' | ||
verbose_name_plural = 'Events' | ||
|
||
|
||
@register(ModelEntry) | ||
class ModelEntryAdmin(ReadOnlyAdminMixin): | ||
""" admin page specification for ModelEntry """ | ||
|
||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
|
||
self.readonly_fields = [*self.readonly_fields, 'get_model', 'get_application'] | ||
|
||
def changelist_view(self, request, **kwargs): | ||
""" instead of showing the changelist view redirect to the parent app_list""" | ||
return redirect('admin:app_list', self.model._meta.app_label) | ||
|
||
def has_module_permission(self, request): | ||
""" remove model entries from the index.html list """ | ||
return False | ||
|
||
def get_model(self, instance): | ||
""" get the model mirror """ | ||
return self.model_admin_url(instance.mirror) | ||
|
||
get_model.short_description = 'Model' | ||
|
||
def get_application(self, instance): | ||
""" get the application """ | ||
return instance.mirror.application | ||
|
||
get_application.short_description = 'Application' | ||
|
||
fieldsets = ( | ||
( | ||
'Information', | ||
{'fields': ('id', 'get_model', 'get_application', 'primary_key', 'value')}, | ||
), | ||
) | ||
|
||
inlines = [ModelEventInline] |
Oops, something went wrong.