Initial Commit

This commit is contained in:
Tyrel Souza 2011-07-18 20:54:31 -07:00
commit 601b79b3f2
14 changed files with 278 additions and 0 deletions

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
.hg/
.hgignore
*.pyc
local_settings.py

0
__init__.py Normal file
View File

0
logbook/__init__.py Normal file
View File

13
logbook/admin.py Normal file
View File

@ -0,0 +1,13 @@
from django.contrib import admin
from logbook.models import LogBookEntry, Airplane
class LogEntryAdmin(admin.ModelAdmin):
list_display = ('flight_date','total_duration_of_flight','airport_from','airport_to','username')
date_hierarchy = 'flight_date'
admin.site.register(LogBookEntry,LogEntryAdmin)
class AirplaneAdmin(admin.ModelAdmin):
list_display = ('ident', 'make','airplane_model','year')
admin.site.register(Airplane,AirplaneAdmin)

42
logbook/models.py Normal file
View File

@ -0,0 +1,42 @@
from django.db import models
from django.contrib.auth.models import User
# Create your models here.
class LogBookEntry(models.Model):
username= models.ForeignKey(User, )
flight_date = models.DateField()
plane = models.ForeignKey('Airplane')
airport_from = models.CharField(max_length=4)
airport_to = models.CharField(max_length=4)
remarks = models.TextField(null=True,blank=True)
number_instructor_app = models.DecimalField(decimal_places=1,max_digits=3,null=True,blank=True)
number_landings = models.DecimalField(decimal_places=1,max_digits=3,null=True,blank=True)
airplane_sel = models.DecimalField(decimal_places=1,max_digits=3,null=True,blank=True)
airplane_mel = models.DecimalField(decimal_places=1,max_digits=3,null=True,blank=True)
cross_country = models.DecimalField(decimal_places=1,max_digits=3,null=True,blank=True)
day_time = models.DecimalField(decimal_places=1,max_digits=3,null=True,blank=True)
night_time = models.DecimalField(decimal_places=1,max_digits=3,null=True,blank=True)
actual_instrument = models.DecimalField(decimal_places=1,max_digits=3,null=True,blank=True)
simulated_instrument = models.DecimalField(decimal_places=1,max_digits=3,null=True,blank=True)
ground_trainer = models.DecimalField(decimal_places=1,max_digits=3,null=True,blank=True)
dual_received = models.DecimalField(decimal_places=1,max_digits=3,null=True,blank=True)
pilot_in_command = models.DecimalField(decimal_places=1,max_digits=3,null=True,blank=True)
instructor = models.CharField(max_length=30,null=True,blank=True)
total_duration_of_flight = models.DecimalField(decimal_places=1,max_digits=3)
link = models.CharField(max_length=200,null=True,blank=True)
def __unicode__(self):
return "Date: %s Total: %s" % (self.flight_date,self.total_duration_of_flight)
class Airplane(models.Model):
make = models.CharField(max_length=30)
airplane_model = models.CharField(max_length=30)
year = models.CharField(max_length=4)
ident = models.CharField(max_length=6)
def __unicode__(self):
return "%s" % (self.airplane_model)

View File

@ -0,0 +1,37 @@
<html>
<head>
<link href="/media/favicon.ico" rel="icon" type="image/x-icon">
<style>
span{
margin-left:20px;
}
</style>
</head>
<body>
<h1>{{log.flight_date}} </h1>
{% if log.make_and_model %} <label for="makeandmodel">Make and Model</label><span id="makeandmodel">{{log.make_and_model}}</span> <br> {% endif %}
{% if log.ident %} <label for="ident">Ident</label><span id="ident">{{log.ident}}</span> <br> {% endif %}
{% if log.airport_from %} <label for="af">Airport From</label><span id="af">{{log.airport_from}}</span> <br> {% endif %}
{% if log.airport_to %} <label for="at">Airport To</label><span id="at">{{log.airport_to}}</span> <br> {% endif %}
{% if log.number_instructor_app %} <label for="nia">Number of Instructor App.</label><span id="nia">{{log.number_instructor_app}}</span> <br> {% endif %}
{% if log.number_landings %} <label for="nl">Number Landings</label><span id="nl">{{log.number_landings}}</span> <br> {% endif %}
{% if log.airplane_sel %} <label for="sel">Airport SEL</label><span id="sel">{{log.airplane_sel}}</span> <br> {% endif %}
{% if log.airplane_mel %} <label for="mel">Airport MEL</label><span id="mel">{{log.airplane_mel}}</span> <br> {% endif %}
{% if log.cross_country %} <label for="cc">Cross Country</label><span id="cc">{{log.cross_country}}</span> <br> {% endif %}
{% if log.day_time %} <label for="dt">Day Time</label><span id="dt">{{log.day_time}}</span> <br> {% endif %}
{% if log.night_time %} <label for="nt">Night Time</label><span id="nt">{{log.night_time}}</span> <br> {% endif %}
{% if log.actual_instrument %} <label for="ai">Actual Instrument</label><span id="ai">{{log.actual_instrument}}</span> <br> {% endif %}
{% if log.simulated_instrument %} <label for="si">Simulated Instrument</label><span id="si">{{log.simulated_instrument}}</span> <br> {% endif %}
{% if log.ground_trainer %} <label for="gt">Ground Trainer</label><span id="gt">{{log.ground_trainer}}</span> <br> {% endif %}
{% if log.dual_received %} <label for="dr">Dual Received</label><span id="dr">{{log.dual_received}}</span> <br> {% endif %}
{% if log.pilot_in_command %} <label for="pic">Pilot in Command</label><span id="pic">{{log.pilot_in_command}}</span> <br> {% endif %}
{% if log.total_duration_of_flight %} <label for="total">Duration of Flight</label><span id="total">{{log.total_duration_of_flight}}</span> {%endif%}
<br>
<br>
<br>
<label for="remarks"></label><span id="remarks">{{log.remarks}}</span>
</body>
</html>

