maposmatic-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Maposmatic-dev] [PATCH maposmatic 2/2] Implement the "Recreate Map" fea


From: Maxime Petazzoni
Subject: [Maposmatic-dev] [PATCH maposmatic 2/2] Implement the "Recreate Map" feature
Date: Fri, 14 May 2010 11:57:19 +0200

Each completed job now features a "Recreate map" button that reschedules
a similar map on the queue. The button only appears for completed maps
(status >= 2), and triggers a rendering_already_exists() check before
creating a new MapRenderingJob.

Signed-off-by: Maxime Petazzoni <address@hidden>
---
 www/maposmatic/forms.py                |   16 ++++++++++++++
 www/maposmatic/views.py                |   36 ++++++++++++++++++++++++++++++++
 www/media/style.css                    |   12 ++++++++++
 www/templates/maposmatic/job-page.html |    7 ++++++
 www/templates/maposmatic/job.html      |   13 ++++++++++-
 www/templates/maposmatic/map.html      |   14 +++++++++++-
 www/urls.py                            |    3 ++
 7 files changed, 99 insertions(+), 2 deletions(-)

diff --git a/www/maposmatic/forms.py b/www/maposmatic/forms.py
index abd6e70..ecbdea6 100644
--- a/www/maposmatic/forms.py
+++ b/www/maposmatic/forms.py
@@ -135,3 +135,19 @@ class MapRenderingJobForm(forms.ModelForm):
 
         return cleaned_data
 
+class MapRecreateForm(forms.Form):
+    """
+    The map recreate form, to reschedule an already processed job on the queue.
+    """
+
+    jobid = forms.IntegerField(widget=forms.HiddenInput, required=True)
+
+    def clean(self):
+        cleaned_data = self.cleaned_data
+
+        try:
+            cleaned_data["jobid"] = int(cleaned_data.get("jobid", 0))
+        except ValueError:
+            cleaned_data["jobid"] = 0
+
+        return cleaned_data
diff --git a/www/maposmatic/views.py b/www/maposmatic/views.py
index 5cc02ae..39cb977 100644
--- a/www/maposmatic/views.py
+++ b/www/maposmatic/views.py
@@ -223,3 +223,39 @@ def query_nominatim(request, format, squery):
                             mimetype='text/json')
     # Support other formats here.
 
+def recreate(request):
+    if request.method == 'POST':
+        form = forms.MapRecreateForm(request.POST)
+        if form.is_valid():
+            job = get_object_or_404(models.MapRenderingJob,
+                                    id=form.cleaned_data['jobid'])
+
+            existing = helpers.rendering_already_exists(job)
+            if existing:
+                request.session['redirected'] = True
+                return HttpResponseRedirect(reverse('job-by-id',
+                                                    args=[existing]))
+
+            newjob = models.MapRenderingJob()
+            newjob.maptitle = job.maptitle
+
+            newjob.administrative_city = job.administrative_city
+            newjob.administrative_osmid = job.administrative_osmid
+
+            newjob.lat_upper_left = job.lat_upper_left
+            newjob.lon_upper_left = job.lon_upper_left
+            newjob.lat_bottom_right = job.lat_bottom_right
+            newjob.lon_bottom_right = job.lon_bottom_right
+
+            newjob.status = 0 # Submitted
+            newjob.submitterip = request.META['REMOTE_ADDR']
+            newjob.map_language = job.map_language
+            newjob.index_queue_at_submission = (models.MapRenderingJob.objects
+                                               .queue_size())
+            newjob.save()
+
+            return HttpResponseRedirect(reverse('job-by-id',
+                                                args=[newjob.id]))
+
+    return HttpResponseBadRequest("ERROR: Invalid request")
+
diff --git a/www/media/style.css b/www/media/style.css
index e0956b5..77a80c3 100644
--- a/www/media/style.css
+++ b/www/media/style.css
@@ -246,6 +246,18 @@ p.infobox img {
   background: #fff6bf;
 }
 
