Added support for group assignment during VLAN import

This commit is contained in:
Jeremy Stretch 2016-07-18 11:59:55 -04:00
parent d201dad535
commit cb4643d810
2 changed files with 9 additions and 2 deletions

View File

@ -503,13 +503,15 @@ class VLANForm(forms.ModelForm, BootstrapMixin):
class VLANFromCSVForm(forms.ModelForm): class VLANFromCSVForm(forms.ModelForm):
site = forms.ModelChoiceField(queryset=Site.objects.all(), to_field_name='name', site = forms.ModelChoiceField(queryset=Site.objects.all(), to_field_name='name',
error_messages={'invalid_choice': 'Device not found.'}) error_messages={'invalid_choice': 'Device not found.'})
group = forms.ModelChoiceField(queryset=VLANGroup.objects.all(), required=False, to_field_name='name',
error_messages={'invalid_choice': 'VLAN group not found.'})
status_name = forms.ChoiceField(choices=[(s[1], s[0]) for s in VLAN_STATUS_CHOICES]) status_name = forms.ChoiceField(choices=[(s[1], s[0]) for s in VLAN_STATUS_CHOICES])
role = forms.ModelChoiceField(queryset=Role.objects.all(), required=False, to_field_name='name', role = forms.ModelChoiceField(queryset=Role.objects.all(), required=False, to_field_name='name',
error_messages={'invalid_choice': 'Invalid role.'}) error_messages={'invalid_choice': 'Invalid role.'})
class Meta: class Meta:
model = VLAN model = VLAN
fields = ['site', 'vid', 'name', 'status_name', 'role'] fields = ['site', 'group', 'vid', 'name', 'status_name', 'role']
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
m = super(VLANFromCSVForm, self).save(commit=False) m = super(VLANFromCSVForm, self).save(commit=False)

View File

@ -33,6 +33,11 @@
<td>Name of assigned site</td> <td>Name of assigned site</td>
<td>LAS2</td> <td>LAS2</td>
</tr> </tr>
<tr>
<td>Group</td>
<td>Name of VLAN group (optional)</td>
<td>Backend Network</td>
</tr>
<tr> <tr>
<td>ID</td> <td>ID</td>
<td>Configured VLAN ID</td> <td>Configured VLAN ID</td>
@ -56,7 +61,7 @@
</tbody> </tbody>
</table> </table>
<h4>Example</h4> <h4>Example</h4>
<pre>LAS2,1400,Cameras,Active,Security</pre> <pre>LAS2,Backend Network,1400,Cameras,Active,Security</pre>
</div> </div>
</div> </div>
{% endblock %} {% endblock %}