Support multiple rendering formats and display links to generated files

stable
Thomas Petazzoni 2009-08-29 17:23:11 +02:00
rodzic 331d738c89
commit 2b13d8bc3f
5 zmienionych plików z 54 dodań i 10 usunięć

Wyświetl plik

@ -5,7 +5,7 @@ import time, os , sys, select, signal
from datetime import datetime
from www.maposmatic.models import MapRenderingJob
from www.settings import RENDERING_RESULT_PATH, logdaemon
from www.settings import RENDERING_RESULT_PATH, logdaemon, RENDERING_RESULT_FORMATS
import ocitysmap
def handler(signum, frame, pipe_write):
@ -26,10 +26,10 @@ def render_job_process(job):
outfile_prefix = os.path.join(RENDERING_RESULT_PATH, job.files_prefix())
_map = renderer.render_into_files(job.maptitle, outfile_prefix,
["png"], "zoom:16")
RENDERING_RESULT_FORMATS, "zoom:16")
renderer.render_index(job.maptitle, outfile_prefix,
["png"], _map.width, _map.height)
RENDERING_RESULT_FORMATS, _map.width, _map.height)
sys.exit(0)

Wyświetl plik

@ -1,5 +1,6 @@
from django.db import models
from datetime import datetime
import www.settings
import re
import logging
@ -60,6 +61,30 @@ class MapRenderingJob(models.Model):
self.resultmsg = resultmsg
self.save()
def is_waiting(self):
return self.status == 0
def is_rendering(self):
return self.status == 1
def is_done(self):
return self.status == 2
def is_done_ok(self):
return self.is_done() and self.resultmsg == "ok"
def is_done_failed(self):
return self.is_done() and self.resultmsg != "ok"
def output_files(self):
allfiles = []
for format in www.settings.RENDERING_RESULT_FORMATS:
allfiles.append((www.settings.RENDERING_RESULT_URL + "/" + self.files_prefix() + "." + format,
self.maptitle + " %s Map" % format.upper()))
allfiles.append((www.settings.RENDERING_RESULT_URL + "/" + self.files_prefix() + "_index." + format,
self.maptitle + " %s Index" % format.upper()))
return allfiles
def current_position_in_queue(self):
return MapRenderingJob.objects.filter(status=0).filter(index_queue_at_submission__lte=self.index_queue_at_submission).count()

Wyświetl plik

@ -14,6 +14,7 @@ DATABASE_PORT = '' # Set to empty string for default. Not used with
RENDERING_RESULT_PATH = '/tmp/direc/tory'
RENDERING_RESULT_URL = 'http://host.name/dir/ec/tory'
RENDERING_RESULT_FORMATS = ['png', 'svg', 'pdf']
WWW_LOGFILE = '/tmp/maposmatic-www.log'
WWW_LOGLEVEL = logging.INFO

Wyświetl plik

@ -7,7 +7,7 @@ class="activelink"
{% endblock %}
{% block page %}
<h1>Map Status</h1>
<h1>Map <i>{{ job.maptitle }}</i> Status</h1>
<table>
<tr>
@ -41,24 +41,24 @@ class="activelink"
<tr>
<td>Start of rendering time</td>
<td>
{% ifequal job.status 0 %}
{% if job.is_waiting %}
Rendering not started yet
{% else %}
{{ job.startofrendering_time|date:"l d M Y \a\t H:i:s" }}
{% endifequal %}
{% endif %}
</td>
</tr>
<tr>
<td>End of rendering time</td>
<td>
{% ifequal job.status 2 %}
{% if job.is_done %}
{{ job.endofrendering_time|date:"l d M Y \a\t H:i:s" }}
{% else %}
Rendering not finished yet
{% endifequal %}
{% endif %}
</td>
</tr>
{% ifequal job.status 0 %}
{% if job.is_waiting %}
<tr>
<td>Current position in queue</td>
<td>{{ job.current_position_in_queue }}
@ -67,7 +67,19 @@ class="activelink"
<td>Estimated rendering time completion</td>
<td>{{ job.rendering_estimated_start_time|timeuntil }}</td>
</tr>
{% endifequal %}
{% endif %}
{% if job.is_done_ok %}
<tr>
<td>Result files</td>
<td>
<ul>
{% for file in job.output_files %}
<li><a href="{{file.0}}">{{file.1}}</a></li>
{% endfor %}
</ul>
</td>
</tr>
{% endif %}
</table>

Wyświetl plik

@ -16,4 +16,10 @@ urlpatterns = patterns('',
(r'^jobs/$', maposmatic.views.all_jobs),
(r'^maps/$', maposmatic.views.all_maps),
(r'^about/$', maposmatic.views.about),
(r'^results/(?P<path>.*)$',
'django.views.static.serve',
{'document_root': '/tmp/foo/'}),
)