Commit f28d4ff8 authored by Daniel W Bond's avatar Daniel W Bond
Browse files

moved files into renamed settings directory

parent 0c0eee9e
from django.contrib import admin
from api.models import Class, Building, Address, Room
# Register your models here.
admin.site.register(Class)
admin.site.register(Building)
admin.site.register(Address)
admin.site.register(Room)
from django.db import models
from django.contrib.auth.models import User
# Create your models here.
class Class(models.Model):
year_int = models.IntegerField()
FRESHMAN = 'FR'
SOPHOMORE = 'SO'
JUNIOR = 'JR'
SENIOR = 'SR'
YEAR_IN_SCHOOL_CHOICES = (
(FRESHMAN, 'Freshman'),
(SOPHOMORE, 'Sophomore'),
(JUNIOR, 'Junior'),
(SENIOR, 'Senior'),
)
year_in_school = models.CharField(max_length=2,
choices=YEAR_IN_SCHOOL_CHOICES,
default=FRESHMAN)
def __str__(self): # __unicode__ on Python 2
return self.year_int
class Building(models.Model):
name = models.CharField(max_length=100)
NONE = 'na'
AQUIA = 'aq'
RAPPAHANNOCK = 'ra'
SHENANDOAH = 'sh'
NEIGHBOURHOOD_CHOICES = (
(NONE, 'None'),
(AQUIA, 'Aquia'),
(RAPPAHANNOCK, 'Rappahannock'),
(SHENANDOAH, 'Shenandoah'),
)
neighbourhood = models.CharField(max_length=100, choices=NEIGHBOURHOOD_CHOICES,
default=NONE)
address = models.ForeignKey('Address')
def __str__(self): # __unicode__ on Python 2
return self.name
def __unicode__(self): # __unicode__ on Python 2
return unicode(self.name)
class Room(models.Model):
number = models.IntegerField()
floor = models.IntegerField()
bedA = models.CharField(max_length=80)
bedB = models.CharField(max_length=80, blank=True)
bedC = models.CharField(max_length=80, blank=True)
bedD = models.CharField(max_length=80, blank=True)
building = models.ForeignKey('Building')
def __str__(self): # __unicode__ on Python 2
return self.building.__str__()+" "+self.number.__str__()
class Address(models.Model):
street = models.CharField(max_length=100)
zip_code = models.IntegerField(max_length=5)
state = models.CharField(max_length=2)
def __str__(self): # __unicode__ on Python 2
return self.street
from django.contrib import admin
# Register your models here.
from django.db import models
# Create your models here.
from django.test import TestCase
# Create your tests here.
from django.conf.urls import patterns, include, url
from roomlist import views
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^$', views.index, name='index'),
url(r'^accounts/login/$', views.login, name='login'),
url(r'^accounts/logout/$', views.logout_view, name='logout_view'),
url(r'^buildings/$', views.buildings, name='buildings'),
url(r'^building/(?P<buildingName>[a-zA-Z]+)$', views.building, name='building'),
)
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render
from django.template import RequestContext, loader
from django.contrib.auth.forms import AuthenticationForm
from django.contrib.auth import authenticate, logout
from api.models import Building, Room
# Create your views here.
def index(request):
template = loader.get_template('index.html')
context = RequestContext(request, {
})
return HttpResponse(template.render(context))
def buildings(request):
building_list = Building.objects.order_by('name')[:5]
template = loader.get_template('buildings.html')
context = RequestContext(request, {
'building_list' : building_list,
})
return HttpResponse(template.render(context))
def building(request, buildingName):
building = Building.objects.get(name__iexact=''+buildingName)
room_list = Room.objects.filter(building__name=''+building.name).order_by('number')
template = loader.get_template('building.html')
context = RequestContext(request, {
'building' : building,
'room_list' : room_list,
})
return HttpResponse(template.render(context))
def login(request):
# if this is a POST request we need to process the form data
if request.method == 'POST':
# create a form instance and populate it with data from the request:
# check whether it's valid:
username = request.POST['username']
password = request.POST['password']
user = authenticate(username=username, password=password)
if user is not None:
# the password verified for the user
if user.is_active:
print("User is valid, active and authenticated")
else:
print("The password is valid, but the account has been disabled!")
else:
# the authentication system was unable to verify the username and password
print("The username and password were incorrect.")
return HttpResponseRedirect('/')
# if a GET (or any other method) we'll create a blank form
else:
form = AuthenticationForm()
template = loader.get_template('login.html')
context = RequestContext(request, {
'form' : form,
})
return HttpResponse(template.render(context))
def logout_view(request):
logout(request)
return HttpResponseRedirect('/')
...@@ -11,7 +11,12 @@ https://docs.djangoproject.com/en/1.6/ref/settings/ ...@@ -11,7 +11,12 @@ https://docs.djangoproject.com/en/1.6/ref/settings/
# Build paths inside the project like this: os.path.join(BASE_DIR, ...) # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__)) BASE_DIR = os.path.dirname(os.path.dirname(__file__))
TEMPLATE_DIRS = [os.path.join(BASE_DIR, 'templates')]
TEMPLATE_DIRS = (
os.path.join(BASE_DIR, 'templates'),
os.path.join(BASE_DIR, 'housing/templates'),
)
STATICFILES_DIRS = ( STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'), os.path.join(BASE_DIR, 'static'),
) )
......
{% extends 'layouts/base.html' %} {% block title %} GMU RoomList &bull; Homepage {% endblock %} {% block content %}
<div class="page-header" id="banner">
<div class="row">
<div class="col-lg-12 text-center">
<h1><strong>GMU</strong>ROOMLIST</h1>
<p class="lead">{{ building.name }}</p>
</div>
</div>
</div>
<ul style="list-style-type: none">
{% for room in room_list %}
<li>
{{ room.number }}
</li>
<li>
<ul>
<li>
{{ room.bedA }}
</li>
{% if room.bedB %}
<li>
{{ room.bedB }}
</li>
{% endif %}
{% if room.bedC %}
<li>
{{ room.bedC }}
</li>
{% endif %}
{% if room.bedD %}
<li>
{{ room.bedD }}
</li>
{% endif %}
</ul>
</li>
{% endfor %}
</ul>
{% endblock %}
{% extends 'layouts/base.html' %}
{% block title %}
GMU RoomList &bull; Homepage
{% endblock %}
{% block content %}
<div class="page-header" id="banner">
<div class="row">
<div class="col-lg-12 text-center">
<h1><strong>GMU</strong>ROOMLIST</h1>
<p class="lead">Building List</p>
</div>
</div>
</div>
<ul>
{% for building in building_list %}
<li>
<a href="/building/{{ building.name }}">{{ building.name }}</a> - {{ building.address }} {{ building.address.zip_code }}, {{ building.address.state}}
</li>
{% endfor %}
</ul>
{% endblock %}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment