Skip to content

Commit

Permalink
Update uploader (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
meomancer authored Dec 22, 2023
1 parent 94e8cfd commit ad89edc
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 15 deletions.
11 changes: 10 additions & 1 deletion tasks/uploader/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def __init__(self, error):

class BaseUploader(WellEditing):
""" Convert excel into json and save the data """
UPLOADER_NAME = ''
AUTOCREATE_WELL = False
SHEETS = []
START_ROW = 2
Expand Down Expand Up @@ -73,10 +74,16 @@ def __init__(self, upload_session: UploadSession, restart: bool = False):
records[sheet_name] = sheet_records
self.total_records += len(sheet_records)
except KeyError as e:
error = (
f'Sheet {e} in excel is not found. '
f'This sheet is used by {self.UPLOADER_NAME}. '
f'Please check if you use the correct uploader/tab. '
)

self.upload_session.update_progress(
finished=True,
progress=100,
status='Sheet {} is needed'.format(e)
status=error
)
return
self.records = records
Expand Down Expand Up @@ -142,6 +149,8 @@ def process(self):
index += 1
if index <= resumed_index:
continue
if len(raw_record) == 0:
continue

process_percent = (index / total_records) * 50

Expand Down
1 change: 1 addition & 0 deletions tasks/uploader/general_information.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

class GeneralInformationUploader(BaseUploader):
""" Save well uploader from excel """
UPLOADER_NAME = 'General Information'
AUTOCREATE_WELL = True
SHEETS = [
'General Information'
Expand Down
1 change: 1 addition & 0 deletions tasks/uploader/monitoring_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

class MonitoringDataUploader(BaseUploader):
""" Save well uploader from excel """
UPLOADER_NAME = 'Monitoring Data'
AUTOCREATE_WELL = False
SHEETS = [
'Groundwater Level',
Expand Down
54 changes: 40 additions & 14 deletions templates/upload_well_csv.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ <h1>Upload Excel File For Well Data.</h1>
}

.template-indicator {
margin-top: 20px;
margin-bottom: 20px;
font-style: italic;
color: grey;
}
Expand Down Expand Up @@ -126,13 +126,15 @@ <h5>{% trans "Current upload" %}</h5>
</div>
</div>
<div class="col-xs-2">
<p>Uploader</p>
<p>Filename</p>
<p>Organisation</p>
<p>Uploaded at</p>
<p>Status</p>
<p></p>
</div>
<div class="col-xs-10">
<p>: {% if upload_session.category == 'well_upload' %}General Information{% else %}Monitoring Data{% endif %}</p>
<p>:
<a href="{{ upload_session.upload_file.url }}">
{{ upload_session.filename }}
Expand Down Expand Up @@ -191,6 +193,17 @@ <h5>{% trans "Current upload" %}</h5>
<div class="tab-content" id="myTabContent">
<div class="tab-pane fade" id="well-descriptor"
role="tabpanel" aria-labelledby="home-tab">
<div class="template-indicator">
{% trans "This Batch Upload allows you to import several Well data at one time. The Batch Upload currently supports the upload of General Information (i.e. identification and location of your data points)." %}
<br>
{% trans "Download the templates and fill them in with your data, then simply upload these files. Don't forget to assign permissions on your data: is it public? which organisations can access the data?" %}
<br>
<br>
{% trans "Template" %} :
<a href="{% static 'upload_template/well.xlsx' %}">
{% trans "here" %}
</a>
</div>
<p>
{{ form.license.label_tag }}
{{ form.license }}
Expand All @@ -207,26 +220,26 @@ <h5>{% trans "Current upload" %}</h5>
{{ form.gw_well_file.label_tag }}
{{ form.gw_well_file }}
</p>
<div class="template-indicator">
{% trans "This Batch Upload allows you to import several Well data at one time. The Batch Upload currently supports the upload of General Information (i.e. identification and location of your data points). Download the templates and fill them in with your data, then simply upload these files. Don't forget to assign permissions on your data: is it public? which organisations can access the data?" %}

{% trans "Template" %} : <a
href="{% static 'upload_template/well.xlsx' %}">{% trans "here" %}</a>
</div>
</div>
<div class="tab-pane fade" id="well-monitoring"
role="tabpanel"
aria-labelledby="profile-tab">
<div class="template-indicator">
{% trans "This Batch Upload allows you to import several Monitoring Data at one time. Upload the well information before using this form." %}
<br>
{% trans "Download the templates and fill them in with your data, then simply upload these files. Don't forget to link the monitoring data with the well ID that is already imported." %}

<br>
<br>
{% trans "Template" %} :
<a href="{% static 'upload_template/monitoring_data.xlsx' %}">
{% trans "here" %}
</a>
</div>
<p>
{{ form.gw_well_monitoring_file.label_tag }}
{{ form.gw_well_monitoring_file }}
</p>
<div class="template-indicator">
{% trans "This Batch Upload allows you to import several Monitoring Data at one time. Upload the well information before using this form. Download the templates and fill them in with your data, then simply upload these files. Don't forget to link the monitoring data with the well ID that is already imported." %}

{% trans "Template" %} : <a
href="{% static 'upload_template/monitoring_data.xlsx' %}">{% trans "here" %}</a>
</div>
</div>
</div>

Expand Down Expand Up @@ -311,12 +324,14 @@ <h5>{% trans "Past upload sessions" %}</h5>
<div class="well well-sm past-upload ${value.category}" style="border: 1px solid ${color}" data-id="${value.id}" data-report="${value.report_filename}">
<div class="container-fluid row" style="padding-top: 10px;">
<div class="col-xs-2">
<p>Uploader</p>
<p>Filename</p>
<p>Organisation</p>
<p>Uploaded at</p>
<p></p>
</div>
<div class="col-xs-10">
<p>: ${value.category === 'well_upload' ? 'General Information' : 'Monitoring Data' }</p>
<p>: ${value.filename}</p>
<p>: ${value.organisation}</p>
<p>: ${new Date(value.uploaded_at)}</p>
Expand Down Expand Up @@ -382,10 +397,21 @@ <h5>{% trans "Past upload sessions" %}</h5>
}
$('#upload-progress-status').html(status);
}
if (data.task_status !== 'DONE') {
setTimeout(function () {
fetchData()
}, 2000);
} else {
window.open(data.report_filename);
}
},
error: function (xhr, ajaxOptions, thrownError) {
setTimeout(function () {
fetchData()
}, 2000);
}
});
}
setInterval(fetchData, 2000);
fetchData()
{% endif %}
})
Expand Down

0 comments on commit ad89edc

Please sign in to comment.