View File

@ -0,0 +1,39 @@
<html>
<head>
<link href="/media/favicon.ico" rel="icon" type="image/x-icon">
</head>
<body>
<table border=1>
<tr>
<td>Date</td>
<td>Tail Number</td>
<td>Airport from</td>
<td>Airport to</td>
<td>Number of landings</td>
<td>Duration of Flight</td>
<td>Info</td>
</tr>
{% for l in logs%}
<tr>
<td>{{l.flight_date}}</td>
<td>{{l.plane.ident}}</td>
<td>{{l.airport_from}}</td>
<td>{{l.airport_to}}</td>
<td>{{l.number_landings}}</td>
<td>{{l.total_duration_of_flight}}</td>
<td><a href="flight/{{l.id}}/">Info</a></td>
</tr>
{% endfor %}
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td>{{total_landings}}</td>
<td>{{total_time}}</td>
<td></td>
</tr>
</table>
</body>
</html>

View File

@ -0,0 +1 @@
hi

6
logbook/urls.py Normal file
View File

@ -0,0 +1,6 @@
from django.conf.urls.defaults import *
urlpatterns = patterns('',
(r'^flight/(?P<flight>.*)/','logbook.views.flight'),
(r'^$', 'logbook.views.index'),
)

39
logbook/views.py Normal file
View File

@ -0,0 +1,39 @@
from django.contrib.auth.decorators import login_required
from django.shortcuts import get_object_or_404, render_to_response, redirect
from django.http import HttpResponseRedirect,HttpResponse
from django.template import RequestContext
from django.conf import settings
from django.contrib.auth.models import User
from django.template import RequestContext
from django.shortcuts import render_to_response
from django.core.context_processors import csrf
from logbook.models import LogBookEntry
def index(request):
user = User.objects.get(username="tyrel")
logs = LogBookEntry.objects.order_by('flight_date').filter(username=user)
total_time = 0
total_landings= 0
for l in logs:
total_time += l.total_duration_of_flight
total_landings += l.number_landings
return render_to_response('logbook/index.html',
{
'logs':logs,
'total_time':total_time,
'total_landings':total_landings,
})
def flight(request,flight):
log = get_object_or_404(LogBookEntry,pk=flight)
return render_to_response('logbook/flight.html',
{
'log':log,
})
def goaway(request):
return HttpResponse("Go Away")

11
manage.py Executable file
View File

@ -0,0 +1,11 @@
#!/usr/bin/env 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)

73
settings.py Normal file
View File

@ -0,0 +1,73 @@
try:
from local_settings import *
except:
DEBUG = True
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'tyrellogbook', # 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.
}
}
# Django settings for flight project.
import os
TEMPLATE_DEBUG = DEBUG
ADMINS = (
# ('Your Name', 'your_email@domain.com'),
)
MANAGERS = ADMINS
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
TIME_ZONE = 'America/New_York'
LANGUAGE_CODE = 'en-us'
SITE_ID = 1
USE_I18N = True
USE_L10N = True
MEDIA_ROOT = os.path.join(PROJECT_ROOT, 'public/media/')
MEDIA_URL = '/media/'
ADMIN_MEDIA_PREFIX = '/media/'
SECRET_KEY = '-u2an)@echbftmxy&2=(0uv(2h465fwq0x+k1%(+exvt@zr!z*'
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 = 'flight.urls'
TEMPLATE_DIRS = (
# 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.
os.path.join(os.path.dirname(__file__),'templates')
)
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
'flight.logbook',
)
LOGIN_URL="/admin/"

1
templates/404.html Normal file
View File

@ -0,0 +1 @@
Not Done. Quit telling me about problems.

12
urls.py Normal file
View File

@ -0,0 +1,12 @@
from django.conf.urls.defaults import *
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
(r'^admin/', include(admin.site.urls)),
(r'^book/', include('logbook.urls')),
(r'^favicon\.ico$', 'django.views.generic.simple.redirect_to', {'url': '/media/favicon.ico'}),
#(r'^$', 'logbook.views.goaway'),
)