Skip to content

Commit 3aef43f

Browse files
committed
poll application
0 parents  commit 3aef43f

35 files changed

+3117
-0
lines changed

data.db

37 KB
Binary file not shown.

db.sqlite3

37 KB
Binary file not shown.

manage.py

+10
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)

mysite/__init__.py

Whitespace-only changes.

mysite/__init__.pyc

126 Bytes
Binary file not shown.

mysite/settings.py

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
"""
2+
Django settings for mysite project.
3+
4+
For more information on this file, see
5+
https://docs.djangoproject.com/en/1.6/topics/settings/
6+
7+
For the full list of settings and their values, see
8+
https://docs.djangoproject.com/en/1.6/ref/settings/
9+
"""
10+
11+
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
12+
import os
13+
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
14+
15+
16+
# Quick-start development settings - unsuitable for production
17+
# See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/
18+
19+
# SECURITY WARNING: keep the secret key used in production secret!
20+
SECRET_KEY = '62v^rqr-)a6o85ff3eqg2%%4@4)h9rggbs=s_bl48@&tx@=e4y'
21+
22+
# SECURITY WARNING: don't run with debug turned on in production!
23+
DEBUG = True
24+
25+
TEMPLATE_DEBUG = True
26+
27+
ALLOWED_HOSTS = []
28+
29+
30+
# Application definition
31+
32+
INSTALLED_APPS = (
33+
'django.contrib.admin',
34+
'django.contrib.auth',
35+
'django.contrib.contenttypes',
36+
'django.contrib.sessions',
37+
'django.contrib.messages',
38+
'django.contrib.staticfiles',
39+
'polls',
40+
)
41+
42+
MIDDLEWARE_CLASSES = (
43+
'django.contrib.sessions.middleware.SessionMiddleware',
44+
'django.middleware.common.CommonMiddleware',
45+
'django.middleware.csrf.CsrfViewMiddleware',
46+
'django.contrib.auth.middleware.AuthenticationMiddleware',
47+
'django.contrib.messages.middleware.MessageMiddleware',
48+
'django.middleware.clickjacking.XFrameOptionsMiddleware',
49+
)
50+
51+
ROOT_URLCONF = 'mysite.urls'
52+
53+
WSGI_APPLICATION = 'mysite.wsgi.application'
54+
55+
56+
# Database
57+
# https://docs.djangoproject.com/en/1.6/ref/settings/#databases
58+
59+
DATABASES = {
60+
'default': {
61+
'ENGINE': 'django.db.backends.sqlite3',
62+
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
63+
}
64+
}
65+
66+
# Internationalization
67+
# https://docs.djangoproject.com/en/1.6/topics/i18n/
68+
#os.path.join(BASE_DIR, 'db.sqlite3')
69+
LANGUAGE_CODE = 'en-us'
70+
71+
TIME_ZONE = 'UTC'
72+
73+
USE_I18N = True
74+
75+
USE_L10N = True
76+
77+
USE_TZ = True
78+
79+
80+
# Static files (CSS, JavaScript, Images)
81+
# https://docs.djangoproject.com/en/1.6/howto/static-files/
82+
83+
STATIC_URL = '/static/'
84+
85+
TEMPLATE_DIRS = [os.path.join(BASE_DIR, 'templates')]

mysite/settings.pyc

2.16 KB
Binary file not shown.

