Skip to content

Commit

Permalink
Merge 5177edb into 0aa112e
Browse files Browse the repository at this point in the history
  • Loading branch information
samkitshah18 committed Apr 28, 2024
2 parents 0aa112e + 5177edb commit 830a46b
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 16 deletions.
Binary file modified .coverage
Binary file not shown.
31 changes: 27 additions & 4 deletions Dashboard/templates/Dashboard/tutor_info.html
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,14 @@ <h2 class="fw-bold mb-0 fs-2 text-center w-100">Your Tutor Profile</h2>
{{ tutor_form.salary_max }}
</div>
</div>
<div id="timeslot-error-message" class="alert alert-danger" style="display: none;">
Minimum Hourly Rate must be less than Maximum Hourly Rate
</div>
<div class="mb-3">
{{ tutor_transcript_form.transcript.label_tag }}
{% if tutor_form.instance.transcript %}
<p> <a href="{% url 'Dashboard:download_transcript' tutor_form.instance.id %}" download>{{tutor_form.instance.transcript.name|cut:'transcripts/' }}</a></p>
<p> <a href="{% url 'Dashboard:download_transcript' tutor_form.instance.id %}"
download>{{tutor_form.instance.transcript.name|cut:'transcripts/' }}</a></p>
{% endif %}
{{ tutor_transcript_form.transcript }}

Expand Down Expand Up @@ -152,10 +156,29 @@ <h5 class="modal-title" id="imagePreviewModalLabel">Image Preview</h5>
$("#id_availabilities").val(JSON.stringify(availabilities));

}

prepopulateAvailabilities();
});

$(document).ready(function () {
console.log("Script loaded successfully");
$('form').submit(function (event) {
var minSalary = parseFloat($('#id_salary_min').val());
var maxSalary = parseFloat($('#id_salary_max').val());

if (minSalary >= maxSalary) {
event.preventDefault();
const errorMessageDiv = document.getElementById('timeslot-error-message');
errorMessageDiv.style.display = 'block';
}
});

$('#id_salary_min, #id_salary_max').change(function () {
const errorMessageDiv = document.getElementById('timeslot-error-message');
errorMessageDiv.style.display = 'none';
});
});



function addAvailability() {

Expand Down Expand Up @@ -213,12 +236,12 @@ <h5 class="modal-title" id="imagePreviewModalLabel">Image Preview</h5>
function displayError(message) {
var errorDiv = $("#availability-error");
errorDiv.text(message);
errorDiv.show();
errorDiv.show();
}

function clearError() {
var errorDiv = $("#availability-error");
errorDiv.hide();
errorDiv.hide();
}


Expand Down
25 changes: 15 additions & 10 deletions Dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,17 +468,22 @@ def Requests(request):


def AcceptRequest(request, session_id):
session = TutoringSession.objects.get(pk=session_id)

if session.status == "Pending":
session.status = "Accepted"
session.save()
else:
# If status is not 'Pending', raise an error message
messages.error(
request, "This request has been cancelled and cannot be accepted."
accepted_session = TutoringSession.objects.get(pk=session_id)
accepted_session.status = "Accepted"
accepted_session.save()
overlapping_sessions = (
TutoringSession.objects.filter(
tutor_id=accepted_session.tutor_id,
date=accepted_session.date,
status="Pending",
)

.exclude(pk=session_id)
.exclude(
Q(start_time__gte=accepted_session.end_time)
| Q(end_time__lte=accepted_session.start_time)
)
)
overlapping_sessions.update(status="Declined")
return redirect("Dashboard:requests")


Expand Down
8 changes: 7 additions & 1 deletion TutorFilter/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from Dashboard.choices import EXPERTISE_CHOICES
from django.utils import timezone
from datetime import timedelta
from django.core.validators import MinValueValidator
from django.core.exceptions import ValidationError


class TutorFilterForm(forms.Form):
Expand Down Expand Up @@ -176,9 +178,13 @@ class TutoringSessionRequestForm(forms.ModelForm):
choices=[], widget=forms.Select(attrs={"class": "form-select"})
)

offering_rate = forms.DecimalField(
validators=[MinValueValidator(0.01)],
widget=forms.NumberInput(attrs={"class": "form-control", "min": "0.01"}),
)

def __init__(self, *args, tutor_user=None, **kwargs):
super().__init__(*args, **kwargs)

available_subject_choices = []
if tutor_user:
tutor_profile = ProfileT.objects.filter(user=tutor_user).first()
Expand Down
2 changes: 1 addition & 1 deletion TutorFilter/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ def test_request_tutoring_session_post_valid(self):
data = {
"tutoring_mode": "remote",
"subject": "math",
"date": "2024-04-01",
"date": "2025-04-01",
"offering_rate": 50,
"message": "Looking forward to the session!",
"selected_timeslots": json.dumps([{"start": "09:00", "end": "09:30"}]),
Expand Down

0 comments on commit 830a46b

Please sign in to comment.