mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
* Initial work on #8248 * Add tests * Fix tests * Add feature query for bookmarks * Add BookmarksWidget * Correct generic relation name * Add docs for bookmarks * Remove inheritance from ChangeLoggedModel
This commit is contained in:
15
netbox/utilities/templates/buttons/bookmark.html
Normal file
15
netbox/utilities/templates/buttons/bookmark.html
Normal file
@@ -0,0 +1,15 @@
|
||||
<form action="{{ form_url }}?return_url={{ return_url }}" method="post">
|
||||
{% csrf_token %}
|
||||
{% for field, value in form_data.items %}
|
||||
<input type="hidden" name="{{ field }}" value="{{ value }}" />
|
||||
{% endfor %}
|
||||
{% if bookmark %}
|
||||
<button type="submit" class="btn btn-sm btn-info">
|
||||
<i class="mdi mdi-bookmark-minus"></i> Unbookmark
|
||||
</button>
|
||||
{% else %}
|
||||
<button type="submit" class="btn btn-sm btn-info">
|
||||
<i class="mdi mdi-bookmark-check"></i> Bookmark
|
||||
</button>
|
||||
{% endif %}
|
||||
</form>
|
@@ -2,11 +2,12 @@ from django import template
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.urls import NoReverseMatch, reverse
|
||||
|
||||
from extras.models import ExportTemplate
|
||||
from extras.models import Bookmark, ExportTemplate
|
||||
from utilities.utils import get_viewname, prepare_cloned_fields
|
||||
|
||||
__all__ = (
|
||||
'add_button',
|
||||
'bookmark_button',
|
||||
'bulk_delete_button',
|
||||
'bulk_edit_button',
|
||||
'clone_button',
|
||||
@@ -24,6 +25,37 @@ register = template.Library()
|
||||
# Instance buttons
|
||||
#
|
||||
|
||||
@register.inclusion_tag('buttons/bookmark.html', takes_context=True)
|
||||
def bookmark_button(context, instance):
|
||||
# Check if this user has already bookmarked the object
|
||||
content_type = ContentType.objects.get_for_model(instance)
|
||||
bookmark = Bookmark.objects.filter(
|
||||
object_type=content_type,
|
||||
object_id=instance.pk,
|
||||
user=context['request'].user
|
||||
).first()
|
||||
|
||||
# Compile form URL & data
|
||||
if bookmark:
|
||||
form_url = reverse('extras:bookmark_delete', kwargs={'pk': bookmark.pk})
|
||||
form_data = {
|
||||
'confirm': 'true',
|
||||
}
|
||||
else:
|
||||
form_url = reverse('extras:bookmark_add')
|
||||
form_data = {
|
||||
'object_type': content_type.pk,
|
||||
'object_id': instance.pk,
|
||||
}
|
||||
|
||||
return {
|
||||
'bookmark': bookmark,
|
||||
'form_url': form_url,
|
||||
'form_data': form_data,
|
||||
'return_url': instance.get_absolute_url(),
|
||||
}
|
||||
|
||||
|
||||
@register.inclusion_tag('buttons/clone.html')
|
||||
def clone_button(instance):
|
||||
url = reverse(get_viewname(instance, 'add'))
|
||||
|
Reference in New Issue
Block a user