mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
#12795: Complete support for description field on custom Group model
This commit is contained in:
@ -17,6 +17,10 @@
|
||||
<th scope="row">{% trans "Name" %}</th>
|
||||
<td>{{ object.name }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">{% trans "Description" %}</th>
|
||||
<td>{{ object.description|placeholder }}</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -29,7 +29,7 @@ class GroupSerializer(ValidatedModelSerializer):
|
||||
class Meta:
|
||||
model = Group
|
||||
fields = ('id', 'url', 'display', 'name', 'permissions', 'user_count')
|
||||
brief_fields = ('id', 'url', 'display', 'name')
|
||||
brief_fields = ('id', 'url', 'display', 'name', 'description')
|
||||
|
||||
|
||||
class UserSerializer(ValidatedModelSerializer):
|
||||
|
@ -40,7 +40,10 @@ class GroupFilterSet(BaseFilterSet):
|
||||
def search(self, queryset, name, value):
|
||||
if not value.strip():
|
||||
return queryset
|
||||
return queryset.filter(name__icontains=value)
|
||||
return queryset.filter(
|
||||
Q(name__icontains=value) |
|
||||
Q(description__icontains=value)
|
||||
)
|
||||
|
||||
|
||||
class UserFilterSet(BaseFilterSet):
|
||||
|
@ -10,6 +10,7 @@ from utilities.forms.rendering import FieldSet
|
||||
from utilities.forms.widgets import BulkEditNullBooleanSelect, DateTimePicker
|
||||
|
||||
__all__ = (
|
||||
'GroupBulkEditForm',
|
||||
'ObjectPermissionBulkEditForm',
|
||||
'UserBulkEditForm',
|
||||
'TokenBulkEditForm',
|
||||
@ -54,6 +55,24 @@ class UserBulkEditForm(forms.Form):
|
||||
nullable_fields = ('first_name', 'last_name')
|
||||
|
||||
|
||||
class GroupBulkEditForm(forms.Form):
|
||||
pk = forms.ModelMultipleChoiceField(
|
||||
queryset=Group.objects.all(),
|
||||
widget=forms.MultipleHiddenInput
|
||||
)
|
||||
description = forms.CharField(
|
||||
label=_('Description'),
|
||||
max_length=200,
|
||||
required=False
|
||||
)
|
||||
|
||||
model = User
|
||||
fieldsets = (
|
||||
FieldSet('description'),
|
||||
)
|
||||
nullable_fields = ('description',)
|
||||
|
||||
|
||||
class ObjectPermissionBulkEditForm(forms.Form):
|
||||
pk = forms.ModelMultipleChoiceField(
|
||||
queryset=ObjectPermission.objects.all(),
|
||||
|
@ -15,9 +15,7 @@ class GroupImportForm(CSVModelForm):
|
||||
|
||||
class Meta:
|
||||
model = Group
|
||||
fields = (
|
||||
'name',
|
||||
)
|
||||
fields = ('name', 'description')
|
||||
|
||||
|
||||
class UserImportForm(CSVModelForm):
|
||||
|
@ -19,12 +19,12 @@ from utilities.forms.widgets import DateTimePicker
|
||||
from utilities.permissions import qs_filter_from_constraints
|
||||
|
||||
__all__ = (
|
||||
'UserTokenForm',
|
||||
'GroupForm',
|
||||
'ObjectPermissionForm',
|
||||
'TokenForm',
|
||||
'UserConfigForm',
|
||||
'UserForm',
|
||||
'UserTokenForm',
|
||||
'TokenForm',
|
||||
)
|
||||
|
||||
@ -237,7 +237,7 @@ class GroupForm(forms.ModelForm):
|
||||
)
|
||||
|
||||
fieldsets = (
|
||||
FieldSet('name'),
|
||||
FieldSet('name', 'description'),
|
||||
FieldSet('users', name=_('Users')),
|
||||
FieldSet('object_permissions', name=_('Permissions')),
|
||||
)
|
||||
@ -245,7 +245,7 @@ class GroupForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Group
|
||||
fields = [
|
||||
'name', 'users', 'object_permissions',
|
||||
'name', 'description', 'users', 'object_permissions',
|
||||
]
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
|
@ -68,10 +68,7 @@ class GroupTable(NetBoxTable):
|
||||
|
||||
class Meta(NetBoxTable.Meta):
|
||||
model = Group
|
||||
fields = (
|
||||
'pk', 'id', 'name', 'users_count',
|
||||
)
|
||||
default_columns = ('pk', 'name', 'users_count', )
|
||||
fields = ('pk', 'id', 'name', 'users_count', 'description')
|
||||
|
||||
|
||||
class ObjectPermissionTable(NetBoxTable):
|
||||
|
@ -66,6 +66,7 @@ class GroupTestCase(
|
||||
ViewTestCases.DeleteObjectViewTestCase,
|
||||
ViewTestCases.ListObjectsViewTestCase,
|
||||
ViewTestCases.BulkImportObjectsViewTestCase,
|
||||
ViewTestCases.BulkEditObjectsViewTestCase,
|
||||
ViewTestCases.BulkDeleteObjectsViewTestCase,
|
||||
):
|
||||
model = Group
|
||||
@ -99,6 +100,10 @@ class GroupTestCase(
|
||||
f"{groups[2].pk},group9",
|
||||
)
|
||||
|
||||
cls.bulk_edit_data = {
|
||||
'description': 'New description',
|
||||
}
|
||||
|
||||
|
||||
class ObjectPermissionTestCase(
|
||||
ViewTestCases.GetObjectViewTestCase,
|
||||
|
@ -25,6 +25,7 @@ urlpatterns = [
|
||||
# Groups
|
||||
path('groups/', views.GroupListView.as_view(), name='group_list'),
|
||||
path('groups/add/', views.GroupEditView.as_view(), name='group_add'),
|
||||
path('groups/edit/', views.GroupBulkEditView.as_view(), name='group_bulk_edit'),
|
||||
path('groups/import/', views.GroupBulkImportView.as_view(), name='group_import'),
|
||||
path('groups/delete/', views.GroupBulkDeleteView.as_view(), name='group_bulk_delete'),
|
||||
path('groups/<int:pk>/', include(get_model_urls('users', 'group'))),
|
||||
|
@ -138,6 +138,13 @@ class GroupBulkImportView(generic.BulkImportView):
|
||||
model_form = forms.GroupImportForm
|
||||
|
||||
|
||||
class GroupBulkEditView(generic.BulkEditView):
|
||||
queryset = Group.objects.all()
|
||||
filterset = filtersets.GroupFilterSet
|
||||
table = tables.GroupTable
|
||||
form = forms.GroupBulkEditForm
|
||||
|
||||
|
||||
class GroupBulkDeleteView(generic.BulkDeleteView):
|
||||
queryset = Group.objects.annotate(users_count=Count('user')).order_by('name')
|
||||
filterset = filtersets.GroupFilterSet
|
||||
|
Reference in New Issue
Block a user