Skip to content

Commit

Permalink
spreadsheet: Add spreadsheet upload and download option
Browse files Browse the repository at this point in the history
  • Loading branch information
odscjames committed Dec 2, 2022
1 parent b9fb48f commit ee03f50
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 5 deletions.
52 changes: 49 additions & 3 deletions cove_ofds/templates/cove_ofds/explore.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ <h4 class="panel-title">
</p>

<div class="row">
<div class="col-md-4">
<div class="col-md-6">


<div class="panel {% if original_format == 'json' %}panel-info{% else %}panel-success{% endif %}">
Expand Down Expand Up @@ -87,7 +87,7 @@ <h4 class="panel-title">
</div>

</div>
<div class="col-md-4">
<div class="col-md-6">

<div class="panel {% if original_format == 'geojson' %}panel-info{% else %}panel-success{% endif %}">
<div id="download-geojson-panel" class="panel-heading pointer" role="region"
Expand Down Expand Up @@ -126,7 +126,10 @@ <h4 class="panel-title">
</div>

</div>
<div class="col-md-4">
</div>

<div class="row">
<div class="col-md-6">

<div class="panel {% if original_format == 'csvs' %}panel-info{% else %}panel-success{% endif %}">
<div id="download-csvs-panel" class="panel-heading pointer" role="region" aria-expanded="true"
Expand Down Expand Up @@ -169,6 +172,49 @@ <h4 class="panel-title">
</div>

</div>

<div class="col-md-6">

<div class="panel {% if original_format == 'spreadsheet' %}panel-info{% else %}panel-success{% endif %}">
<div id="download-spreadsheet-panel" class="panel-heading pointer" role="region" aria-expanded="true"
aria-controls="dataConversion" data-toggle="collapse" data-target="#downloadDataSpreadsheet">
<h4 class="panel-title">
<span class="glyphicon glyphicon-collapse-up"></span>{% trans 'Spreadsheet' %} {% if original_format == 'spreadsheet' %}{% trans '(original)' %}{% endif %}
</h4>
</div>
<div id="downloadDataSpreadsheet" class="collapse in panel-body">
{% if original_format == 'spreadsheet' %}
<ul class="list-unstyled">
{% for supplied_data_file in supplied_data_files %}
<li>
<span class="glyphicon glyphicon-download" aria-hidden="true"></span>
<a href="{{ supplied_data_file.upload_url }}">{{ supplied_data_file.filename }} ({{ supplied_data_file.size|filesizeformat }})</a>
</li>
{% endfor %}
</ul>
{% else %}
{% if can_download_ods or can_download_xlsx %}
<p>{% trans 'Your data was successfully converted to spreadsheet format.' %}</p>
<ul class="list-unstyled">
{% if can_download_ods %}
<li>
<span class="glyphicon glyphicon-download" aria-hidden="true"></span>
<a href="{{download_ods_url}}">Open Office, ODS ({{ download_ods_size|filesizeformat }})</a>
</li>
{% endif %}
{% if can_download_xlsx %}
<li>
<span class="glyphicon glyphicon-download" aria-hidden="true"></span>
<a href="{{download_xlsx_url}}">Excel, XLSX ({{ download_xlsx_size|filesizeformat }})</a>
</li>
{% endif %}
</ul>
{% endif %}
{% endif %}
</div>
</div>

</div>
</div>

</div>
Expand Down
37 changes: 36 additions & 1 deletion cove_ofds/templates/cove_ofds/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


<p>
Use the form below to submit your data and check that it conforms to the <a href="https://open-fibre-data-standard.readthedocs.io/en/latest/" target="_blank">Open Fibre Data Standard</a> (OFDS). You can submit data in either JSON, GeoJSON or CSV format.
Use the form below to submit your data and check that it conforms to the <a href="https://open-fibre-data-standard.readthedocs.io/en/latest/" target="_blank">Open Fibre Data Standard</a> (OFDS). You can submit data in either JSON, GeoJSON, CSV or spreadsheet format.
For more information, see the <a href="https://open-fibre-data-standard.readthedocs.io/en/latest/reference/publication_formats/index.html" target="_blank">publication format reference</a>.
</p>
<p>
Expand All @@ -30,6 +30,11 @@
CSV
</a>
</li>
<li>
<a href="#spreadsheet" role="tab" data-toggle="tab">
Spreadsheet
</a>
</li>
</ul>

<!-- Tab panes -->
Expand Down Expand Up @@ -148,6 +153,36 @@ <h4 class="panel-title">
</div>

</div>
<div class="tab-pane fade" id="spreadsheet">

<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingTen" data-toggle="collapse" data-parent="#accordion" data-target="#collapseTen" aria-expanded="true" aria-controls="collapseTen">
<h4 class="panel-title">
<a class="accordion-toggle">
<span class="glyphicon glyphicon-upload" aria-hidden="true"></span>{% trans "Upload" %}
</a>
</h4>
</div>
<div id="collapseTen" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingTen">
<div class="panel-body">

<p>
<strong>Accepted formats:</strong> a UTF-8, Windows-1252 or ISO-8859-1 encoded .xlsx or .ods file with sheets that conform to the <a href="https://open-fibre-data-standard.readthedocs.io/en/latest/reference/publication_formats/csv.html" target="_blank">CSV publication format</a>.
</p>

<form method="POST" action="{% url 'new_spreadsheet' %}" enctype="multipart/form-data">{% csrf_token %}
{% bootstrap_form forms.spreadsheet.upload_form %}
{% buttons %}
<button type="submit" class="btn btn-primary">
{% trans 'Submit' %}
</button>
{% endbuttons %}
</form>
</div>
</div>
</div>

</div>
</div>


Expand Down
6 changes: 5 additions & 1 deletion cove_ofds/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
WasJSONUploaded,
)
from libcoveweb2.models import SuppliedData
from libcoveweb2.views import CSVS_FORM_CLASSES, JSON_FORM_CLASSES, explore_data_context
from libcoveweb2.views import CSVS_FORM_CLASSES, JSON_FORM_CLASSES, SPREADSHEET_FORM_CLASSES, explore_data_context

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -51,6 +51,10 @@ def index(request):
form_name: form_class()
for form_name, form_class in GEOJSON_FORM_CLASSES.items()
},
"spreadsheet": {
form_name: form_class()
for form_name, form_class in SPREADSHEET_FORM_CLASSES.items()
},
}

return render(request, "cove_ofds/index.html", {"forms": forms})
Expand Down
4 changes: 4 additions & 0 deletions libcoveweb2/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ def new_csvs(request):
return render(request, "libcoveweb2/new_csvs.html", {"forms": forms})


SPREADSHEET_FORM_CLASSES = {
"upload_form": NewSpreadsheetUploadForm,
}

def new_spreadsheet(request):

forms = {
Expand Down

0 comments on commit ee03f50

Please sign in to comment.