-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CSV importer for hosting provider (#296)
* Improved and documented pytests * WIP: Reading and validating a csv file * Fixed function call and provided some todo's * WIP: Included bulk import files, creating a csv upload page * Expanded the base importer to allow ip ranges * WIP: Implemented an option to import csv files * Update tests so we have our failing examples * Add missing pipffile.lock * Get CSV importer parsing info as intended Add tests and refactor importer * Pass a type, not a value in the method signature * Add tests and code for import preview in admin * Add indication of ip range length before import * Update method signature for updating tests * Update form to use new CSV importer * Add __init__ file for CSV Importer * Update the importer to work with hosting provider objects not ids * Add tests to check that the importer saves to db * Update flow for import show imported networks * Comment out unimplemented "replace" feature * update importer to use sightly more idiomatic python * Move upload CSV option to admin section So only admins can see it and use it Co-authored-by: Roald Teunissen <[email protected]>
- Loading branch information
1 parent
95e0abc
commit ef7a43a
Showing
19 changed files
with
1,381 additions
and
330 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
{% extends "admin/base_site.html" %} | ||
{% load i18n static %} | ||
|
||
{% block pretitle %} | ||
<h1>Import IP Ranges from a CSV file for {{ provider }}</h1> | ||
|
||
|
||
{% endblock %} | ||
|
||
{% block content %} | ||
|
||
{% if ip_ranges %} | ||
|
||
<hr / style="margin-top:3rem; margin-bottom:3rem;"> | ||
|
||
<h2>IP Range Import Preview</h2> | ||
|
||
<p>The following IP ranges would be imported for <strong>{{ provider }}</strong>:</p> | ||
|
||
<table> | ||
<th>IP Range start</th><th>Ip Range End</th><th>Created / Updated</th><th>Length</th> | ||
|
||
{% for ip in ip_ranges.green_ips %} | ||
|
||
<tr> | ||
<td>{{ ip.ip_start }}</td> | ||
<td>{{ ip.ip_end }}</td> | ||
<td> | ||
{% if ip.id %} | ||
Updated | ||
{% else %} | ||
Created | ||
{% endif %} | ||
</td> | ||
<td> | ||
{{ ip.ip_range_length }} | ||
</td> | ||
</tr> | ||
|
||
{% endfor %} | ||
</table> | ||
|
||
<h2>AS Import Preview</h2> | ||
|
||
<p>The following AS Numbers ranges would be imported for <strong>{{ provider }}</strong>:</p> | ||
|
||
<table> | ||
<th>AS number</th><th>Created / Updated</th> | ||
|
||
{% for as in ip_ranges.green_asns %} | ||
|
||
<tr> | ||
<td>{{ as.asn }}</td> | ||
<td> | ||
{% if as.id %} | ||
Updated | ||
{% else %} | ||
Created | ||
{% endif %} | ||
</td> | ||
</tr> | ||
|
||
{% endfor %} | ||
</table> | ||
|
||
{% endif %} | ||
|
||
<hr / style="margin-top:3rem; margin-bottom:3rem;"> | ||
|
||
<form enctype="multipart/form-data" action="{% url 'greenweb_admin:accounts_hostingprovider_save_import_from_csv' provider.id %}" method="post"> | ||
{% csrf_token %} | ||
{{ form.as_p }} | ||
<input type="submit" value="Submit" | ||
style="margin-top: 0px; padding: 6px 15px"> | ||
|
||
|
||
|
||
<a style="margin-left:1rem;margin-right:1rem;" href="{% url 'greenweb_admin:accounts_hostingprovider_start_import_from_csv' provider.id %}">Back to import start</a> | ||
|
||
<a style="margin-left:1rem;margin-right:1rem;" class="" href="{% url 'greenweb_admin:accounts_hostingprovider_change' provider.id %}">Back to hosting provider</a> | ||
</form> | ||
|
||
|
||
|
||
{% endblock content %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
{% extends "admin/base_site.html" %} | ||
{% load i18n static %} | ||
|
||
{% block pretitle %} | ||
<h1>CSV Import Results for {{ provider }}</h1> | ||
{% endblock %} | ||
|
||
{% block content %} | ||
|
||
|
||
{% if ip_ranges %} | ||
|
||
<hr / style="margin-top:3rem; margin-bottom:3rem;"> | ||
|
||
<h2>IP Range Import </h2> | ||
|
||
<p>The following IP ranges were imported for <strong>{{ provider }}</strong>:</p> | ||
|
||
<table> | ||
<th>IP Range start</th><th>Ip Range End</th><th>Created / Updated</th><th>Length</th> | ||
|
||
{% for ip in ip_ranges.green_ips %} | ||
|
||
<tr> | ||
<td>{{ ip.ip_start }}</td> | ||
<td>{{ ip.ip_end }}</td> | ||
<td> | ||
{% if ip.id %} | ||
Updated | ||
{% else %} | ||
Created | ||
{% endif %} | ||
</td> | ||
<td> | ||
{{ ip.ip_range_length }} | ||
</td> | ||
</tr> | ||
|
||
{% endfor %} | ||
</table> | ||
|
||
<h2>AS Import</h2> | ||
|
||
<p>The following AS Numbers ranges were imported for <strong>{{ provider }}</strong>:</p> | ||
|
||
<table> | ||
<th>AS number</th><th>Created / Updated</th> | ||
|
||
{% for as in ip_ranges.green_asns %} | ||
|
||
<tr> | ||
<td>{{ as.asn }}</td> | ||
<td> | ||
{% if as.id %} | ||
Updated | ||
{% else %} | ||
Created | ||
{% endif %} | ||
</td> | ||
</tr> | ||
|
||
{% endfor %} | ||
</table> | ||
|
||
{% endif %} | ||
|
||
<hr / style="margin-top:3rem; margin-bottom:3rem;"> | ||
|
||
<style> | ||
.submit-row a.button{ | ||
margin-right: 1rem; | ||
} | ||
.submit-row a.button:visited{ | ||
color: #fff; | ||
} | ||
</style> | ||
|
||
<div class="submit-row"> | ||
<a class="button" href="{% url 'greenweb_admin:accounts_hostingprovider_change' provider.id %}">Back to hosting provider</a> | ||
|
||
| | ||
|
||
<a style="margin-left:1rem;" class="button" href="{% url 'greenweb_admin:accounts_hostingprovider_start_import_from_csv' provider.id %}">Make another CSV Import</a> | ||
</form> | ||
|
||
{% endblock content %} |
Oops, something went wrong.