mysite/settings.py~

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
"""
2+
Django settings for mysite project.
3+
4+
For more information on this file, see
5+
https://docs.djangoproject.com/en/1.6/topics/settings/
6+
7+
For the full list of settings and their values, see
8+
https://docs.djangoproject.com/en/1.6/ref/settings/
9+
"""
10+
11+
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
12+
import os
13+
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
14+
15+
16+
# Quick-start development settings - unsuitable for production
17+
# See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/
18+
19+
# SECURITY WARNING: keep the secret key used in production secret!
20+
SECRET_KEY = '62v^rqr-)a6o85ff3eqg2%%4@4)h9rggbs=s_bl48@&tx@=e4y'
21+
22+
# SECURITY WARNING: don't run with debug turned on in production!
23+
DEBUG = True
24+
25+
TEMPLATE_DEBUG = True
26+
27+
ALLOWED_HOSTS = []
28+
29+
30+
# Application definition
31+
32+
INSTALLED_APPS = (
33+
'django.contrib.admin',
34+
'django.contrib.auth',
35+
'django.contrib.contenttypes',
36+
'django.contrib.sessions',
37+
'django.contrib.messages',
38+
'django.contrib.staticfiles',
39+
'polls',
40+
)
41+
42+
MIDDLEWARE_CLASSES = (
43+
'django.contrib.sessions.middleware.SessionMiddleware',
44+
'django.middleware.common.CommonMiddleware',
45+
'django.middleware.csrf.CsrfViewMiddleware',
46+
'django.contrib.auth.middleware.AuthenticationMiddleware',
47+
'django.contrib.messages.middleware.MessageMiddleware',
48+
'django.middleware.clickjacking.XFrameOptionsMiddleware',
49+
)
50+
51+
ROOT_URLCONF = 'mysite.urls'
52+
53+
WSGI_APPLICATION = 'mysite.wsgi.application'
54+
55+
56+
# Database
57+
# https://docs.djangoproject.com/en/1.6/ref/settings/#databases
58+
59+
DATABASES = {
60+
'default': {
61+
'ENGINE': 'django.db.backends.sqlite3',
62+
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
63+
}
64+
}
65+
66+
# Internationalization
67+
# https://docs.djangoproject.com/en/1.6/topics/i18n/
68+
69+
LANGUAGE_CODE = 'en-us'
70+
71+
TIME_ZONE = 'UTC'
72+
73+
USE_I18N = True
74+
75+
USE_L10N = True
76+
77+
USE_TZ = True
78+
79+
80+
# Static files (CSS, JavaScript, Images)
81+
# https://docs.djangoproject.com/en/1.6/howto/static-files/
82+
83+
STATIC_URL = '/static/'
84+
85+
TEMPLATE_DIRS = [os.path.join(BASE_DIR, 'templates')]

mysite/urls.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from django.conf.urls import patterns, include, url
2+
3+
from django.contrib import admin
4+
5+
admin.autodiscover()
6+
7+
urlpatterns = patterns('',
8+
# Examples:
9+
# url(r'^$', 'mysite.views.home', name='home'),
10+
# url(r'^blog/', include('blog.urls')),
11+
url(r'^admin/', include(admin.site.urls)),
12+
url(r'^polls/', include('polls.urls', namespace= "polls")),
13+
14+
)

mysite/urls.pyc

483 Bytes
Binary file not shown.

mysite/urls.py~

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from django.conf.urls import patterns, include, url
2+
3+
from django.contrib import admin
4+
admin.autodiscover()
5+
6+
urlpatterns = patterns('',
7+
# Examples:
8+
# url(r'^$', 'mysite.views.home', name='home'),
9+
# url(r'^blog/', include('blog.urls')),
10+
url(r'^polls/', include('polls.urls')),
11+
url(r'^admin/', include(admin.site.urls)),
12+
)

mysite/wsgi.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
"""
2+
WSGI config for mysite project.
3+
4+
It exposes the WSGI callable as a module-level variable named ``application``.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/1.6/howto/deployment/wsgi/
8+
"""
9+
10+
import os
11+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
12+
13+
from django.core.wsgi import get_wsgi_application
14+
application = get_wsgi_application()

mysite/wsgi.pyc

581 Bytes
Binary file not shown.

polls/__init__.py

Whitespace-only changes.

polls/__init__.pyc

125 Bytes
Binary file not shown.

polls/admin.py

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from django.contrib import admin
2+
from polls.models import Choice, Poll
3+
4+
5+
class ChoiceInLine(admin.TabularInline):
6+
model = Choice
7+
extra = 3
8+
9+
10+
class PollAdmin(admin.ModelAdmin):
11+
list_display = ('question','pub_date')
12+
list_filter = ['pub_date']
13+
search_fields = ['question']
14+
fieldsets= [
15+
(None, {'fields' :['question']}),
16+
('date information', {'fields' :['pub_date'],'classes' :['collapse']}),
17+
]
18+
19+
inlines = [ChoiceInLine]
20+
21+
22+
23+
admin.site.register(Poll,PollAdmin)
24+
#admin.site.register(Choice)
25+
26+

polls/admin.pyc

1.01 KB
Binary file not shown.

polls/admin.py~

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
9+
10+
class PollAdmin(admin.ModelAdmin):
11+
list_display = ('question','pub_date')
12+
list_filter = ['pub_date']
13+
search_fields = ['question']
14+
fieldsets= [
15+
(None, {'fields' :['question']}),
16+
('date information', {'fields' :['pub_date'],'classes' :['collapse']}),
17+
]
18+
19+
inlines = [ChoiceInLine]
20+
21+
22+
23+
admin.site.register(Poll,PollAdmin)
24+
#admin.site.register(Choice)
25+
26+

