first commit
This commit is contained in:
commit
6736c92b7a
21
README
Normal file
21
README
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
indianrails
|
||||||
|
|
||||||
|
Get:
|
||||||
|
bzr branch PUBLIC_URL indianrails
|
||||||
|
cd indianrails
|
||||||
|
virtualenv .
|
||||||
|
pip -E . install -r requirements.txt
|
||||||
|
|
||||||
|
Develop:
|
||||||
|
create indianrails/local_settings.py
|
||||||
|
|
||||||
|
. bin/activate
|
||||||
|
cd indianrails
|
||||||
|
python manage.py shell
|
||||||
|
|
||||||
|
python manage.py runserver
|
||||||
|
|
||||||
|
Deploy:
|
||||||
|
create indianrails/local_settings.py
|
||||||
|
|
||||||
|
create /etc/apache2/sites-availavle/sitename.conf
|
0
indianrails/__init__.py
Normal file
0
indianrails/__init__.py
Normal file
11
indianrails/manage.py
Executable file
11
indianrails/manage.py
Executable file
|
@ -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)
|
130
indianrails/settings.py
Normal file
130
indianrails/settings.py
Normal file
|
@ -0,0 +1,130 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# vi:si:et:sw=4:sts=4:ts=4
|
||||||
|
# Django settings for indianrails project.
|
||||||
|
import os
|
||||||
|
from os.path import join
|
||||||
|
|
||||||
|
SITENAME = 'indianrails'
|
||||||
|
|
||||||
|
PROJECT_ROOT = os.path.normpath(os.path.dirname(__file__))
|
||||||
|
|
||||||
|
DEBUG = True
|
||||||
|
TEMPLATE_DEBUG = DEBUG
|
||||||
|
JSON_DEBUG = False
|
||||||
|
|
||||||
|
XSENDFILE = False
|
||||||
|
|
||||||
|
ADMINS = (
|
||||||
|
('sanj', 'b@pad.ma'),
|
||||||
|
)
|
||||||
|
|
||||||
|
DEFAULT_FROM_EMAIL='b@pad.ma'
|
||||||
|
|
||||||
|
MANAGERS = ADMINS
|
||||||
|
|
||||||
|
DATABASES = {
|
||||||
|
'default': {
|
||||||
|
'ENGINE': 'django.contrib.gis.db.backends.postgis',
|
||||||
|
'NAME': 'indianrails',
|
||||||
|
'USER': 'sanj',
|
||||||
|
'PASSWORD': '',
|
||||||
|
'HOST': '',
|
||||||
|
'PORT': '',
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#CACHE_BACKEND = 'memcached://127.0.0.1:11211/'
|
||||||
|
|
||||||
|
# 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 = 'Europe/Berlin'
|
||||||
|
#TIME_ZONE = 'Asia/Kolkata'
|
||||||
|
|
||||||
|
# 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
|
||||||
|
APPEND_SLASH = False
|
||||||
|
|
||||||
|
# Absolute path to the directory that holds media.
|
||||||
|
# Example: "/home/media/media.lawrence.com/"
|
||||||
|
MEDIA_ROOT = join(PROJECT_ROOT, 'media')
|
||||||
|
STATIC_ROOT = join(PROJECT_ROOT, 'static')
|
||||||
|
|
||||||
|
|
||||||
|
# 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 = '/media/'
|
||||||
|
|
||||||
|
STATIC_URL = '/static/'
|
||||||
|
|
||||||
|
# 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 = '/admin/media/'
|
||||||
|
|
||||||
|
# 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',
|
||||||
|
'oxdjango.middleware.ExceptionMiddleware',
|
||||||
|
)
|
||||||
|
|
||||||
|
ROOT_URLCONF = 'indianrails.urls'
|
||||||
|
|
||||||
|
TEMPLATE_DIRS = (
|
||||||
|
join(PROJECT_ROOT, 'templates'),
|
||||||
|
)
|
||||||
|
|
||||||
|
INSTALLED_APPS = (
|
||||||
|
'django.contrib.auth',
|
||||||
|
'django.contrib.contenttypes',
|
||||||
|
'django.contrib.sessions',
|
||||||
|
'django.contrib.sites',
|
||||||
|
'django.contrib.admin',
|
||||||
|
'django.contrib.humanize',
|
||||||
|
'django.contrib.gis',
|
||||||
|
'trains',
|
||||||
|
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
#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)
|
0
indianrails/trains/__init__.py
Normal file
0
indianrails/trains/__init__.py
Normal file
75
indianrails/trains/models.py
Normal file
75
indianrails/trains/models.py
Normal file
|
@ -0,0 +1,75 @@
|
||||||
|
from django.contrib.gis.db import models
|
||||||
|
|
||||||
|
|
||||||
|
class State(models.Model):
|
||||||
|
name = models.CharField(max_length=255)
|
||||||
|
polygon = models.PolygonField(null=True)
|
||||||
|
|
||||||
|
def __unicode__(self):
|
||||||
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
|
class Station(models.Model):
|
||||||
|
data_id = models.IntegerField() #id in the source data
|
||||||
|
code = models.CharField(max_length=10)
|
||||||
|
name = models.CharField(max_length=255)
|
||||||
|
zone = models.CharField(max_length=10)
|
||||||
|
state = models.ForeignKey(State)
|
||||||
|
address = models.TextField()
|
||||||
|
point = models.PointField(null=True)
|
||||||
|
|
||||||
|
def __unicode__(self):
|
||||||
|
return "%s: %s" % (self.code, self.name,)
|
||||||
|
|
||||||
|
|
||||||
|
class Train(models.Model):
|
||||||
|
data_id = models.IntegerField()
|
||||||
|
name = models.CharField(max_length=255)
|
||||||
|
number = models.CharField(max_length=12)
|
||||||
|
return_train = models.CharField(max_length=12)
|
||||||
|
duration_h = models.IntegerField()
|
||||||
|
duration_m = models.IntegerField()
|
||||||
|
zone = models.CharField(max_length=10)
|
||||||
|
date_from = models.DateField(null=True)
|
||||||
|
date_to = models.DateField(null=True)
|
||||||
|
from_station = models.ForeignKey(Station, related_name='trains_from')
|
||||||
|
to_station = models.ForeignKey(Station, related_name='trains_to')
|
||||||
|
number_of_halts = models.IntegerField()
|
||||||
|
typ = models.CharField(max_length=12)
|
||||||
|
departure = models.TimeField()
|
||||||
|
arrival = models.TimeField()
|
||||||
|
distance = models.IntegerField()
|
||||||
|
departure_days = models.CharField(max_length=12) #this is just a string for display, we use the booleans in our code
|
||||||
|
monday = models.BooleanField()
|
||||||
|
tuesday = models.BooleanField()
|
||||||
|
wednesday = models.BooleanField()
|
||||||
|
thursday = models.BooleanField()
|
||||||
|
friday = models.BooleanField()
|
||||||
|
saturday = models.BooleanField()
|
||||||
|
sunday = models.BooleanField()
|
||||||
|
classes = models.CharField(max_length=32)
|
||||||
|
chair_car = models.BooleanField()
|
||||||
|
sleeper = models.BooleanField()
|
||||||
|
first_class = models.BooleanField()
|
||||||
|
third_ac = models.BooleanField()
|
||||||
|
second_ac = models.BooleanField()
|
||||||
|
first_ac = models.BooleanField()
|
||||||
|
|
||||||
|
def __unicode__(self):
|
||||||
|
return "%s: %s" % (self.number, self.name,)
|
||||||
|
|
||||||
|
|
||||||
|
class Schedule(models.Model):
|
||||||
|
data_id = models.IntegerField()
|
||||||
|
arrival = models.TimeField() # if blank, get departure time from train models
|
||||||
|
departure = models.TimeField()
|
||||||
|
halt = models.IntegerField(null=True)
|
||||||
|
stop_number = models.DecimalField(max_digits=3, decimal_places=2)
|
||||||
|
station = models.ForeignKey(Station)
|
||||||
|
train = models.ForeignKey(Train)
|
||||||
|
day = models.IntegerField()
|
||||||
|
distance_travelled = models.IntegerField()
|
||||||
|
|
||||||
|
def __unicode__(self):
|
||||||
|
return "%d: %s at %s" % (self.stop_number, self.train.name, self.station.name,)
|
||||||
|
# Create your models here.
|
23
indianrails/trains/tests.py
Normal file
23
indianrails/trains/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
indianrails/trains/views.py
Normal file
1
indianrails/trains/views.py
Normal file
|
@ -0,0 +1 @@
|
||||||
|
# Create your views here.
|
16
indianrails/urls.py
Normal file
16
indianrails/urls.py
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
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'^indianrails/', include('indianrails.foo.urls')),
|
||||||
|
|
||||||
|
# Uncomment the admin/doc line below 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)),
|
||||||
|
)
|
2
requirements.txt
Normal file
2
requirements.txt
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
django==1.3
|
||||||
|
-e bzr+http://code.0x2620.org/python-ox/#egg=python-ox
|
27
wsgi/django.wsgi
Normal file
27
wsgi/django.wsgi
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
# django.wsgi for indianrails
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import site
|
||||||
|
|
||||||
|
project_module = 'indianrails'
|
||||||
|
|
||||||
|
root_dir = os.path.normpath(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
|
||||||
|
|
||||||
|
#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))
|
||||||
|
|
||||||
|
sys.path.append(root_dir)
|
||||||
|
sys.path.append(os.path.join(root_dir, project_module))
|
||||||
|
|
||||||
|
#reload if this django.wsgi gets touched
|
||||||
|
from oxdjango import monitor
|
||||||
|
monitor.start(interval=1.0)
|
||||||
|
|
||||||
|
monitor.track(os.path.abspath(os.path.dirname(__file__)))
|
||||||
|
|
||||||
|
os.environ['DJANGO_SETTINGS_MODULE'] = project_module + '.settings'
|
||||||
|
|
||||||
|
import django.core.handlers.wsgi
|
||||||
|
|
||||||
|
application = django.core.handlers.wsgi.WSGIHandler()
|
Loading…
Reference in New Issue
Block a user