From 43c127d7441424b72d4cfe06c98942b3c4645d43 Mon Sep 17 00:00:00 2001 From: binaryDiv Date: Mon, 27 May 2019 15:15:06 +0200 Subject: [PATCH 1/4] 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 2/4] 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 3/4] 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 4/4] 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'), ]