From 6c43c8b36071a7e544b9fd3ee8f31aad90e22f52 Mon Sep 17 00:00:00 2001 From: binaryDiv Date: Wed, 20 Mar 2019 22:14:36 +0100 Subject: [PATCH 01/13] Initial project and app commit --- issues/__init__.py | 0 issues/admin.py | 3 + issues/apps.py | 5 ++ issues/migrations/__init__.py | 0 issues/models.py | 3 + issues/tests.py | 3 + issues/views.py | 3 + manage.py | 15 +++++ tofu/__init__.py | 0 tofu/settings.py | 120 ++++++++++++++++++++++++++++++++++ tofu/urls.py | 21 ++++++ tofu/wsgi.py | 16 +++++ 12 files changed, 189 insertions(+) create mode 100644 issues/__init__.py create mode 100644 issues/admin.py create mode 100644 issues/apps.py create mode 100644 issues/migrations/__init__.py create mode 100644 issues/models.py create mode 100644 issues/tests.py create mode 100644 issues/views.py create mode 100755 manage.py create mode 100644 tofu/__init__.py create mode 100644 tofu/settings.py create mode 100644 tofu/urls.py create mode 100644 tofu/wsgi.py diff --git a/issues/__init__.py b/issues/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/issues/admin.py b/issues/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/issues/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/issues/apps.py b/issues/apps.py new file mode 100644 index 0000000..73a36a0 --- /dev/null +++ b/issues/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class IssuesConfig(AppConfig): + name = 'issues' diff --git a/issues/migrations/__init__.py b/issues/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/issues/models.py b/issues/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/issues/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/issues/tests.py b/issues/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/issues/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/issues/views.py b/issues/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/issues/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. diff --git a/manage.py b/manage.py new file mode 100755 index 0000000..2700ab5 --- /dev/null +++ b/manage.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python +import os +import sys + +if __name__ == '__main__': + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'tofu.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) diff --git a/tofu/__init__.py b/tofu/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tofu/settings.py b/tofu/settings.py new file mode 100644 index 0000000..fddf93d --- /dev/null +++ b/tofu/settings.py @@ -0,0 +1,120 @@ +""" +Django settings for tofu project. + +Generated by 'django-admin startproject' using Django 2.1.7. + +For more information on this file, see +https://docs.djangoproject.com/en/2.1/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/2.1/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.1/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'p53=*^ls87h6@*b^-d&t!0suv4r5slw=o(%ji!v+ap_%_!lmm2' + +# 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 = 'tofu.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 = 'tofu.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/2.1/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.1/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.1/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.1/howto/static-files/ + +STATIC_URL = '/static/' diff --git a/tofu/urls.py b/tofu/urls.py new file mode 100644 index 0000000..c6a89d2 --- /dev/null +++ b/tofu/urls.py @@ -0,0 +1,21 @@ +"""tofu URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/2.1/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/tofu/wsgi.py b/tofu/wsgi.py new file mode 100644 index 0000000..9c30b16 --- /dev/null +++ b/tofu/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for tofu 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.1/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'tofu.settings') + +application = get_wsgi_application() From 9d77a7d232e8d2712ecc9290b5746d4623fac39e Mon Sep 17 00:00:00 2001 From: binaryDiv Date: Wed, 20 Mar 2019 23:35:33 +0100 Subject: [PATCH 02/13] add index view; add Project and Issue models --- issues/admin.py | 5 +++- issues/migrations/0001_initial.py | 39 +++++++++++++++++++++++++++++++ issues/models.py | 20 +++++++++++++++- issues/urls.py | 7 ++++++ issues/views.py | 7 ++++-- tofu/settings.py | 3 ++- tofu/urls.py | 3 ++- 7 files changed, 78 insertions(+), 6 deletions(-) create mode 100644 issues/migrations/0001_initial.py create mode 100644 issues/urls.py diff --git a/issues/admin.py b/issues/admin.py index 8c38f3f..034f76d 100644 --- a/issues/admin.py +++ b/issues/admin.py @@ -1,3 +1,6 @@ from django.contrib import admin -# Register your models here. +from .models import Project, Issue + +admin.site.register(Project) +admin.site.register(Issue) diff --git a/issues/migrations/0001_initial.py b/issues/migrations/0001_initial.py new file mode 100644 index 0000000..e9e18f9 --- /dev/null +++ b/issues/migrations/0001_initial.py @@ -0,0 +1,39 @@ +# Generated by Django 2.1.7 on 2019-03-20 22:34 + +from django.db import migrations, models +import django.db.models.deletion +import django.utils.timezone + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Issue', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('title', models.CharField(max_length=200)), + ('text', models.TextField(blank=True)), + ('create_date', models.DateTimeField(default=django.utils.timezone.now)), + ], + ), + migrations.CreateModel( + name='Project', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('project_key', models.CharField(max_length=16, unique=True)), + ('name', models.CharField(max_length=200)), + ('description', models.TextField(blank=True)), + ], + ), + migrations.AddField( + model_name='issue', + name='project', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='issues.Project'), + ), + ] diff --git a/issues/models.py b/issues/models.py index 71a8362..cc04388 100644 --- a/issues/models.py +++ b/issues/models.py @@ -1,3 +1,21 @@ from django.db import models +from django.utils import timezone -# Create your models here. + +class Project(models.Model): + project_key = models.CharField(max_length=16, unique=True) + name = models.CharField(max_length=200) + description = models.TextField(blank=True) + + def __str__(self): + return self.name + + +class Issue(models.Model): + project = models.ForeignKey(Project, on_delete=models.CASCADE) + title = models.CharField(max_length=200) + text = models.TextField(blank=True) + create_date = models.DateTimeField(default=timezone.now) + + def __str__(self): + return self.title diff --git a/issues/urls.py b/issues/urls.py new file mode 100644 index 0000000..2fcca0d --- /dev/null +++ b/issues/urls.py @@ -0,0 +1,7 @@ +from django.urls import path + +from . import views + +urlpatterns = [ + path('', views.index, name='index') +] diff --git a/issues/views.py b/issues/views.py index 91ea44a..3879a9b 100644 --- a/issues/views.py +++ b/issues/views.py @@ -1,3 +1,6 @@ -from django.shortcuts import render +# from django.shortcuts import render +from django.http import HttpResponse -# Create your views here. + +def index(request): + return HttpResponse('Hello Tofu.') diff --git a/tofu/settings.py b/tofu/settings.py index fddf93d..a6d2ece 100644 --- a/tofu/settings.py +++ b/tofu/settings.py @@ -31,6 +31,7 @@ ALLOWED_HOSTS = [] # Application definition INSTALLED_APPS = [ + 'issues.apps.IssuesConfig', 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', @@ -105,7 +106,7 @@ AUTH_PASSWORD_VALIDATORS = [ LANGUAGE_CODE = 'en-us' -TIME_ZONE = 'UTC' +TIME_ZONE = 'Europe/Berlin' USE_I18N = True diff --git a/tofu/urls.py b/tofu/urls.py index c6a89d2..30e127a 100644 --- a/tofu/urls.py +++ b/tofu/urls.py @@ -14,8 +14,9 @@ Including another URLconf 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ from django.contrib import admin -from django.urls import path +from django.urls import include, path urlpatterns = [ + path('issues/', include('issues.urls')), path('admin/', admin.site.urls), ] From 43c127d7441424b72d4cfe06c98942b3c4645d43 Mon Sep 17 00:00:00 2001 From: binaryDiv Date: Mon, 27 May 2019 15:15:06 +0200 Subject: [PATCH 03/13] ignore PyCharm project files --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 058ad98..7213d8e 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,6 @@ dist/ # Installer logs pip-log.txt pip-delete-this-directory.txt + +# IDE stuff +.idea/ From a14ab339272a3f5388107a844b6efe0983190da4 Mon Sep 17 00:00:00 2001 From: binaryDiv Date: Mon, 27 May 2019 15:18:57 +0200 Subject: [PATCH 04/13] implement issues index and detail view, using templates --- issues/templates/issues/detail.html | 6 ++++++ issues/templates/issues/index.html | 11 +++++++++++ issues/urls.py | 4 +++- issues/views.py | 17 ++++++++++++++--- 4 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 issues/templates/issues/detail.html create mode 100644 issues/templates/issues/index.html diff --git a/issues/templates/issues/detail.html b/issues/templates/issues/detail.html new file mode 100644 index 0000000..42ea47c --- /dev/null +++ b/issues/templates/issues/detail.html @@ -0,0 +1,6 @@ +

