first commit
This commit is contained in:
commit
11eadcbaa8
46
fabfile.py
vendored
Normal file
46
fabfile.py
vendored
Normal file
|
@ -0,0 +1,46 @@
|
|||
#this is a fabfile, use it with fab from http://fabfile.org/
|
||||
#
|
||||
# initial setup:
|
||||
# fab production setup
|
||||
#
|
||||
# deploy changes:
|
||||
# fab production deploy
|
||||
#
|
||||
|
||||
from os.path import join
|
||||
from fabric.api import run, local, sudo, put, env
|
||||
|
||||
env.project_name = 'openmumbai'
|
||||
|
||||
def production():
|
||||
env.hosts = ['%(project_name)s@topomancy.com'%env, ]
|
||||
env.project_root = '/srv/%(project_name)s'%env
|
||||
|
||||
def bzr_push():
|
||||
local('bzr push bzr+ssh://%(project_name)s@%(host)s%(project_root)s'%env)
|
||||
|
||||
def bzr_update():
|
||||
run('cd %(project_root)s;bzr update'%env)
|
||||
|
||||
def virtual_run(cmd, *a, **kw):
|
||||
cmd = 'cd %s; source bin/activate; %s' % (env.project_root, cmd)
|
||||
run(cmd, *a, **kw)
|
||||
|
||||
def update_requirements():
|
||||
run('pip -E %(project_root)s install -r %(project_root)s/requirements.txt'%env)
|
||||
|
||||
def setup():
|
||||
"""
|
||||
Setup a fresh virtualenv
|
||||
"""
|
||||
local('bzr push --use-existing-dir bzr+ssh://%(project_name)s@%(host)s%(project_root)s'%env)
|
||||
run('cd %(project_root)s; test -e .bzr/checkout || bzr checkout'%env)
|
||||
run('virtualenv %(project_root)s'%env)
|
||||
put(join('settings', '%(host)s.py'%env), join(env.project_root, env.project_name, 'local_settings.py'))
|
||||
update_requirements()
|
||||
|
||||
def deploy():
|
||||
# bzr_push()
|
||||
bzr_update()
|
||||
# virtual_run('python %(project_root)s/%(project_name)s/manage.py syncdb;python %(project_root)s/%(project_name)s/manage.py migrate'%env)
|
||||
run('touch %(project_root)s/wsgi/django.wsgi'%env)
|
0
openmumbai/__init__.py
Normal file
0
openmumbai/__init__.py
Normal file
0
openmumbai/base/__init__.py
Normal file
0
openmumbai/base/__init__.py
Normal file
18
openmumbai/base/models.py
Normal file
18
openmumbai/base/models.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
from django.contrib.gis.db import models
|
||||
import datetime
|
||||
|
||||
class BaseModel(models.Model):
|
||||
changed = models.DateTimeField(null=True, editable=False)
|
||||
created = models.DateTimeField(null=True, editable=False)
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
if not self.id:
|
||||
self.created = datetime.datetime.today()
|
||||
self.changed = datetime.datetime.today()
|
||||
if self.created == None:
|
||||
self.created = self.changed
|
||||
super(BaseModel, self).save(*args, **kwargs)
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
23
openmumbai/base/tests.py
Normal file
23
openmumbai/base/tests.py
Normal file
|
@ -0,0 +1,23 @@
|
|||
"""
|
||||
This file demonstrates two different styles of tests (one doctest and one
|
||||
unittest). These will both pass when you run "manage.py test".
|
||||
|
||||
Replace these 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.failUnlessEqual(1 + 1, 2)
|
||||
|
||||
__test__ = {"doctest": """
|
||||
Another way to test that 1 + 1 is equal to 2.
|
||||
|
||||
>>> 1 + 1 == 2
|
||||
True
|
||||
"""}
|
||||
|
1
openmumbai/base/views.py
Normal file
1
openmumbai/base/views.py
Normal file
|
@ -0,0 +1 @@
|
|||
# Create your views here.
|
25
openmumbai/manage.py
Normal file
25
openmumbai/manage.py
Normal file
|
@ -0,0 +1,25 @@
|
|||
#!/usr/bin/env python
|
||||
#!/usr/bin/env python
|
||||
import os
|
||||
|
||||
root_dir = os.path.normpath(os.path.abspath(os.path.dirname(__file__)))
|
||||
os.chdir(root_dir)
|
||||
|
||||
#using virtualenv's activate_this.py to reorder sys.path
|
||||
activate_this = os.path.join(root_dir, '..', 'bin', 'activate_this.py')
|
||||
execfile(activate_this, dict(__file__=activate_this))
|
||||
|
||||
|
||||
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)
|
0
openmumbai/places/__init__.py
Normal file
0
openmumbai/places/__init__.py
Normal file
29
openmumbai/places/admin.py
Normal file
29
openmumbai/places/admin.py
Normal file
|
@ -0,0 +1,29 @@
|
|||
from django.contrib.gis import admin
|
||||
from models import *
|
||||
# from forms import BaseRelationsFormSet
|
||||
#from django import forms
|
||||
#from django.contrib.admin import SimpleListFilter
|
||||
#from ajax_select.fields import AutoCompleteSelectMultipleField, AutoCompleteSelectField
|
||||
|
||||
|
||||
|
||||
class PlaceAdmin(admin.OSMGeoAdmin):
|
||||
# fields = ('preferred_name', 'feature_type', 'admin1', 'admin2', 'geometry', 'url', 'authority_record', 'time_frame', 'is_primary',)
|
||||
search_fields = ['name', 'location']
|
||||
# list_filter = ('feature_type',)
|
||||
# inlines = [FeatureNamesInline]
|
||||
# list_display = ('__unicode__', 'feature_type_name', 'admin1', 'admin2', 'time_start', 'time_end',)
|
||||
# list_per_page = 30
|
||||
# list_filter = (FeatureTypeFilter,)
|
||||
openlayers_url = 'http://openlayers.org/dev/OpenLayers.js'
|
||||
openlayers_img_path = None
|
||||
# form = featuresForm
|
||||
# readonly_fields = ['geometry']
|
||||
# map_template = 'gis/admin/osm.html'
|
||||
# default_lon = 72.855211097628413
|
||||
# default_lat = 19.415775291486027
|
||||
# default_zoom = 4
|
||||
# extra_js = ['http://openstreetmap.org/openlayers/OpenStreetMap.js', 'http://openlayers.org/dev/OpenLayers.js']
|
||||
|
||||
admin.site.register(Place, PlaceAdmin)
|
||||
|
24
openmumbai/places/import_csv.py
Normal file
24
openmumbai/places/import_csv.py
Normal file
|
@ -0,0 +1,24 @@
|
|||
import csv
|
||||
from models import *
|
||||
from decimal import Decimal
|
||||
|
||||
def do(filename):
|
||||
CsvFile = csv.reader(open(filename), delimiter="\t")
|
||||
for row in CsvFile:
|
||||
p = Place()
|
||||
p.ward = row[0].strip()
|
||||
p.reservation = row[1].strip()
|
||||
try:
|
||||
p.pk_serial = int(row[2].strip())
|
||||
except:
|
||||
p.pk_serial = None
|
||||
p.occupied = (row[3].strip() == '*')
|
||||
p.name = row[4]
|
||||
p.address = row[5]
|
||||
p.cts = row[6]
|
||||
try:
|
||||
p.area = Decimal(row[7].strip())
|
||||
except:
|
||||
p.area = 0.0
|
||||
p.save()
|
||||
print "%s saved" % p.name
|
18
openmumbai/places/models.py
Normal file
18
openmumbai/places/models.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
from base.models import BaseModel
|
||||
from django.contrib.gis.db import models
|
||||
|
||||
class Place(BaseModel):
|
||||
ward = models.CharField(max_length=4, blank=True)
|
||||
reservation = models.CharField(max_length=16, blank=True)
|
||||
pk_serial = models.IntegerField(null=True, blank=True) #serial acc to PK Das excel sheets
|
||||
occupied = models.BooleanField(default=False)
|
||||
name = models.CharField(max_length=1024, blank=True)
|
||||
address = models.TextField()
|
||||
cts = models.CharField(max_length=512, null=True, blank=True)
|
||||
area = models.DecimalField(max_digits=15, decimal_places=3)
|
||||
geometry = models.GeometryField(null=True, blank=True)
|
||||
|
||||
def __unicode__(self):
|
||||
return "%s %s %s" % (self.ward, self.reservation, self.name,)
|
||||
|
||||
# Create your models here.
|
16
openmumbai/places/tests.py
Normal file
16
openmumbai/places/tests.py
Normal file
|
@ -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)
|
1
openmumbai/places/views.py
Normal file
1
openmumbai/places/views.py
Normal file
|
@ -0,0 +1 @@
|
|||
# Create your views here.
|
179
openmumbai/settings.py
Normal file
179
openmumbai/settings.py
Normal file
|
@ -0,0 +1,179 @@
|
|||
# Django settings for openmumbai project.
|
||||
import os
|
||||
from os.path import join
|
||||
|
||||
DEBUG = True
|
||||
TEMPLATE_DEBUG = DEBUG
|
||||
|
||||
JSON_DEBUG = False
|
||||
APPEND_SLASH = True
|
||||
#XSENDFILE = False
|
||||
|
||||
ADMINS = (
|
||||
('Sanjay Bhangar', 'b@pad.ma'),
|
||||
# ('Your Name', 'your_email@example.com'),
|
||||
)
|
||||
|
||||
MANAGERS = ADMINS
|
||||
|
||||
PROJECT_ROOT = os.path.normpath(os.path.dirname(__file__))
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.contrib.gis.db.backends.postgis', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
|
||||
'NAME': 'openmumbai', # Or path to database file if using sqlite3.
|
||||
'USER': '', # Not used with sqlite3.
|
||||
'PASSWORD': '', # 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 = join(PROJECT_ROOT, 'static')
|
||||
|
||||
# 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',
|
||||
)
|
||||
|
||||
# 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',
|
||||
# 'debug_toolbar.middleware.DebugToolbarMiddleware',
|
||||
)
|
||||
|
||||
ROOT_URLCONF = 'openmumbai.urls'
|
||||
|
||||
TEMPLATE_DIRS = (
|
||||
join(PROJECT_ROOT, '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',
|
||||
# Uncomment the next line to enable the admin:
|
||||
'django.contrib.admin',
|
||||
# Uncomment the next line to enable admin documentation:
|
||||
'django.contrib.admindocs',
|
||||
'django_extensions',
|
||||
'places',
|
||||
# 'debug_toolbar',
|
||||
)
|
||||
|
||||
# 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,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
#overwrite default settings with local settings
|
||||
try:
|
||||
from local_settings import *
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
# Make this unique, creates random key first at first time.
|
||||
try:
|
||||
SECRET_KEY
|
||||
except NameError:
|
||||
SECRET_FILE = os.path.join(PROJECT_ROOT, 'secret.txt')
|
||||
try:
|
||||
SECRET_KEY = open(SECRET_FILE).read().strip()
|
||||
except IOError:
|
||||
try:
|
||||
from random import choice
|
||||
SECRET_KEY = ''.join([choice('abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)') for i in range(50)])
|
||||
secret = file(SECRET_FILE, 'w')
|
||||
secret.write(SECRET_KEY)
|
||||
secret.close()
|
||||
except IOError:
|
||||
Exception('Please create a %s file with random characters to generate your secret key!' % SECRET_FILE)
|
4
openmumbai/templates/gis/admin/google.html
Normal file
4
openmumbai/templates/gis/admin/google.html
Normal file
|
@ -0,0 +1,4 @@
|
|||
{% extends "gis/admin/openlayers.html" %}
|
||||
{% block openlayers %}
|
||||
{% include "gis/admin/google.js" %}
|
||||
{% endblock %}
|
11
openmumbai/templates/gis/admin/google.js
Normal file
11
openmumbai/templates/gis/admin/google.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
{% extends "gis/admin/openlayers.js" %}
|
||||
{% block base_layer %}
|
||||
new OpenLayers.Layer.Google("Google Terrain", {type: G_PHYSICAL_MAP, 'sphericalMercator': true});
|
||||
{% endblock %}
|
||||
|
||||
{% block extra_layers %}
|
||||
{{ module }}.layers.overlay = new OpenLayers.Layer.OSM.Mapnik("OpenStreetMap (Mapnik)");
|
||||
{{ module }}.map.addLayer({{ module }}.layers.overlay);
|
||||
{% endblock %}
|
||||
|
||||
|
38
openmumbai/templates/gis/admin/openlayers.html
Normal file
38
openmumbai/templates/gis/admin/openlayers.html
Normal file
|
@ -0,0 +1,38 @@
|
|||
{% block extrastyle %}
|
||||
{% load static %}
|
||||
<style type="text/css">
|
||||
#{{ id }}_map { width: {{ map_width }}px; height: {{ map_height }}px; }
|
||||
#{{ id }}_map .aligned label { float:inherit; }
|
||||
#{{ id }}_admin_map { position: relative; vertical-align: top; float: {{ LANGUAGE_BIDI|yesno:"right,left" }}; }
|
||||
{% if not display_wkt %}#{{ id }} { display: none; }{% endif %}
|
||||
.olControlEditingToolbar .olControlModifyFeatureItemActive {
|
||||
background-image: url("{% static "admin/img/gis/move_vertex_on.png" %}");
|
||||
background-repeat: no-repeat;
|
||||
}
|
||||
.olControlEditingToolbar .olControlModifyFeatureItemInactive {
|
||||
background-image: url("{% static "admin/img/gis/move_vertex_off.png" %}");
|
||||
background-repeat: no-repeat;
|
||||
}
|
||||
</style>
|
||||
<!--[if IE]>
|
||||
<style type="text/css">
|
||||
/* This fixes the mouse offset issues in IE. */
|
||||
#{{ id }}_admin_map { position: static; vertical-align: top; }
|
||||
/* `font-size: 0` fixes the 1px border between tiles, but borks LayerSwitcher.
|
||||
Thus, this is disabled until a better fix is found.
|
||||
#{{ id }}_map { width: {{ map_width }}px; height: {{ map_height }}px; font-size: 0; } */
|
||||
</style>
|
||||
<![endif]-->
|
||||
{% endblock %}
|
||||
<span id="{{ id }}_admin_map">
|
||||
<script type="text/javascript">
|
||||
//<![CDATA[
|
||||
{% block openlayers %}{% include "gis/admin/openlayers.js" %}{% endblock %}
|
||||
//]]>
|
||||
</script>
|
||||
<div id="{{ id }}_map"{% if LANGUAGE_BIDI %} dir="ltr"{% endif %}></div>
|
||||
<a href="javascript:{{ module }}.clearFeatures()">Delete all Features</a>
|
||||
{% if display_wkt %}<p> WKT debugging window:</p>{% endif %}
|
||||
<textarea id="{{ id }}" class="vWKTField required" cols="150" rows="10" name="{{ name }}">{{ wkt }}</textarea>
|
||||
<script type="text/javascript">{% block init_function %}{{ module }}.init();{% endblock %}</script>
|
||||
</span>
|
172
openmumbai/templates/gis/admin/openlayers.js
Normal file
172
openmumbai/templates/gis/admin/openlayers.js
Normal file
|
@ -0,0 +1,172 @@
|
|||
{% load l10n %}{# Author: Justin Bronn, Travis Pinney & Dane Springmeyer #}
|
||||
OpenLayers.Projection.addTransform("EPSG:4326", "EPSG:3857", OpenLayers.Layer.SphericalMercator.projectForward);
|
||||
{% block vars %}var {{ module }} = {};
|
||||
{{ module }}.map = null; {{ module }}.controls = null; {{ module }}.panel = null; {{ module }}.re = new RegExp("^SRID=\\d+;(.+)", "i"); {{ module }}.layers = {};
|
||||
{{ module }}.modifiable = {{ modifiable|yesno:"true,false" }};
|
||||
{{ module }}.wkt_f = new OpenLayers.Format.WKT();
|
||||
{{ module }}.is_collection = {{ is_collection|yesno:"true,false" }};
|
||||
{{ module }}.collection_type = '{{ collection_type }}';
|
||||
{{ module }}.is_linestring = {{ is_linestring|yesno:"true,false" }};
|
||||
{{ module }}.is_polygon = {{ is_polygon|yesno:"true,false" }};
|
||||
{{ module }}.is_point = {{ is_point|yesno:"true,false" }};
|
||||
{% endblock %}
|
||||
{{ module }}.get_ewkt = function(feat){return 'SRID={{ srid }};' + {{ module }}.wkt_f.write(feat);}
|
||||
{{ module }}.read_wkt = function(wkt){
|
||||
// OpenLayers cannot handle EWKT -- we make sure to strip it out.
|
||||
// EWKT is only exposed to OL if there's a validation error in the admin.
|
||||
var match = {{ module }}.re.exec(wkt);
|
||||
if (match){wkt = match[1];}
|
||||
return {{ module }}.wkt_f.read(wkt);
|
||||
}
|
||||
{{ module }}.write_wkt = function(feat){
|
||||
if ({{ module }}.is_collection){ {{ module }}.num_geom = feat.geometry.components.length;}
|
||||
else { {{ module }}.num_geom = 1;}
|
||||
document.getElementById('{{ id }}').value = {{ module }}.get_ewkt(feat);
|
||||
}
|
||||
{{ module }}.add_wkt = function(event){
|
||||
// This function will sync the contents of the `vector` layer with the
|
||||
// WKT in the text field.
|
||||
if ({{ module }}.is_collection){
|
||||
var feat = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.{{ geom_type }}());
|
||||
for (var i = 0; i < {{ module }}.layers.vector.features.length; i++){
|
||||
feat.geometry.addComponents([{{ module }}.layers.vector.features[i].geometry]);
|
||||
}
|
||||
{{ module }}.write_wkt(feat);
|
||||
} else {
|
||||
// Make sure to remove any previously added features.
|
||||
if ({{ module }}.layers.vector.features.length > 1){
|
||||
old_feats = [{{ module }}.layers.vector.features[0]];
|
||||
{{ module }}.layers.vector.removeFeatures(old_feats);
|
||||
{{ module }}.layers.vector.destroyFeatures(old_feats);
|
||||
}
|
||||
{{ module }}.write_wkt(event.feature);
|
||||
}
|
||||
}
|
||||
{{ module }}.modify_wkt = function(event){
|
||||
if ({{ module }}.is_collection){
|
||||
if ({{ module }}.is_point){
|
||||
{{ module }}.add_wkt(event);
|
||||
return;
|
||||
} else {
|
||||
// When modifying the selected components are added to the
|
||||
// vector layer so we only increment to the `num_geom` value.
|
||||
var feat = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.{{ geom_type }}());
|
||||
for (var i = 0; i < {{ module }}.num_geom; i++){
|
||||
feat.geometry.addComponents([{{ module }}.layers.vector.features[i].geometry]);
|
||||
}
|
||||
{{ module }}.write_wkt(feat);
|
||||
}
|
||||
} else {
|
||||
{{ module }}.write_wkt(event.feature);
|
||||
}
|
||||
}
|
||||
// Function to clear vector features and purge wkt from div
|
||||
{{ module }}.deleteFeatures = function(){
|
||||
{{ module }}.layers.vector.removeFeatures({{ module }}.layers.vector.features);
|
||||
{{ module }}.layers.vector.destroyFeatures();
|
||||
}
|
||||
{{ module }}.clearFeatures = function (){
|
||||
{{ module }}.deleteFeatures();
|
||||
document.getElementById('{{ id }}').value = '';
|
||||
{% localize off %}
|
||||
{{ module }}.map.setCenter(new OpenLayers.LonLat({{ default_lon }}, {{ default_lat }}), {{ default_zoom }});
|
||||
{% endlocalize %}
|
||||
}
|
||||
// Add Select control
|
||||
{{ module }}.addSelectControl = function(){
|
||||
var select = new OpenLayers.Control.SelectFeature({{ module }}.layers.vector, {'toggle' : true, 'clickout' : true});
|
||||
{{ module }}.map.addControl(select);
|
||||
select.activate();
|
||||
}
|
||||
{{ module }}.enableDrawing = function(){ {{ module }}.map.getControlsByClass('OpenLayers.Control.DrawFeature')[0].activate();}
|
||||
{{ module }}.enableEditing = function(){ {{ module }}.map.getControlsByClass('OpenLayers.Control.ModifyFeature')[0].activate();}
|
||||
// Create an array of controls based on geometry type
|
||||
{{ module }}.getControls = function(lyr){
|
||||
{{ module }}.panel = new OpenLayers.Control.Panel({'displayClass': 'olControlEditingToolbar'});
|
||||
var nav = new OpenLayers.Control.Navigation();
|
||||
var draw_ctl;
|
||||
if ({{ module }}.is_linestring){
|
||||
draw_ctl = new OpenLayers.Control.DrawFeature(lyr, OpenLayers.Handler.Path, {'displayClass': 'olControlDrawFeaturePath'});
|
||||
} else if ({{ module }}.is_polygon){
|
||||
draw_ctl = new OpenLayers.Control.DrawFeature(lyr, OpenLayers.Handler.Polygon, {'displayClass': 'olControlDrawFeaturePolygon'});
|
||||
} else if ({{ module }}.is_point){
|
||||
draw_ctl = new OpenLayers.Control.DrawFeature(lyr, OpenLayers.Handler.Point, {'displayClass': 'olControlDrawFeaturePoint'});
|
||||
}
|
||||
if ({{ module }}.modifiable){
|
||||
var mod = new OpenLayers.Control.ModifyFeature(lyr, {'displayClass': 'olControlModifyFeature'});
|
||||
{{ module }}.controls = [nav, draw_ctl, mod];
|
||||
} else {
|
||||
if(!lyr.features.length){
|
||||
{{ module }}.controls = [nav, draw_ctl];
|
||||
} else {
|
||||
{{ module }}.controls = [nav];
|
||||
}
|
||||
}
|
||||
}
|
||||
{{ module }}.init = function(){
|
||||
{% block map_options %}// The options hash, w/ zoom, resolution, and projection settings.
|
||||
var options = {
|
||||
{% autoescape off %}{% for item in map_options.items %} '{{ item.0 }}' : {{ item.1 }}{% if not forloop.last %},{% endif %}
|
||||
{% endfor %}{% endautoescape %} };{% endblock %}
|
||||
// The admin map for this geometry field.
|
||||
{{ module }}.map = new OpenLayers.Map('{{ id }}_map', options);
|
||||
// Base Layer
|
||||
{{ module }}.layers.base = {% block base_layer %}new OpenLayers.Layer.WMS( "{{ wms_name }}", "{{ wms_url }}", {layers: '{{ wms_layer }}'} );{% endblock %}
|
||||
{{ module }}.map.addLayer({{ module }}.layers.base);
|
||||
{% block extra_layers %}{% endblock %}
|
||||
{% if is_linestring %}OpenLayers.Feature.Vector.style["default"]["strokeWidth"] = 3; // Default too thin for linestrings. {% endif %}
|
||||
{{ module }}.layers.vector = new OpenLayers.Layer.Vector(" {{ field_name }}");
|
||||
{{ module }}.map.addLayer({{ module }}.layers.vector);
|
||||
// Read WKT from the text field.
|
||||
var wkt = document.getElementById('{{ id }}').value;
|
||||
if (wkt){
|
||||
// After reading into geometry, immediately write back to
|
||||
// WKT <textarea> as EWKT (so that SRID is included).
|
||||
var admin_geom = {{ module }}.read_wkt(wkt);
|
||||
{{ module }}.write_wkt(admin_geom);
|
||||
if ({{ module }}.is_collection){
|
||||
// If geometry collection, add each component individually so they may be
|
||||
// edited individually.
|
||||
for (var i = 0; i < {{ module }}.num_geom; i++){
|
||||
{{ module }}.layers.vector.addFeatures([new OpenLayers.Feature.Vector(admin_geom.geometry.components[i].clone())]);
|
||||
}
|
||||
} else {
|
||||
{{ module }}.layers.vector.addFeatures([admin_geom]);
|
||||
}
|
||||
// Zooming to the bounds.
|
||||
{{ module }}.map.zoomToExtent(admin_geom.geometry.getBounds());
|
||||
if ({{ module }}.is_point){
|
||||
{{ module }}.map.zoomTo({{ point_zoom }});
|
||||
}
|
||||
} else {
|
||||
{% localize off %}
|
||||
{{ module }}.map.setCenter(new OpenLayers.LonLat({{ default_lon }}, {{ default_lat }}), {{ default_zoom }});
|
||||
{% endlocalize %}
|
||||
}
|
||||
// This allows editing of the geographic fields -- the modified WKT is
|
||||
// written back to the content field (as EWKT, so that the ORM will know
|
||||
// to transform back to original SRID).
|
||||
{{ module }}.layers.vector.events.on({"featuremodified" : {{ module }}.modify_wkt});
|
||||
{{ module }}.layers.vector.events.on({"featureadded" : {{ module }}.add_wkt});
|
||||
{% block controls %}
|
||||
// Map controls:
|
||||
// Add geometry specific panel of toolbar controls
|
||||
{{ module }}.getControls({{ module }}.layers.vector);
|
||||
{{ module }}.panel.addControls({{ module }}.controls);
|
||||
{{ module }}.map.addControl({{ module }}.panel);
|
||||
{{ module }}.addSelectControl();
|
||||
// Then add optional visual controls
|
||||
{% if mouse_position %}{{ module }}.map.addControl(new OpenLayers.Control.MousePosition());{% endif %}
|
||||
{% if scale_text %}{{ module }}.map.addControl(new OpenLayers.Control.Scale());{% endif %}
|
||||
{% if layerswitcher %}{{ module }}.map.addControl(new OpenLayers.Control.LayerSwitcher());{% endif %}
|
||||
// Then add optional behavior controls
|
||||
{% if not scrollable %}{{ module }}.map.getControlsByClass('OpenLayers.Control.Navigation')[0].disableZoomWheel();{% endif %}
|
||||
{% endblock %}
|
||||
if (wkt){
|
||||
if ({{ module }}.modifiable){
|
||||
{{ module }}.enableEditing();
|
||||
}
|
||||
} else {
|
||||
{{ module }}.enableDrawing();
|
||||
}
|
||||
}
|
2
openmumbai/templates/gis/admin/osm.html
Normal file
2
openmumbai/templates/gis/admin/osm.html
Normal file
|
@ -0,0 +1,2 @@
|
|||
{% extends "gis/admin/openlayers.html" %}
|
||||
{% block openlayers %}{% include "gis/admin/osm.js" %}{% endblock %}
|
2
openmumbai/templates/gis/admin/osm.js
Normal file
2
openmumbai/templates/gis/admin/osm.js
Normal file
|
@ -0,0 +1,2 @@
|
|||
{% extends "gis/admin/openlayers.js" %}
|
||||
{% block base_layer %}new OpenLayers.Layer.OSM("OpenStreetMap (Mapnik)");{% endblock %}
|
12
openmumbai/templates/gis/google/google-map.html
Normal file
12
openmumbai/templates/gis/google/google-map.html
Normal file
|
@ -0,0 +1,12 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" {{ gmap.xmlns }}>
|
||||
<head>
|
||||
<title>{% block title %}Google Maps via GeoDjango{% endblock %}</title>
|
||||
{{ gmap.style }}
|
||||
{{ gmap.scripts }}
|
||||
</head>
|
||||
<body {{ gmap.onload }} {{ gmap.onunload }}>
|
||||
{% if gmap.dom_ids %}{% for dom_id in gmap.dom_ids %}<div id="{{ dom_id }}" style="width:600px;height:400px;"></div>{% endfor %}
|
||||
{% else %}<div id="{{ gmap.dom_id }}" style="width:600px;height:400px;"></div>{% endif %}
|
||||
</body>
|
||||
</html>
|
37
openmumbai/templates/gis/google/google-map.js
Normal file
37
openmumbai/templates/gis/google/google-map.js
Normal file
|
@ -0,0 +1,37 @@
|
|||
{% load l10n %}
|
||||
{% autoescape off %}
|
||||
{% localize off %}
|
||||
{% block vars %}var geodjango = {};{% for icon in icons %}
|
||||
var {{ icon.varname }} = new GIcon(G_DEFAULT_ICON);
|
||||
{% if icon.image %}{{ icon.varname }}.image = "{{ icon.image }}";{% endif %}
|
||||
{% if icon.shadow %}{{ icon.varname }}.shadow = "{{ icon.shadow }}";{% endif %} {% if icon.shadowsize %}{{ icon.varname }}.shadowSize = new GSize({{ icon.shadowsize.0 }}, {{ icon.shadowsize.1 }});{% endif %}
|
||||
{% if icon.iconanchor %}{{ icon.varname }}.iconAnchor = new GPoint({{ icon.iconanchor.0 }}, {{ icon.iconanchor.1 }});{% endif %} {% if icon.iconsize %}{{ icon.varname }}.iconSize = new GSize({{ icon.iconsize.0 }}, {{ icon.iconsize.1 }});{% endif %}
|
||||
{% if icon.infowindowanchor %}{{ icon.varname }}.infoWindowAnchor = new GPoint({{ icon.infowindowanchor.0 }}, {{ icon.infowindowanchor.1 }});{% endif %}{% endfor %}
|
||||
{% endblock vars %}{% block functions %}
|
||||
{% block load %}{{ js_module }}.{{ dom_id }}_load = function(){
|
||||
if (GBrowserIsCompatible()) {
|
||||
{{ js_module }}.{{ dom_id }} = new GMap2(document.getElementById("{{ dom_id }}"));
|
||||
{{ js_module }}.{{ dom_id }}.setCenter(new GLatLng({{ center.1 }}, {{ center.0 }}), {{ zoom }});
|
||||
{% block controls %}{{ js_module }}.{{ dom_id }}.setUIToDefault();{% endblock %}
|
||||
{% if calc_zoom %}var bounds = new GLatLngBounds(); var tmp_bounds = new GLatLngBounds();{% endif %}
|
||||
{% for kml_url in kml_urls %}{{ js_module }}.{{ dom_id }}_kml{{ forloop.counter }} = new GGeoXml("{{ kml_url }}");
|
||||
{{ js_module }}.{{ dom_id }}.addOverlay({{ js_module }}.{{ dom_id }}_kml{{ forloop.counter }});{% endfor %}
|
||||
{% for polygon in polygons %}{{ js_module }}.{{ dom_id }}_poly{{ forloop.counter }} = new {{ polygon }};
|
||||
{{ js_module }}.{{ dom_id }}.addOverlay({{ js_module }}.{{ dom_id }}_poly{{ forloop.counter }});
|
||||
{% for event in polygon.events %}GEvent.addListener({{ js_module }}.{{ dom_id }}_poly{{ forloop.parentloop.counter }}, {{ event }});{% endfor %}
|
||||
{% if calc_zoom %}tmp_bounds = {{ js_module }}.{{ dom_id }}_poly{{ forloop.counter }}.getBounds(); bounds.extend(tmp_bounds.getSouthWest()); bounds.extend(tmp_bounds.getNorthEast());{% endif %}{% endfor %}
|
||||
{% for polyline in polylines %}{{ js_module }}.{{ dom_id }}_polyline{{ forloop.counter }} = new {{ polyline }};
|
||||
{{ js_module }}.{{ dom_id }}.addOverlay({{ js_module }}.{{ dom_id }}_polyline{{ forloop.counter }});
|
||||
{% for event in polyline.events %}GEvent.addListener({{ js_module }}.{{ dom_id }}_polyline{{ forloop.parentloop.counter }}, {{ event }}); {% endfor %}
|
||||
{% if calc_zoom %}tmp_bounds = {{ js_module }}.{{ dom_id }}_polyline{{ forloop.counter }}.getBounds(); bounds.extend(tmp_bounds.getSouthWest()); bounds.extend(tmp_bounds.getNorthEast());{% endif %}{% endfor %}
|
||||
{% for marker in markers %}{{ js_module }}.{{ dom_id }}_marker{{ forloop.counter }} = new {{ marker }};
|
||||
{{ js_module }}.{{ dom_id }}.addOverlay({{ js_module }}.{{ dom_id }}_marker{{ forloop.counter }});
|
||||
{% for event in marker.events %}GEvent.addListener({{ js_module }}.{{ dom_id }}_marker{{ forloop.parentloop.counter }}, {{ event }}); {% endfor %}
|
||||
{% if calc_zoom %}bounds.extend({{ js_module }}.{{ dom_id }}_marker{{ forloop.counter }}.getLatLng()); {% endif %}{% endfor %}
|
||||
{% if calc_zoom %}{{ js_module }}.{{ dom_id }}.setCenter(bounds.getCenter(), {{ js_module }}.{{ dom_id }}.getBoundsZoomLevel(bounds));{% endif %}
|
||||
{% block load_extra %}{% endblock %}
|
||||
}else {
|
||||
alert("Sorry, the Google Maps API is not compatible with this browser.");
|
||||
}
|
||||
}
|
||||
{% endblock load %}{% endblock functions %}{% endlocalize %}{% endautoescape %}
|
8
openmumbai/templates/gis/google/google-multi.js
Normal file
8
openmumbai/templates/gis/google/google-multi.js
Normal file
|
@ -0,0 +1,8 @@
|
|||
{% extends "gis/google/google-map.js" %}
|
||||
{% block functions %}
|
||||
{{ load_map_js }}
|
||||
{{ js_module }}.load = function(){
|
||||
{% for dom_id in dom_ids %}{{ js_module }}.{{ dom_id }}_load();
|
||||
{% endfor %}
|
||||
}
|
||||
{% endblock %}
|
2
openmumbai/templates/gis/google/google-single.js
Normal file
2
openmumbai/templates/gis/google/google-single.js
Normal file
|
@ -0,0 +1,2 @@
|
|||
{% extends "gis/google/google-map.js" %}
|
||||
{% block vars %}{# No vars here because used within GoogleMapSet #}{% endblock %}
|
6
openmumbai/templates/gis/kml/base.kml
Normal file
6
openmumbai/templates/gis/kml/base.kml
Normal file
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<kml xmlns="http://earth.google.com/kml/{% block kml_version %}2.1{% endblock %}">
|
||||
<Document>{% block name %}{% endblock %}
|
||||
{% block placemarks %}{% endblock %}
|
||||
</Document>
|
||||
</kml>
|
8
openmumbai/templates/gis/kml/placemarks.kml
Normal file
8
openmumbai/templates/gis/kml/placemarks.kml
Normal file
|
@ -0,0 +1,8 @@
|
|||
{% extends "gis/kml/base.kml" %}
|
||||
{% block placemarks %}{% for place in places %}
|
||||
<Placemark>
|
||||
<name>{% if place.name %}{{ place.name }}{% else %}{{ place }}{% endif %}</name>
|
||||
<description>{% if place.description %}{{ place.description }}{% else %}{{ place }}{% endif %}</description>
|
||||
{{ place.kml|safe }}
|
||||
</Placemark>{% endfor %}{% endblock %}
|
||||
|
17
openmumbai/templates/gis/sitemaps/geo_sitemap.xml
Normal file
17
openmumbai/templates/gis/sitemaps/geo_sitemap.xml
Normal file
|
@ -0,0 +1,17 @@
|
|||
{% autoescape off %}<?xml version="1.0" encoding="UTF-8"?>
|
||||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:geo="http://www.google.com/geo/schemas/sitemap/1.0">
|
||||
{% spaceless %}
|
||||
{% for url in urlset %}
|
||||
<url>
|
||||
<loc>{{ url.location|escape }}</loc>
|
||||
{% if url.lastmod %}<lastmod>{{ url.lastmod|date:"Y-m-d" }}</lastmod>{% endif %}
|
||||
{% if url.changefreq %}<changefreq>{{ url.changefreq }}</changefreq>{% endif %}
|
||||
{% if url.priority %}<priority>{{ url.priority }}</priority>{% endif %}
|
||||
{% if url.geo_format %}<geo:geo>
|
||||
<geo:format>{{ url.geo_format }}</geo:format>
|
||||
</geo:geo>{% endif %}
|
||||
</url>
|
||||
{% endfor %}
|
||||
{% endspaceless %}
|
||||
</urlset>
|
||||
{% endautoescape %}
|
18
openmumbai/urls.py
Normal file
18
openmumbai/urls.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
from django.conf.urls.defaults import patterns, include, url
|
||||
|
||||
# Uncomment the next two lines to enable the admin:
|
||||
from django.contrib import admin
|
||||
admin.autodiscover()
|
||||
|
||||
urlpatterns = patterns('',
|
||||
# Examples:
|
||||
# url(r'^$', 'domains.views.home', name='home'),
|
||||
# url(r'^domains/', include('domains.foo.urls')),
|
||||
|
||||
# Uncomment the admin/doc line below to enable admin documentation:
|
||||
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
|
||||
|
||||
# Uncomment the next line to enable the admin:
|
||||
url(r'^admin/', include(admin.site.urls)),
|
||||
)
|
||||
|
4
requirements.txt
Normal file
4
requirements.txt
Normal file
|
@ -0,0 +1,4 @@
|
|||
Django==1.4
|
||||
django_extensions
|
||||
#sorl-thumbnail
|
||||
#django-haystack
|
Loading…
Reference in New Issue
Block a user