Browse Source

initial version of django code.

master
Marc Poulhies 11 years ago
commit
8d73979aa0
  1. 0
      __init__.py
  2. 0
      airspace/__init__.py
  3. 4
      airspace/admin.py
  4. 19
      airspace/load.py
  5. 20
      airspace/models.py
  6. 16
      airspace/tests.py
  7. 20
      airspace/views.py
  8. 14
      manage.py
  9. 148
      settings.py
  10. 9
      templates/airspace/airspaces_list.html
  11. 57
      templates/airspace/amap.html
  12. 25
      urls.py

0
__init__.py

0
airspace/__init__.py

4
airspace/admin.py

@ -0,0 +1,4 @@
from django.contrib.gis import admin
from models import AirSpaces
admin.site.register(AirSpaces, admin.OSMGeoAdmin)

19
airspace/load.py

@ -0,0 +1,19 @@
import os
from django.contrib.gis.utils import LayerMapping
from models import AirSpaces
airspaces_mapping = {
'name' : 'NAME',
'clazz' : 'CLASS',
'ceiling' : 'CEILING',
'floor' : 'FLOOR',
'geom' : 'POLYGON',
}
airspace_shp = os.path.abspath(os.path.join(os.path.dirname(__file__), 'data/layer.shp'))
def run(verbose=True):
lm = LayerMapping(AirSpaces, airspace_shp, airspaces_mapping,
transform=False, encoding='UTF-8')
lm.save(strict=True, verbose=verbose)

20
airspace/models.py

@ -0,0 +1,20 @@
# Create your models here.
# This is an auto-generated Django model module created by ogrinspect.
from django.contrib.gis.db import models
class AirSpaces(models.Model):
name = models.CharField(max_length=100)
clazz = models.CharField(max_length=5)
ceiling = models.CharField(max_length=200)
floor = models.CharField(max_length=200)
geom = models.PolygonField()
objects = models.GeoManager()
# So the model is pluralized correctly in the admin.
class Meta:
verbose_name_plural = "Air Spaces"
# Returns the string representation of the model.
def __unicode__(self):
return self.name

16
airspace/tests.py

@ -0,0 +1,16 @@
"""
This file demonstrates writing tests using the unittest module. These will pass
when you run "manage.py test".
Replace this with more appropriate tests for your application.
"""
from django.test import TestCase
class SimpleTest(TestCase):
def test_basic_addition(self):
"""
Tests that 1 + 1 always equals 2.
"""
self.assertEqual(1 + 1, 2)

20
airspace/views.py

@ -0,0 +1,20 @@
from django.http import HttpResponse
from airspace.models import AirSpaces
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.http import Http404
def json_zone(request, zone_id):
try:
z = AirSpaces.objects.get(pk=zone_id)
s = z.geom.json
except AirSpaces.DoesNotExist:
raise Http404
return HttpResponse(s, mimetype='application/json')
def amap(request):
return render_to_response('airspace/amap.html',
{},
context_instance=RequestContext(request))

14
manage.py

@ -0,0 +1,14 @@
#!/usr/bin/python
from django.core.management import execute_manager
import imp
try:
imp.find_module('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" % __file__)
sys.exit(1)
import settings
if __name__ == "__main__":
execute_manager(settings)

148
settings.py

@ -0,0 +1,148 @@
# Django settings for GDairspace project.
DEBUG = True
TEMPLATE_DEBUG = DEBUG
ADMINS = (
('XXXX', 'XXXXX'),
)
MANAGERS = ADMINS
DATABASES = {
'default': {
'ENGINE': 'django.contrib.gis.db.backends.postgis', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'airspace-db', # Or path to database file if using sqlite3.
'USER': 'airspace-user', # Not used with sqlite3.
'PASSWORD': 'XXXXXXX', # Not used with sqlite3.
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
'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.
# On Unix systems, a value of None will cause Django to use the same
# timezone as the operating system.
# 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
# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale
USE_L10N = True
# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/media/"
MEDIA_ROOT = ''
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
MEDIA_URL = ''
# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/home/media/media.lawrence.com/static/"
STATIC_ROOT = ''
# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = '/static/'
# URL prefix for admin static files -- CSS, JavaScript and images.
# Make sure to use a trailing slash.
# Examples: "http://foo.com/static/admin/", "/static/admin/".
ADMIN_MEDIA_PREFIX = '/static/admin/'
# Additional locations of static files
STATICFILES_DIRS = (
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)
# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
# Make this unique, and don't share it with anybody.
SECRET_KEY = '_sy38&7bki&awz*-d=t5*7_xc0m5nea990c7w+#hc1^)9y#hbb'
# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
# 'django.template.loaders.eggs.Loader',
)
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
)
ROOT_URLCONF = 'GDairspace.urls'
TEMPLATE_DIRS = (
'/home/marc/geodjango/GDairspace/templates/',
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.gis',
'airspace',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
)
# A sample logging configuration. The only tangible logging
# performed by this configuration is to send an email to
# the site admins on every HTTP 500 error.
# See http://docs.djangoproject.com/en/dev/topics/logging for
# more details on how to customize your logging configuration.
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'mail_admins': {
'level': 'ERROR',
'class': 'django.utils.log.AdminEmailHandler'
}
},
'loggers': {
'django.request': {
'handlers': ['mail_admins'],
'level': 'ERROR',
'propagate': True,
},
}
}