#{{ issue.id }}: {{ issue.title }}

+

+ Project: {{ issue.project }}
+ Created: {{ issue.create_date }} +

+

{{ issue.text }}

\ No newline at end of file diff --git a/issues/templates/issues/index.html b/issues/templates/issues/index.html new file mode 100644 index 0000000..bcf3760 --- /dev/null +++ b/issues/templates/issues/index.html @@ -0,0 +1,11 @@ +{% if issue_list %} + +{% else %} +

No issues.

+{% endif %} \ No newline at end of file diff --git a/issues/urls.py b/issues/urls.py index 2fcca0d..93ae9ac 100644 --- a/issues/urls.py +++ b/issues/urls.py @@ -2,6 +2,8 @@ from django.urls import path from . import views +app_name = 'issues' urlpatterns = [ - path('', views.index, name='index') + path('', views.index, name='index'), + path('/', views.detail, name='detail'), ] diff --git a/issues/views.py b/issues/views.py index 3879a9b..b6d463a 100644 --- a/issues/views.py +++ b/issues/views.py @@ -1,6 +1,17 @@ -# from django.shortcuts import render -from django.http import HttpResponse +from django.shortcuts import get_object_or_404, render + +from .models import Issue def index(request): - return HttpResponse('Hello Tofu.') + issue_list = Issue.objects.order_by('create_date') + return render(request, 'issues/index.html', { + 'issue_list': issue_list, + }) + + +def detail(request, issue_id): + issue = get_object_or_404(Issue, pk=issue_id) + return render(request, 'issues/detail.html', { + 'issue': issue, + }) From 0013410ac1e5b1d3a213fe317beaaf7480871d4a Mon Sep 17 00:00:00 2001 From: binaryDiv Date: Mon, 27 May 2019 15:22:49 +0200 Subject: [PATCH 05/13] create projects app; move Project model to projects app; recreate migrations because moving the model caused problems o.o --- issues/admin.py | 3 +-- issues/migrations/0001_initial.py | 18 +++--------------- issues/models.py | 9 +-------- projects/__init__.py | 0 projects/admin.py | 5 +++++ projects/apps.py | 5 +++++ projects/migrations/0001_initial.py | 23 +++++++++++++++++++++++ projects/migrations/__init__.py | 0 projects/models.py | 10 ++++++++++ projects/templates/projects/index.html | 11 +++++++++++ projects/templates/projects/view.html | 15 +++++++++++++++ projects/tests.py | 3 +++ projects/urls.py | 9 +++++++++ projects/views.py | 20 ++++++++++++++++++++ tofu/settings.py | 1 + tofu/urls.py | 1 + 16 files changed, 108 insertions(+), 25 deletions(-) create mode 100644 projects/__init__.py create mode 100644 projects/admin.py create mode 100644 projects/apps.py create mode 100644 projects/migrations/0001_initial.py create mode 100644 projects/migrations/__init__.py create mode 100644 projects/models.py create mode 100644 projects/templates/projects/index.html create mode 100644 projects/templates/projects/view.html create mode 100644 projects/tests.py create mode 100644 projects/urls.py create mode 100644 projects/views.py diff --git a/issues/admin.py b/issues/admin.py index 034f76d..dfbf979 100644 --- a/issues/admin.py +++ b/issues/admin.py @@ -1,6 +1,5 @@ from django.contrib import admin -from .models import Project, Issue +from .models import Issue -admin.site.register(Project) admin.site.register(Issue) diff --git a/issues/migrations/0001_initial.py b/issues/migrations/0001_initial.py index e9e18f9..82fb950 100644 --- a/issues/migrations/0001_initial.py +++ b/issues/migrations/0001_initial.py @@ -1,4 +1,4 @@ -# Generated by Django 2.1.7 on 2019-03-20 22:34 +# Generated by Django 2.2.1 on 2019-05-27 12:56 from django.db import migrations, models import django.db.models.deletion @@ -10,6 +10,7 @@ class Migration(migrations.Migration): initial = True dependencies = [ + ('projects', '0001_initial'), ] operations = [ @@ -20,20 +21,7 @@ class Migration(migrations.Migration): ('title', models.CharField(max_length=200)), ('text', models.TextField(blank=True)), ('create_date', models.DateTimeField(default=django.utils.timezone.now)), + ('project', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='projects.Project')), ], ), - migrations.CreateModel( - name='Project', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('project_key', models.CharField(max_length=16, unique=True)), - ('name', models.CharField(max_length=200)), - ('description', models.TextField(blank=True)), - ], - ), - migrations.AddField( - model_name='issue', - name='project', - field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='issues.Project'), - ), ] diff --git a/issues/models.py b/issues/models.py index cc04388..180923f 100644 --- a/issues/models.py +++ b/issues/models.py @@ -1,14 +1,7 @@ from django.db import models from django.utils import timezone - -class Project(models.Model): - project_key = models.CharField(max_length=16, unique=True) - name = models.CharField(max_length=200) - description = models.TextField(blank=True) - - def __str__(self): - return self.name +from projects.models import Project class Issue(models.Model): diff --git a/projects/__init__.py b/projects/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/projects/admin.py b/projects/admin.py new file mode 100644 index 0000000..badc1bb --- /dev/null +++ b/projects/admin.py @@ -0,0 +1,5 @@ +from django.contrib import admin + +from .models import Project + +admin.site.register(Project) diff --git a/projects/apps.py b/projects/apps.py new file mode 100644 index 0000000..3ef44de --- /dev/null +++ b/projects/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class ProjectsConfig(AppConfig): + name = 'projects' diff --git a/projects/migrations/0001_initial.py b/projects/migrations/0001_initial.py new file mode 100644 index 0000000..55089c4 --- /dev/null +++ b/projects/migrations/0001_initial.py @@ -0,0 +1,23 @@ +# Generated by Django 2.2.1 on 2019-05-27 12:56 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Project', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('project_key', models.CharField(max_length=16, unique=True)), + ('name', models.CharField(max_length=200)), + ('description', models.TextField(blank=True)), + ], + ), + ] diff --git a/projects/migrations/__init__.py b/projects/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/projects/models.py b/projects/models.py new file mode 100644 index 0000000..c6ba458 --- /dev/null +++ b/projects/models.py @@ -0,0 +1,10 @@ +from django.db import models + + +class Project(models.Model): + project_key = models.CharField(max_length=16, unique=True) + name = models.CharField(max_length=200) + description = models.TextField(blank=True) + + def __str__(self): + return self.name diff --git a/projects/templates/projects/index.html b/projects/templates/projects/index.html new file mode 100644 index 0000000..b64c0da --- /dev/null +++ b/projects/templates/projects/index.html @@ -0,0 +1,11 @@ +{% if project_list %} + +{% else %} +

