From 8561dbab9fb63d2ecd2128f83c803f8d4e7b8744 Mon Sep 17 00:00:00 2001 From: samuel Date: Fri, 26 Jun 2020 15:58:27 +0200 Subject: [PATCH 1/6] added some final stage to the quiz --- .../.#learn-german.org | 1 + sami/learn-python-the-hard-way/.#quiz2.py | 1 - sami/learn-python-the-hard-way/quiz.py | 20 +++++++++++++------ 3 files changed, 15 insertions(+), 7 deletions(-) create mode 120000 sami/learn-python-the-hard-way/.#learn-german.org delete mode 120000 sami/learn-python-the-hard-way/.#quiz2.py diff --git a/sami/learn-python-the-hard-way/.#learn-german.org b/sami/learn-python-the-hard-way/.#learn-german.org new file mode 120000 index 0000000..f748d3d --- /dev/null +++ b/sami/learn-python-the-hard-way/.#learn-german.org @@ -0,0 +1 @@ +sami@afro-linux-lenovo-b50-30.2711:1593172229 \ No newline at end of file diff --git a/sami/learn-python-the-hard-way/.#quiz2.py b/sami/learn-python-the-hard-way/.#quiz2.py deleted file mode 120000 index d7a8c4f..0000000 --- a/sami/learn-python-the-hard-way/.#quiz2.py +++ /dev/null @@ -1 +0,0 @@ -sami@afro-linux-lenovo-b50-30.18673:1593006374 \ No newline at end of file diff --git a/sami/learn-python-the-hard-way/quiz.py b/sami/learn-python-the-hard-way/quiz.py index de9505e..24f27f4 100644 --- a/sami/learn-python-the-hard-way/quiz.py +++ b/sami/learn-python-the-hard-way/quiz.py @@ -29,13 +29,14 @@ questions = [ Question(question_prompts[9], "a"), ] -def run_quiz(questions): +def quiz(questions): score = 0 for question in questions: answer = input(question.prompt) if answer == question.answer: score += 5 print("Correct! Your score is", score,) + else: print("Incorrect!") @@ -43,11 +44,18 @@ def run_quiz(questions): print("You lost 3 points!") print ("Score: ", score) print ("\n") - + +# Final stage +score = 0 +if score >= -30: + print("Your total score is:", score, "- You suck!") + +elif score == 10 or 15 : + print("Your total score is:", score, "- You went ok!") + +else: + print("Your total score is:", score, "- You are awesome!") - - - -run_quiz(questions) +quiz(questions) From 94f3ecab148c47050e211bd737cf3cc50c78011e Mon Sep 17 00:00:00 2001 From: samuel Date: Mon, 29 Jun 2020 16:57:59 +0200 Subject: [PATCH 2/6] installing django and .org filel + .gitignore file --- sami/django/#django.org# | 28 +++++++++++++++++++ sami/django/.#django.org | 1 + sami/django/.gitignore | 5 ++++ sami/django/env/bin/python | 1 + sami/django/env/bin/python3 | 1 + sami/django/env/lib64 | 1 + sami/django/env/pyvenv.cfg | 3 ++ .../.#learn-german.org | 1 - .../ungleich-learning-circle | 1 + 9 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 sami/django/#django.org# create mode 120000 sami/django/.#django.org create mode 100644 sami/django/.gitignore create mode 120000 sami/django/env/bin/python create mode 120000 sami/django/env/bin/python3 create mode 120000 sami/django/env/lib64 create mode 100644 sami/django/env/pyvenv.cfg delete mode 120000 sami/learn-python-the-hard-way/.#learn-german.org create mode 160000 sami/learn-python-the-hard-way/ungleich-learning-circle diff --git a/sami/django/#django.org# b/sami/django/#django.org# new file mode 100644 index 0000000..271ff85 --- /dev/null +++ b/sami/django/#django.org# @@ -0,0 +1,28 @@ +*** Django #1: Introduction +**** Objective + - We will build a IPv6 ULA registry with Django in the + next lectures +**** Lecture content + - Create a new directory in your learning cirle repository named "django" + - Write down the answers to the following questions in django/django.org + - Research and answer the following questions: (1/2 of the time) + - What is IPv6 ULA? + - addresses that are only ment to be used in privte segment. + - unique Local address they can be easly identified by FD00::/8 + - equivllent to privte address in v4 + - Which registries did exist historically? + - How should an IPv6 ULA registry work? + - Get started with Django + - Create a new python virtual env using `python3 -m venv` + - Create the venv in django/venv + - Create a file .gitignore in django/ + - Add 'venv/' (without the quotes to that file + - Use magit to verify that the venv is being ignored + - Add and commit the .gitignore file + - Inside this virtual env, install django using `pip` + - Go to https://www.djangoproject.com/ + - Finish tutorial 1: https://docs.djangoproject.com/en/3.0/intro/tutorial01/ + - Commit the django code to your repository + - Exclude '*.pyc' in the .gitignore + - Also exclude the sqlite database + diff --git a/sami/django/.#django.org b/sami/django/.#django.org new file mode 120000 index 0000000..d64e808 --- /dev/null +++ b/sami/django/.#django.org @@ -0,0 +1 @@ +sami@afro-linux-lenovo-b50-30.13724:1593172229 \ No newline at end of file diff --git a/sami/django/.gitignore b/sami/django/.gitignore new file mode 100644 index 0000000..7f07ff3 --- /dev/null +++ b/sami/django/.gitignore @@ -0,0 +1,5 @@ +venv + +*.pyc + + diff --git a/sami/django/env/bin/python b/sami/django/env/bin/python new file mode 120000 index 0000000..b8a0adb --- /dev/null +++ b/sami/django/env/bin/python @@ -0,0 +1 @@ +python3 \ No newline at end of file diff --git a/sami/django/env/bin/python3 b/sami/django/env/bin/python3 new file mode 120000 index 0000000..ae65fda --- /dev/null +++ b/sami/django/env/bin/python3 @@ -0,0 +1 @@ +/usr/bin/python3 \ No newline at end of file diff --git a/sami/django/env/lib64 b/sami/django/env/lib64 new file mode 120000 index 0000000..7951405 --- /dev/null +++ b/sami/django/env/lib64 @@ -0,0 +1 @@ +lib \ No newline at end of file diff --git a/sami/django/env/pyvenv.cfg b/sami/django/env/pyvenv.cfg new file mode 100644 index 0000000..bafe8a4 --- /dev/null +++ b/sami/django/env/pyvenv.cfg @@ -0,0 +1,3 @@ +home = /usr/bin +include-system-site-packages = false +version = 3.7.5 diff --git a/sami/learn-python-the-hard-way/.#learn-german.org b/sami/learn-python-the-hard-way/.#learn-german.org deleted file mode 120000 index f748d3d..0000000 --- a/sami/learn-python-the-hard-way/.#learn-german.org +++ /dev/null @@ -1 +0,0 @@ -sami@afro-linux-lenovo-b50-30.2711:1593172229 \ No newline at end of file diff --git a/sami/learn-python-the-hard-way/ungleich-learning-circle b/sami/learn-python-the-hard-way/ungleich-learning-circle new file mode 160000 index 0000000..a0012ef --- /dev/null +++ b/sami/learn-python-the-hard-way/ungleich-learning-circle @@ -0,0 +1 @@ +Subproject commit a0012ef6c4d44c875a3173fc746ab0a9259bc531 From 5c51e6e1e609b0575a09d0f14f4c2b009a2440d9 Mon Sep 17 00:00:00 2001 From: samuel Date: Fri, 3 Jul 2020 16:59:57 +0200 Subject: [PATCH 3/6] django tutorial-1&2 --- sami/django/mysite/db.sqlite3 | Bin 0 -> 143360 bytes sami/django/mysite/manage.py | 21 +++ sami/django/mysite/mysite/__init__.py | 0 sami/django/mysite/mysite/settings.py | 130 ++++++++++++++++++ sami/django/mysite/mysite/urls.py | 22 +++ sami/django/mysite/mysite/wsgi.py | 16 +++ sami/django/mysite/polls/__init__.py | 0 sami/django/mysite/polls/admin.py | 7 + sami/django/mysite/polls/apps.py | 5 + .../mysite/polls/migrations/0001_initial.py | 32 +++++ .../mysite/polls/migrations/__init__.py | 0 sami/django/mysite/polls/models.py | 40 ++++++ sami/django/mysite/polls/tests.py | 3 + sami/django/mysite/polls/urls.py | 7 + sami/django/mysite/polls/views.py | 17 +++ 15 files changed, 300 insertions(+) create mode 100644 sami/django/mysite/db.sqlite3 create mode 100755 sami/django/mysite/manage.py create mode 100644 sami/django/mysite/mysite/__init__.py create mode 100644 sami/django/mysite/mysite/settings.py create mode 100644 sami/django/mysite/mysite/urls.py create mode 100644 sami/django/mysite/mysite/wsgi.py create mode 100644 sami/django/mysite/polls/__init__.py create mode 100644 sami/django/mysite/polls/admin.py create mode 100644 sami/django/mysite/polls/apps.py create mode 100644 sami/django/mysite/polls/migrations/0001_initial.py create mode 100644 sami/django/mysite/polls/migrations/__init__.py create mode 100644 sami/django/mysite/polls/models.py create mode 100644 sami/django/mysite/polls/tests.py create mode 100644 sami/django/mysite/polls/urls.py create mode 100644 sami/django/mysite/polls/views.py diff --git a/sami/django/mysite/db.sqlite3 b/sami/django/mysite/db.sqlite3 new file mode 100644 index 0000000000000000000000000000000000000000..93a0f5aa5bde94e9573c36b62db461ad169ceb24 GIT binary patch literal 143360 zcmeI5TWlNIdB4T&e7+)zVpP$KdR15Rk|>E2Vsb)^ zg`@FH()1-so|L2UWGor$^>Bk@GZn2;(M!d{GDR;*$;p@~C*$&~Jsxi0>Wo^eZjhTq zmD*NTt!m0vxpaS5+0x1d-SF0QTjoKEN{Og^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U;~JjRsF+)wi*Dr0Tcz9at-d>h{TG$2RQTu{CAYPx#fhgEMj> zuBFvPv%y)jSdD*z9Gt%acHN8?osQG&n8E(VA#X?_o5+jKmQuHE?alFYMw`~s&C<>s zAJB;vB| znTW$qQkVrkeDb+ns%n+iqf6vb<}AYDe=-SQ^dVmTL009sH0T2KI5C8!X009sH0T6hc1Tg=9 zoOIzE1V8`;KmY_l00ck)1V8`;KmY`u3<3cvqvy%c0u>+t0w4eaAOHd&00JNY0w4ea zAOHf7hX9@bhr8mO@IB!x!p{q7;gZlD{JY>E2EQ0A2N!~q!M?!12L3AWdx3WX%Yo7E z|Lp#t`**q@cK>YmtKH9c{d?E9x_-CoVb>aQfENgW00@8p2!H?xfB*n8>dW@@)=Sce4L?=^YerI%Dj(Pn;h}cA;ou(d#l_|)wJ7w6JiX3*P zBr_&FKMOYxIqvLK< zs+DePWEMfg!qjG2n4;+A^8sQpIOe8etYoT!zCYJZ(uN~0cK2MlRNJcGo?VS}k@T?% zmwErXg(<+WIbqnC3hFkd1a^JaPi%%RxTuD@0Tsb6F8WC7c&vk|u)meJF2#;|(Mv3+ zk{zZVJAvAoqU^{QI}K}7nVmqbO?h_Y3m#$}iFQzpb}TieLhYFIZV%_b5M^S?_hOTl zR^F{kB@tm3bJ0bt#${8e)6SG>TXrx@Q>4?m2hqA6>I)4#_0S%7P}NrPR8SMd^(EH|9h$`7GgmF z1V8`;KmY_l00ck)1V8`;K;V%G;Q#+W5;kN40T2KI5C8!X009sH0T2KI5CDOviopK? D0QDux literal 0 HcmV?d00001 diff --git a/sami/django/mysite/manage.py b/sami/django/mysite/manage.py new file mode 100755 index 0000000..577e446 --- /dev/null +++ b/sami/django/mysite/manage.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python3 +"""Django's command-line utility for administrative tasks.""" +import os +import sys + + +def main(): + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings') + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + execute_from_command_line(sys.argv) + + +if __name__ == '__main__': + main() diff --git a/sami/django/mysite/mysite/__init__.py b/sami/django/mysite/mysite/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/sami/django/mysite/mysite/settings.py b/sami/django/mysite/mysite/settings.py new file mode 100644 index 0000000..dd259dc --- /dev/null +++ b/sami/django/mysite/mysite/settings.py @@ -0,0 +1,130 @@ +""" +Django settings for mysite project. + +Generated by 'django-admin startproject' using Django 2.2.12. + +For more information on this file, see +https://docs.djangoproject.com/en/2.2/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/2.2/ref/settings/ +""" + +import os + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'p+k-n&d40pt2yi@yyq1(u%+b!b4#yloa%1ct%#jibl41x9z1b@' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', +] + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = 'mysite.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'mysite.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/2.2/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + } +} + + +# Password validation +# https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/2.2/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/2.2/howto/static-files/ + +STATIC_URL = '/static/' + +INSTALLED_APPS = [ + 'polls.apps.PollsConfig', + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', +] diff --git a/sami/django/mysite/mysite/urls.py b/sami/django/mysite/mysite/urls.py new file mode 100644 index 0000000..cba3a35 --- /dev/null +++ b/sami/django/mysite/mysite/urls.py @@ -0,0 +1,22 @@ +"""mysite URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/2.2/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: path('', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.urls import include, path + 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) +""" +from django.contrib import admin +from django.urls import include, path + +urlpatterns = [ + path('polls/', include('polls.urls')), + path('admin/', admin.site.urls), +] diff --git a/sami/django/mysite/mysite/wsgi.py b/sami/django/mysite/mysite/wsgi.py new file mode 100644 index 0000000..45e28c9 --- /dev/null +++ b/sami/django/mysite/mysite/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for mysite project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/2.2/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings') + +application = get_wsgi_application() diff --git a/sami/django/mysite/polls/__init__.py b/sami/django/mysite/polls/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/sami/django/mysite/polls/admin.py b/sami/django/mysite/polls/admin.py new file mode 100644 index 0000000..3f3d36e --- /dev/null +++ b/sami/django/mysite/polls/admin.py @@ -0,0 +1,7 @@ +# Register your models here. + +from django.contrib import admin + +from .models import Question + +admin.site.register(Question) diff --git a/sami/django/mysite/polls/apps.py b/sami/django/mysite/polls/apps.py new file mode 100644 index 0000000..d0f109e --- /dev/null +++ b/sami/django/mysite/polls/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class PollsConfig(AppConfig): + name = 'polls' diff --git a/sami/django/mysite/polls/migrations/0001_initial.py b/sami/django/mysite/polls/migrations/0001_initial.py new file mode 100644 index 0000000..88946ea --- /dev/null +++ b/sami/django/mysite/polls/migrations/0001_initial.py @@ -0,0 +1,32 @@ +# Generated by Django 2.2.12 on 2020-07-03 14:26 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Question', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('question_text', models.CharField(max_length=200)), + ('pub_date', models.DateTimeField(verbose_name='date published')), + ], + ), + migrations.CreateModel( + name='Choice', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('choice_text', models.CharField(max_length=200)), + ('votes', models.IntegerField(default=0)), + ('question', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='polls.Question')), + ], + ), + ] diff --git a/sami/django/mysite/polls/migrations/__init__.py b/sami/django/mysite/polls/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/sami/django/mysite/polls/models.py b/sami/django/mysite/polls/models.py new file mode 100644 index 0000000..0570fbb --- /dev/null +++ b/sami/django/mysite/polls/models.py @@ -0,0 +1,40 @@ +from django.db import models + +# Create your models here. + +class Question(models.Model): + question_text = models.CharField(max_length=200) + pub_date = models.DateTimeField('date published') + + +class Choice(models.Model): + question = models.ForeignKey(Question, on_delete=models.CASCADE) + choice_text = models.CharField(max_length=200) + + votes = models.IntegerField(default=0) + + +from django.db import models + +class Question(models.Model): + # ... + def __str__(self): + return self.question_text + +class Choice(models.Model): + # ... + def __str__(self): + return self.choice_text + + + +import datetime + +from django.db import models +from django.utils import timezone + + +class Question(models.Model): + # ... + def was_published_recently(self): + return self.pub_date >= timezone.now() - datetime.timedelta(days=1) diff --git a/sami/django/mysite/polls/tests.py b/sami/django/mysite/polls/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/sami/django/mysite/polls/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/sami/django/mysite/polls/urls.py b/sami/django/mysite/polls/urls.py new file mode 100644 index 0000000..88a9cac --- /dev/null +++ b/sami/django/mysite/polls/urls.py @@ -0,0 +1,7 @@ +from django.urls import path + +from . import views + +urlpatterns = [ + path('', views.index, name='index'), +] diff --git a/sami/django/mysite/polls/views.py b/sami/django/mysite/polls/views.py new file mode 100644 index 0000000..8531097 --- /dev/null +++ b/sami/django/mysite/polls/views.py @@ -0,0 +1,17 @@ +# from django.shortcuts import render + +# Create your views here. + +#from django.urls import path + +#from . import views + +#urlpatterns = [ + # path('', views.index, name='index'), +#] + +from django.http import HttpResponse + + +def index(request): + return HttpResponse("Hello, world. You're at the polls index.") From 8216cadd15c6a2484e77e9d833c810dd34c8583f Mon Sep 17 00:00:00 2001 From: samuel Date: Fri, 10 Jul 2020 15:02:03 +0200 Subject: [PATCH 4/6] new-project created and polls --- sami/django/mysite2/db.sqlite3 | 0 sami/django/mysite2/manage.py | 21 +++ sami/django/mysite2/mysite2/__init__.py | 0 sami/django/mysite2/mysite2/settings.py | 120 ++++++++++++++++++ sami/django/mysite2/mysite2/urls.py | 21 +++ sami/django/mysite2/mysite2/wsgi.py | 16 +++ sami/django/mysite2/polls/__init__.py | 0 sami/django/mysite2/polls/admin.py | 3 + sami/django/mysite2/polls/apps.py | 5 + .../mysite2/polls/migrations/__init__.py | 0 sami/django/mysite2/polls/models.py | 3 + sami/django/mysite2/polls/tests.py | 3 + sami/django/mysite2/polls/views.py | 3 + 13 files changed, 195 insertions(+) create mode 100644 sami/django/mysite2/db.sqlite3 create mode 100755 sami/django/mysite2/manage.py create mode 100644 sami/django/mysite2/mysite2/__init__.py create mode 100644 sami/django/mysite2/mysite2/settings.py create mode 100644 sami/django/mysite2/mysite2/urls.py create mode 100644 sami/django/mysite2/mysite2/wsgi.py create mode 100644 sami/django/mysite2/polls/__init__.py create mode 100644 sami/django/mysite2/polls/admin.py create mode 100644 sami/django/mysite2/polls/apps.py create mode 100644 sami/django/mysite2/polls/migrations/__init__.py create mode 100644 sami/django/mysite2/polls/models.py create mode 100644 sami/django/mysite2/polls/tests.py create mode 100644 sami/django/mysite2/polls/views.py diff --git a/sami/django/mysite2/db.sqlite3 b/sami/django/mysite2/db.sqlite3 new file mode 100644 index 0000000..e69de29 diff --git a/sami/django/mysite2/manage.py b/sami/django/mysite2/manage.py new file mode 100755 index 0000000..f7bf114 --- /dev/null +++ b/sami/django/mysite2/manage.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python3 +"""Django's command-line utility for administrative tasks.""" +import os +import sys + + +def main(): + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite2.settings') + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + execute_from_command_line(sys.argv) + + +if __name__ == '__main__': + main() diff --git a/sami/django/mysite2/mysite2/__init__.py b/sami/django/mysite2/mysite2/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/sami/django/mysite2/mysite2/settings.py b/sami/django/mysite2/mysite2/settings.py new file mode 100644 index 0000000..9db30f1 --- /dev/null +++ b/sami/django/mysite2/mysite2/settings.py @@ -0,0 +1,120 @@ +""" +Django settings for mysite2 project. + +Generated by 'django-admin startproject' using Django 2.2.12. + +For more information on this file, see +https://docs.djangoproject.com/en/2.2/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/2.2/ref/settings/ +""" + +import os + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'sb1cbc!m_esjnb381eh8!+(1$zi-%$h@ewu#3=cog+ls)d%)3z' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', +] + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = 'mysite2.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'mysite2.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/2.2/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + } +} + + +# Password validation +# https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/2.2/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/2.2/howto/static-files/ + +STATIC_URL = '/static/' diff --git a/sami/django/mysite2/mysite2/urls.py b/sami/django/mysite2/mysite2/urls.py new file mode 100644 index 0000000..7ab8fd1 --- /dev/null +++ b/sami/django/mysite2/mysite2/urls.py @@ -0,0 +1,21 @@ +"""mysite2 URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/2.2/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: path('', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.urls import include, path + 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) +""" +from django.contrib import admin +from django.urls import path + +urlpatterns = [ + path('admin/', admin.site.urls), +] diff --git a/sami/django/mysite2/mysite2/wsgi.py b/sami/django/mysite2/mysite2/wsgi.py new file mode 100644 index 0000000..916825e --- /dev/null +++ b/sami/django/mysite2/mysite2/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for mysite2 project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/2.2/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite2.settings') + +application = get_wsgi_application() diff --git a/sami/django/mysite2/polls/__init__.py b/sami/django/mysite2/polls/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/sami/django/mysite2/polls/admin.py b/sami/django/mysite2/polls/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/sami/django/mysite2/polls/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/sami/django/mysite2/polls/apps.py b/sami/django/mysite2/polls/apps.py new file mode 100644 index 0000000..d0f109e --- /dev/null +++ b/sami/django/mysite2/polls/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class PollsConfig(AppConfig): + name = 'polls' diff --git a/sami/django/mysite2/polls/migrations/__init__.py b/sami/django/mysite2/polls/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/sami/django/mysite2/polls/models.py b/sami/django/mysite2/polls/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/sami/django/mysite2/polls/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/sami/django/mysite2/polls/tests.py b/sami/django/mysite2/polls/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/sami/django/mysite2/polls/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/sami/django/mysite2/polls/views.py b/sami/django/mysite2/polls/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/sami/django/mysite2/polls/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. From 3c1672b7530eb04ce099661541c5c2099c563f93 Mon Sep 17 00:00:00 2001 From: samuel Date: Mon, 13 Jul 2020 17:12:39 +0200 Subject: [PATCH 5/6] step4 --- sami/django/mysite2/db.sqlite3 | Bin 0 -> 143360 bytes sami/django/mysite2/mysite2/settings.py | 7 ++- sami/django/mysite2/mysite2/urls.py | 4 +- sami/django/mysite2/polls/.#models.py | 1 + .../mysite2/polls/migrations/0001_initial.py | 32 +++++++++++ sami/django/mysite2/polls/models.py | 24 ++++++++ .../mysite2/polls/templates/polls/detail.html | 1 + .../mysite2/polls/templates/polls/index.html | 22 ++++++++ .../polls/templates/polls/results.html | 9 +++ sami/django/mysite2/polls/urls.py | 13 +++++ sami/django/mysite2/polls/views.py | 52 +++++++++++++++++- 11 files changed, 160 insertions(+), 5 deletions(-) create mode 120000 sami/django/mysite2/polls/.#models.py create mode 100644 sami/django/mysite2/polls/migrations/0001_initial.py create mode 100644 sami/django/mysite2/polls/templates/polls/detail.html create mode 100644 sami/django/mysite2/polls/templates/polls/index.html create mode 100644 sami/django/mysite2/polls/templates/polls/results.html create mode 100644 sami/django/mysite2/polls/urls.py diff --git a/sami/django/mysite2/db.sqlite3 b/sami/django/mysite2/db.sqlite3 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..95016afdcda3372d141ae70285e53f77a5419a45 100644 GIT binary patch literal 143360 zcmeI5du$uYeaCnC5JgMmO0s3%ogboP>uf@2X}QbgLznBF&eqBDSyUv;4=FjYOL8Ty z%!f=;mgQ>-(D5Zj()N!A4bTAX6$Og6X#Z%_0#_itKbo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K#&_ zrLNUFZ(Sm9WzH(>|B=B^YT27_QV;mFfc^jXbOgXT2!H?xfB*=900@8p2!H?xfB*Um@y6_DGAOHd&00JNY0w4ea zAOHd&00NH(0XqM83-55k4}|ZMKX`!v2!H?xfB*=900@8p2!H?xfB*=*{|R{AJnwO{ z(B*OSevdK#{|+boQ24&^o%eqQQ3DVF0T2KI5C8!X009sH0T2KI5C8!}fX@A0Zjakf zLbu-^AW81vKXAey3onpAc!2;2fB*=900@8p2!H?xfB*=9!26NFhuwZ|Mi{Q}JTHlo zcuq{5i;CfBd|HlA$CSxbJeHE9Qd!ScKJ@xnuAr7T$itnc!>^NPOlie@jU0Z+@mMGF zbNt4GrC$5UM_%)|T#X*rA?m(yp7*!;my*-b|BlC5krUVtk!qfe95f$T zWga)5qGc#a@~oN@yx-qiO(`)Ql_sN7G?t26GSqzDs3fffo&SgXVw~`G;j_X|30YxU z=nwvV@b`kB4pxKd;AC(p@E?J{3jB89jlfFaRR8z-zuf;@{rCHSy#E9JLw*0!_xZkG z>HCSkYs3LwAOHd&00JNY0w4eaAn=3|2#38Ke`=!lwyy1DjK_POSIc1<4I9zZBgEp& zR4;irrbZqbYugwJmeona%9wXJtc(QH>f{MxH5%z9AKM)!BxZRz&b;`T8tds_O+8k^ z*<-|NLiU-8tYm6uYO<2fK4Vy#s;p#cY3j0)#-1jYT(!SS!Q(N2(dVq@ER>x zDc7}fy}rApHI<(nFrMbNM?wOJOXC>nhxKrBv-d#D&I zo2sD4C;Lg>XvEFVzEQ1gZ#7TPVq<+IfBc-=Jb%-|6kymKGHgr*O&e1Jiy!wBn~^ha zs-bB>MX<=(UXnW@yO;|5sk}`ocG7b`VmXy?nR@IDYHNzJ6QAobtW9Nh2DLWj*@@43 ziFG9Eq8jZ~YD$ILDW^SN&VMG##FFP?lb%-HZAv8xVU}{%O{^vqQ>fF= timezone.now() -datetime.timedelta(days=1) + +class Choice(models.Model): + question = models.ForeignKey(Question, on_delete=models.CASCADE) + choice_text = models.CharField(max_length=200) + votes = models.IntegerField(default=0) + + def __str__(self): + return self.choice_text + + diff --git a/sami/django/mysite2/polls/templates/polls/detail.html b/sami/django/mysite2/polls/templates/polls/detail.html new file mode 100644 index 0000000..6667640 --- /dev/null +++ b/sami/django/mysite2/polls/templates/polls/detail.html @@ -0,0 +1 @@ +{{ question }} diff --git a/sami/django/mysite2/polls/templates/polls/index.html b/sami/django/mysite2/polls/templates/polls/index.html new file mode 100644 index 0000000..71c2249 --- /dev/null +++ b/sami/django/mysite2/polls/templates/polls/index.html @@ -0,0 +1,22 @@ +{% if latest_question_list %} + +{% else %} +

