Skip to content

Commit

Permalink
input: Forms in front page in tabs & remove spreadsheets option
Browse files Browse the repository at this point in the history
  • Loading branch information
jarofgreen committed Nov 7, 2022
1 parent c5bb5c6 commit b33c210
Show file tree
Hide file tree
Showing 5 changed files with 175 additions and 17 deletions.
6 changes: 4 additions & 2 deletions cove_ofds/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,24 @@

class NewGeoJSONUploadForm(forms.Form):
nodes_file_upload = forms.FileField(
label="Select GeoJSON Nodes file",
widget=forms.FileInput(
attrs={
"accept": ",".join(
settings.ALLOWED_GEOJSON_CONTENT_TYPES
+ settings.ALLOWED_GEOJSON_EXTENSIONS
)
}
)
),
)
spans_file_upload = forms.FileField(
label="Select GeoJSON Spans file",
widget=forms.FileInput(
attrs={
"accept": ",".join(
settings.ALLOWED_GEOJSON_CONTENT_TYPES
+ settings.ALLOWED_GEOJSON_EXTENSIONS
)
}
)
),
)
142 changes: 131 additions & 11 deletions cove_ofds/templates/cove_ofds/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,137 @@

{% block content %}

<div>
<a href="{% url 'new_json' %}">Upload JSON</a>
</div>
<div>
<a href="{% url 'new_spreadsheet' %}">Upload Spreadsheet</a>
</div>
<div>
<a href="{% url 'new_csvs' %}">Upload CSVs</a>
</div>
<div>
<a href="{% url 'new_geojson' %}">Upload GeoJSON</a>

<p>
Use the form below to submit your data. You can submit data in either JSON, GeoJSON or CSV format.
For more information, see the <a href="https://open-fibre-data-standard.readthedocs.io/en/latest/reference/publication_formats.html" target="_blank">publication format reference</a>.
</p>

<!-- Nav tabs -->
<ul class="nav nav-tabs" role="tablist" style="margin-bottom: 30px;">
<li class="active">
<a href="#json" role="tab" data-toggle="tab">
JSON
</a>
</li>
<li>
<a href="#geojson" role="tab" data-toggle="tab">
GeoJSON
</a>
</li>
<li>
<a href="#csvs" role="tab" data-toggle="tab">
CSVs
</a>
</li>
</ul>

<!-- Tab panes -->
<div class="tab-content">
<div class="tab-pane fade active in" id="json">


<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingOne" data-toggle="collapse" data-parent="#accordion" data-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
<h4 class="panel-title">
<a class="accordion-toggle">
<span class="glyphicon glyphicon-upload" aria-hidden="true"></span>{% trans "Upload" %}
</a>
</h4>
</div>
<div id="collapseOne" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingOne">
<div class="panel-body">
<form method="POST" action="{% url 'new_json' %}" enctype="multipart/form-data">{% csrf_token %}
{% bootstrap_form forms.json.upload_form %}
{% buttons %}
<button type="submit" class="btn btn-primary">
{% trans 'Submit' %}
</button>
{% endbuttons %}
</form>
</div>
</div>
</div>


<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingTwo" data-toggle="collapse" data-parent="#accordion" data-target="#collapseTwo" aria-expanded="true" aria-controls="collapseTwo">
<h4 class="panel-title">
<a class="accordion-toggle">
<span class="glyphicon glyphicon-upload" aria-hidden="true"></span>{% trans "Paste" %}
</a>
</h4>
</div>
<div id="collapseTwo" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingTwo">
<div class="panel-body">
<form method="POST" action="{% url 'new_json' %}" enctype="multipart/form-data">{% csrf_token %}
{% bootstrap_form forms.json.text_form %}
{% buttons %}
<button type="submit" class="btn btn-primary">
{% trans 'Submit' %}
</button>
{% endbuttons %}
</form>
</div>
</div>
</div>


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


<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingFour" data-toggle="collapse" data-parent="#accordion" data-target="#collapseFour" aria-expanded="true" aria-controls="collapseFour">
<h4 class="panel-title">
<a class="accordion-toggle">
<span class="glyphicon glyphicon-upload" aria-hidden="true"></span>{% trans "Upload" %}
</a>
</h4>
</div>
<div id="collapseFour" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingFour">
<div class="panel-body">
<form method="POST" action="{% url 'new_geojson' %}" enctype="multipart/form-data">{% csrf_token %}
{% bootstrap_form forms.geojson.upload_form %}
{% buttons %}
<button type="submit" class="btn btn-primary">
{% trans 'Submit' %}
</button>
{% endbuttons %}
</form>
</div>
</div>
</div>

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


