2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-04-28 11:36:44 +00:00
Matthias Mair fb77158496
Add news reader (#3445)
* add model for feed entries

* add task to update feed entries

* Add API routes

* Fix name in model

* rename model

* fix read endpoint

* reduce duplication in NewsFeed API endpoints

* reduce duplicated code

* add ui elements to index

* add missing migrations

* add ressource route

* add new model to admin

* reorder fields

* format timestamp

* make title linked

* reduce migrations to 1

* fix merge

* fix js style

* add model to ruleset
2022-11-10 12:20:06 +11:00

71 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']
else:
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']
else:
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)