No polls are available.

+{% endif %} + +

{{ question.question_text }}

+ +{% if error_message %}

{{ error_message }}

{% endif %} + +
+{% csrf_token %} +{% for choice in question.choice_set.all %} + +
+{% endfor %} + +
diff --git a/sami/django/mysite2/polls/templates/polls/results.html b/sami/django/mysite2/polls/templates/polls/results.html new file mode 100644 index 0000000..3b2c74f --- /dev/null +++ b/sami/django/mysite2/polls/templates/polls/results.html @@ -0,0 +1,9 @@ +

{{ question.question_text }}

+ +
    +{% for choice in question.choice_set.all %} +
  • {{ choice.choice_text }} -- {{ choice.votes }} vote{{ choice.votes|pluralize }}
  • +{% endfor %} +
+ +Vote again? diff --git a/sami/django/mysite2/polls/urls.py b/sami/django/mysite2/polls/urls.py new file mode 100644 index 0000000..0b66ce8 --- /dev/null +++ b/sami/django/mysite2/polls/urls.py @@ -0,0 +1,13 @@ +from django.urls import path +# Here is importing the views which I modified +from . import views +app_name = 'polls' +urlpatterns = [ + path('', views.index, name='index'), + # ex: /polls/5/ + path('/', views.detail, name='detail'), + # ex: /polls/5/results/ + path('/results/', views.results, name='results'), + # ex: /polls/5/vote/ + path('/vote/', views.vote, name='vote'), +] diff --git a/sami/django/mysite2/polls/views.py b/sami/django/mysite2/polls/views.py index 91ea44a..b018678 100644 --- a/sami/django/mysite2/polls/views.py +++ b/sami/django/mysite2/polls/views.py @@ -1,3 +1,53 @@ +# Here is the fist view add by Sami from Diesbach from django.shortcuts import render +from django.http import HttpResponse +from django.shortcuts import Http404 +from .models import Choice, Question +from django.template import loader +from django.shortcuts import get_object_or_404, render +from django.http import HttpResponse, HttpResponseRedirect +from django.urls import reverse +from django.views import generic + + + +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/detail.html' + + +class ResultsView(generic.DetailView): + model = Question + template_name = 'polls/results.html' + + + + +def vote(request, question_id): + question = get_object_or_404(Question, pk=question_id) + try: + selected_choice = question.choice_set.get(pk=request.POST['choice']) + except (KeyError, Choice.DoesNotExist): + # Redisplay the question voting form. + return render(request, 'polls/detail.html', { + 'question': question, + '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=(question.id,))) + -# Create your views here. From a5f071afadfbb261c1453a3eaebbb2605e9a9ba6 Mon Sep 17 00:00:00 2001 From: samuel Date: Wed, 15 Jul 2020 16:36:19 +0200 Subject: [PATCH 6/6] sweets22 --- sami/django/mysite2/polls/.#models.py | 1 - sami/django/mysite2/polls/models.py | 15 +- .../mysite2/polls/templates/detail.html | 13 ++ .../mysite2/polls/templates/polls/detail.html | 13 +- .../mysite2/polls/templates/polls/index.html | 15 +- sami/django/mysite2/polls/tests.py | 129 +++++++++++++++++- sami/django/mysite2/polls/urls.py | 12 +- sami/django/mysite2/polls/views.py | 47 +++++-- 8 files changed, 200 insertions(+), 45 deletions(-) delete mode 120000 sami/django/mysite2/polls/.#models.py create mode 100644 sami/django/mysite2/polls/templates/detail.html diff --git a/sami/django/mysite2/polls/.#models.py b/sami/django/mysite2/polls/.#models.py deleted file mode 120000 index 3884ade..0000000 --- a/sami/django/mysite2/polls/.#models.py +++ /dev/null @@ -1 +0,0 @@ -sami@afro-linux-lenovo-b50-30.8898:1594292241 \ No newline at end of file diff --git a/sami/django/mysite2/polls/models.py b/sami/django/mysite2/polls/models.py index 1914ee2..a7c5580 100644 --- a/sami/django/mysite2/polls/models.py +++ b/sami/django/mysite2/polls/models.py @@ -1,7 +1,7 @@ -from django.utils import timezone -from django.db import models import datetime +from django.db import models +from django.utils import timezone # Create your models here. @@ -9,19 +9,20 @@ import datetime 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): - return self.pub_date >= timezone.now() -datetime.timedelta(days=1) + now = timezone.now() + return now - datetime.timedelta(days=1) <= self.pub_date <= now + #def was_published_recently(self): + #return self.pub_date >= timezone.now() - datetime.timedelta(days=1) + + class Choice(models.Model): question = models.ForeignKey(Question, on_delete=models.CASCADE) choice_text = models.CharField(max_length=200) votes = models.IntegerField(default=0) - def __str__(self): return self.choice_text - - diff --git a/sami/django/mysite2/polls/templates/detail.html b/sami/django/mysite2/polls/templates/detail.html new file mode 100644 index 0000000..c225d49 --- /dev/null +++ b/sami/django/mysite2/polls/templates/detail.html @@ -0,0 +1,13 @@ +

