From 9ce871baddba8034c4efad1b98b8e3e037b1dc0e Mon Sep 17 00:00:00 2001 From: Shekhar Krishnan Date: Mon, 7 Mar 2011 16:05:55 +0530 Subject: [PATCH] first commit --- README | 7 ++ citysurvey/__init__.py | 0 citysurvey/cs/__init__.py | 0 citysurvey/cs/admin.py | 18 +++++ citysurvey/cs/models.py | 42 +++++++++++ citysurvey/cs/tests.py | 23 ++++++ citysurvey/cs/views.py | 1 + citysurvey/import_stable.py | 29 ++++++++ citysurvey/manage.py | 11 +++ citysurvey/settings.py | 86 ++++++++++++++++++++++ citysurvey/templates/gis/admin/google.html | 4 + citysurvey/templates/gis/admin/google.js | 11 +++ citysurvey/urls.py | 17 +++++ 13 files changed, 249 insertions(+) create mode 100644 README create mode 100644 citysurvey/__init__.py create mode 100644 citysurvey/cs/__init__.py create mode 100644 citysurvey/cs/admin.py create mode 100644 citysurvey/cs/models.py create mode 100644 citysurvey/cs/tests.py create mode 100644 citysurvey/cs/views.py create mode 100644 citysurvey/import_stable.py create mode 100755 citysurvey/manage.py create mode 100644 citysurvey/settings.py create mode 100644 citysurvey/templates/gis/admin/google.html create mode 100644 citysurvey/templates/gis/admin/google.js create mode 100644 citysurvey/urls.py diff --git a/README b/README new file mode 100644 index 0000000..3d613a7 --- /dev/null +++ b/README @@ -0,0 +1,7 @@ +To enter virtualenv: +. bin/activate + +To run server: +cd citysurvey +python manage.py runserver + diff --git a/citysurvey/__init__.py b/citysurvey/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/citysurvey/cs/__init__.py b/citysurvey/cs/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/citysurvey/cs/admin.py b/citysurvey/cs/admin.py new file mode 100644 index 0000000..34da1d8 --- /dev/null +++ b/citysurvey/cs/admin.py @@ -0,0 +1,18 @@ +from django.contrib.gis import admin +# from django.contrib.gis.maps.google import GoogleMap +from models import * + +class PropertyAdmin(admin.OSMGeoAdmin): + list_display = ('__unicode__', 'street_locality', 'tenure', 'ground_rent_due', 'laughton_no', 'area_sqm',) + list_filter = ('stable',) + search_fields = ('street_locality',) + map_template = 'gis/admin/google.html' + default_lon = 72.855211097628413 + default_lat = 19.415775291486027 + default_zoom = 4 + extra_js = ['http://openstreetmap.org/openlayers/OpenStreetMap.js', 'http://maps.google.com/maps?file=api&v=2&key=%s' % 'abcd'] + + + +admin.site.register(Property, PropertyAdmin) +admin.site.register(Stable) diff --git a/citysurvey/cs/models.py b/citysurvey/cs/models.py new file mode 100644 index 0000000..e37ca53 --- /dev/null +++ b/citysurvey/cs/models.py @@ -0,0 +1,42 @@ +from django.contrib.gis.db import models + +class Property(models.Model): + filename = models.CharField(max_length=255) + division = models.CharField(max_length=255) + cs_no = models.CharField(max_length=255) + cs_reg_no = models.CharField(max_length=255) + cs_pg_no = models.CharField(max_length=255, blank=True, null=True) + cs_sheet_no = models.CharField(max_length=255, blank=True, null=True) + street_locality = models.TextField(blank=True, null=True) + street_no = models.CharField(max_length=255, blank=True, null=True) + tenure = models.CharField(max_length=255, blank=True, null=True) + area_sqm = models.CharField(max_length=255, blank=True, null=True) + laughton_no = models.CharField(max_length=255, blank=True, null=True) + collector_new_no = models.CharField(max_length=255, blank=True, null=True) + collector_rent_no = models.CharField(max_length=255, blank=True, null=True) + ground_rent_due = models.FloatField(blank=True, null=True) + grant = models.FloatField(blank=True, null=True) + total_due = models.FloatField(blank=True, null=True) + holders_history = models.TextField(blank=True, null=True) + stable = models.ForeignKey("Stable") + polygon = models.PolygonField(null=True) + objects = models.GeoManager() + + def __unicode__(self): + return "%s: %s" % (self.division, self.cs_no,) + + class Meta: + verbose_name_plural = "Properties" + + +class Stable(models.Model): + stable_id = models.IntegerField() + name = models.CharField(max_length=255) + polygon = models.PolygonField(null=True) + objects = models.GeoManager() + + def __unicode__(self): + return self.name + + class Meta: + ordering = ['stable_id'] diff --git a/citysurvey/cs/tests.py b/citysurvey/cs/tests.py new file mode 100644 index 0000000..2247054 --- /dev/null +++ b/citysurvey/cs/tests.py @@ -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 +"""} + diff --git a/citysurvey/cs/views.py b/citysurvey/cs/views.py new file mode 100644 index 0000000..60f00ef --- /dev/null +++ b/citysurvey/cs/views.py @@ -0,0 +1 @@ +# Create your views here. diff --git a/citysurvey/import_stable.py b/citysurvey/import_stable.py new file mode 100644 index 0000000..8823423 --- /dev/null +++ b/citysurvey/import_stable.py @@ -0,0 +1,29 @@ +#Usage: +# python manage.py shell +# import import_stable as i +# i.importStable(1, "Fort") + +from cs.models import * +from os.path import join +import json + +JSON_DIR = '/home/shekhar/Documents/projects/citysurvey' + +def importStable(no, name): + s = Stable(stable_id=no, name=name) + s.save() + filename = join(JSON_DIR, "JSONforStable%d.json" % no) + data = json.loads(open(filename).read()) + for d in data: + p = Property() + for key in d.keys(): + val = d[key] + if key in ['ground_rent_due', 'grant', 'total_due']: + if val == '': + val = 0.0 +# if key in ['cs_no', 'cs_reg_no', 'cs_pg_no', 'cs_sheet_no']: +# if val == '' or val.find('..') != -1: +# val = 0 + p.__setattr__(key, val) + p.__setattr__('stable', s) + p.save() diff --git a/citysurvey/manage.py b/citysurvey/manage.py new file mode 100755 index 0000000..bcdd55e --- /dev/null +++ b/citysurvey/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/citysurvey/settings.py b/citysurvey/settings.py new file mode 100644 index 0000000..4b14f3e --- /dev/null +++ b/citysurvey/settings.py @@ -0,0 +1,86 @@ +# Django settings for citysurvey project. +import os +from os.path import join + +DEBUG = True +TEMPLATE_DEBUG = DEBUG +PROJECT_PATH = os.path.dirname(__file__) + +ADMINS = ( + # ('Your Name', 'your_email@domain.com'), +) + +MANAGERS = ADMINS + +DATABASE_ENGINE = 'postgresql_psycopg2' # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'. +DATABASE_NAME = 'cts' # Or path to database file if using sqlite3. +DATABASE_USER = '' # Not used with sqlite3. +DATABASE_PASSWORD = '' # Not used with sqlite3. +DATABASE_HOST = '' # 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 = 'x(x-q&zurdz(u)ab9gi%iefi)bt-ho*!&pv52-qd3f4*omurq-' + +# 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 = 'citysurvey.urls' + +TEMPLATE_DIRS = ( + join(PROJECT_PATH, "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.admin', + 'django.contrib.gis', + 'cs', +) diff --git a/citysurvey/templates/gis/admin/google.html b/citysurvey/templates/gis/admin/google.html new file mode 100644 index 0000000..1134839 --- /dev/null +++ b/citysurvey/templates/gis/admin/google.html @@ -0,0 +1,4 @@ +{% extends "gis/admin/openlayers.html" %} +{% block openlayers %} +{% include "gis/admin/google.js" %} +{% endblock %} diff --git a/citysurvey/templates/gis/admin/google.js b/citysurvey/templates/gis/admin/google.js new file mode 100644 index 0000000..ed9090d --- /dev/null +++ b/citysurvey/templates/gis/admin/google.js @@ -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 %} + + diff --git a/citysurvey/urls.py b/citysurvey/urls.py new file mode 100644 index 0000000..20f89d2 --- /dev/null +++ b/citysurvey/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() + +urlpatterns = patterns('', + # Example: + # (r'^citysurvey/', include('citysurvey.foo.urls')), + + # Uncomment the admin/doc line below and add 'django.contrib.admindocs' + # to INSTALLED_APPS to enable admin documentation: + # (r'^admin/doc/', include('django.contrib.admindocs.urls')), + + # Uncomment the next line to enable the admin: + (r'^admin/', include(admin.site.urls)), +)