+form.recreate {
+  float: right;
+}
+
+.job form.recreate {
+  visibility: hidden;
+}
+
+.job:hover form.recreate {
+  visibility: visible;
+}
+
 h2.jobtitle {
   margin: 0;
   padding: 0;
diff --git a/www/templates/maposmatic/job-page.html 
b/www/templates/maposmatic/job-page.html
index bc55b2c..e7184ed 100644
--- a/www/templates/maposmatic/job-page.html
+++ b/www/templates/maposmatic/job-page.html
@@ -33,6 +33,13 @@
 {% block menu-jobs %}class="activelink"{% endblock %}
 
 {% block page %}
+{% if not job.needs_waiting %}
+<form method="post" action="{% url recreate %}" class="recreate">
+  <input type="hidden" name="jobid" value="{{ job.id }}" />
+  <input type="submit" value="{% trans "Recreate map" %}" />
+</form>
+{% endif %}
+
 <h1>{{ job.maptitle }}</h1>
 
 {% if redirected %}
diff --git a/www/templates/maposmatic/job.html 
b/www/templates/maposmatic/job.html
index d8acae0..65b63cb 100644
--- a/www/templates/maposmatic/job.html
+++ b/www/templates/maposmatic/job.html
@@ -28,7 +28,18 @@
 
 {% load extratags %}
 
-{% if not single %}<h2 class="jobtitle"><a href="{% url job-by-id job.id 
%}">{{ job.maptitle }}</a></h2>{% endif %}
+{% if not single %}
+{% if not job.needs_waiting %}
+<form method="post" action="{% url recreate %}" class="recreate">
+  <input type="hidden" name="jobid" value="{{ job.id }}" />
+  <input type="submit" value="{% trans "Recreate map" %}" />
+</form>
+{% endif %}
+
+<h2 class="jobtitle">
+  <a href="{% url job-by-id job.id %}">{{ job.maptitle }}</a>
+</h2>
+{% endif %}
 <table class="jobinfo"><tbody><tr>
   <td class="status">
     <img src="/smedia/{{ job.status|job_status_to_icon_name:job.resultmsg 
}}.png" title="{{ job.status|job_status_to_str:job.resultmsg }} ({{ job.status 
}})" />
diff --git a/www/templates/maposmatic/map.html 
b/www/templates/maposmatic/map.html
index 3642b52..56141f4 100644
--- a/www/templates/maposmatic/map.html
+++ b/www/templates/maposmatic/map.html
@@ -28,7 +28,19 @@
 
 {% load extratags %}
 
-{% if not single %}<h2 class="jobtitle"><a href="/jobs/{{ job.id }}">{{ 
job.maptitle }}</a></h2>{% endif %}
+{% if not single %}
+{% if not job.needs_waiting %}
+<form method="post" action="{% url recreate %}" class="recreate">
+  <input type="hidden" name="jobid" value="{{ job.id }}" />
+  <input type="submit" value="{% trans "Recreate map" %}" />
+</form>
+{% endif %}
+
+<h2 class="jobtitle">
+  <a href="/jobs/{{ job.id }}">{{ job.maptitle }}</a>
+</h2>
+{% endif %}
+
 <table class="jobinfo"><tbody><tr>
   <td class="thumb">{% if job.get_thumbnail %}<img src="{{ job.get_thumbnail 
}}" />{% endif %}</td>
   <td class="info">
diff --git a/www/urls.py b/www/urls.py
index 388121c..4dadb98 100644
--- a/www/urls.py
+++ b/www/urls.py
@@ -55,6 +55,9 @@ urlpatterns = patterns('',
     url(r'^new/$', maposmatic.views.new,
         name='new'),
 
+    url(r'^recreate/$', maposmatic.views.recreate,
+        name='recreate'),
+
     (r'^nominatim/([^/]*/)?(.*)$', maposmatic.views.query_nominatim),
 
     # Internationalization
-- 
1.6.3.3.341.g9b22d




reply via email to

[Prev in Thread] Current Thread [Next in Thread]