{{ question.question_text }}

+ +{% if error_message %}

{{ error_message }}

{% endif %} + +
+{% csrf_token %} +{% for choice in question.choice_set.all %} + +
+{% endfor %} + +
+p diff --git a/sami/django/mysite2/polls/templates/polls/detail.html b/sami/django/mysite2/polls/templates/polls/detail.html index 6667640..3e55544 100644 --- a/sami/django/mysite2/polls/templates/polls/detail.html +++ b/sami/django/mysite2/polls/templates/polls/detail.html @@ -1 +1,12 @@ -{{ question }} +

{{ question.question_text }}

+ +{% if error_message %}

{{ error_message }}

{% endif %} + +
+{% csrf_token %} +{% for choice in question.choice_set.all %} + +
+{% endfor %} + +
diff --git a/sami/django/mysite2/polls/templates/polls/index.html b/sami/django/mysite2/polls/templates/polls/index.html index 71c2249..4560139 100644 --- a/sami/django/mysite2/polls/templates/polls/index.html +++ b/sami/django/mysite2/polls/templates/polls/index.html @@ -1,22 +1,9 @@ {% if latest_question_list %} {% else %}

No polls are available.

{% endif %} - -

{{ question.question_text }}

- -{% if error_message %}

{{ error_message }}

{% endif %} - -
-{% csrf_token %} -{% for choice in question.choice_set.all %} - -
-{% endfor %} - -
diff --git a/sami/django/mysite2/polls/tests.py b/sami/django/mysite2/polls/tests.py index 7ce503c..3604a06 100644 --- a/sami/django/mysite2/polls/tests.py +++ b/sami/django/mysite2/polls/tests.py @@ -1,3 +1,128 @@ -from django.test import TestCase +import datetime -# Create your tests here. +from django.test import TestCase +from django.utils import timezone +from django.urls import reverse + +from .models import Question + + +class QuestionModelTests(TestCase): + + def test_was_published_recently_with_future_question(self): + """ + was_published_recently() returns False for questions whose pub_date + is in the future. + """ + time = timezone.now() + datetime.timedelta(days=30) + future_question = Question(pub_date=time) + self.assertIs(future_question.was_published_recently(), False) + + def test_was_published_recently_with_old_question(self): + """ + was_published_recently() returns False for questions whose pub_date + is older than 1 day. + """ + time = timezone.now() - datetime.timedelta(days=1, seconds=1) + old_question = Question(pub_date=time) + self.assertIs(old_question.was_published_recently(), False) + + def test_was_published_recently_with_recent_question(self): + """ + was_published_recently() returns True for questions whose pub_date + is within the last day. + """ + time = timezone.now() - datetime.timedelta(hours=23, minutes=59, seconds=59) + recent_question = Question(pub_date=time) + self.assertIs(recent_question.was_published_recently(), True) + + + +def create_question(question_text, days): + """ + Create a question with the given `question_text` and published the + given number of `days` offset to now (negative for questions published + in the past, positive for questions that have yet to be published). + """ + time = timezone.now() + datetime.timedelta(days=days) + return Question.objects.create(question_text=question_text, pub_date=time) + + +class QuestionIndexViewTests(TestCase): + def test_no_questions(self): + """ + If no questions exist, an appropriate message is displayed. + """ + response = self.client.get(reverse('polls:index')) + self.assertEqual(response.status_code, 200) + self.assertContains(response, "No polls are available.") + self.assertQuerysetEqual(response.context['latest_question_list'], []) + + def test_past_question(self): + """ + Questions with a pub_date in the past are displayed on the + index page. + """ + create_question(question_text="Past question.", days=-30) + response = self.client.get(reverse('polls:index')) + self.assertQuerysetEqual( + response.context['latest_question_list'], + [''] + ) + + def test_future_question(self): + """ + Questions with a pub_date in the future aren't displayed on + the index page. + """ + create_question(question_text="Future question.", days=30) + response = self.client.get(reverse('polls:index')) + self.assertContains(response, "No polls are available.") + self.assertQuerysetEqual(response.context['latest_question_list'], []) + + def test_future_question_and_past_question(self): + """ + Even if both past and future questions exist, only past questions + are displayed. + """ + create_question(question_text="Past question.", days=-30) + create_question(question_text="Future question.", days=30) + response = self.client.get(reverse('polls:index')) + self.assertQuerysetEqual( + response.context['latest_question_list'], + [''] + ) + + def test_two_past_questions(self): + """ + The questions index page may display multiple questions. + """ + create_question(question_text="Past question 1.", days=-30) + create_question(question_text="Past question 2.", days=-5) + response = self.client.get(reverse('polls:index')) + self.assertQuerysetEqual( + response.context['latest_question_list'], + ['', ''] + ) + + +class QuestionDetailViewTests(TestCase): + def test_future_question(self): + """ + The detail view of a question with a pub_date in the future + returns a 404 not found. + """ + future_question = create_question(question_text='Future question.', days=5) + url = reverse('polls:detail', args=(future_question.id,)) + response = self.client.get(url) + self.assertEqual(response.status_code, 404) + + def test_past_question(self): + """ + The detail view of a question with a pub_date in the past + displays the question's text. + """ + past_question = create_question(question_text='Past Question.', days=-5) + url = reverse('polls:detail', args=(past_question.id,)) + response = self.client.get(url) + self.assertContains(response, past_question.question_text) diff --git a/sami/django/mysite2/polls/urls.py b/sami/django/mysite2/polls/urls.py index 0b66ce8..eff2be0 100644 --- a/sami/django/mysite2/polls/urls.py +++ b/sami/django/mysite2/polls/urls.py @@ -1,13 +1,11 @@ from django.urls import path -# Here is importing the views which I modified + from . import views + app_name = 'polls' urlpatterns = [ - path('', views.index, name='index'), - # ex: /polls/5/ - path('/', views.detail, name='detail'), - # ex: /polls/5/results/ - path('/results/', views.results, name='results'), - # ex: /polls/5/vote/ + path('', views.IndexView.as_view(), name='index'), + path('/', views.DetailView.as_view(), name='detail'), + path('/results/', views.ResultsView.as_view(), name='results'), path('/vote/', views.vote, name='vote'), ] diff --git a/sami/django/mysite2/polls/views.py b/sami/django/mysite2/polls/views.py index b018678..68cf7b5 100644 --- a/sami/django/mysite2/polls/views.py +++ b/sami/django/mysite2/polls/views.py @@ -1,38 +1,61 @@ -# Here is the fist view add by Sami from Diesbach -from django.shortcuts import render -from django.http import HttpResponse -from django.shortcuts import Http404 -from .models import Choice, Question +from django.http import HttpResponse, HttpResponseRedirect +#from django.http import Http404 from django.template import loader from django.shortcuts import get_object_or_404, render -from django.http import HttpResponse, HttpResponseRedirect from django.urls import reverse from django.views import generic +from django.utils import timezone + +from .models import Choice, Question - +#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) 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] + """ + Return the last 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] + #"""Return the last five published questions.""" + #return Question.objects.order_by('-pub_date')[:5] +#def detail(request, question_id): +# #return HttpResponse("You're looking at question %s." % question_id) +# question = get_object_or_404(Question, pk=question_id) +# return render(request, 'polls/detail.html', {'question': question}) class DetailView(generic.DetailView): model = Question template_name = 'polls/detail.html' + + def get_queryset(self): + """ + Excludes any questions that aren't published yet. + """ + return Question.objects.filter(pub_date__lte=timezone.now()) +#def results(request, question_id): +# #response = "You're looking at the results of question %s." +# #return HttpResponse(response % question_id) +# question = get_object_or_404(Question, pk=question_id) +# return render(request, 'polls/results.html', {'question': question}) class ResultsView(generic.DetailView): model = Question template_name = 'polls/results.html' - - def vote(request, question_id): + #return HttpResponse("You're voting on question %s." % question_id) question = get_object_or_404(Question, pk=question_id) try: selected_choice = question.choice_set.get(pk=request.POST['choice']) @@ -49,5 +72,3 @@ def vote(request, question_id): # with POST data. This prevents data from being posted twice if a # user hits the Back button. return HttpResponseRedirect(reverse('polls:results', args=(question.id,))) - -