No projects.

+{% endif %} \ No newline at end of file diff --git a/projects/templates/projects/view.html b/projects/templates/projects/view.html new file mode 100644 index 0000000..e38e16f --- /dev/null +++ b/projects/templates/projects/view.html @@ -0,0 +1,15 @@ +

{{ project.project_key }} - {{ project.name }}

+

{{ project.description }}

+ +

Issues

+{% if issue_list %} + +{% else %} +

This project has no issues yet.

+{% endif %} \ No newline at end of file diff --git a/projects/tests.py b/projects/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/projects/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/projects/urls.py b/projects/urls.py new file mode 100644 index 0000000..d53296a --- /dev/null +++ b/projects/urls.py @@ -0,0 +1,9 @@ +from django.urls import path + +from . import views + +app_name = 'projects' +urlpatterns = [ + path('', views.index, name='index'), + path('/', views.view, name='view'), +] diff --git a/projects/views.py b/projects/views.py new file mode 100644 index 0000000..8f914a0 --- /dev/null +++ b/projects/views.py @@ -0,0 +1,20 @@ +from django.shortcuts import get_object_or_404, render + +from .models import Project +from issues.models import Issue + + +def index(request): + project_list = Project.objects.order_by('project_key') + return render(request, 'projects/index.html', { + 'project_list': project_list, + }) + + +def view(request, project_key): + project = get_object_or_404(Project, project_key=project_key) + issue_list = Issue.objects.filter(project=project.id).order_by('create_date') + return render(request, 'projects/view.html', { + 'project': project, + 'issue_list': issue_list, + }) diff --git a/tofu/settings.py b/tofu/settings.py index a6d2ece..c0a261a 100644 --- a/tofu/settings.py +++ b/tofu/settings.py @@ -32,6 +32,7 @@ ALLOWED_HOSTS = [] INSTALLED_APPS = [ 'issues.apps.IssuesConfig', + 'projects.apps.ProjectsConfig', 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', diff --git a/tofu/urls.py b/tofu/urls.py index 30e127a..cda4b72 100644 --- a/tofu/urls.py +++ b/tofu/urls.py @@ -18,5 +18,6 @@ from django.urls import include, path urlpatterns = [ path('issues/', include('issues.urls')), + path('projects/', include('projects.urls')), path('admin/', admin.site.urls), ] From 23f3d2a96f42bd7c4424ff97e450b1470fdcca3b Mon Sep 17 00:00:00 2001 From: binaryDiv Date: Mon, 3 Jun 2019 00:14:40 +0200 Subject: [PATCH 06/13] create 'new issue' form --- issues/forms.py | 9 +++++++++ issues/templates/issues/index.html | 4 +++- issues/templates/issues/new.html | 15 +++++++++++++++ issues/urls.py | 1 + issues/views.py | 16 ++++++++++++++++ projects/models.py | 2 +- projects/urls.py | 2 +- 7 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 issues/forms.py create mode 100644 issues/templates/issues/new.html diff --git a/issues/forms.py b/issues/forms.py new file mode 100644 index 0000000..c7c5dc9 --- /dev/null +++ b/issues/forms.py @@ -0,0 +1,9 @@ +from django.forms import ModelForm + +from .models import Issue + + +class IssueForm(ModelForm): + class Meta: + model = Issue + fields = ['project', 'title', 'text'] diff --git a/issues/templates/issues/index.html b/issues/templates/issues/index.html index bcf3760..c109698 100644 --- a/issues/templates/issues/index.html +++ b/issues/templates/issues/index.html @@ -8,4 +8,6 @@ {% else %}

No issues.

-{% endif %} \ No newline at end of file +{% endif %} + +

Create new issue

diff --git a/issues/templates/issues/new.html b/issues/templates/issues/new.html new file mode 100644 index 0000000..e9b9899 --- /dev/null +++ b/issues/templates/issues/new.html @@ -0,0 +1,15 @@ +

Create new issue

+ +{% if error_message %}

{{ error_message }}

{% endif %} + +
+ {% csrf_token %} + + {{ form.as_table }} + + + +
+ +
+
diff --git a/issues/urls.py b/issues/urls.py index 93ae9ac..323d620 100644 --- a/issues/urls.py +++ b/issues/urls.py @@ -5,5 +5,6 @@ from . import views app_name = 'issues' urlpatterns = [ path('', views.index, name='index'), + path('new', views.new, name='new'), path('/', views.detail, name='detail'), ] diff --git a/issues/views.py b/issues/views.py index b6d463a..0c43bcc 100644 --- a/issues/views.py +++ b/issues/views.py @@ -1,5 +1,7 @@ +from django.http import HttpResponseRedirect from django.shortcuts import get_object_or_404, render +from .forms import IssueForm from .models import Issue @@ -15,3 +17,17 @@ def detail(request, issue_id): return render(request, 'issues/detail.html', { 'issue': issue, }) + + +def new(request): + if request.method == 'POST': + form = IssueForm(request.POST) + if form.is_valid(): + new_issue = form.save() + return HttpResponseRedirect('/issues/{}'.format(new_issue.id)) + else: + form = IssueForm() + + return render(request, 'issues/new.html', { + 'form': form, + }) diff --git a/projects/models.py b/projects/models.py index c6ba458..9345b06 100644 --- a/projects/models.py +++ b/projects/models.py @@ -7,4 +7,4 @@ class Project(models.Model): description = models.TextField(blank=True) def __str__(self): - return self.name + return '{} - {}'.format(self.project_key, self.name) diff --git a/projects/urls.py b/projects/urls.py index d53296a..7be94af 100644 --- a/projects/urls.py +++ b/projects/urls.py @@ -5,5 +5,5 @@ from . import views app_name = 'projects' urlpatterns = [ path('', views.index, name='index'), - path('/', views.view, name='view'), + path('/', views.view, name='view'), ] From 89e0328a53e89087a7c3a101f7de3bd55cf7ee14 Mon Sep 17 00:00:00 2001 From: binaryDiv Date: Mon, 3 Jun 2019 17:57:25 +0200 Subject: [PATCH 07/13] use generic views --- issues/urls.py | 4 ++-- issues/views.py | 28 +++++++++++++++++----------- projects/urls.py | 4 ++-- projects/views.py | 30 ++++++++++++++++-------------- 4 files changed, 37 insertions(+), 29 deletions(-) diff --git a/issues/urls.py b/issues/urls.py index 323d620..8402305 100644 --- a/issues/urls.py +++ b/issues/urls.py @@ -4,7 +4,7 @@ from . import views app_name = 'issues' urlpatterns = [ - path('', views.index, name='index'), + path('', views.IndexView.as_view(), name='index'), path('new', views.new, name='new'), - path('/', views.detail, name='detail'), + path('/', views.DetailView.as_view(), name='detail'), ] diff --git a/issues/views.py b/issues/views.py index 0c43bcc..20b5a19 100644 --- a/issues/views.py +++ b/issues/views.py @@ -1,24 +1,30 @@ from django.http import HttpResponseRedirect -from django.shortcuts import get_object_or_404, render +from django.shortcuts import render +from django.views import generic from .forms import IssueForm from .models import Issue -def index(request): - issue_list = Issue.objects.order_by('create_date') - return render(request, 'issues/index.html', { - 'issue_list': issue_list, - }) +class IndexView(generic.ListView): + template_name = 'issues/index.html' + context_object_name = 'issue_list' + + def get_queryset(self): + return Issue.objects.order_by('create_date') -def detail(request, issue_id): - issue = get_object_or_404(Issue, pk=issue_id) - return render(request, 'issues/detail.html', { - 'issue': issue, - }) +class DetailView(generic.DetailView): + model = Issue + template_name = 'issues/detail.html' + pk_url_kwarg = 'issue_id' +# class NewIssueForm(generic.FormView): +# template_name = 'issues/new.html' +# form_class = IssueForm +# success_url = + def new(request): if request.method == 'POST': form = IssueForm(request.POST) diff --git a/projects/urls.py b/projects/urls.py index 7be94af..3b0b3b9 100644 --- a/projects/urls.py +++ b/projects/urls.py @@ -4,6 +4,6 @@ from . import views app_name = 'projects' urlpatterns = [ - path('', views.index, name='index'), - path('/', views.view, name='view'), + path('', views.IndexView.as_view(), name='index'), + path('/', views.ProjectView.as_view(), name='view'), ] diff --git a/projects/views.py b/projects/views.py index 8f914a0..ed37e2c 100644 --- a/projects/views.py +++ b/projects/views.py @@ -1,20 +1,22 @@ -from django.shortcuts import get_object_or_404, render +from django.views import generic from .models import Project -from issues.models import Issue -def index(request): - project_list = Project.objects.order_by('project_key') - return render(request, 'projects/index.html', { - 'project_list': project_list, - }) +class IndexView(generic.ListView): + template_name = 'projects/index.html' + context_object_name = 'project_list' + + def get_queryset(self): + return Project.objects.order_by('project_key') -def view(request, project_key): - project = get_object_or_404(Project, project_key=project_key) - issue_list = Issue.objects.filter(project=project.id).order_by('create_date') - return render(request, 'projects/view.html', { - 'project': project, - 'issue_list': issue_list, - }) +class ProjectView(generic.DetailView): + model = Project + template_name = 'projects/view.html' + slug_field = slug_url_kwarg = 'project_key' + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + context['issue_list'] = self.get_object().issue_set.order_by('create_date') + return context From aba821305326b6955f2e0efdc5f26ff6a5a87d85 Mon Sep 17 00:00:00 2001 From: binaryDiv Date: Sun, 10 Nov 2019 02:17:29 +0100 Subject: [PATCH 08/13] update .gitignore --- .gitignore | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 7213d8e..04f8d27 100644 --- a/.gitignore +++ b/.gitignore @@ -11,9 +11,7 @@ db.sqlite3 # Environments .python-version -.env .venv -env/ venv/ # Distribution / packaging @@ -27,3 +25,4 @@ pip-delete-this-directory.txt # IDE stuff .idea/ +.vscode/ From c4ae7f2759bca85a5778b26e567ca02999bc0756 Mon Sep 17 00:00:00 2001 From: binaryDiv Date: Sun, 10 Nov 2019 02:26:46 +0100 Subject: [PATCH 09/13] add basic Makefile, requirements.txt --- Makefile | 18 ++++++++++++++++++ manage.py | 2 +- requirements.txt | 1 + 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 Makefile create mode 100644 requirements.txt diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..c2bda28 --- /dev/null +++ b/Makefile @@ -0,0 +1,18 @@ +# General settings +APP_NAME := tofu +PYTHON ?= python3 + +# Development server +SERVER_LISTEN ?= 0.0.0.0:8037 + +.PHONY: run + +# Default target: none +all: + + +### Local development + +# Run django development server +run: + $(PYTHON) manage.py runserver $(SERVER_LISTEN) diff --git a/manage.py b/manage.py index 2700ab5..dd7d3a3 100755 --- a/manage.py +++ b/manage.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 import os import sys diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..d3e4ba5 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +django From faea970affcb7b13fd6b461cf946db77935566f6 Mon Sep 17 00:00:00 2001 From: binaryDiv Date: Sun, 10 Nov 2019 23:05:39 +0100 Subject: [PATCH 10/13] #1: add login page; require login for views --- issues/views.py | 9 ++++++--- projects/views.py | 6 +++--- templates/registration/login.html | 7 +++++++ tofu/settings.py | 10 +++++++++- tofu/urls.py | 6 ++++++ 5 files changed, 31 insertions(+), 7 deletions(-) create mode 100644 templates/registration/login.html diff --git a/issues/views.py b/issues/views.py index 20b5a19..a41005d 100644 --- a/issues/views.py +++ b/issues/views.py @@ -1,3 +1,5 @@ +from django.contrib.auth.decorators import login_required +from django.contrib.auth.mixins import LoginRequiredMixin from django.http import HttpResponseRedirect from django.shortcuts import render from django.views import generic @@ -6,7 +8,7 @@ from .forms import IssueForm from .models import Issue -class IndexView(generic.ListView): +class IndexView(LoginRequiredMixin, generic.ListView): template_name = 'issues/index.html' context_object_name = 'issue_list' @@ -14,17 +16,18 @@ class IndexView(generic.ListView): return Issue.objects.order_by('create_date') -class DetailView(generic.DetailView): +class DetailView(LoginRequiredMixin, generic.DetailView): model = Issue template_name = 'issues/detail.html' pk_url_kwarg = 'issue_id' -# class NewIssueForm(generic.FormView): +# class NewIssueForm(LoginRequiredMixin, generic.FormView): # template_name = 'issues/new.html' # form_class = IssueForm # success_url = +@login_required def new(request): if request.method == 'POST': form = IssueForm(request.POST) diff --git a/projects/views.py b/projects/views.py index ed37e2c..3886a1e 100644 --- a/projects/views.py +++ b/projects/views.py @@ -1,9 +1,9 @@ +from django.contrib.auth.mixins import LoginRequiredMixin from django.views import generic from .models import Project - -class IndexView(generic.ListView): +class IndexView(LoginRequiredMixin, generic.ListView): template_name = 'projects/index.html' context_object_name = 'project_list' @@ -11,7 +11,7 @@ class IndexView(generic.ListView): return Project.objects.order_by('project_key') -class ProjectView(generic.DetailView): +class ProjectView(LoginRequiredMixin, generic.DetailView): model = Project template_name = 'projects/view.html' slug_field = slug_url_kwarg = 'project_key' diff --git a/templates/registration/login.html b/templates/registration/login.html new file mode 100644 index 0000000..1325723 --- /dev/null +++ b/templates/registration/login.html @@ -0,0 +1,7 @@ +

Login

+ +
+ {% csrf_token %} + {{ form.as_p }} + +
diff --git a/tofu/settings.py b/tofu/settings.py index c0a261a..236b664 100644 --- a/tofu/settings.py +++ b/tofu/settings.py @@ -56,7 +56,9 @@ ROOT_URLCONF = 'tofu.urls' TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'DIRS': [], + 'DIRS': [ + os.path.join(BASE_DIR, 'templates'), + ], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ @@ -120,3 +122,9 @@ USE_TZ = True # https://docs.djangoproject.com/en/2.1/howto/static-files/ STATIC_URL = '/static/' + + +# Other settings + +LOGIN_REDIRECT_URL = '/projects/' +LOGOUT_REDIRECT_URL = '/account/login/' diff --git a/tofu/urls.py b/tofu/urls.py index cda4b72..596418a 100644 --- a/tofu/urls.py +++ b/tofu/urls.py @@ -14,10 +14,16 @@ Including another URLconf 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ from django.contrib import admin +from django.shortcuts import redirect from django.urls import include, path urlpatterns = [ + path('account/', include('django.contrib.auth.urls')), path('issues/', include('issues.urls')), path('projects/', include('projects.urls')), + path('admin/', admin.site.urls), + + # TODO temporarily: just redirect / to /projects/ + path('', lambda request: redirect('projects/', permanent=False)), ] From fe7fce76c00f698927fc9fc84e9b23fdb6a4be94 Mon Sep 17 00:00:00 2001 From: binaryDiv Date: Sun, 10 Nov 2019 23:26:10 +0100 Subject: [PATCH 11/13] #1: correct login URL --- tofu/settings.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tofu/settings.py b/tofu/settings.py index 236b664..cc78a18 100644 --- a/tofu/settings.py +++ b/tofu/settings.py @@ -126,5 +126,6 @@ STATIC_URL = '/static/' # Other settings +LOGIN_URL = '/account/login/' LOGIN_REDIRECT_URL = '/projects/' LOGOUT_REDIRECT_URL = '/account/login/' From b7311f230812038a8e2c144a4e740c6f5f6bccaa Mon Sep 17 00:00:00 2001 From: binaryDiv Date: Sun, 10 Nov 2019 23:37:31 +0100 Subject: [PATCH 12/13] #4: add base template; extend base template in views --- issues/templates/issues/detail.html | 18 +++++++++----- issues/templates/issues/index.html | 30 ++++++++++++++--------- issues/templates/issues/new.html | 32 ++++++++++++++---------- projects/templates/projects/index.html | 28 ++++++++++++--------- projects/templates/projects/view.html | 34 +++++++++++++++----------- templates/base.html | 12 +++++++++ templates/registration/login.html | 18 +++++++++----- 7 files changed, 110 insertions(+), 62 deletions(-) create mode 100644 templates/base.html diff --git a/issues/templates/issues/detail.html b/issues/templates/issues/detail.html index 42ea47c..e25b70d 100644 --- a/issues/templates/issues/detail.html +++ b/issues/templates/issues/detail.html @@ -1,6 +1,12 @@ -

#{{ issue.id }}: {{ issue.title }}

-

- Project: {{ issue.project }}
- Created: {{ issue.create_date }} -

-

{{ issue.text }}

\ No newline at end of file +{% extends "base.html" %} + +{% block title %}Issue: {{ issue.title }}{% endblock %} + +{% block content %} +

#{{ issue.id }}: {{ issue.title }}

+

+ Project: {{ issue.project }}
+ Created: {{ issue.create_date }} +

+

{{ issue.text }}

+{% endblock %} diff --git a/issues/templates/issues/index.html b/issues/templates/issues/index.html index c109698..9eb3e07 100644 --- a/issues/templates/issues/index.html +++ b/issues/templates/issues/index.html @@ -1,13 +1,19 @@ -{% if issue_list %} - -{% else %} -

No issues.

-{% endif %} +{% extends "base.html" %} -

Create new issue

+{% block title %}Issues{% endblock %} + +{% block content %} + {% if issue_list %} + + {% else %} +

No issues.

+ {% endif %} + +

Create new issue

+{% endblock %} diff --git a/issues/templates/issues/new.html b/issues/templates/issues/new.html index e9b9899..0e6d87c 100644 --- a/issues/templates/issues/new.html +++ b/issues/templates/issues/new.html @@ -1,15 +1,21 @@ -

Create new issue

+{% extends "base.html" %} -{% if error_message %}

{{ error_message }}

{% endif %} +{% block title %}Create issue{% endblock %} -
- {% csrf_token %} - - {{ form.as_table }} - - - -
- -
-
+{% block content %} +

Create new issue

+ + {% if error_message %}

{{ error_message }}

{% endif %} + +
+ {% csrf_token %} + + {{ form.as_table }} + + + +
+ +
+
+{% endblock %} diff --git a/projects/templates/projects/index.html b/projects/templates/projects/index.html index b64c0da..ee9bb64 100644 --- a/projects/templates/projects/index.html +++ b/projects/templates/projects/index.html @@ -1,11 +1,17 @@ -{% if project_list %} - -{% else %} -

No projects.

-{% endif %} \ No newline at end of file +{% extends "base.html" %} + +{% block title %}Projects{% endblock %} + +{% block content %} + {% if project_list %} + + {% else %} +

No projects.

+ {% endif %} +{% endblock %} diff --git a/projects/templates/projects/view.html b/projects/templates/projects/view.html index e38e16f..afae756 100644 --- a/projects/templates/projects/view.html +++ b/projects/templates/projects/view.html @@ -1,15 +1,21 @@ -

{{ project.project_key }} - {{ project.name }}

-

{{ project.description }}

+{% extends "base.html" %} -

Issues

-{% if issue_list %} - -{% else %} -

This project has no issues yet.

-{% endif %} \ No newline at end of file +{% block title %}Project: {{ project.name }}{% endblock %} + +{% block content %} +

{{ project.project_key }} - {{ project.name }}

+

{{ project.description }}

+ +

Issues

+ {% if issue_list %} + + {% else %} +

This project has no issues yet.

+ {% endif %} +{% endblock %} diff --git a/templates/base.html b/templates/base.html new file mode 100644 index 0000000..c54107f --- /dev/null +++ b/templates/base.html @@ -0,0 +1,12 @@ + + + + {% block title %}Tofu{% endblock %} - Tofu + + + +

Tofu

+ + {% block content %}No content.{% endblock %} + + diff --git a/templates/registration/login.html b/templates/registration/login.html index 1325723..f3d53be 100644 --- a/templates/registration/login.html +++ b/templates/registration/login.html @@ -1,7 +1,13 @@ -

Login

+{% extends "base.html" %} -
- {% csrf_token %} - {{ form.as_p }} - -
+{% block title %}Login{% endblock %} + +{% block content %} +

Login

+ +
+ {% csrf_token %} + {{ form.as_p }} + +
+{% endblock %} From fc21c309cc279f5ab83020c021d704489adb3dc0 Mon Sep 17 00:00:00 2001 From: binaryDiv Date: Mon, 11 Nov 2019 18:45:13 +0100 Subject: [PATCH 13/13] add _tmp to .gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 04f8d27..d37e6f6 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,6 @@ pip-delete-this-directory.txt # IDE stuff .idea/ .vscode/ + +# Other stuff +_tmp