diff --git a/logbook/tests.py b/logbook/tests.py index 7ce503c..2931933 100644 --- a/logbook/tests.py +++ b/logbook/tests.py @@ -1,3 +1,7 @@ from django.test import TestCase # Create your tests here. +from views import get_week_entries + +w = get_week_entries(week_number=1) +print(w) \ No newline at end of file diff --git a/logbook/urls.py b/logbook/urls.py index 2d3db2f..c59f5c7 100644 --- a/logbook/urls.py +++ b/logbook/urls.py @@ -16,6 +16,7 @@ operations_edit_view, operations_delete_view, update_activity_diagram, + get_week_entries, ) urlpatterns = [ @@ -67,5 +68,9 @@ update_activity_diagram, name="diagram_update", ), - + path( + 'week-entries//', + get_week_entries, + name='get_week_entries' + ), ] diff --git a/logbook/views.py b/logbook/views.py index 140c280..0682363 100644 --- a/logbook/views.py +++ b/logbook/views.py @@ -1,5 +1,5 @@ from django.shortcuts import render, redirect, HttpResponse -from django.urls import reverse +from django.http import JsonResponse from home.views import process_login, logout from .models import Student, Logbook, Entry, Week_operation, User from datetime import datetime, timedelta @@ -627,4 +627,32 @@ def update_activity_diagram(request, logbook_id): 'logbook': logbook, } - return render(request, 'logbook/logbook_operations_diagram.html', context) \ No newline at end of file + return render(request, 'logbook/logbook_operations_diagram.html', context) + +def get_week_entries(request, week_number): + login_pass = is_allowed(request) + if login_pass is not True: + return login_pass + + try: + student = Student.objects.get(user=request.user) + logbook = Logbook.objects.get(student=student, week_number=week_number) + except Student.DoesNotExist: + return JsonResponse({"error": "Student profile not found."}, status=404) + except Logbook.DoesNotExist: + return JsonResponse({"error": "Logbook not found."}, status=404) + + days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'] + entries = [] + + for day in days: + try: + entry = Entry.objects.get(logbook=logbook, day=day) + entries.append({ + 'day': day, + 'activity': entry.activity.strip() + }) + except Entry.DoesNotExist: + continue + + return JsonResponse(entries, safe=False) \ No newline at end of file diff --git a/templates/logbook/logbook_entry.html b/templates/logbook/logbook_entry.html index 74aa7c9..b273a78 100644 --- a/templates/logbook/logbook_entry.html +++ b/templates/logbook/logbook_entry.html @@ -1,100 +1,189 @@ {% extends 'logbook/includes/base.html' %} {% load static %} - {% block main_block %} -
- -
-
-
- {% if form_errors %} -
- - - - {{form_errors}} -
- {% endif %} -
{% csrf_token %} - -
-
-
-

Entry information

-
-
-
-
- - -
-
-
+
+
+
+
+ + {% if form_errors %} +
+ + + {{ form_errors }} +
+ {% endif %} + + + {% csrf_token %} -
+ +
+
+
+

Entry information

+
+
+
- - + +
+ +
+
+ + + +
+
-
+
-
-
-
- Back -

Week - {{logbook.week_number}}( +
+
+
+ + Back + +

Week - {{ logbook.week_number }} + ( {% if entry.date %} - {{entry.date}} + {{ entry.date }} {% else %} - {{logbook.from_date}} - {% endif %})

-

Summarized Entry

-

- Input the date using the provided calendar or by typing it in the correct format. Next, Describe your activities concisely and specifically. Optionally, add any additional information in that fields like "Notes" or "Comments." Review your input, and once satisfied, click "Save" to save the entry. -

-
-
-
- Regenerate + {{ logbook.from_date }} + {% endif %}) +

+

Summarized Entry

+

+ Input the date using the provided calendar or by typing it in the correct format. + Next, describe your activities concisely and specifically. Optionally, add any + additional information in fields like "Notes" or "Comments." Review your input, and + once satisfied, click "Save" to save the entry. +

+
+
+
+ Regenerate - original + Original - -
- +
+ + + +
+
+ + + + + + + }); +}); -{% endblock main_block %} \ No newline at end of file + }); + +{% endblock main_block %} diff --git a/templates/logbook/logbook_operations.html b/templates/logbook/logbook_operations.html index b53a454..45ef058 100644 --- a/templates/logbook/logbook_operations.html +++ b/templates/logbook/logbook_operations.html @@ -54,6 +54,7 @@
Machinery
diff --git a/templates/logbook/logbook_operations_create.html b/templates/logbook/logbook_operations_create.html index 3956d96..89602be 100644 --- a/templates/logbook/logbook_operations_create.html +++ b/templates/logbook/logbook_operations_create.html @@ -1,66 +1,180 @@ {% extends 'logbook/includes/base.html' %} {% load static %} - {% block main_block %} -
- -
-
-
- {% if form_errors %} -
- - - - {{form_errors}} -
- {% endif %} -
- -
-
-
-

Add Operation for week {{logbook.week_number}}

-

Aida guide

-

Please fill in the form below to add a week operation. Write a summary of the operation in the "Operation" field, and mention the tools or machinery used in the "Machinery" field. Be as detailed as possible to document your practical training activities.

-
+
+
+
+
+ + {% if form_errors %} +
+ + + {{ form_errors }} +
+ {% endif %} + +

Debug: Logbook ID = {{ logbook.id }}, Week Number = {{ logbook.week_number }}

+ +
+
+
+
+

Add Operation for week {{ logbook.week_number }}

+

Aida guide

+

+ Please fill in the form below to add a week operation. Write a summary of the operation in the "Operation" field, and mention the tools or machinery used in the "Machinery" field. Be as detailed as possible to document your practical training activities. +

- -
-
{% csrf_token %} -

Add Week Operation

+
+ +
+
+
+

Add Week Operation

+
+ + {% csrf_token %}
- - {% csrf_token %} -
-
-
- - -
-
+
+ +
- -
-
- - -
+
+ + +
- - -
- + +
+
-
+ + + Back to Logbook + +
+
+ + + + {% endblock main_block %} \ No newline at end of file