mirror of
https://github.com/inventree/InvenTree.git
synced 2026-05-21 16:56:47 +00:00
eb79bd1743
The use of `else` or `elif` becomes redundant and can be dropped if the last statement under the leading `if` / `elif` block is a `return` statement. In the case of an `elif` after `return`, it can be written as a separate `if` block. For `else` blocks after `return`, the statements can be shifted out of `else`. Please refer to the examples below for reference. Refactoring the code this way can improve code-readability and make it easier to maintain. Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>
69 lines
2.1 KiB
Python
69 lines
2.1 KiB
Python
"""Admin for the common app."""
|
|
|
|
from django.contrib import admin
|
|
|
|
from import_export.admin import ImportExportModelAdmin
|
|
|
|
import common.models
|
|
|
|
|
|
class SettingsAdmin(ImportExportModelAdmin):
|
|
"""Admin settings for InvenTreeSetting."""
|
|
|
|
list_display = ('key', 'value')
|
|
|
|
def get_readonly_fields(self, request, obj=None): # pragma: no cover
|
|
"""Prevent the 'key' field being edited once the setting is created."""
|
|
if obj:
|
|
return ['key']
|
|
return []
|
|
|
|
|
|
class UserSettingsAdmin(ImportExportModelAdmin):
|
|
"""Admin settings for InvenTreeUserSetting."""
|
|
|
|
list_display = ('key', 'value', 'user', )
|
|
|
|
def get_readonly_fields(self, request, obj=None): # pragma: no cover
|
|
"""Prevent the 'key' field being edited once the setting is created."""
|
|
if obj:
|
|
return ['key']
|
|
return []
|
|
|
|
|
|
class WebhookAdmin(ImportExportModelAdmin):
|
|
"""Admin settings for Webhook."""
|
|
|
|
list_display = ('endpoint_id', 'name', 'active', 'user')
|
|
|
|
|
|
class NotificationEntryAdmin(admin.ModelAdmin):
|
|
"""Admin settings for NotificationEntry."""
|
|
|
|
list_display = ('key', 'uid', 'updated', )
|
|
|
|
|
|
class NotificationMessageAdmin(admin.ModelAdmin):
|
|
"""Admin settings for NotificationMessage."""
|
|
|
|
list_display = ('age_human', 'user', 'category', 'name', 'read', 'target_object', 'source_object', )
|
|
|
|
list_filter = ('category', 'read', 'user', )
|
|
|
|
search_fields = ('name', 'category', 'message', )
|
|
|
|
|
|
class NewsFeedEntryAdmin(admin.ModelAdmin):
|
|
"""Admin settings for NewsFeedEntry."""
|
|
|
|
list_display = ('title', 'author', 'published', 'summary', )
|
|
|
|
|
|
admin.site.register(common.models.InvenTreeSetting, SettingsAdmin)
|
|
admin.site.register(common.models.InvenTreeUserSetting, UserSettingsAdmin)
|
|
admin.site.register(common.models.WebhookEndpoint, WebhookAdmin)
|
|
admin.site.register(common.models.WebhookMessage, ImportExportModelAdmin)
|
|
admin.site.register(common.models.NotificationEntry, NotificationEntryAdmin)
|
|
admin.site.register(common.models.NotificationMessage, NotificationMessageAdmin)
|
|
admin.site.register(common.models.NewsFeedEntry, NewsFeedEntryAdmin)
|