mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Converted circuits import views to new scheme
This commit is contained in:
@ -8,8 +8,8 @@ from extras.forms import CustomFieldForm, CustomFieldBulkEditForm, CustomFieldFi
|
|||||||
from tenancy.forms import TenancyForm
|
from tenancy.forms import TenancyForm
|
||||||
from tenancy.models import Tenant
|
from tenancy.models import Tenant
|
||||||
from utilities.forms import (
|
from utilities.forms import (
|
||||||
APISelect, BootstrapMixin, BulkImportForm, ChainedFieldsMixin, ChainedModelChoiceField, CommentField, CSVDataField,
|
APISelect, BootstrapMixin, ChainedFieldsMixin, ChainedModelChoiceField, CommentField, FilterChoiceField,
|
||||||
FilterChoiceField, Livesearch, SmallTextarea, SlugField,
|
SmallTextarea, SlugField,
|
||||||
)
|
)
|
||||||
|
|
||||||
from .models import Circuit, CircuitTermination, CircuitType, Provider
|
from .models import Circuit, CircuitTermination, CircuitType, Provider
|
||||||
@ -39,15 +39,17 @@ class ProviderForm(BootstrapMixin, CustomFieldForm):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class ProviderFromCSVForm(forms.ModelForm):
|
class ProviderCSVForm(forms.ModelForm):
|
||||||
|
slug = SlugField()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Provider
|
model = Provider
|
||||||
fields = ['name', 'slug', 'asn', 'account', 'portal_url']
|
fields = ['name', 'slug', 'asn', 'account', 'portal_url', 'comments']
|
||||||
|
help_texts = {
|
||||||
|
'name': 'Provider name',
|
||||||
class ProviderImportForm(BootstrapMixin, BulkImportForm):
|
'asn': 'Autonomous system number',
|
||||||
csv = CSVDataField(csv_form=ProviderFromCSVForm)
|
'comments': 'Free-form comments'
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class ProviderBulkEditForm(BootstrapMixin, CustomFieldBulkEditForm):
|
class ProviderBulkEditForm(BootstrapMixin, CustomFieldBulkEditForm):
|
||||||
@ -102,21 +104,36 @@ class CircuitForm(BootstrapMixin, TenancyForm, CustomFieldForm):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class CircuitFromCSVForm(forms.ModelForm):
|
class CircuitCSVForm(forms.ModelForm):
|
||||||
provider = forms.ModelChoiceField(Provider.objects.all(), to_field_name='name',
|
provider = forms.ModelChoiceField(
|
||||||
error_messages={'invalid_choice': 'Provider not found.'})
|
queryset=Provider.objects.all(),
|
||||||
type = forms.ModelChoiceField(CircuitType.objects.all(), to_field_name='name',
|
to_field_name='name',
|
||||||
error_messages={'invalid_choice': 'Invalid circuit type.'})
|
help_text='Name of parent provider',
|
||||||
tenant = forms.ModelChoiceField(Tenant.objects.all(), to_field_name='name', required=False,
|
error_messages={
|
||||||
error_messages={'invalid_choice': 'Tenant not found.'})
|
'invalid_choice': 'Provider not found.'
|
||||||
|
}
|
||||||
|
)
|
||||||
|
type = forms.ModelChoiceField(
|
||||||
|
queryset=CircuitType.objects.all(),
|
||||||
|
to_field_name='name',
|
||||||
|
help_text='Name of assigned tenant',
|
||||||
|
error_messages={
|
||||||
|
'invalid_choice': 'Invalid circuit type.'
|
||||||
|
}
|
||||||
|
)
|
||||||
|
tenant = forms.ModelChoiceField(
|
||||||
|
queryset=Tenant.objects.all(),
|
||||||
|
required=False,
|
||||||
|
to_field_name='name',
|
||||||
|
help_text='Name of circuit type',
|
||||||
|
error_messages={
|
||||||
|
'invalid_choice': 'Tenant not found.'
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Circuit
|
model = Circuit
|
||||||
fields = ['cid', 'provider', 'type', 'tenant', 'install_date', 'commit_rate', 'description']
|
fields = ['cid', 'provider', 'type', 'tenant', 'install_date', 'commit_rate', 'description', 'comments']
|
||||||
|
|
||||||
|
|
||||||
class CircuitImportForm(BootstrapMixin, BulkImportForm):
|
|
||||||
csv = CSVDataField(csv_form=CircuitFromCSVForm)
|
|
||||||
|
|
||||||
|
|
||||||
class CircuitBulkEditForm(BootstrapMixin, CustomFieldBulkEditForm):
|
class CircuitBulkEditForm(BootstrapMixin, CustomFieldBulkEditForm):
|
||||||
|
@ -12,7 +12,7 @@ from django.views.generic import View
|
|||||||
from extras.models import Graph, GRAPH_TYPE_PROVIDER
|
from extras.models import Graph, GRAPH_TYPE_PROVIDER
|
||||||
from utilities.forms import ConfirmationForm
|
from utilities.forms import ConfirmationForm
|
||||||
from utilities.views import (
|
from utilities.views import (
|
||||||
BulkDeleteView, BulkEditView, BulkImportView, ObjectDeleteView, ObjectEditView, ObjectListView,
|
BulkDeleteView, BulkEditView, BulkImportView2, ObjectDeleteView, ObjectEditView, ObjectListView,
|
||||||
)
|
)
|
||||||
from . import filters, forms, tables
|
from . import filters, forms, tables
|
||||||
from .models import Circuit, CircuitTermination, CircuitType, Provider, TERM_SIDE_A, TERM_SIDE_Z
|
from .models import Circuit, CircuitTermination, CircuitType, Provider, TERM_SIDE_A, TERM_SIDE_Z
|
||||||
@ -63,11 +63,10 @@ class ProviderDeleteView(PermissionRequiredMixin, ObjectDeleteView):
|
|||||||
default_return_url = 'circuits:provider_list'
|
default_return_url = 'circuits:provider_list'
|
||||||
|
|
||||||
|
|
||||||
class ProviderBulkImportView(PermissionRequiredMixin, BulkImportView):
|
class ProviderBulkImportView(PermissionRequiredMixin, BulkImportView2):
|
||||||
permission_required = 'circuits.add_provider'
|
permission_required = 'circuits.add_provider'
|
||||||
form = forms.ProviderImportForm
|
model_form = forms.ProviderCSVForm
|
||||||
table = tables.ProviderTable
|
table = tables.ProviderTable
|
||||||
template_name = 'circuits/provider_import.html'
|
|
||||||
default_return_url = 'circuits:provider_list'
|
default_return_url = 'circuits:provider_list'
|
||||||
|
|
||||||
|
|
||||||
@ -161,11 +160,10 @@ class CircuitDeleteView(PermissionRequiredMixin, ObjectDeleteView):
|
|||||||
default_return_url = 'circuits:circuit_list'
|
default_return_url = 'circuits:circuit_list'
|
||||||
|
|
||||||
|
|
||||||
class CircuitBulkImportView(PermissionRequiredMixin, BulkImportView):
|
class CircuitBulkImportView(PermissionRequiredMixin, BulkImportView2):
|
||||||
permission_required = 'circuits.add_circuit'
|
permission_required = 'circuits.add_circuit'
|
||||||
form = forms.CircuitImportForm
|
model_form = forms.CircuitCSVForm
|
||||||
table = tables.CircuitTable
|
table = tables.CircuitTable
|
||||||
template_name = 'circuits/circuit_import.html'
|
|
||||||
default_return_url = 'circuits:circuit_list'
|
default_return_url = 'circuits:circuit_list'
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,55 +0,0 @@
|
|||||||
{% extends 'utilities/obj_import.html' %}
|
|
||||||
|
|
||||||
{% block title %}Circuit Import{% endblock %}
|
|
||||||
|
|
||||||
{% block instructions %}
|
|
||||||
<h4>CSV Format</h4>
|
|
||||||
<table class="table">
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th>Field</th>
|
|
||||||
<th>Description</th>
|
|
||||||
<th>Example</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
<tr>
|
|
||||||
<td>Circuit ID</td>
|
|
||||||
<td>Alphanumeric circuit identifier</td>
|
|
||||||
<td>IC-603122</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>Provider</td>
|
|
||||||
<td>Name of circuit provider</td>
|
|
||||||
<td>TeliaSonera</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>Type</td>
|
|
||||||
<td>Circuit type</td>
|
|
||||||
<td>Transit</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>Tenant</td>
|
|
||||||
<td>Name of tenant (optional)</td>
|
|
||||||
<td>Strickland Propane</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>Install Date</td>
|
|
||||||
<td>Date in YYYY-MM-DD format (optional)</td>
|
|
||||||
<td>2016-02-23</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>Commit rate</td>
|
|
||||||
<td>Commited rate in Kbps (optional)</td>
|
|
||||||
<td>2000</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>Description</td>
|
|
||||||
<td>Short description (optional)</td>
|
|
||||||
<td>Primary for voice</td>
|
|
||||||
</tr>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
<h4>Example</h4>
|
|
||||||
<pre>IC-603122,TeliaSonera,Transit,Strickland Propane,2016-02-23,2000,Primary for voice</pre>
|
|
||||||
{% endblock %}
|
|
@ -1,45 +0,0 @@
|
|||||||
{% extends 'utilities/obj_import.html' %}
|
|
||||||
|
|
||||||
{% block title %}Provider Import{% endblock %}
|
|
||||||
|
|
||||||
{% block instructions %}
|
|
||||||
<h4>CSV Format</h4>
|
|
||||||
<table class="table">
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th>Field</th>
|
|
||||||
<th>Description</th>
|
|
||||||
<th>Example</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
<tr>
|
|
||||||
<td>Name</td>
|
|
||||||
<td>Provider's proper name</td>
|
|
||||||
<td>Level 3</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>Slug</td>
|
|
||||||
<td>URL-friendly name</td>
|
|
||||||
<td>level3</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>ASN</td>
|
|
||||||
<td>Autonomous system number (optional)</td>
|
|
||||||
<td>3356</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>Account</td>
|
|
||||||
<td>Account number (optional)</td>
|
|
||||||
<td>08931544</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>Portal URL</td>
|
|
||||||
<td>Customer service portal URL (optional)</td>
|
|
||||||
<td>https://mylevel3.net</td>
|
|
||||||
</tr>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
<h4>Example</h4>
|
|
||||||
<pre>Level 3,level3,3356,08931544,https://mylevel3.net</pre>
|
|
||||||
{% endblock %}
|
|
@ -1,3 +0,0 @@
|
|||||||
{% extends 'utilities/obj_import.html' %}
|
|
||||||
|
|
||||||
{% block title %}Tenant Import{% endblock %}
|
|
@ -1,8 +1,9 @@
|
|||||||
{% extends '_base.html' %}
|
{% extends '_base.html' %}
|
||||||
|
{% load helpers %}
|
||||||
{% load form_helpers %}
|
{% load form_helpers %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h1>{% block title %}{% endblock %}</h1>
|
<h1>{% block title %}{{ obj_type|bettertitle }} Import{% endblock %}</h1>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-6">
|
<div class="col-md-6">
|
||||||
{% if form.non_field_errors %}
|
{% if form.non_field_errors %}
|
||||||
@ -40,7 +41,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td><code>{{ name }}</code></td>
|
<td><code>{{ name }}</code></td>
|
||||||
<td>{% if field.required %}<i class="glyphicon glyphicon-ok" title="Required"></i>{% endif %}</td>
|
<td>{% if field.required %}<i class="glyphicon glyphicon-ok" title="Required"></i>{% endif %}</td>
|
||||||
<td>{{ field.help_text }}</td>
|
<td>{{ field.help_text|default:field.label }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
|
@ -36,10 +36,12 @@ class TenantForm(BootstrapMixin, CustomFieldForm):
|
|||||||
|
|
||||||
|
|
||||||
class TenantCSVForm(forms.ModelForm):
|
class TenantCSVForm(forms.ModelForm):
|
||||||
|
slug = SlugField()
|
||||||
group = forms.ModelChoiceField(
|
group = forms.ModelChoiceField(
|
||||||
queryset=TenantGroup.objects.all(),
|
queryset=TenantGroup.objects.all(),
|
||||||
required=False,
|
required=False,
|
||||||
to_field_name='name',
|
to_field_name='name',
|
||||||
|
help_text='Name of parent group',
|
||||||
error_messages={
|
error_messages={
|
||||||
'invalid_choice': 'Group not found.'
|
'invalid_choice': 'Group not found.'
|
||||||
}
|
}
|
||||||
@ -48,6 +50,10 @@ class TenantCSVForm(forms.ModelForm):
|
|||||||
class Meta:
|
class Meta:
|
||||||
model = Tenant
|
model = Tenant
|
||||||
fields = ['name', 'slug', 'group', 'description', 'comments']
|
fields = ['name', 'slug', 'group', 'description', 'comments']
|
||||||
|
help_texts = {
|
||||||
|
'name': 'Tenant name',
|
||||||
|
'comments': 'Free-form comments'
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class TenantBulkEditForm(BootstrapMixin, CustomFieldBulkEditForm):
|
class TenantBulkEditForm(BootstrapMixin, CustomFieldBulkEditForm):
|
||||||
|
@ -99,7 +99,6 @@ class TenantBulkImportView(PermissionRequiredMixin, BulkImportView2):
|
|||||||
permission_required = 'tenancy.add_tenant'
|
permission_required = 'tenancy.add_tenant'
|
||||||
model_form = forms.TenantCSVForm
|
model_form = forms.TenantCSVForm
|
||||||
table = tables.TenantTable
|
table = tables.TenantTable
|
||||||
template_name = 'tenancy/tenant_import.html'
|
|
||||||
default_return_url = 'tenancy:tenant_list'
|
default_return_url = 'tenancy:tenant_list'
|
||||||
|
|
||||||
|
|
||||||
|
@ -276,7 +276,9 @@ class CSVDataField2(forms.CharField):
|
|||||||
if not self.initial:
|
if not self.initial:
|
||||||
self.initial = ','.join(required_fields) + '\n'
|
self.initial = ','.join(required_fields) + '\n'
|
||||||
if not self.help_text:
|
if not self.help_text:
|
||||||
self.help_text = 'Enter one line per record. Use commas to separate values.'
|
self.help_text = 'Enter the list of column headers followed by one line per record to be imported. Use ' \
|
||||||
|
'commas to separate values. Multi-line data and values containing commas may be wrapped ' \
|
||||||
|
'in double quotes.'
|
||||||
|
|
||||||
def to_python(self, value):
|
def to_python(self, value):
|
||||||
|
|
||||||
|
@ -435,8 +435,8 @@ class BulkImportView2(View):
|
|||||||
"""
|
"""
|
||||||
model_form = None
|
model_form = None
|
||||||
table = None
|
table = None
|
||||||
template_name = None
|
|
||||||
default_return_url = None
|
default_return_url = None
|
||||||
|
template_name = 'utilities/obj_import.html'
|
||||||
|
|
||||||
def _import_form(self, *args, **kwargs):
|
def _import_form(self, *args, **kwargs):
|
||||||
|
|
||||||
@ -453,6 +453,7 @@ class BulkImportView2(View):
|
|||||||
return render(request, self.template_name, {
|
return render(request, self.template_name, {
|
||||||
'form': self._import_form(),
|
'form': self._import_form(),
|
||||||
'fields': self.model_form().fields,
|
'fields': self.model_form().fields,
|
||||||
|
'obj_type': self.model_form._meta.model._meta.verbose_name,
|
||||||
'return_url': self.default_return_url,
|
'return_url': self.default_return_url,
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -496,6 +497,7 @@ class BulkImportView2(View):
|
|||||||
return render(request, self.template_name, {
|
return render(request, self.template_name, {
|
||||||
'form': form,
|
'form': form,
|
||||||
'fields': self.model_form().fields,
|
'fields': self.model_form().fields,
|
||||||
|
'obj_type': self.model_form._meta.model._meta.verbose_name,
|
||||||
'return_url': self.default_return_url,
|
'return_url': self.default_return_url,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user