-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
460 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
try: | ||
from . import parsers | ||
except ImportError: | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,8 @@ eggs += | |
pydot | ||
pyparsing | ||
|
||
unzip=true | ||
|
||
[bpython] | ||
recipe = zc.recipe.egg:scripts | ||
eggs = ${buildout:eggs} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from __future__ import absolute_import | ||
|
||
import os | ||
|
||
from celery import Celery | ||
|
||
# set the default Django settings module for the 'celery' program. | ||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'geotrek.settings.default') | ||
|
||
from django.conf import settings | ||
|
||
app = Celery('geotrek') | ||
|
||
# Using a string here means the worker will not have to | ||
# pickle the object when using Windows. | ||
app.config_from_object('django.conf:settings') | ||
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS) | ||
|
||
|
||
@app.task(bind=True) | ||
def debug_task(self): | ||
print('Request: {0!r}'.format(self.request)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#progress-bars { | ||
margin-top: 1.5em; | ||
} | ||
|
||
#progress-bars .close { | ||
display: block; | ||
float: none; | ||
text-align: right; | ||
width: 100%; | ||
} | ||
|
||
#progress-bars div.pull-left { | ||
width: 35px; | ||
margin-left: 5px; | ||
margin-right: 5px; | ||
} | ||
|
||
#progress-bars div.alert-error { | ||
margin-left: 45px; | ||
display: none; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
function updateImportProgressBars() { | ||
$.getJSON('/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"; | ||
} | ||
|
||
if (element = document.getElementById(row.id)) { | ||
element.querySelector('.bar').style.width = local_percent; | ||
element.querySelector('.pull-left').innerHTML = local_percent; | ||
} else { | ||
element = document.createElement('div'); | ||
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; | ||
|
||
parent.appendChild(element); | ||
} | ||
if (row.result.exc_message) { | ||
element.querySelector('.alert span').innerHTML = "Error message : " + row.result.exc_message; | ||
element.querySelector('.alert').style.display = 'block'; | ||
} | ||
|
||
if (!element.querySelector('.progress').classList.contains(status_class)) { | ||
element.querySelector('.progress').classList.add(status_class); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
$(document).ready(function() { | ||
updateImportProgressBars(); | ||
setInterval(updateImportProgressBars, 1000); | ||
}); |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from __future__ import absolute_import | ||
|
||
import importlib | ||
import sys | ||
from celery import shared_task, current_task | ||
|
||
|
||
@shared_task | ||
def import_datas(filename, class_name, module_name="bulkimport.parsers"): | ||
try: | ||
module = importlib.import_module(module_name) | ||
Parser = getattr(module, class_name) | ||
except: | ||
raise ImportError("Failed to import parser class '{0}' from module '{1}'".format( | ||
class_name, module_name)) | ||
|
||
def progress_cb(progress): | ||
current_task.update_state( | ||
state='PROGRESS', | ||
meta={ | ||
'current': int(100 * progress), | ||
'total': 100, | ||
} | ||
) | ||
sys.stdout.write( | ||
"{progress:02d}%".format(progress=int(100 * progress))) | ||
|
||
try: | ||
parser = Parser(progress_cb=progress_cb) | ||
parser.parse(filename) | ||
except Exception as e: | ||
raise e | ||
|
||
return |
17 changes: 17 additions & 0 deletions
17
geotrek/common/templates/common/common_usermenu_fragment.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{% load i18n %} | ||
|
||
{{appname}} | ||
|
||
{% if appname == "common" %} | ||
<div class="btn-group"> | ||
<a class="btn dropdown-toggle" data-toggle="dropdown" href="#"> | ||
<strong> | ||
{% trans "Imports" %} | ||
</strong> | ||
<span class="caret"></span> | ||
</a> | ||
<ul class="dropdown-menu"> | ||
<li><a href="{% url 'common:import_dataset' %}">{% trans "Imports" %}</a></li> | ||
</ul> | ||
</div> | ||
{% endif %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{% extends "mapentity/base.html" %} | ||
{% load static crispy_forms_tags %} | ||
|
||
{% block extrahead %} | ||
<script type="text/javascript" src="{% static "common/js/import.js" %}"></script> | ||
<link rel="stylesheet" href="{% static "common/css/import.css" %}" /> | ||
{% endblock extrahead %} | ||
|
||
{% block toolbar %} | ||
{% endblock toolbar %} | ||
|
||
{% block mainpanel %} | ||
<div class="span3 offset2"> | ||
{% block mainform %} | ||
{% crispy form form.helper %} | ||
{% endblock mainform %} | ||
</div> | ||
<div id="progress-bars" class="span5"> | ||
</div> | ||
|
||
<script id="import-template" type="text/template"> | ||
<div id="progress-tpl"> | ||
<button type="button" class="close" data-dismiss="alert">×</button> | ||
<div class="pull-left"> | ||
<span></span> | ||
</div> | ||
<div class="progress progress-striped active"> | ||
<div class="bar"></div> | ||
</div> | ||
<div class="alert alert-error"> | ||
<span></span> | ||
</div> | ||
<hr></hr> | ||
</div> | ||
</script> | ||
{% endblock mainpanel %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# -*- encoding: utf-8 -*- | ||
|
||
from django.test import TestCase | ||
|
||
from geotrek.common.tasks import import_datas | ||
|
||
|
||
class TasksTest(TestCase): | ||
|
||
def test_import_exceptions(self): | ||
self.assertRaises( | ||
ImportError, import_datas, filename='bombadil', class_name='haricot', module_name='toto') | ||
|
||
def test_import_message_exception(self): | ||
self.assertRaisesMessage( | ||
ImportError, | ||
"Failed to import parser class 'haricot' from module 'toto'", | ||
import_datas, | ||
filename='bombadil', | ||
class_name='haricot', | ||
module_name='toto' | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.