9
templates/airspace/airspaces_list.html

@ -0,0 +1,9 @@
{% block content %}
<h2>AirSpaces</h2>
<ul>
{% for as in object_list %}
<li>{{ as.name }} :: <a href="json/{{ as.id }}">JSON</a></li>
{% endfor %}
</ul>
{% endblock %}

57
templates/airspace/amap.html

@ -0,0 +1,57 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Air Space map</title>
<script src="{{ STATIC_URL }}OpenLayers.js"></script>
<script src="{{ STATIC_URL }}js/airspace.js"></script>
<script src="{{ STATIC_URL }}js/jquery-1.5.1.js"></script>
<link rel="stylesheet" href="{{ STATIC_URL }}style2.css" type="text/css">
<link rel="stylesheet" href="{{STATIC_URL }}style.css" type="text/css">
</head>
<body>
<div id="map" class="smallmap"></div>
<div id="highlighted"></div>
<div id="info"></div>
<form id="interload">
Inter: <input type="text" id="interurl" name="interurl" /> <br />
<input type="submit" name="load" />
</form>
<script defer="defer" type="text/javascript">
var map = new OpenLayers.Map('map', {
projection: new OpenLayers.Projection("EPSG:900913")
});
// var wms = new OpenLayers.Layer.WMS( "OpenLayers WMS",
// "http://vmap0.tiles.osgeo.org/wms/vmap0", {layers: 'basic'} );
var osm = new OpenLayers.Layer.OSM();
osm.setIsBaseLayer(true);
map.addLayers([osm]);
/* displayAirspace(map, spaces); */
var layer_switcher = new OpenLayers.Control.LayerSwitcher();
map.addControl(layer_switcher);
layer_switcher.activate();
map.setCenter(new OpenLayers.LonLat(0, 0), 1);
var gjson = { "type": "Polygon", "coordinates": [ [ [ 2.866667, 49.232778 ], [ 3.056389, 49.188333 ], [ 3.146111, 49.021389 ], [ 3.036111, 48.874722 ], [ 3.036111, 48.874722 ], [ 3.035333, 48.874966 ], [ 3.034527, 48.875208 ], [ 3.033715, 48.875440 ], [ 3.032897, 48.875663 ], [ 3.032073, 48.875877 ], [ 3.031244, 48.876081 ], [ 3.030409, 48.876276 ], [ 3.029569, 48.876461 ], [ 3.028725, 48.876636 ], [ 3.027876, 48.876801 ], [ 3.027022, 48.876957 ], [ 3.026165, 48.877103 ], [ 3.025304, 48.877239 ], [ 3.024439, 48.877365 ], [ 3.023571, 48.877482 ], [ 3.022701, 48.877588 ], [ 3.021827, 48.877684 ], [ 3.020951, 48.877770 ], [ 3.020073, 48.877846 ], [ 3.019193, 48.877912 ], [ 3.018312, 48.877968 ], [ 3.017429, 48.878014 ], [ 3.016545, 48.878049 ], [ 3.015660, 48.878075 ], [ 3.014775, 48.878090 ], [ 3.013889, 48.878095 ], [ 3.013003, 48.878090 ], [ 3.012118, 48.878075 ], [ 3.011233, 48.878049 ], [ 3.010349, 48.878014 ], [ 3.009466, 48.877968 ], [ 3.008585, 48.877912 ], [ 3.007705, 48.877846 ], [ 3.006827, 48.877770 ], [ 3.005951, 48.877684 ], [ 3.005077, 48.877588 ], [ 3.004206, 48.877482 ], [ 3.003339, 48.877365 ], [ 3.002474, 48.877239 ], [ 3.001613, 48.877103 ], [ 3.000756, 48.876957 ], [ 2.999902, 48.876801 ], [ 2.999053, 48.876636 ], [ 2.998208, 48.876461 ], [ 2.997369, 48.876276 ], [ 2.996534, 48.876081 ], [ 2.995704, 48.875877 ], [ 2.994881, 48.875663 ], [ 2.994062, 48.875440 ], [ 2.993250, 48.875208 ], [ 2.992445, 48.874966 ], [ 2.991645, 48.874715 ], [ 2.990853, 48.874455 ], [ 2.990068, 48.874186 ], [ 2.989289, 48.873908 ], [ 2.988519, 48.873621 ], [ 2.987756, 48.873325 ], [ 2.987001, 48.873021 ], [ 2.986254, 48.872708 ], [ 2.985516, 48.872386 ], [ 2.984787, 48.872056 ], [ 2.984066, 48.871718 ], [ 2.983354, 48.871371 ], [ 2.982652, 48.871016 ], [ 2.981959, 48.870653 ], [ 2.981276, 48.870283 ], [ 2.980603, 48.869904 ], [ 2.979940, 48.869518 ], [ 2.979287, 48.869124 ], [ 2.978645, 48.868723 ], [ 2.978014, 48.868315 ], [ 2.977394, 48.867899 ], [ 2.976785, 48.867477 ], [ 2.976187, 48.867047 ], [ 2.975600, 48.866610 ], [ 2.975026, 48.866167 ], [ 2.974463, 48.865718 ], [ 2.973912, 48.865262 ], [ 2.973373, 48.864799 ], [ 2.972847, 48.864331 ], [ 2.972333, 48.863857 ], [ 2.971832, 48.863376 ], [ 2.971344, 48.862891 ], [ 2.970869, 48.862399 ], [ 2.970406, 48.861902 ], [ 2.969957, 48.861400 ], [ 2.969522, 48.860893 ], [ 2.969100, 48.860381 ], [ 2.968692, 48.859864 ], [ 2.968297, 48.859343 ], [ 2.967916, 48.858817 ], [ 2.967550, 48.858287 ], [ 2.967197, 48.857753 ], [ 2.966859, 48.857214 ], [ 2.966535, 48.856672 ], [ 2.966225, 48.856127 ], [ 2.965931, 48.855577 ], [ 2.965650, 48.855025 ], [ 2.965384, 48.854469 ], [ 2.965134, 48.853911 ], [ 2.964898, 48.853349 ], [ 2.964677, 48.852785 ], [ 2.964470, 48.852219 ], [ 2.964279, 48.851650 ], [ 2.964103, 48.851079 ], [ 2.963943, 48.850507 ], [ 2.963797, 48.849932 ], [ 2.963667, 48.849356 ], [ 2.963552, 48.848778 ], [ 2.963452, 48.848200 ], [ 2.963368, 48.847620 ], [ 2.963299, 48.847039 ], [ 2.963246, 48.846458 ], [ 2.963208, 48.845876 ], [ 2.963185, 48.845294 ], [ 2.963178, 48.844711 ], [ 2.963186, 48.844129 ], [ 2.963210, 48.843546 ], [ 2.963249, 48.842965 ], [ 2.963304, 48.842383 ], [ 2.963374, 48.841803 ], [ 2.963459, 48.841223 ], [ 2.963560, 48.840644 ], [ 2.963676, 48.840067 ], [ 2.963808, 48.839491 ], [ 2.963954, 48.838916 ], [ 2.964116, 48.838344 ], [ 2.964293, 48.837773 ], [ 2.964485, 48.837204 ], [ 2.964692, 48.836638 ], [ 2.964915, 48.836074 ], [ 2.965278, 48.835278 ], [ 2.965278, 48.835278 ], [ 2.857778, 48.813889 ], [ 2.840556, 48.661667 ], [ 2.840556, 48.661667 ], [ 2.618889, 48.698611 ], [ 2.549444, 48.656389 ], [ 2.488889, 48.618889 ], [ 2.488333, 48.505833 ], [ 2.395833, 48.406389 ], [ 2.165833, 48.434722 ], [ 2.051389, 48.507778 ], [ 2.025833, 48.524167 ], [ 1.999167, 48.633333 ], [ 1.994167, 48.653889 ], [ 1.986667, 48.798611 ], [ 1.996667, 48.798889 ], [ 1.998333, 48.890833 ], [ 1.999444, 48.990556 ], [ 2.197222, 49.121111 ], [ 2.314444, 49.141111 ], [ 2.866667, 49.232778 ] ] ] };
displaySingleAirspace(map, gjson);
$('#interload').submit(function() {
$.getJSON($('#interurl').val(), function(data){
$.each(data, function(index, inter) {
displayIntersection(map, inter);
});
});
return false;
});
</script>
</body>
</html>

25
urls.py

@ -0,0 +1,25 @@
from django.conf.urls.defaults import patterns, include, url
from django.contrib.gis import admin
from django.views.generic import ListView
from airspace.models import AirSpaces
# Uncomment the next two lines to enable the admin:
# from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'GDairspace.views.home', name='home'),
# url(r'^GDairspace/', include('GDairspace.foo.urls')),
url(r'^airspace/$', ListView.as_view(
model=AirSpaces,
)),
url(r'^airspace/json/(?P<zone_id>\d+)$', 'airspace.views.json_zone' ),
# Uncomment the admin/doc line below to enable admin documentation:
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
url(r'^airspace/amap/', 'airspace.views.amap'),
# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)),
)
Loading…
Cancel
Save