Skip to content

Commit 551e055

Browse files
committed
Initial import
0 parents  commit 551e055

File tree

673 files changed

+134227
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

673 files changed

+134227
-0
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
*.class
2+
*.pyc
3+
*.pyo
4+
cpp_home/settings_local.py
5+
.pydevproject

.project

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>cpp_home</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.python.pydev.PyDevBuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.python.pydev.pythonNature</nature>
16+
<nature>org.python.pydev.django.djangoNature</nature>
17+
</natures>
18+
</projectDescription>

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
cpp_home
2+
========
3+
The ChokePoint Project map page, now in a tasty Python flavour.
4+
5+
## Requirements
6+
* django 1.4 - https://docs.djangoproject.com/en/dev/intro/install/
7+
* django-compositekey HEAD - https://github.com/simone/django-compositekey.git
8+
9+
## Installation
10+
* Copy cpp_home/settings_local-SAMPLE.py to cpp_home/settings_local.py and
11+
** Edit settings_local.py to match your environment.
12+
** Please specify your own CloudMade API key. Get yours at http://CloudMade.com/
13+
* If using Eclipse+pydev, copy pydevproject-SAMPLE to .pydevproject
14+
15+
## Running
16+
```
17+
$ cd cpp_home
18+
$ python manage.py runserver
19+
```
20+

cpp_home/home/models.py

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
# This is an auto-generated Django model module.
2+
# You'll have to do the following manually to clean this up:
3+
# * Rearrange models' order
4+
# * Make sure each model has one field with primary_key=True
5+
# Feel free to rename the models, but don't rename db_table values or field names.
6+
#
7+
# Also note: You'll have to insert the output of 'django-admin.py sqlcustom [appname]'
8+
# into your database.
9+
10+
from django.db import models
11+
from compositekey import db
12+
13+
class Usr(models.Model):
14+
id = models.CharField(max_length=192, primary_key=True)
15+
date_created = models.DateTimeField(null=True, blank=True)
16+
last_updated = models.DateTimeField(null=True, blank=True)
17+
first_name = models.CharField(max_length=765, blank=True)
18+
last_name = models.CharField(max_length=765, blank=True)
19+
email = models.CharField(max_length=765, blank=True)
20+
class Meta:
21+
db_table = u'usr'
22+
23+
class IncidentType(models.Model):
24+
id = models.CharField(max_length=48, primary_key=True)
25+
name = models.CharField(max_length=765)
26+
class_field = models.CharField(max_length=765, db_column='class', blank=True) # Field renamed because it was a Python reserved word.
27+
class Meta:
28+
db_table = u'incident_type'
29+
30+
class Incident(models.Model):
31+
id = models.IntegerField(primary_key=True)
32+
date_created = models.DateTimeField(null=True, blank=True)
33+
last_updated = models.DateTimeField(null=True, blank=True)
34+
ts = models.DateTimeField(null=True, blank=True)
35+
ts_end = models.DateTimeField(null=True, blank=True)
36+
type = models.ForeignKey(IncidentType, null=True, db_column='type', blank=True)
37+
source = models.CharField(max_length=48, blank=True)
38+
source_id = models.CharField(max_length=192, blank=True)
39+
usr = models.CharField(max_length=192, blank=True)
40+
name = models.CharField(max_length=765, blank=True)
41+
descr = models.TextField(blank=True)
42+
lat = models.FloatField(null=True, blank=True)
43+
lon = models.FloatField(null=True, blank=True)
44+
class Meta:
45+
db_table = u'incident'
46+
47+
class Country(models.Model):
48+
id = models.CharField(max_length=6, primary_key=True)
49+
name = models.CharField(max_length=765, blank=True)
50+
lat = models.FloatField(null=True, blank=True)
51+
lon = models.FloatField(null=True, blank=True)
52+
bb_nw_lat = models.FloatField(null=True, blank=True)
53+
bb_nw_lon = models.FloatField(null=True, blank=True)
54+
bb_se_lat = models.FloatField(null=True, blank=True)
55+
bb_se_lon = models.FloatField(null=True, blank=True)
56+
incidents = models.ManyToManyField('Incident',through='CountryIncident')
57+
def __unicode__(self):
58+
return self.id
59+
class Meta:
60+
db_table = u'country'
61+
62+
class CountryContent(models.Model):
63+
country = models.ForeignKey(Country, db_column='country')
64+
id = models.CharField(max_length=48, primary_key=True)
65+
date_created = models.DateTimeField(null=True, blank=True)
66+
last_updated = models.DateTimeField(null=True, blank=True)
67+
content = models.TextField(blank=True)
68+
usr = models.ForeignKey(Usr, db_column='usr')
69+
class Meta:
70+
db_table = u'country_content'
71+
72+
class CountryIncident(models.Model):
73+
id = db.MultiFieldPK("incident","country")
74+
incident = models.ForeignKey(Incident, db_column='incident')
75+
country = models.ForeignKey(Country, db_column='country')
76+
class Meta:
77+
db_table = u'country_incident'
78+
79+
class Page(models.Model):
80+
id = models.CharField(max_length=192, primary_key=True)
81+
date_created = models.DateTimeField(null=True, blank=True)
82+
last_updated = models.DateTimeField(null=True, blank=True)
83+
content = models.TextField(blank=True)
84+
class Meta:
85+
db_table = u'page'
86+
87+
class Region(models.Model):
88+
id = models.CharField(max_length=48, primary_key=True)
89+
type = models.CharField(max_length=48, blank=True)
90+
name = models.CharField(max_length=765, blank=True)
91+
lat = models.FloatField(null=True, blank=True)
92+
lon = models.FloatField(null=True, blank=True)
93+
class Meta:
94+
db_table = u'region'
95+
96+
97+
class RegionContent(models.Model):
98+
region = models.ForeignKey(Region, db_column='region')
99+
id = models.CharField(max_length=48, primary_key=True)
100+
date_created = models.DateTimeField(null=True, blank=True)
101+
last_updated = models.DateTimeField(null=True, blank=True)
102+
content = models.TextField(blank=True)
103+
usr = models.ForeignKey(Usr, db_column='usr')
104+
class Meta:
105+
db_table = u'region_content'
106+
107+
class RegionCountry(models.Model):
108+
id = db.MultiFieldPK("region","country")
109+
region = models.ForeignKey(Region, db_column='region')
110+
country = models.ForeignKey(Country, db_column='country')
111+
class Meta:
112+
db_table = u'region_country'
113+
114+
class RegionIncident(models.Model):
115+
incident = models.ForeignKey(Incident, db_column='incident')
116+
region = models.ForeignKey(Region, db_column='region')
117+
class Meta:
118+
db_table = u'region_incident'
119+
120+
class Source(models.Model):
121+
id = models.CharField(max_length=48, primary_key=True)
122+
name = models.CharField(max_length=765)
123+
class Meta:
124+
db_table = u'source'
125+

