mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-26 01:06:11 -06:00
Add BookmarksWidget
This commit is contained in:
parent
5f5ac03f68
commit
1fee71d67d
@ -79,6 +79,21 @@ class CustomLinkButtonClassChoices(ButtonColorChoices):
|
|||||||
(LINK, 'Link'),
|
(LINK, 'Link'),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# Bookmarks
|
||||||
|
#
|
||||||
|
|
||||||
|
class BookmarkOrderingChoices(ChoiceSet):
|
||||||
|
|
||||||
|
ORDERING_NEWEST = '-created'
|
||||||
|
ORDERING_OLDEST = 'created'
|
||||||
|
|
||||||
|
CHOICES = (
|
||||||
|
(ORDERING_NEWEST, 'Newest'),
|
||||||
|
(ORDERING_OLDEST, 'Oldest'),
|
||||||
|
)
|
||||||
|
|
||||||
#
|
#
|
||||||
# ObjectChanges
|
# ObjectChanges
|
||||||
#
|
#
|
||||||
@ -98,7 +113,7 @@ class ObjectChangeActionChoices(ChoiceSet):
|
|||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Jounral entries
|
# Journal entries
|
||||||
#
|
#
|
||||||
|
|
||||||
class JournalEntryKindChoices(ChoiceSet):
|
class JournalEntryKindChoices(ChoiceSet):
|
||||||
|
@ -15,6 +15,7 @@ from django.template.loader import render_to_string
|
|||||||
from django.urls import NoReverseMatch, resolve, reverse
|
from django.urls import NoReverseMatch, resolve, reverse
|
||||||
from django.utils.translation import gettext as _
|
from django.utils.translation import gettext as _
|
||||||
|
|
||||||
|
from extras.choices import BookmarkOrderingChoices
|
||||||
from extras.utils import FeatureQuery
|
from extras.utils import FeatureQuery
|
||||||
from utilities.forms import BootstrapMixin
|
from utilities.forms import BootstrapMixin
|
||||||
from utilities.permissions import get_permission_for_model
|
from utilities.permissions import get_permission_for_model
|
||||||
@ -23,6 +24,7 @@ from utilities.utils import content_type_identifier, content_type_name, get_view
|
|||||||
from .utils import register_widget
|
from .utils import register_widget
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
|
'BookmarksWidget',
|
||||||
'DashboardWidget',
|
'DashboardWidget',
|
||||||
'NoteWidget',
|
'NoteWidget',
|
||||||
'ObjectCountsWidget',
|
'ObjectCountsWidget',
|
||||||
@ -318,3 +320,42 @@ class RSSFeedWidget(DashboardWidget):
|
|||||||
return {
|
return {
|
||||||
'feed': feed,
|
'feed': feed,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@register_widget
|
||||||
|
class BookmarksWidget(DashboardWidget):
|
||||||
|
default_title = _('Bookmarks')
|
||||||
|
default_config = {
|
||||||
|
'order_by': BookmarkOrderingChoices.ORDERING_NEWEST,
|
||||||
|
}
|
||||||
|
description = _('Show your personal bookmarks')
|
||||||
|
template_name = 'extras/dashboard/widgets/bookmarks.html'
|
||||||
|
|
||||||
|
class ConfigForm(WidgetConfigForm):
|
||||||
|
object_types = forms.MultipleChoiceField(
|
||||||
|
# TODO: Restrict the choices by FeatureQuery('bookmarks')
|
||||||
|
choices=get_content_type_labels,
|
||||||
|
required=False
|
||||||
|
)
|
||||||
|
order_by = forms.ChoiceField(
|
||||||
|
choices=BookmarkOrderingChoices
|
||||||
|
)
|
||||||
|
max_items = forms.IntegerField(
|
||||||
|
min_value=1,
|
||||||
|
required=False
|
||||||
|
)
|
||||||
|
|
||||||
|
def render(self, request):
|
||||||
|
from extras.models import Bookmark
|
||||||
|
|
||||||
|
bookmarks = Bookmark.objects.filter(user=request.user).order_by(self.config['order_by'])
|
||||||
|
if object_types := self.config.get('object_types'):
|
||||||
|
models = get_models_from_content_types(object_types)
|
||||||
|
conent_types = ContentType.objects.get_for_models(*models).values()
|
||||||
|
bookmarks = bookmarks.filter(object_type__in=conent_types)
|
||||||
|
if max_items := self.config.get('max_items'):
|
||||||
|
bookmarks = bookmarks[:max_items]
|
||||||
|
|
||||||
|
return render_to_string(self.template_name, {
|
||||||
|
'bookmarks': bookmarks,
|
||||||
|
})
|
||||||
|
9
netbox/templates/extras/dashboard/widgets/bookmarks.html
Normal file
9
netbox/templates/extras/dashboard/widgets/bookmarks.html
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
{% if bookmarks %}
|
||||||
|
<div class="list-group list-group-flush">
|
||||||
|
{% for bookmark in bookmarks %}
|
||||||
|
<a href="{{ bookmark.object.get_absolute_url }}" class="list-group-item list-group-item-action">
|
||||||
|
{{ bookmark.object }}
|
||||||
|
</a>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
Loading…
Reference in New Issue
Block a user