polls/models.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from django.db import models
2+
from django.utils import timezone
3+
4+
class Poll(models.Model):
5+
question = models.CharField(max_length = 200)
6+
pub_date = models.DateTimeField('date published')
7+
8+
def __unicode__(self):
9+
return self.question
10+
11+
def was_published_recently(self):
12+
return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
13+
was_published_recently.admin_order_field = 'pub_date'
14+
was_published_recently.boolean = True
15+
was_published_recently.short_description = 'Published recently?'
16+
17+
class Choice(models.Model):
18+
poll = models.ForeignKey(Poll)
19+
choice_text = models.CharField(max_length = 200)
20+
votes = models.IntegerField(default = 0)
21+
22+
def __unicode__ (self):
23+
return self.choice_text

polls/models.pyc

1.52 KB
Binary file not shown.

polls/models.py~

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from django.db import models
2+
from django.utils import timezone
3+
4+
class Poll(models.Model):
5+
question = models.CharField(max_length = 200)
6+
pub_date = models.DateTimeField('date published')
7+
8+
def __unicode__(self):
9+
return self.question
10+
11+
def was_published_recently(self):
12+
return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
13+
was_published_recently.admin_order_field = 'pub_date'
14+
was_published_recently.boolean = True
15+
was_published_recently.short_description = 'Published recently?'
16+
17+
class Choice(models.Model):
18+
poll = models.ForeignKey(Poll)
19+
choice_text = models.CharField(max_length = 200)
20+
votes = models.IntegerField(default = 0)
21+
22+
def __unicode__ (self):
23+
return self.choice_text

polls/templates/polls/detail.html

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<h1>{{poll.question}}</h1>
2+
{% if error_message %}<p><strong>{{error_message}}</strong></p>{% endif %}
3+
4+
<form action="{ url 'polls:vote' poll.id %}" method = "post">
5+
{% csrf_token %}
6+
{% for choices in poll.choice_set.all %}
7+
<input type="radio" name = "choices" id="choices{{forloop.counter}}" value="{{choice.id}}"/>
8+
<lable for="choice{{ forloop.counter }}" > {{choice.choice_text}}</label><br />
9+
{% endfor %}
10+
<input type = "submit" value = "vote" />
11+
</form>

polls/templates/polls/index.html

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{% load url from future %}
2+
{% if latest_poll_list %}
3+
<ul>
4+
{% for poll in latest_poll_list %}
5+
<li><a href = {% url 'polls:detail' poll.id %}>{{ poll.question }}</a></li>
6+
{% endfor %}
7+
</ul>
8+
{% else %}
9+
<p>No polls are available.</p>
10+
{% endif %}

polls/templates/polls/index.html~

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{% if latest_poll_list %}
2+
<ul>
3+
{% for poll in latest_poll_list %}
4+
<li><a href="/polls/{{ poll.id }}/">{{ poll.question }}</a></li>
5+
{% endfor %}
6+
</ul>
7+
{% else %}
8+
<p>No polls are available.</p>
9+
{% endif %}

polls/templates/polls/result.html

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<h1>{{ poll.question }}</h1>
2+
3+
<ul>
4+
{% for choice in poll.choice_set.all %}
5+
<li>{{ choice.choice_text }} -- {{ choice.votes }} vote{{ choice.votes|pluralize }}</li>
6+
{% endfor %}
7+
</ul>
8+
9+
<a href="{% url 'polls:detail' poll.id %}">vote again?</a>

polls/tests.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.test import TestCase
2+
3+
# Create your tests here.

polls/urls.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from django.conf.urls import patterns, url
2+
3+
from polls import views
4+
5+
urlpatterns = patterns('',
6+
url(r'^$',views.index, name='index'),
7+
url(r'^(?P<poll_id>\d+)/$',views.detail, name = 'detail'),
8+
url(r'^(?P<poll_id>\d+)/results/$', views.results, name='results'),
9+
url(r'^(?P<poll_id>\d+)/vote/$', views.vote, name = 'vote'),
10+
)

polls/urls.pyc

543 Bytes
Binary file not shown.

polls/urls.py~

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from django.conf.urls import patterns, url
2+
3+
from polls import views
4+
5+
urlpatterns = patterns('',
6+
#url(r'^$',views.index, name='index'),
7+
url(r'^(?P<poll_id>\d+)/$',views.details, name = 'detail'),
8+
url(r'^(?P<poll_id>\d+)/results/$', views.results, name='results'),
9+
url(r'^(?P<poll_id>\d+)/vote/$', views.vote, name = 'vote'),
10+
)

0 commit comments

Comments
 (0)