cpp_home/home/views.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import string
2+
import logging
3+
import json
4+
from django.conf import settings
5+
from django.shortcuts import render_to_response
6+
from home.models import Country,Region,RegionCountry
7+
8+
logger = logging.getLogger('django')
9+
10+
def root(request):
11+
return render_to_response('index.html', {'settings':settings})
12+
13+
def about(request):
14+
return render_to_response('about.html', {'settings':settings})
15+
16+
def countries(request):
17+
section_list = {}
18+
country_list = Country.objects.all().order_by('name')
19+
for country in country_list:
20+
initial = country.name[0].lower()
21+
if not initial in section_list:
22+
section_list[initial] = []
23+
section_list[initial].append(country)
24+
return render_to_response('country/index.html', {
25+
'settings':settings,
26+
'countries': country_list,
27+
'sections':sorted(section_list.iteritems()),
28+
'initials':sorted(section_list.keys())
29+
})
30+
31+
32+
def regions(request):
33+
section_list = {}
34+
for cr in RegionCountry.objects.all():
35+
region = cr.region.name
36+
if not region in section_list:
37+
section_list[region] = []
38+
section_list[region].append(cr.country)
39+
return render_to_response('region/index.html', {
40+
'settings':settings,
41+
'sections':sorted(section_list.iteritems()),
42+
})
43+
44+
def country(request, country_id):
45+
country = Country.objects.get(id=country_id)
46+
transparency = country.incidents.filter(type__in=[17,18]).order_by('-ts')[:20]
47+
incidents = country.incidents.all().order_by('-ts')[:20]
48+
features = []
49+
for incident in incidents:
50+
rec = {'id':incident.id,'properties':{'html':incident.descr},'geometry':{'type':'Point','coordinates':[incident.lon,incident.lat]}}
51+
features.append(rec)
52+
return render_to_response('country/view.html', {
53+
'settings':settings,
54+
'country': country,
55+
'incidents': incidents,
56+
'incident_count': incidents.count(),
57+
'transparency_incidents': transparency,
58+
'transparency_incident_count': transparency.count(),
59+
'features_json': json.dumps(features)
60+
})

