mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Merge branch 'develop' into api2
Conflicts: netbox/dcim/api/serializers.py netbox/dcim/api/urls.py netbox/dcim/api/views.py netbox/dcim/filters.py
This commit is contained in:
@@ -169,6 +169,27 @@ class SelectWithDisabled(forms.Select):
|
||||
force_text(option_label))
|
||||
|
||||
|
||||
class ArrayFieldSelectMultiple(SelectWithDisabled, forms.SelectMultiple):
|
||||
"""
|
||||
MultiSelect widgets for a SimpleArrayField. Choices must be populated on the widget.
|
||||
"""
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.delimiter = kwargs.pop('delimiter', ',')
|
||||
super(ArrayFieldSelectMultiple, self).__init__(*args, **kwargs)
|
||||
|
||||
def render_options(self, selected_choices):
|
||||
# Split the delimited string of values into a list
|
||||
if selected_choices:
|
||||
selected_choices = selected_choices.split(self.delimiter)
|
||||
return super(ArrayFieldSelectMultiple, self).render_options(selected_choices)
|
||||
|
||||
def value_from_datadict(self, data, files, name):
|
||||
# Condense the list of selected choices into a delimited string
|
||||
data = super(ArrayFieldSelectMultiple, self).value_from_datadict(data, files, name)
|
||||
return self.delimiter.join(data)
|
||||
|
||||
|
||||
class APISelect(SelectWithDisabled):
|
||||
"""
|
||||
A select widget populated via an API call
|
||||
|
@@ -27,6 +27,14 @@ def getlist(value, arg):
|
||||
return value.getlist(arg)
|
||||
|
||||
|
||||
@register.filter
|
||||
def getkey(value, key):
|
||||
"""
|
||||
Return a dictionary item specified by key
|
||||
"""
|
||||
return value[key]
|
||||
|
||||
|
||||
@register.filter(is_safe=True)
|
||||
def gfm(value):
|
||||
"""
|
||||
|
@@ -145,9 +145,9 @@ class ObjectEditView(View):
|
||||
return get_object_or_404(self.model, pk=kwargs['pk'])
|
||||
return self.model()
|
||||
|
||||
def alter_obj(self, obj, args, kwargs):
|
||||
def alter_obj(self, obj, request, url_args, url_kwargs):
|
||||
# Allow views to add extra info to an object before it is processed. For example, a parent object can be defined
|
||||
# given some parameter from the request URI.
|
||||
# given some parameter from the request URL.
|
||||
return obj
|
||||
|
||||
def get_return_url(self, obj):
|
||||
@@ -159,7 +159,7 @@ class ObjectEditView(View):
|
||||
def get(self, request, *args, **kwargs):
|
||||
|
||||
obj = self.get_object(kwargs)
|
||||
obj = self.alter_obj(obj, args, kwargs)
|
||||
obj = self.alter_obj(obj, request, args, kwargs)
|
||||
initial_data = {k: request.GET[k] for k in self.fields_initial if k in request.GET}
|
||||
form = self.form_class(instance=obj, initial=initial_data)
|
||||
|
||||
@@ -173,7 +173,7 @@ class ObjectEditView(View):
|
||||
def post(self, request, *args, **kwargs):
|
||||
|
||||
obj = self.get_object(kwargs)
|
||||
obj = self.alter_obj(obj, args, kwargs)
|
||||
obj = self.alter_obj(obj, request, args, kwargs)
|
||||
form = self.form_class(request.POST, instance=obj)
|
||||
|
||||
if form.is_valid():
|
||||
|
Reference in New Issue
Block a user