Skip to content

Commit

Permalink
fix views.py
Browse files Browse the repository at this point in the history
  • Loading branch information
submarcos committed Nov 26, 2024
1 parent caeb20a commit 6efc923
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 50 deletions.
4 changes: 2 additions & 2 deletions geotrek/api/templates/mobile/sync_mobile.html
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ <h3>{% trans "Mobile sync" %}</h3>
</div>

<div class="card-body">
<div class="progress progress-striped" role="progressbar">
<div class="progress-bar progress-bar-striped" style="width: 0;" id="progress-bar"></div>
<div class="progress">
<div class="progress-bar progress-bar-striped" style="width: 0;" id="progress-bar" role="progressbar"></div>
</div>
<div id="exception-message" style="display: none;" class="alert alert-danger">
</div>
Expand Down
2 changes: 0 additions & 2 deletions geotrek/common/static/common/css/import.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@
}

#progress-bars div.alert {
margin-left: 45px;
display: none;
}

#progress-bars div.description {
margin-left: 45px;
}

#progress-bars span.parser{
Expand Down
40 changes: 22 additions & 18 deletions geotrek/common/static/common/js/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,42 @@ function updateImportProgressBars() {
$.getJSON('/commands/import-update.json', function(json) {
parent = document.querySelector('#progress-bars');
json.forEach(function(row) {
var local_percent = row.result.current + "%";
var status_class = 'pogress-info';

if (row.status == 'SUCCESS') {
local_percent = "100%";
status_class = "progress-success";
} else if (row.status == 'FAILURE') {
local_percent = "100%";
status_class = "progress-danger";
var local_percent = row.result.current;
var status_class = '';

if (row.status === 'SUCCESS') {
local_percent = "100";
status_class = "bg-success";
} else if (row.status === 'FAILURE') {
local_percent = "100";
status_class = "bg-danger";
}

// Update element if exists
if (element = document.getElementById(row.id)) {
element.querySelector('.bar').style.width = local_percent;
element.querySelector('.pull-left').innerHTML = local_percent;
element.querySelector('.progress-bar').setAttribute('style', 'width: ' + local_percent + '% ;');
element.querySelector('.progress-bar').setAttribute('aria-valuenow', local_percent);
element.querySelector('.progress-bar').innerHTML = local_percent + "%";

if(!element.querySelector('.alert').classList.contains('alert-success')) {
// Add report if success.
if (row.result.report) {
alert = element.querySelector('.alert');
alert.classList.add('alert-success');
alert.innerHTML = row.result.report;
message = element.querySelector('.message');
message.innerHTML = row.result.report;
alert.style.display = 'block';
}
}

} else { //Create element in dom.
element = document.createElement('div');
element.innerHTML = document.querySelector('#import-template').innerHTML
element.innerHTML = document.querySelector('#import-template').innerHTML;
element.id = row.id;
element.querySelector('.bar').style.width = local_percent + ' : ';
element.querySelector('.pull-left').innerHTML = local_percent;
element.querySelector('.progress-bar').setAttribute('style', 'width: ' + local_percent + '% ;');
element.querySelector('.progress-bar').setAttribute('aria-valuenow', local_percent);
element.querySelector('.progress-bar').innerHTML = local_percent + "%";

element.querySelector('.parser').innerHTML = row.result.parser;
element.querySelector('.filename').innerHTML = row.result.filename;

Expand All @@ -43,13 +47,13 @@ function updateImportProgressBars() {
// Handle errors if any.
if (row.result.exc_message) {
element.querySelector('.alert').classList.add('alert-danger');
element.querySelector('.alert span').innerHTML = row.result.exc_type + " : " + row.result.exc_message;
element.querySelector('.message span').innerHTML = row.result.exc_type + " : " + row.result.exc_message;
element.querySelector('.alert').style.display = 'block';
}

// Add class on status change.
if (!element.querySelector('.progress').classList.contains(status_class)) {
element.querySelector('.progress').classList.add(status_class);
if (!element.querySelector('.progress-bar').classList.contains(status_class)) {
element.querySelector('.progress-bar').classList.add(status_class);
}
});
});
Expand Down
19 changes: 8 additions & 11 deletions geotrek/common/templates/common/import_dataset.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,19 @@

<script id="import-template" type="text/template">
<div id="progress-tpl">
<button type="button" class="close" data-dismiss="alert">&times;</button>
<div class="description">
<span class="parser"></span>
<span class="filename">
</span>
<span class="filename"></span>
</div>
<div class="pull-left">
<span></span>
<div class="progress">
<div class="progress-bar progress-bar-striped" role="progressbar" style="width: 0%" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100"></div>
</div>
<div class="progress progress-striped active">
<div class="bar"></div>
<div class="alert alert-warning alert-dismissible fade show" role="alert">
<span class="message"></span>
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="alert">
<span></span>
</div>
<hr></hr>
</div>
</script>
{% endblock mainpanel %}
26 changes: 9 additions & 17 deletions geotrek/common/views.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import ast
import json
import logging
import mimetypes
import os
import re
from datetime import timedelta
from zipfile import ZipFile, is_zipfile

import logging
import redis
from django.apps import apps
from django.conf import settings
Expand All @@ -19,29 +19,21 @@
from django.contrib.gis.db.models import Extent, GeometryField
from django.core.exceptions import PermissionDenied
from django.db.models.functions import Cast
from django.http import (Http404, HttpResponse, HttpResponseRedirect,
JsonResponse)
from django.shortcuts import get_object_or_404, redirect, render
from django.urls import reverse
from django.utils import timezone
from django.http import JsonResponse, Http404, HttpResponse, HttpResponseRedirect
from django.shortcuts import get_object_or_404, render, redirect
from django.urls import reverse, reverse_lazy
from django.utils import timezone, translation
from django.urls import reverse
from django.utils import timezone
from django.utils.decorators import method_decorator
from django.utils.encoding import force_str
from django.utils.translation import gettext as _
from django.views import static
from django.views.defaults import page_not_found
from django.views.decorators.http import require_http_methods, require_POST
from django.views.generic import TemplateView, UpdateView, View
from django.views.generic import RedirectView, TemplateView, UpdateView, View
from django.views.decorators.http import require_POST, require_http_methods
from django.views.generic import RedirectView, View, FormView
from django.views.defaults import page_not_found
from django.views.generic import TemplateView
from django.views.generic import UpdateView
from django.views.generic import View
from django_celery_results.models import TaskResult
from django_large_image.rest import LargeImageFileDetailMixin
from geotrek.common.filters import HDViewPointFilterSet
from large_image import config
from mapentity import views as mapentity_views
from mapentity.helpers import api_bbox
Expand All @@ -54,11 +46,9 @@

from geotrek import __version__
from geotrek.celery import app as celery_app
from geotrek.common.filters import HDViewPointFilterSet
from geotrek.common.viewsets import GeotrekMapentityViewSet
from geotrek.feedback.parsers import SuricateParser

from ..altimetry.models import Dem
from ..core.models import Path
from .forms import (AttachmentAccessibilityForm, HDViewPointAnnotationForm,
HDViewPointForm, ImportDatasetForm,
ImportDatasetFormWithFile, ImportSuricateForm)
Expand All @@ -70,6 +60,8 @@
from .utils import leaflet_bounds
from .utils.import_celery import (create_tmp_destination,
discover_available_parsers)
from ..altimetry.models import Dem
from ..core.models import Path

logger = logging.getLogger(__name__)

Expand Down

0 comments on commit 6efc923

Please sign in to comment.