From 7c283573691dfd66eec142d0fb31e746d2f6f1a1 Mon Sep 17 00:00:00 2001 From: Thomas Petazzoni Date: Fri, 28 Aug 2009 15:36:10 +0200 Subject: [PATCH] First import of maposmatic web service --- www/__init__.py | 0 www/manage.py | 11 ++++ www/maposmatic/__init__.py | 0 www/maposmatic/models.py | 24 ++++++++ www/maposmatic/views.py | 47 +++++++++++++++ www/media/style.css | 69 ++++++++++++++++++++++ www/settings.py | 80 ++++++++++++++++++++++++++ www/templates/maposmatic/all_jobs.html | 28 +++++++++ www/templates/maposmatic/base.html | 44 ++++++++++++++ www/templates/maposmatic/index.html | 59 +++++++++++++++++++ www/templates/maposmatic/job.html | 8 +++ www/urls.py | 17 ++++++ 12 files changed, 387 insertions(+) create mode 100644 www/__init__.py create mode 100755 www/manage.py create mode 100644 www/maposmatic/__init__.py create mode 100644 www/maposmatic/models.py create mode 100644 www/maposmatic/views.py create mode 100644 www/media/style.css create mode 100644 www/settings.py create mode 100644 www/templates/maposmatic/all_jobs.html create mode 100644 www/templates/maposmatic/base.html create mode 100644 www/templates/maposmatic/index.html create mode 100644 www/templates/maposmatic/job.html create mode 100644 www/urls.py diff --git a/www/__init__.py b/www/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/www/manage.py b/www/manage.py new file mode 100755 index 00000000..bcdd55e2 --- /dev/null +++ b/www/manage.py @@ -0,0 +1,11 @@ +#!/usr/bin/python +from django.core.management import execute_manager +try: + import settings # Assumed to be in the same directory. +except ImportError: + import sys + sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n(If the file settings.py does indeed exist, it's causing an ImportError somehow.)\n" % __file__) + sys.exit(1) + +if __name__ == "__main__": + execute_manager(settings) diff --git a/www/maposmatic/__init__.py b/www/maposmatic/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/www/maposmatic/models.py b/www/maposmatic/models.py new file mode 100644 index 00000000..63b875f3 --- /dev/null +++ b/www/maposmatic/models.py @@ -0,0 +1,24 @@ +from django.db import models + +class MapRenderingJob(models.Model): + + STATUS_LIST = ( + (0, 'Submitted'), + (1, 'In progress'), + (2, 'Done'), + ) + + maptitle = models.CharField(max_length=256) + administrative_city = models.CharField(max_length=256, blank=True, null=True) + lat_upper_left = models.FloatField(blank=True, null=True) + long_upper_left = models.FloatField(blank=True, null=True) + lat_bottom_right = models.FloatField(blank=True, null=True) + long_bottom_right = models.FloatField(blank=True, null=True) + status = models.IntegerField(choices=STATUS_LIST) + submission_time = models.DateTimeField(auto_now_add=True) + startofrendering_time = models.DateTimeField(null=True) + endofrendering_time = models.DateTimeField(null=True) + resultmsg = models.CharField(max_length=256, null=True) + submitterip = models.IPAddressField() + index_queue_at_submission = models.IntegerField() + diff --git a/www/maposmatic/views.py b/www/maposmatic/views.py new file mode 100644 index 00000000..3c58c797 --- /dev/null +++ b/www/maposmatic/views.py @@ -0,0 +1,47 @@ +# Create your views here. + +from django.forms import ModelForm +from django.shortcuts import get_object_or_404, render_to_response +from django.http import HttpResponseRedirect +from www.maposmatic.models import MapRenderingJob + +class MapRenderingJobForm(ModelForm): + class Meta: + model = MapRenderingJob + fields = ('maptitle', 'administrative_city', 'lat_upper_left', 'long_upper_left', + 'lat_bottom_right', 'long_bottom_right') + +def index(request): + if request.method == 'POST': + print 'POST' + form = MapRenderingJobForm(request.POST) + if form.is_valid(): + print 'form_valid' + job = MapRenderingJob() + job.maptitle = form.cleaned_data['maptitle'] + job.administrative_city = form.cleaned_data['administrative_city'] + job.lat_upper_left = form.cleaned_data['lat_upper_left'] + job.long_upper_left = form.cleaned_data['long_upper_left'] + job.lat_bottom_right = form.cleaned_data['lat_bottom_right'] + job.long_bottom_right = form.cleaned_data['long_bottom_right'] + job.status = 0 # Submitted + job.submitterip = request.META['REMOTE_ADDR'] + job.index_queue_at_submission = 0 + job.save() + + return HttpResponseRedirect('/jobs/%d' % job.id) + else: + form = MapRenderingJobForm() + return render_to_response('maposmatic/index.html', + { 'form' : form }) + +def job(request, job_id): + job = get_object_or_404(MapRenderingJob, id=job_id) + return render_to_response('maposmatic/job.html', + { 'job' : job }) + +def all_jobs(request): + jobs = MapRenderingJob.objects.all() + print jobs + return render_to_response('maposmatic/all_jobs.html', + { 'jobs' : jobs }) diff --git a/www/media/style.css b/www/media/style.css new file mode 100644 index 00000000..bdd50566 --- /dev/null +++ b/www/media/style.css @@ -0,0 +1,69 @@ +html,body { + margin:0; + padding:0; +} + +body{font: 85%/1.3 sans-serif; + text-align: left;background: #fff;padding-bottom:20px} +a { color: #0066B3; background: inherit; text-decoration: none;} +h1 { font: bold 2.1em Sans-Serif; color: #036DA7 } +h2 { font: bold 1.1em Sans-Serif; padding: 0; margin: 0; } + +div#header{width:100%;overflow:hidden;background: #BBD9EE; } +div#header h1,div#menu{width:770px;margin:0 auto;text-align:left} +div#header h1{padding: 30px 0 20px;color: #fff} + +ul#nav,ul#nav li{list-style-type:none;margin:0;padding:0} +ul#nav{float:right;font-size: 80%} +ul#nav li{float:left;margin-left: 3px;text-align: center} +ul#nav a{float:left;width: 95px;padding: 5px 0;background: #E7F1F8;text-decoration:none;color: #666; border-top : 1px solid #fff; border-left : 1px solid #fff; border-right : 1px solid #fff;} +ul#nav a:hover{background: #fff;color: #000} +ul#nav li.activelink a,ul#nav li.activelink a:hover{background: #FFF;color: #003} + +#right { + float: left; + width: 76%; + padding: 1em; + margin-bottom: 1.2em; + background: #eee; + text-align: justify; +} + +#left { + float: right; + width: 20%; + margin: 0 0 10px 0; +} + +#left .box { + padding: 1em; + margin: 0 0 1em 0; + background : #FFF6BF; +} + + +#content { + font: 95%/1.3 sans-serif; + margin: 0 auto; + padding: 15px; + background: #fff; +} + +ul { padding: 0; margin: 0;} +li { list-style-type: none;} + +input { + background: #FFF6BF; + border: 3px solid #CCC; + width: 300px; + padding: 3px; +} + +input:hover { + border: 3px solid #AAA; +} + +input[type="submit"] +{ + width: auto; +} \ No newline at end of file diff --git a/www/settings.py b/www/settings.py new file mode 100644 index 00000000..29e78cbd --- /dev/null +++ b/www/settings.py @@ -0,0 +1,80 @@ +# Django settings for www project. + +DEBUG = True +TEMPLATE_DEBUG = DEBUG + +ADMINS = ( + # ('Your Name', 'your_email@domain.com'), +) + +MANAGERS = ADMINS + +DATABASE_ENGINE = 'postgresql_psycopg2' # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'. +DATABASE_NAME = 'testdb' # Or path to database file if using sqlite3. +DATABASE_USER = 'test' # Not used with sqlite3. +DATABASE_PASSWORD = 'test' # Not used with sqlite3. +DATABASE_HOST = 'localhost' # Set to empty string for localhost. Not used with sqlite3. +DATABASE_PORT = '' # Set to empty string for default. Not used with sqlite3. + +# Local time zone for this installation. Choices can be found here: +# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name +# although not all choices may be available on all operating systems. +# If running in a Windows environment this must be set to the same as your +# system time zone. +TIME_ZONE = 'America/Chicago' + +# Language code for this installation. All choices can be found here: +# http://www.i18nguy.com/unicode/language-identifiers.html +LANGUAGE_CODE = 'en-us' + +SITE_ID = 1 + +# If you set this to False, Django will make some optimizations so as not +# to load the internationalization machinery. +USE_I18N = True + +# Absolute path to the directory that holds media. +# Example: "/home/media/media.lawrence.com/" +MEDIA_ROOT = '' + +# URL that handles the media served from MEDIA_ROOT. Make sure to use a +# trailing slash if there is a path component (optional in other cases). +# Examples: "http://media.lawrence.com", "http://example.com/media/" +MEDIA_URL = '' + +# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a +# trailing slash. +# Examples: "http://foo.com/media/", "/media/". +ADMIN_MEDIA_PREFIX = '/media/' + +# Make this unique, and don't share it with anybody. +SECRET_KEY = 'tm+wb)lp5q%br=p0d2toz&km_-w)cmcelv!7inons&^v9(q!d2' + +# List of callables that know how to import templates from various sources. +TEMPLATE_LOADERS = ( + 'django.template.loaders.filesystem.load_template_source', + 'django.template.loaders.app_directories.load_template_source', +# 'django.template.loaders.eggs.load_template_source', +) + +MIDDLEWARE_CLASSES = ( + 'django.middleware.common.CommonMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', +) + +ROOT_URLCONF = 'www.urls' + +import os.path + +PROJECT_PATH = os.path.dirname(os.path.abspath(__file__)) + +TEMPLATE_DIRS = ( + os.path.join(PROJECT_PATH, 'templates'), +) + +LOCAL_MEDIA_PATH = os.path.join(PROJECT_PATH, 'media') + +INSTALLED_APPS = ( + 'www.maposmatic', +) diff --git a/www/templates/maposmatic/all_jobs.html b/www/templates/maposmatic/all_jobs.html new file mode 100644 index 00000000..fc2997bc --- /dev/null +++ b/www/templates/maposmatic/all_jobs.html @@ -0,0 +1,28 @@ +{% extends "maposmatic/base.html" %} + +{% block page %} + +