<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingSeven" data-toggle="collapse" data-parent="#accordion" data-target="#collapseSeven" aria-expanded="true" aria-controls="collapseSeven">
<h4 class="panel-title">
<a class="accordion-toggle">
<span class="glyphicon glyphicon-upload" aria-hidden="true"></span>{% trans "Upload" %}
</a>
</h4>
</div>
<div id="collapseSeven" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingSeven">
<div class="panel-body">
<form method="POST" action="{% url 'new_csvs' %}" enctype="multipart/form-data">{% csrf_token %}
{% bootstrap_form forms.csvs.upload_form %}
{% buttons %}
<button type="submit" class="btn btn-primary">
{% trans 'Submit' %}
</button>
{% endbuttons %}
</form>
</div>
</div>
</div>

</div>
</div>



{% endblock %}
24 changes: 22 additions & 2 deletions 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 explore_data_context
from libcoveweb2.views import CSVS_FORM_CLASSES, JSON_FORM_CLASSES, explore_data_context

logger = logging.getLogger(__name__)

Expand All @@ -31,9 +31,29 @@ def default(self, obj):
return json.JSONEncoder.default(self, obj)


GEOJSON_FORM_CLASSES = {
"upload_form": NewGeoJSONUploadForm,
}


def index(request):

return render(request, "cove_ofds/index.html", {})
forms = {
"json": {
form_name: form_class()
for form_name, form_class in JSON_FORM_CLASSES.items()
},
"csvs": {
form_name: form_class()
for form_name, form_class in CSVS_FORM_CLASSES.items()
},
"geojson": {
form_name: form_class()
for form_name, form_class in GEOJSON_FORM_CLASSES.items()
},
}

return render(request, "cove_ofds/index.html", {"forms": forms})


def new_geojson(request):
Expand Down
15 changes: 13 additions & 2 deletions libcoveweb2/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ class NewJSONUploadForm(forms.Form):
+ settings.ALLOWED_JSON_EXTENSIONS
)
}
)
),
label="Select JSON file",
)


Expand All @@ -37,15 +38,17 @@ class NewCSVsUploadForm(forms.Form):
# something that allows any number of uploads with no limits this will do for now
file_field_names = ["file_upload" + str(i) for i in range(0, 10)]
file_upload0 = forms.FileField(
label="Select CSV file",
widget=forms.FileInput(
attrs={
"accept": ",".join(
settings.ALLOWED_CSV_CONTENT_TYPES + settings.ALLOWED_CSV_EXTENSIONS
)
}
)
),
)
file_upload1 = forms.FileField(
label="Select CSV file",
widget=forms.FileInput(
attrs={
"accept": ",".join(
Expand All @@ -56,6 +59,7 @@ class NewCSVsUploadForm(forms.Form):
required=False,
)
file_upload2 = forms.FileField(
label="Select CSV file",
widget=forms.FileInput(
attrs={
"accept": ",".join(
Expand All @@ -66,6 +70,7 @@ class NewCSVsUploadForm(forms.Form):
required=False,
)
file_upload3 = forms.FileField(
label="Select CSV file",
widget=forms.FileInput(
attrs={
"accept": ",".join(
Expand All @@ -76,6 +81,7 @@ class NewCSVsUploadForm(forms.Form):
required=False,
)
file_upload4 = forms.FileField(
label="Select CSV file",
widget=forms.FileInput(
attrs={
"accept": ",".join(
Expand All @@ -86,6 +92,7 @@ class NewCSVsUploadForm(forms.Form):
required=False,
)
file_upload5 = forms.FileField(
label="Select CSV file",
widget=forms.FileInput(
attrs={
"accept": ",".join(
Expand All @@ -96,6 +103,7 @@ class NewCSVsUploadForm(forms.Form):
required=False,
)
file_upload6 = forms.FileField(
label="Select CSV file",
widget=forms.FileInput(
attrs={
"accept": ",".join(
Expand All @@ -106,6 +114,7 @@ class NewCSVsUploadForm(forms.Form):
required=False,
)
file_upload7 = forms.FileField(
label="Select CSV file",
widget=forms.FileInput(
attrs={
"accept": ",".join(
Expand All @@ -116,6 +125,7 @@ class NewCSVsUploadForm(forms.Form):
required=False,
)
file_upload8 = forms.FileField(
label="Select CSV file",
widget=forms.FileInput(
attrs={
"accept": ",".join(
Expand All @@ -126,6 +136,7 @@ class NewCSVsUploadForm(forms.Form):
required=False,
)
file_upload9 = forms.FileField(
label="Select CSV file",
widget=forms.FileInput(
attrs={
"accept": ",".join(
Expand Down
5 changes: 5 additions & 0 deletions libcoveweb2/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ def new_json(request):
return render(request, "libcoveweb2/new_json.html", {"forms": forms})


CSVS_FORM_CLASSES = {
"upload_form": NewCSVsUploadForm,
}


def new_csvs(request):

forms = {
Expand Down

0 comments on commit b33c210

Please sign in to comment.