Skip to content

Commit

Permalink
Merge pull request #140 from Ecotrust/property2shp
Browse files Browse the repository at this point in the history
  • Loading branch information
pollardld authored Nov 22, 2024
2 parents cfeff39 + d2f3758 commit f05ee69
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
5 changes: 4 additions & 1 deletion landmapper/app/static/landmapper/css/report.css
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ p {
margin: 4px 0;
}

.action-wrap button:disabled {
.action-wrap .disabled,
.action-wrap :disabled {
background: rgba(60, 60, 60, 0.2);
opacity: 0.5;
pointer-events: none;
}

Expand Down
3 changes: 2 additions & 1 deletion landmapper/app/static/landmapper/js/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ if (copyToAccountBtn) {
*/
function exportLayerHandler() {
const propertyPk = this.getAttribute('data-property-id');
const propertyName = this.getAttribute('data-property-name');
const exportLayerButton = this;

// Disable the button to prevent multiple clicks
Expand All @@ -53,7 +54,7 @@ if (copyToAccountBtn) {
const a = document.createElement('a');
a.style.display = 'none';
a.href = url;
a.download = `${propertyPk}.zip`;
a.download = `${propertyName}.zip`;
document.body.appendChild(a);
a.click();
window.URL.revokeObjectURL(url);
Expand Down
15 changes: 7 additions & 8 deletions landmapper/app/templates/landmapper/report/report-overview.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,15 @@ <h2 class="d-print-none">Export your property data</h2>

{% if user.is_authenticated and property.user_id == user_id %}

<!-- Export Layer Button -->
<button id="export-layer-button" class="btn btn-primary btn-action d-print-none" data-property-id="{{ property.pk }}" aria-label="Dowmload Shape file of Property">
<!-- Export SHP Button -->
<button id="export-layer-button" class="btn btn-primary btn-action d-print-none" data-property-id="{{ property.pk }}" data-property-name="{{ property_name }}" aria-label="Dowmload Shape file of Property" title="Download shape file of property">
<img src="{% static 'landmapper/img/icon/icon-shp.svg' %}" class="icon-shp icon" alt="Shape file icon" />
{% comment %} <span>SHP</span> {% endcomment %}
</button>

{% elif user.is_authenticated and property.user_id != user_id %}

<!-- Export Layer Button -->
<button disabled id="export-layer-button" class="btn btn-primary btn-action d-print-none disabled" aria-label="Dowmload Shape file of Property">
<!-- Export SHP Button -->
<button disabled id="export-layer-button" class="btn btn-primary btn-action d-print-none disabled" aria-label="Dowmload Shape file of Property" title="Copy to your properties to export shape file">
<img src="{% static 'landmapper/img/icon/icon-shp.svg' %}" class="icon-shp icon" alt="Shape file icon" />
</button>

Expand All @@ -68,11 +67,12 @@ <h2 class="d-print-none">Export your property data</h2>
{% else %}

<!-- Export Layer Button -->
<button disabled id="export-layer-button" class="btn btn-primary btn-action d-print-none disabled" aria-label="Dowmload Shape file of Property">
<button disabled id="export-layer-button" class="btn btn-primary btn-action d-print-none disabled" aria-label="Dowmload Shape file of Property" title="login to download shape file of property">
<img src="{% static 'landmapper/img/icon/icon-shp.svg' %}" class="icon-shp icon" alt="Shape file icon" />
{% comment %} <span>SHP</span> {% endcomment %}
</button>

<a href="/auth/login/?next=/landmapper/report/{{ property_id }}" class="link-primary" target="_blank"><strong>Login to download</strong></a>

{% endif %}

</div>
Expand All @@ -94,7 +94,6 @@ <h2 class="d-print-none">Download and share your report</h2>

<a href="" class="btn btn-primary btn-action d-print-none disabled" target="_blank" aria-label="Download PDF report">
<img src="{% static 'landmapper/img/icon/icon-pdf.svg' %}" class="icon-download icon" alt="PDF icon" />
{% comment %} <span>PDF</span> {% endcomment %}
</a>

<a href="/auth/login/?next=/landmapper/report/{{ property_id }}" class="link-primary" target="_blank"><strong>Login to download</strong></a>
Expand Down
2 changes: 1 addition & 1 deletion landmapper/app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@ def export_layer(request, property_pk):
database_name = settings.DATABASES['default']['NAME']
sanitized_name = re.sub(r'[^a-zA-Z0-9_-]', '_', property_record.name)
filename = f"{sanitized_name}"
shpdir = os.path.join(settings.SHAPEFILE_EXPORT_DIR, property_pk)
shpdir = os.path.join(settings.SHAPEFILE_EXPORT_DIR, sanitized_name)
os.makedirs(shpdir, exist_ok=True)

try:
Expand Down

0 comments on commit f05ee69

Please sign in to comment.