diff --git a/TimeDispatcher/urls.py b/TimeDispatcher/urls.py index 15acdbf..ec053e3 100644 --- a/TimeDispatcher/urls.py +++ b/TimeDispatcher/urls.py @@ -29,6 +29,7 @@ urlpatterns = [ path("parents/", views.ParentsView.as_view(), name="parents"), path("table///", views.get_table_data, name="table_data"), path("table/", views.table_view, name="table"), + path("parents//", views.parent_view, name="parent"), path("projects//", views.project_view, name="project"), path("projects//set_parent", views.set_parent, name="set_parent"), path("stats/by-month///", views.get_stats_by_month, name="stats_by_month"), diff --git a/dispatcher/forms.py b/dispatcher/forms.py index 894c9aa..077684a 100644 --- a/dispatcher/forms.py +++ b/dispatcher/forms.py @@ -1,8 +1,13 @@ from django import forms -from dispatcher.models import Project +from dispatcher.models import Project, Parent +class ParentForm(forms.ModelForm): + class Meta: + model = Parent + fields = "__all__" + class ProjectForm(forms.ModelForm): class Meta: model = Project diff --git a/dispatcher/migrations/0006_alter_parent_project_num.py b/dispatcher/migrations/0006_alter_parent_project_num.py new file mode 100644 index 0000000..95435db --- /dev/null +++ b/dispatcher/migrations/0006_alter_parent_project_num.py @@ -0,0 +1,18 @@ +# Generated by Django 5.1.5 on 2025-02-02 14:32 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('dispatcher', '0005_clocking'), + ] + + operations = [ + migrations.AlterField( + model_name='parent', + name='project_num', + field=models.CharField(blank=True, max_length=32), + ), + ] diff --git a/dispatcher/models.py b/dispatcher/models.py index 10e6b54..18e91f3 100644 --- a/dispatcher/models.py +++ b/dispatcher/models.py @@ -1,7 +1,7 @@ from django.db import models class Parent(models.Model): - project_num = models.CharField(max_length=32) + project_num = models.CharField(max_length=32, blank=True) name = models.CharField(max_length=256) def __str__(self): diff --git a/dispatcher/static/edit.css b/dispatcher/static/edit.css new file mode 100644 index 0000000..ec1034f --- /dev/null +++ b/dispatcher/static/edit.css @@ -0,0 +1,30 @@ +.container { + display: flex; + flex-direction: column; + width: 100%; + max-width: 30em; + align-self: center; + gap: 2em; +} + +form { + display: flex; + flex-direction: column; + gap: 1.6em; +} + +form > div { + display: flex; + flex-direction: column; + gap: 0.4em; +} + +form label { + font-style: italic; + color: var(--light2); +} + +form button { + align-self: center; + padding: 0.4em 1.2em; +} \ No newline at end of file diff --git a/dispatcher/static/parents.js b/dispatcher/static/parents.js new file mode 100644 index 0000000..652239a --- /dev/null +++ b/dispatcher/static/parents.js @@ -0,0 +1,8 @@ +window.addEventListener("load", () => { + document.querySelectorAll(".list li").forEach(row => { + let id = row.dataset.id + row.querySelector("button.edit").addEventListener("click", () => { + window.location.href = `${id}/` + }) + }) +}) \ No newline at end of file diff --git a/dispatcher/static/projects.js b/dispatcher/static/projects.js index b171c65..2f8f37f 100644 --- a/dispatcher/static/projects.js +++ b/dispatcher/static/projects.js @@ -11,7 +11,7 @@ window.addEventListener("load", () => { }) }) - row.querySelector("button.see").addEventListener("click", () => { + row.querySelector("button.edit").addEventListener("click", () => { window.location.href = `${id}/` }) }) diff --git a/dispatcher/views.py b/dispatcher/views.py index 8a1f6f8..bb12bf5 100644 --- a/dispatcher/views.py +++ b/dispatcher/views.py @@ -9,7 +9,7 @@ from django.views.decorators.csrf import csrf_exempt from django.views.decorators.http import require_POST from dispatcher.core import import_tasks -from dispatcher.forms import ProjectForm, ImportForm +from dispatcher.forms import ProjectForm, ImportForm, ParentForm from dispatcher.models import Project, Parent, Clocking from dispatcher.serializers import ClockingSerializer @@ -28,14 +28,30 @@ def projects_view(request): } return render(request, "projects.html", context) + +def parent_view(request, id): + parent = get_object_or_404(Parent, id=id) + context = { + "class": "parent", + "id": id + } + form = ParentForm(request.POST or None, request.FILES or None, instance=parent) + if form.is_valid(): + form.save() + context["form"] = ParentForm(instance=parent) + return render(request, "edit.html", context) + def project_view(request, id): project = get_object_or_404(Project, id=id) - context = {} + context = { + "class": "project", + "id": id + } form = ProjectForm(request.POST or None, request.FILES or None, instance=project) if form.is_valid(): form.save() context["form"] = ProjectForm(instance=project) - return render(request, "project.html", context) + return render(request, "edit.html", context) def table_view(request): return render(request, "table.html") diff --git a/templates/edit.html b/templates/edit.html new file mode 100644 index 0000000..7a1e3d1 --- /dev/null +++ b/templates/edit.html @@ -0,0 +1,16 @@ +{% extends "base.html" %} +{% load static %} +{% block title %}Editing {{ class }} {{ id }}{% endblock %} +{% block head %} + +{% endblock %} +{% block main %} +
+

Editing {{ class }} {{ id }}

+
+ {% csrf_token %} + {{ form }} + +
+
+{% endblock %} \ No newline at end of file diff --git a/templates/list.html b/templates/list.html index fa7d0cb..cf8fd31 100644 --- a/templates/list.html +++ b/templates/list.html @@ -2,6 +2,7 @@ {% load static %} {% block head %} + {% block extra-head %}{% endblock %} {% endblock %} {% block main %}
    diff --git a/templates/parents.html b/templates/parents.html index 996318a..d980a23 100644 --- a/templates/parents.html +++ b/templates/parents.html @@ -2,6 +2,9 @@ {% load static %} {% block title %}Parents{% endblock %} {% block element_name %}parent{% endblock %} +{% block extra-head %} + +{% endblock %} {% block element %}
    {{ element.name }}
    ({{ element.project_num }})
    diff --git a/templates/project.html b/templates/project.html deleted file mode 100644 index e68fc06..0000000 --- a/templates/project.html +++ /dev/null @@ -1,10 +0,0 @@ -{% extends "base.html" %} - -{% block main %} -

    Editing project

    -
    - {% csrf_token %} - {{ form }} - -
    -{% endblock %} \ No newline at end of file diff --git a/templates/projects.html b/templates/projects.html index fac6f96..0a8d8d0 100644 --- a/templates/projects.html +++ b/templates/projects.html @@ -29,7 +29,7 @@ - +