Skip to content

Commit 0f42646

Browse files
committed
2 parents b1b6e55 + dffa7a6 commit 0f42646

File tree

21 files changed

+1742
-34
lines changed

21 files changed

+1742
-34
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env python
2+
import os
3+
import sys
4+
5+
if __name__ == "__main__":
6+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
7+
8+
from django.core.management import execute_from_command_line
9+
10+
execute_from_command_line(sys.argv)

assignments/teachers/week06/answers/mysite/mysite/__init__.py

Whitespace-only changes.
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
# Django settings for mysite project.
2+
3+
DEBUG = True
4+
TEMPLATE_DEBUG = DEBUG
5+
6+
ADMINS = (
7+
# ('Your Name', '[email protected]'),
8+
)
9+
10+
MANAGERS = ADMINS
11+
12+
DATABASES = {
13+
'default': {
14+
'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
15+
'NAME': 'mysite.db', # Or path to database file if using sqlite3.
16+
'USER': '', # Not used with sqlite3.
17+
'PASSWORD': '', # Not used with sqlite3.
18+
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
19+
'PORT': '', # Set to empty string for default. Not used with sqlite3.
20+
}
21+
}
22+
23+
# Local time zone for this installation. Choices can be found here:
24+
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
25+
# although not all choices may be available on all operating systems.
26+
# In a Windows environment this must be set to your system time zone.
27+
TIME_ZONE = 'America/Chicago'
28+
29+
# Language code for this installation. All choices can be found here:
30+
# http://www.i18nguy.com/unicode/language-identifiers.html
31+
LANGUAGE_CODE = 'en-us'
32+
33+
SITE_ID = 1
34+
35+
# If you set this to False, Django will make some optimizations so as not
36+
# to load the internationalization machinery.
37+
USE_I18N = True
38+
39+
# If you set this to False, Django will not format dates, numbers and
40+
# calendars according to the current locale.
41+
USE_L10N = True
42+
43+
# If you set this to False, Django will not use timezone-aware datetimes.
44+
USE_TZ = True
45+
46+
# Absolute filesystem path to the directory that will hold user-uploaded files.
47+
# Example: "/home/media/media.lawrence.com/media/"
48+
MEDIA_ROOT = ''
49+
50+
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
51+
# trailing slash.
52+
# Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
53+
MEDIA_URL = ''
54+
55+
# Absolute path to the directory static files should be collected to.
56+
# Don't put anything in this directory yourself; store your static files
57+
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
58+
# Example: "/home/media/media.lawrence.com/static/"
59+
STATIC_ROOT = ''
60+
61+
# URL prefix for static files.
62+
# Example: "http://media.lawrence.com/static/"
63+
STATIC_URL = '/static/'
64+
65+
# Additional locations of static files
66+
STATICFILES_DIRS = (
67+
# Put strings here, like "/home/html/static" or "C:/www/django/static".
68+
# Always use forward slashes, even on Windows.
69+
# Don't forget to use absolute paths, not relative paths.
70+
)
71+
72+
# List of finder classes that know how to find static files in
73+
# various locations.
74+
STATICFILES_FINDERS = (
75+
'django.contrib.staticfiles.finders.FileSystemFinder',
76+
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
77+
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
78+
)
79+
80+
# Make this unique, and don't share it with anybody.
81+
SECRET_KEY = ')-z(0n-exq%$(^6*sunt1b7q#zo!hy$f(-p#2@q1pjcsvc0y@)'
82+
83+
# List of callables that know how to import templates from various sources.
84+
TEMPLATE_LOADERS = (
85+
'django.template.loaders.filesystem.Loader',
86+
'django.template.loaders.app_directories.Loader',
87+
# 'django.template.loaders.eggs.Loader',
88+
)
89+
90+
MIDDLEWARE_CLASSES = (
91+
'django.middleware.common.CommonMiddleware',
92+
'django.contrib.sessions.middleware.SessionMiddleware',
93+
'django.middleware.csrf.CsrfViewMiddleware',
94+
'django.contrib.auth.middleware.AuthenticationMiddleware',
95+
'django.contrib.messages.middleware.MessageMiddleware',
96+
# Uncomment the next line for simple clickjacking protection:
97+
# 'django.middleware.clickjacking.XFrameOptionsMiddleware',
98+
)
99+
100+
ROOT_URLCONF = 'mysite.urls'
101+
102+
# Python dotted path to the WSGI application used by Django's runserver.
103+
WSGI_APPLICATION = 'mysite.wsgi.application'
104+
105+
TEMPLATE_DIRS = (
106+
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
107+
# Always use forward slashes, even on Windows.
108+
# Don't forget to use absolute paths, not relative paths.
109+
)
110+
111+
INSTALLED_APPS = (
112+
'django.contrib.auth',
113+
'django.contrib.contenttypes',
114+
'django.contrib.sessions',
115+
'django.contrib.sites',
116+
'django.contrib.messages',
117+
'django.contrib.staticfiles',
118+
# Uncomment the next line to enable the admin:
119+
'django.contrib.admin',
120+
# Uncomment the next line to enable admin documentation:
121+
# 'django.contrib.admindocs',
122+
'polls',
123+
)
124+
125+
# A sample logging configuration. The only tangible logging
126+
# performed by this configuration is to send an email to
127+
# the site admins on every HTTP 500 error when DEBUG=False.
128+
# See http://docs.djangoproject.com/en/dev/topics/logging for
129+
# more details on how to customize your logging configuration.
130+
LOGGING = {
131+
'version': 1,
132+
'disable_existing_loggers': False,
133+
'filters': {
134+
'require_debug_false': {
135+
'()': 'django.utils.log.RequireDebugFalse'
136+
}
137+
},
138+
'handlers': {
139+
'mail_admins': {
140+
'level': 'ERROR',
141+
'filters': ['require_debug_false'],
142+
'class': 'django.utils.log.AdminEmailHandler'
143+
}
144+
},
145+
'loggers': {
146+
'django.request': {
147+
'handlers': ['mail_admins'],
148+
'level': 'ERROR',
149+
'propagate': True,
150+
},
151+
}
152+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from django.conf.urls import patterns, include, url
2+
3+
# Uncomment the next two lines to enable the admin:
4+
from django.contrib import admin
5+
admin.autodiscover()
6+
7+
urlpatterns = patterns('',
8+
# Examples:
9+
# url(http://github.com/r'^r'^$', 'mysite.views.home', name='home'#39;,%20'mysite.views.home',%20name='home'),
10+
# url(http://github.com/r'^mysite/',%20include('mysite.foo.urls')),
11+
12+
# Uncomment the admin/doc line below to enable admin documentation:
13+
# url(http://github.com/r'^admin/doc/',%20include('django.contrib.admindocs.urls')),
14+
15+
# Uncomment the next line to enable the admin:
16+
url(r'^admin/', include(admin.site.urls)),
17+
url(r'^polls/', include('polls.urls'))
18+
)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"""
2+
WSGI config for mysite project.
3+
4+
This module contains the WSGI application used by Django's development server
5+
and any production WSGI deployments. It should expose a module-level variable
6+
named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover
7+
this application via the ``WSGI_APPLICATION`` setting.
8+
9+
Usually you will have the standard Django WSGI application here, but it also
10+
might make sense to replace the whole Django WSGI application with a custom one
11+
that later delegates to the Django one. For example, you could introduce WSGI
12+
middleware here, or combine a Django application with an application of another
13+
framework.
14+
15+
"""
16+
import os
17+
18+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
19+
20+
# This application object is used by any WSGI server configured to use this
21+
# file. This includes Django's development server, if the WSGI_APPLICATION
22+
# setting points here.
23+
from django.core.wsgi import get_wsgi_application
24+
application = get_wsgi_application()
25+
26+
# Apply WSGI middleware here.
27+
# from helloworld.wsgi import HelloWorldApplication
28+
# application = HelloWorldApplication(application)

assignments/teachers/week06/answers/mysite/polls/__init__.py

Whitespace-only changes.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from django.contrib import admin
2+
from polls.models import Poll, Choice
3+
4+
5+
class ChoiceInline(admin.TabularInline):
6+
model = Choice
7+
extra = 3
8+
ordering = ('choice', )
9+
10+
11+
class PollAdmin(admin.ModelAdmin):
12+
list_display = ('pub_date', 'question',
13+
'published_today')
14+
list_filter = ('pub_date', )
15+
ordering = ('pub_date', )
16+
inlines = (ChoiceInline, )
17+
18+
19+
admin.site.register(Poll, PollAdmin)
20+
admin.site.register(Choice)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from django.db import models
2+
from django.utils import timezone
3+
4+
5+
class Poll(models.Model):
6+
question = models.CharField(max_length=200)
7+
pub_date = models.DateTimeField('date published')
8+
9+
def __unicode__(self):
10+
return self.question
11+
12+
def published_today(self):
13+
now = timezone.now()
14+
time_delta = now - self.pub_date
15+
return time_delta.days == 0
16+
published_today.boolean = True
17+
published_today.short_description = "Published Today?"
18+
19+
def total_votes(self):
20+
total = 0
21+
for choice in self.choice_set.all():
22+
total += choice.votes
23+
return total
24+
25+
26+
class Choice(models.Model):
27+
poll = models.ForeignKey(Poll)
28+
choice = models.CharField(max_length=200)
29+
votes = models.IntegerField(default=0)
30+
31+
def __unicode__(self):
32+
return self.choice
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>My Site</title>
5+
</head>
6+
<body>
7+
<div class="container">
8+
<div class="content">
9+
{% if messages %}
10+
{% for message in messages %}
11+
<p class="notification{% if message.tags %} {{ message.tags }}{% endif %}">
12+
{{ message }}</p>
13+
{% endfor %}
14+
{% endif %}
15+
{% block content %}
16+
{% endblock %}
17+
</div>
18+
</div>
19+
</body>
20+
</html>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{% extends "base.html" %}
2+
3+
{% block content %}
4+
<h1>{{ poll }}</h1>
5+
{% if poll.choice_set.count > 0 %}
6+
<form action="{% url poll_vote poll.pk %}" method="POST">
7+
{% csrf_token %}
8+
{% for choice in poll.choice_set.all %}
9+
<div class="choice">
10+
<label for="choice_{{ choice.pk }}">
11+
<input type="radio" name="choice" id="choice_{{ choice.pk }}" value="{{ choice.pk }}"/>
12+
{{ choice }}
13+
</label>
14+
</div>
15+
{% endfor %}
16+
<input type="submit" name="vote" value="Vote"/>
17+
</form>
18+
{% else %}
19+
<p>No choices are available for this poll</p>
20+
{% endif %}
21+
{% endblock %}

0 commit comments

Comments
 (0)