Job list

+ + +{% for job in jobs %} + + + + +{% endfor %} +
+ {{ job.maptitle }}
+
+ {% ifequal job.status 0 %} + Waiting rendering + {% endifequal %} + {% ifequal job.status 1 %} + Rendering in progress... + {% endifequal %} + {% ifequal job.status 2 %} + Rendering done or failed + {% endifequal %} +
+ +{% endblock %} diff --git a/www/templates/maposmatic/base.html b/www/templates/maposmatic/base.html new file mode 100644 index 00000000..3d43c66e --- /dev/null +++ b/www/templates/maposmatic/base.html @@ -0,0 +1,44 @@ + + + + + + MapOSMatic + + + + {% block extrahead %}{% endblock %} + + + + +
+ + +
+
+

Liens :

+ +
+ +
+
Design par Minimalistic Design
+
+
+
+ + + \ No newline at end of file diff --git a/www/templates/maposmatic/index.html b/www/templates/maposmatic/index.html new file mode 100644 index 00000000..45e8aaba --- /dev/null +++ b/www/templates/maposmatic/index.html @@ -0,0 +1,59 @@ +{% extends "maposmatic/base.html" %} + +{% block extrahead %} + +{% endblock %} + +{% block page %} +

MapOSMatic

+ +
+ + + + + + + + + + + + + + + + + + + + + + +
Nom de la carte{{ form.maptitle }}
Mode de génération + Basé sur la limite administrative
+ Basé sur une bouding box +
Nom de la ville{{ form.administrative_city }}
+ +
+ +{% endblock %} \ No newline at end of file diff --git a/www/templates/maposmatic/job.html b/www/templates/maposmatic/job.html new file mode 100644 index 00000000..2bea819d --- /dev/null +++ b/www/templates/maposmatic/job.html @@ -0,0 +1,8 @@ +{% extends "maposmatic/base.html" %} + +{% block page %} +

MapOSMatic

+ +{{ job.maptitle }} + +{% endblock %} \ No newline at end of file diff --git a/www/urls.py b/www/urls.py new file mode 100644 index 00000000..21fd0e9d --- /dev/null +++ b/www/urls.py @@ -0,0 +1,17 @@ +from django.conf.urls.defaults import * + +# Uncomment the next two lines to enable the admin: +# from django.contrib import admin +# admin.autodiscover() + +import maposmatic.views +import settings + +urlpatterns = patterns('', + (r'^$', maposmatic.views.index), + (r'^smedia/(?P.*)$', + 'django.views.static.serve', + {'document_root': settings.LOCAL_MEDIA_PATH}), + (r'^jobs/(?P\d+)$', maposmatic.views.job), + (r'^jobs/$', maposmatic.views.all_jobs), +)