cpp_home/settings.py

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
# Django settings for cpp_home project.
2+
3+
import os
4+
5+
PROJECT_PATH = os.path.abspath(os.path.dirname(__file__))
6+
7+
DEBUG = True
8+
TEMPLATE_DEBUG = DEBUG
9+
10+
ADMINS = (
11+
# ('Your Name', '[email protected]'),
12+
)
13+
14+
MANAGERS = ADMINS
15+
16+
# Local time zone for this installation. Choices can be found here:
17+
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
18+
# although not all choices may be available on all operating systems.
19+
# On Unix systems, a value of None will cause Django to use the same
20+
# timezone as the operating system.
21+
# If running in a Windows environment this must be set to the same as your
22+
# system time zone.
23+
TIME_ZONE = 'America/Chicago'
24+
25+
# Language code for this installation. All choices can be found here:
26+
# http://www.i18nguy.com/unicode/language-identifiers.html
27+
LANGUAGE_CODE = 'en-us'
28+
29+
SITE_ID = 1
30+
31+
# If you set this to False, Django will make some optimizations so as not
32+
# to load the internationalization machinery.
33+
USE_I18N = True
34+
35+
# If you set this to False, Django will not format dates, numbers and
36+
# calendars according to the current locale
37+
USE_L10N = True
38+
39+
# Absolute filesystem path to the directory that will hold user-uploaded files.
40+
# Example: "/home/media/media.lawrence.com/media/"
41+
MEDIA_ROOT = ''
42+
43+
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
44+
# trailing slash.
45+
# Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
46+
MEDIA_URL = ''
47+
48+
# Absolute path to the directory static files should be collected to.
49+
# Don't put anything in this directory yourself; store your static files
50+
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
51+
# Example: "/home/media/media.lawrence.com/static/"
52+
STATIC_ROOT = ''
53+
54+
# URL prefix for static files.
55+
# Example: "http://media.lawrence.com/static/"
56+
STATIC_URL = '/static/'
57+
58+
# URL prefix for admin static files -- CSS, JavaScript and images.
59+
# Make sure to use a trailing slash.
60+
# Examples: "http://foo.com/static/admin/", "/static/admin/".
61+
ADMIN_MEDIA_PREFIX = '/static/admin/'
62+
63+
# Additional locations of static files
64+
STATICFILES_DIRS = (
65+
# Put strings here, like "/home/html/static" or "C:/www/django/static".
66+
# Always use forward slashes, even on Windows.
67+
# Don't forget to use absolute paths, not relative paths.
68+
os.path.join(PROJECT_PATH, "static"),
69+
)
70+
71+
# List of finder classes that know how to find static files in
72+
# various locations.
73+
STATICFILES_FINDERS = (
74+
'django.contrib.staticfiles.finders.FileSystemFinder',
75+
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
76+
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
77+
)
78+
79+
# Make this unique, and don't share it with anybody.
80+
SECRET_KEY = ')9rg_ai#$y^59qkr_h0ix3ocjb&m-ja0tvmfq6or0t&ny-e($!'
81+
82+
# List of callables that know how to import templates from various sources.
83+
TEMPLATE_LOADERS = (
84+
'django.template.loaders.filesystem.Loader',
85+
'django.template.loaders.app_directories.Loader',
86+
# 'django.template.loaders.eggs.Loader',
87+
)
88+
89+
MIDDLEWARE_CLASSES = (
90+
'django.middleware.common.CommonMiddleware',
91+
'django.contrib.sessions.middleware.SessionMiddleware',
92+
'django.middleware.csrf.CsrfViewMiddleware',
93+
'django.contrib.auth.middleware.AuthenticationMiddleware',
94+
'django.contrib.messages.middleware.MessageMiddleware',
95+
)
96+
97+
ROOT_URLCONF = 'cpp_home.urls'
98+
99+
TEMPLATE_DIRS = (
100+
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
101+
# Always use forward slashes, even on Windows.
102+
# Don't forget to use absolute paths, not relative paths.
103+
os.path.join(PROJECT_PATH, "templates"),
104+
)
105+
106+
INSTALLED_APPS = (
107+
'django.contrib.auth',
108+
'django.contrib.contenttypes',
109+
'django.contrib.sessions',
110+
'django.contrib.sites',
111+
'django.contrib.messages',
112+
'django.contrib.staticfiles',
113+
# Uncomment the next line to enable the admin:
114+
# 'django.contrib.admin',
115+
# Uncomment the next line to enable admin documentation:
116+
# 'django.contrib.admindocs',
117+
'home',
118+
)
119+
120+
# A sample logging configuration. The only tangible logging
121+
# performed by this configuration is to send an email to
122+
# the site admins on every HTTP 500 error.
123+
# See http://docs.djangoproject.com/en/dev/topics/logging for
124+
# more details on how to customize your logging configuration.
125+
LOGGING = {
126+
'version': 1,
127+
'disable_existing_loggers': False,
128+
'handlers': {
129+
'console':{
130+
'level':'INFO',
131+
'class':'logging.StreamHandler',
132+
},
133+
'mail_admins': {
134+
'level': 'ERROR',
135+
'class': 'django.utils.log.AdminEmailHandler'
136+
}
137+
},
138+
'loggers': {
139+
'django': {
140+
'handlers': ['console'],
141+
'level': 'DEBUG',
142+
'propagate': True,
143+
},
144+
'django.request': {
145+
'handlers': ['mail_admins'],
146+
'level': 'ERROR',
147+
'propagate': True,
148+
},
149+
}
150+
}
151+
152+
from settings_local import *

0 commit comments

Comments
 (0)