diff --git a/postgresTest/PROJECT1/__pycache__/forms.cpython-311.pyc b/postgresTest/PROJECT1/__pycache__/forms.cpython-311.pyc index 4f7399e09a726b2053b4c07c0f781a4959adcf74..b5efbc4ef1e22dde3621d756906e6e31f1609a3c 100644 Binary files a/postgresTest/PROJECT1/__pycache__/forms.cpython-311.pyc and b/postgresTest/PROJECT1/__pycache__/forms.cpython-311.pyc differ diff --git a/postgresTest/PROJECT1/__pycache__/models.cpython-311.pyc b/postgresTest/PROJECT1/__pycache__/models.cpython-311.pyc index 45ae273498677559a182e07a598df4ed9ab9940e..fa97e0d747deea46f6c7b8388e4fe07f7b66464a 100644 Binary files a/postgresTest/PROJECT1/__pycache__/models.cpython-311.pyc and b/postgresTest/PROJECT1/__pycache__/models.cpython-311.pyc differ diff --git a/postgresTest/PROJECT1/__pycache__/views.cpython-311.pyc b/postgresTest/PROJECT1/__pycache__/views.cpython-311.pyc index 5cf972a13c7022a6c6b3c9d7e8e18c7c7bf6189d..f80e10874414b5739099558b343fabab3a484244 100644 Binary files a/postgresTest/PROJECT1/__pycache__/views.cpython-311.pyc and b/postgresTest/PROJECT1/__pycache__/views.cpython-311.pyc differ diff --git a/postgresTest/PROJECT1/forms.py b/postgresTest/PROJECT1/forms.py index 925414a5e0c0b3c567cac3c3d05b398c6830e8d9..ab7f43df630820ebc6b71415c273fe58af7a948a 100644 --- a/postgresTest/PROJECT1/forms.py +++ b/postgresTest/PROJECT1/forms.py @@ -4,12 +4,13 @@ from django.contrib.auth import get_user_model from .models import Contact, Forecast, Sale, Account, CustomUser, Meeting import datetime + class ScheduleMeetingForm(forms.ModelForm): class Meta: model = Meeting - fields = ['employee_type', 'meeting_time', 'meeting_date'] + fields = ['employee_type', 'date', 'start_time', 'end_time'] widgets = { - 'meeting_date': forms.HiddenInput(), + 'date': forms.HiddenInput(), } class RoleAssignmentForm(forms.ModelForm): diff --git a/postgresTest/PROJECT1/migrations/0020_rename_meeting_date_meeting_date_and_more.py b/postgresTest/PROJECT1/migrations/0020_rename_meeting_date_meeting_date_and_more.py new file mode 100644 index 0000000000000000000000000000000000000000..0a51f358b182c0ea3fcd8626239de7ed6a6ab2e5 --- /dev/null +++ b/postgresTest/PROJECT1/migrations/0020_rename_meeting_date_meeting_date_and_more.py @@ -0,0 +1,40 @@ +# Generated by Django 5.0.6 on 2024-08-20 08:04 + +import django.db.models.deletion +from django.conf import settings +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('PROJECT1', '0019_meeting'), + ] + + operations = [ + migrations.RenameField( + model_name='meeting', + old_name='meeting_date', + new_name='date', + ), + migrations.RenameField( + model_name='meeting', + old_name='meeting_time', + new_name='end_time', + ), + migrations.RemoveField( + model_name='meeting', + name='created_at', + ), + migrations.AddField( + model_name='meeting', + name='start_time', + field=models.TimeField(blank=True, default=None, null=True), + ), + migrations.AddField( + model_name='meeting', + name='user', + field=models.ForeignKey(default=0, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL), + preserve_default=False, + ), + ] diff --git a/postgresTest/PROJECT1/migrations/__pycache__/0020_rename_meeting_date_meeting_date_and_more.cpython-311.pyc b/postgresTest/PROJECT1/migrations/__pycache__/0020_rename_meeting_date_meeting_date_and_more.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..5391c500605c98c09aaf234482ede6344aecf73d Binary files /dev/null and b/postgresTest/PROJECT1/migrations/__pycache__/0020_rename_meeting_date_meeting_date_and_more.cpython-311.pyc differ diff --git a/postgresTest/PROJECT1/models.py b/postgresTest/PROJECT1/models.py index 6d627ecee349a1644ca98b067bdeb6672297856c..cf8787b380457ced760f6e5ad07c63b64e81020f 100644 --- a/postgresTest/PROJECT1/models.py +++ b/postgresTest/PROJECT1/models.py @@ -4,10 +4,15 @@ from django.contrib.auth.models import AbstractUser, Group, Permission, User # Store Meeting Information class Meeting(models.Model): + user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE) + date = models.DateField() + start_time = models.TimeField(null=True, blank=True, default=None) + end_time = models.TimeField() employee_type = models.CharField(max_length=50) - meeting_time = models.TimeField() - meeting_date = models.DateField() - created_at = models.DateTimeField(auto_now_add=True) + + def __str__(self): + return f"{self.employee_type} meeting on {self.date} from {self.start_time or '--:--:--'} to {self.end_time}" + # Define the LeaveForm model once class LeaveForm(models.Model): diff --git a/postgresTest/PROJECT1/templates/calendar.html b/postgresTest/PROJECT1/templates/calendar.html index 334b6e03c79da251f76b6ce404115b0568abfe3a..0751fe5432ba1790cbcef063c71406ff319942a5 100644 --- a/postgresTest/PROJECT1/templates/calendar.html +++ b/postgresTest/PROJECT1/templates/calendar.html @@ -85,8 +85,20 @@ </select> </div> <div class="form-group"> - <label for="meetingTime">Meeting Time:</label> - <input type="time" class="form-control" id="meetingTime" name="meetingTime"> + <label for="startTime">Start Time:</label> + <select class="form-control" id="startTime" name="startTime"> + {% for time in time_options %} + <option value="{{ time }}">{{ time }}</option> + {% endfor %} + </select> + </div> + <div class="form-group"> + <label for="endTime">End Time:</label> + <select class="form-control" id="endTime" name="endTime"> + {% for time in time_options %} + <option value="{{ time }}">{{ time }}</option> + {% endfor %} + </select> </div> <button type="submit" class="btn btn-primary">Schedule Meeting</button> </form> @@ -146,20 +158,18 @@ timerElement.innerText = `Time Elapsed: ${hours}h ${minutes}m ${seconds}s`; - // Check if the button text is "Punch In" to stop the timer if (punchButton.innerText === "Punch In") { clearInterval(timerInterval); } }, 1000); } - // Set selected day in the modal $('#scheduleModal').on('show.bs.modal', function (event) { - var button = event.relatedTarget; // Button that triggered the modal - var day = button.getAttribute('data-day'); // Extract info from data-* attributes - var modalTitle = scheduleModal.querySelector('.modal-title'); - var modalDay = scheduleModal.querySelector('#modal-day'); - var modalInputDay = scheduleModal.querySelector('#selectedDay'); + var button = event.relatedTarget; + var day = button.getAttribute('data-day'); + var modalTitle = document.getElementById('scheduleModalLabel'); + var modalDay = document.getElementById('modal-day'); + var modalInputDay = document.getElementById('selectedDay'); modalTitle.textContent = 'Schedule a Meeting for Day ' + day; modalDay.textContent = day; diff --git a/postgresTest/PROJECT1/views.py b/postgresTest/PROJECT1/views.py index 246cd0bc189396e90b525868a803f512fadd0fb8..9aab4d86daccd4eafa20b66f6607fbe0808e6c15 100644 --- a/postgresTest/PROJECT1/views.py +++ b/postgresTest/PROJECT1/views.py @@ -13,19 +13,41 @@ from django.contrib.auth.views import LoginView from django.contrib.auth.forms import UserChangeForm import calendar +from django.utils import timezone +from datetime import datetime + @login_required def schedule_meeting(request): if request.method == 'POST': selected_day = request.POST.get('selectedDay') employee_type = request.POST.get('employeeType') - meeting_time = request.POST.get('meetingTime') + start_time = request.POST.get('startTime') + end_time = request.POST.get('endTime') + + # Get the year and month from the session + year = request.session.get('calendar_year') + month = request.session.get('calendar_month') - # Here, add logic to save the scheduled meeting to the database - # Example: - # Meeting.objects.create(user=request.user, date=selected_day, time=meeting_time, employee_type=employee_type) + # Construct the full date string using the year, month, and day + meeting_date_str = f"{year}-{month:02d}-{int(selected_day):02d}" + meeting_date = datetime.strptime(meeting_date_str, "%Y-%m-%d").date() + + # Convert start_time and end_time to time objects + start_time_obj = datetime.strptime(start_time, "%H:%M").time() + end_time_obj = datetime.strptime(end_time, "%H:%M").time() + + # Create and save the meeting + Meeting.objects.create( + user=request.user, + date=meeting_date, + start_time=start_time_obj, + end_time=end_time_obj, + employee_type=employee_type + ) + + # Redirect back to the calendar view + return redirect('calendar_view', year=year, month=month) - # Redirect back to the calendar view or another appropriate page - return redirect('calendar_view', year=timezone.now().year, month=timezone.now().month) # Fetch all leave forms - consolidated function @login_required @@ -160,6 +182,7 @@ def redirect_to_current_month(request): def calendar_view(request, year, month): user = request.user + # Convert month to int and ensure it's within the 1-12 range month = int(month) if month < 1: @@ -193,14 +216,29 @@ def calendar_view(request, year, month): # Get month name month_name = calendar.month_name[month] + # Store the current year and month in the session for use in scheduling + request.session['calendar_year'] = year + request.session['calendar_month'] = month + + # Initialize the form before any conditionals + form = ScheduleMeetingForm() + # Handle meeting scheduling form submission if request.method == 'POST': form = ScheduleMeetingForm(request.POST) if form.is_valid(): - form.save() + selected_day = request.POST.get('selectedDay') + # Construct the full date string + meeting_date_str = f"{year}-{month:02d}-{int(selected_day):02d}" + meeting_date = timezone.datetime.strptime(meeting_date_str, "%Y-%m-%d").date() + meeting = form.save(commit=False) + meeting.user = user + meeting.date = meeting_date + meeting.save() return redirect('calendar_view', year=year, month=month) - else: - form = ScheduleMeetingForm() + + # Time options for the dropdown + time_options = [f"{hour:02}:00" for hour in range(8, 19)] + [f"{hour:02}:30" for hour in range(8, 19)] # Render the template with the context data context = { @@ -216,14 +254,12 @@ def calendar_view(request, year, month): 'previous_month': previous_month, 'next_year': next_year, 'next_month': next_month, - 'form': form, # Add the form to the context + 'form': form, + 'time_options': time_options, # Pass the time options to the template } return render(request, 'calendar.html', context) - - - @login_required def punch(request): if request.method == "POST":