diff --git a/.gitignore b/.gitignore index 99e6452..4155529 100644 --- a/.gitignore +++ b/.gitignore @@ -4,8 +4,6 @@ # Byte-compiled / optimized / DLL files __pycache__/ parker/__pycache__/ -polls/__pycache__/ - *.py[cod] # C extensions diff --git a/polls/__init__.py b/polls/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/polls/admin.py b/polls/admin.py deleted file mode 100644 index 56003fa..0000000 --- a/polls/admin.py +++ /dev/null @@ -1,31 +0,0 @@ -from django.contrib import admin -from django.contrib.admin import AdminSite -from django.utils.translation import ugettext_lazy -from .models import Question, Choice - -class ChoiceInline(admin.TabularInline): - model = Choice - extra = 3 - -class QuestionAdmin(admin.ModelAdmin): - fieldsets = [ - (None, {'fields': ['question_text']}), - ('Date information', {'fields': ['pub_date'], 'classes': ['collapse']}) - ] - inlines = [ChoiceInline] - list_display = ('question_text', 'pub_date', 'was_published_recently') - list_filter = ['pub_date'] - search_fields = ['question_text'] - -class MyAdminSite(AdminSite): - # Text to put at the end of each page's . - site_title = ugettext_lazy('My site admin') - - # Text to put in each page's <h1>. - site_header = ugettext_lazy('My administration') - - # Text to put at the top of the admin index page. - index_title = ugettext_lazy('Site administration') - -admin_site = MyAdminSite() -admin.site.register(Question, QuestionAdmin) diff --git a/polls/migrations/0001_initial.py b/polls/migrations/0001_initial.py deleted file mode 100644 index d5af57d..0000000 --- a/polls/migrations/0001_initial.py +++ /dev/null @@ -1,41 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - -from django.db import models, migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ] - - operations = [ - migrations.CreateModel( - name='Choice', - fields=[ - ('id', models.AutoField(serialize=False, auto_created=True, verbose_name='ID', primary_key=True)), - ('choice_text', models.CharField(max_length=200)), - ('votes', models.IntegerField(default=0)), - ], - options={ - }, - bases=(models.Model,), - ), - migrations.CreateModel( - name='Question', - fields=[ - ('id', models.AutoField(serialize=False, auto_created=True, verbose_name='ID', primary_key=True)), - ('question_test', models.CharField(max_length=200)), - ('pub_date', models.DateTimeField(verbose_name='date published')), - ], - options={ - }, - bases=(models.Model,), - ), - migrations.AddField( - model_name='choice', - name='question', - field=models.ForeignKey(to='polls.Question'), - preserve_default=True, - ), - ] diff --git a/polls/migrations/0002_auto_20150403_1219.py b/polls/migrations/0002_auto_20150403_1219.py deleted file mode 100644 index 426acab..0000000 --- a/polls/migrations/0002_auto_20150403_1219.py +++ /dev/null @@ -1,19 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - -from django.db import models, migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('polls', '0001_initial'), - ] - - operations = [ - migrations.RenameField( - model_name='question', - old_name='question_test', - new_name='question_text', - ), - ] diff --git a/polls/migrations/__init__.py b/polls/migrations/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/polls/models.py b/polls/models.py deleted file mode 100644 index b42bb55..0000000 --- a/polls/models.py +++ /dev/null @@ -1,29 +0,0 @@ -import datetime - -from django.db import models -from django.utils import timezone - - -class Question(models.Model): - question_text = models.CharField(max_length=200) - pub_date = models.DateTimeField('date published') - - def __str__(self): - return self.question_text - - def was_published_recently(self): - now = timezone.now() - return now - datetime.timedelta(days=1) <= self.pub_date <= now - - was_published_recently.admin_order_field = 'pub_date' - was_published_recently.boolean = True - was_published_recently.short_description = "Published recently?" - - -class Choice(models.Model): - question = models.ForeignKey(Question) - choice_text = models.CharField(max_length=200) - votes = models.IntegerField(default=0) - - def __str__(self): - return self.choice_text diff --git a/polls/static/polls/images/background.gif b/polls/static/polls/images/background.gif deleted file mode 100644 index 2194fdb..0000000 Binary files a/polls/static/polls/images/background.gif and /dev/null differ diff --git a/polls/static/polls/style.css b/polls/static/polls/style.css deleted file mode 100644 index 09ccbc4..0000000 --- a/polls/static/polls/style.css +++ /dev/null @@ -1,7 +0,0 @@ -li a { - color: green; -} - -body { - background: white url("images/background.gif") no-repeat right bottom; -} \ No newline at end of file diff --git a/polls/templates/polls/details.html b/polls/templates/polls/details.html deleted file mode 100644 index a9d34cf..0000000 --- a/polls/templates/polls/details.html +++ /dev/null @@ -1,12 +0,0 @@ -<h1>{{ question.question_text }}</h1> - -{% if error_message %}<p><strong>{{ error_message }}</strong></p>{% endif %} - -<form action="{% url 'polls:vote' question.id %}" method="post"> - {% csrf_token %} - {% for choice in question.choice_set.all %} - <input type="radio" name="choice" id="choice{{ forloop.counter }}" value="{{ choice.id }}"/> - <label for="choice{{ forloop.counter }}">{{ choice.choice_text }}</label><br/> - {% endfor %} - <input type="submit" value="Vote"/> -</form> \ No newline at end of file diff --git a/polls/templates/polls/index.html b/polls/templates/polls/index.html deleted file mode 100644 index 8463706..0000000 --- a/polls/templates/polls/index.html +++ /dev/null @@ -1,12 +0,0 @@ -{% load staticfiles %} -<link rel="stylesheet" type="text/css" href="{% static 'polls/style.css' %}" - -{% if latest_question_list %} - <ul> - {% for question in latest_question_list %} - <li><a href="{% url 'polls:details' question.id %}">{{question.question_text}}</a></li> - {% endfor %} - </ul> -{% else %} - <p>No polls are available.</p> -{% endif %} diff --git a/polls/templates/polls/results.html b/polls/templates/polls/results.html deleted file mode 100644 index 14f6d57..0000000 --- a/polls/templates/polls/results.html +++ /dev/null @@ -1,8 +0,0 @@ -<h1>{{ question.question.text }}</h1> -<ul> - {% for choice in question.choice_set.all %} - <li>{{ choice.choice_text }} -- {{ choice.votes }} vote{{ choice.votes|pluralize }}</li> - {% endfor %} -</ul> - -<a href="{% url 'polls:details' question.id %}">Vote again?</a> \ No newline at end of file diff --git a/polls/tests.py b/polls/tests.py deleted file mode 100644 index d0c0aa2..0000000 --- a/polls/tests.py +++ /dev/null @@ -1,35 +0,0 @@ -import datetime - -from django.utils import timezone -from django.test import TestCase - -from .models import Question - - -class QuestionMethodTests(TestCase): - def test_was_published_recently_with_future_question(self): - """ - was_published_recently() should return False for questions whose - pub_date is in future. - """ - time = timezone.now() + datetime.timedelta(days=30) - future_question = Question(pub_date=time) - self.assertEqual(future_question.was_published_recently(), False) - - def test_was_published_recently_with_old_question(self): - """ - was_published_recently() should return False for questions whose - pub_date is older than 1 day - """ - time = timezone.now() - datetime.timedelta(days=30) - old_question = Question(pub_date=time) - self.assertEqual(old_question.was_published_recently(), False) - - def test_was_published_recently_with_recent_question(self): - """ - was_published_recently() should return True for questions whose - pub_date is within the last day - """ - time = timezone.now() - datetime.timedelta(hours=1) - recent_question = Question(pub_date=time) - self.assertEqual(recent_question.was_published_recently(), True) diff --git a/polls/urls.py b/polls/urls.py deleted file mode 100644 index 266a707..0000000 --- a/polls/urls.py +++ /dev/null @@ -1,25 +0,0 @@ -from django.conf.urls import url -from . import views - -urlpatterns = [ - url(r'^$', views.IndexView.as_view(), name='index'), - # ex: polls/5/ - url(r'^(?P<pk>[0-9]+)/$', views.DetailView.as_view(), name='details'), - # ex: /polls/5/results/ - url(r'^(?P<pk>[0-9]+)/results/$', views.ResultsView.as_view(), name='results'), - # ex: polls/5/vote/ - url(r'^(?P<question_id>[0-9]+)/vote/$', views.vote, name='vote'), -] - - -# urlpatterns = [ -# # ex: /polls/ -# url(r'^$', views.index, name='index'), -# # ex: polls/5/ -# url(r'^(?P<question_id>[0-9]+)/$', views.details, name='details'), -# # ex: /polls/5/results/ -# url(r'^(?P<question_id>[0-9]+)/results/$', views.results, name='results'), -# # ex: polls/5/vote/ -# url(r'^(?P<question_id>[0-9]+)/vote/$', views.vote, name='vote'), -# ] - diff --git a/polls/views.py b/polls/views.py deleted file mode 100644 index 20bfe22..0000000 --- a/polls/views.py +++ /dev/null @@ -1,75 +0,0 @@ -from django.shortcuts import render -from django.shortcuts import get_object_or_404 -from django.http import HttpResponseRedirect -from django.core.urlresolvers import reverse -from django.views import generic -from django.utils import timezone - -from .models import Question, Choice - - -class IndexView(generic.ListView): - template_name = "polls/index.html" - context_object_name = "latest_question_list" - - def get_queryset(self): - """Return the last five published questions""" - return Question.objects.order_by('-pub_date')[:5] - - -class DetailView(generic.DetailView): - model = Question - template_name = "polls/details.html" - - -class ResultsView(generic.DetailView): - model = Question - template_name = "polls/results.html" - - -""" -def index(request): - latest_question_list = Question.objects.order_by('-pub_date')[:5] - context = {'latest_question_list': latest_question_list} - return render(request, 'polls/index.html', context) - - -def details(request, question_id): - question = get_object_or_404(Question, pk=question_id) - return render(request, 'polls/details.html', {'question': question}) - - -def results(request, question_id): - question = get_object_or_404(Question, pk=question_id) - return render(request, 'polls/results.html', {'question': question}) -""" - - -def vote(request, question_id): - p = get_object_or_404(Question, pk=question_id) - try: - selected_choice = p.choice_set.get(pk=request.POST['choice']) - # KeyError will be thrown if request.POST['choice'] does not exist - except (KeyError, Choice.DoesNotExist): - # Redisplay the question voting form - return render(request, 'polls/details.html', { - 'question': p, - 'error_message': "You didn't select a choice" - }) - else: - selected_choice.votes += 1 - selected_choice.save() - # Always return an HttpResponseRedirect after successfully dealing - # with POST data. This prevents data from being posted twice if a - # user hits the Back button. - return HttpResponseRedirect(reverse('polls:results', args=(p.id,))) - - -def get_queryset(self): - """ - Return the list five published questions (not including those set to be - published in the future) - """ - return Question.objects.filter( - pub_date__lte=timezone.now() - ).order_by('-pub_date')[:5] \ No newline at end of file