Skip to content

Commit

Permalink
Merge branch 'integration-branch' into 10-transfers-access
Browse files Browse the repository at this point in the history
  • Loading branch information
serge-21 authored Dec 7, 2022
2 parents 7fabd24 + 48c3bf4 commit 97c3eb0
Show file tree
Hide file tree
Showing 24 changed files with 557 additions and 57 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ The members of the team are:
The project is called `msms` (Music School Management System). It currently consists of a single app `lessons` where all functionality resides.

## Deployed version of the application
The deployed version of the application can be found at *<[enter URL here](URL)>*.
The deployed version of the application can be found at *<[https://serge21.pythonanywhere.com/](URL)>*.

## Installation instructions
To install the software and use it in your local development environment, you must first set up and activate a local development environment. From the root of the project:
Expand Down Expand Up @@ -50,4 +50,5 @@ $ python3 manage.py test
## Sources
The packages used by this application are specified in `requirements.txt`

- Clucker code base
- Clucker code base
- Django custom authentication docs https://docs.djangoproject.com/en/4.1/topics/auth/customizing/#authentication-backends
3 changes: 3 additions & 0 deletions lessons/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
from django.contrib.auth.backends import ModelBackend

class EmailLogin(ModelBackend):
'''referenced django docs https://docs.djangoproject.com/en/4.1/topics/auth/customizing/'''
# custom authentication using email instead of username which django specifies by default
def authenticate(self, request, username=None, password=None):
try:
user = User.objects.get(email=username)
# checks password and if the user is active
if user.check_password(password) and self.user_can_authenticate(user):
return user
except User.DoesNotExist:
Expand Down
1 change: 0 additions & 1 deletion lessons/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class Meta:
'availability': forms.DateTimeInput()
}"""


class BookLessonRequestForm(forms.ModelForm):
"""Form for fulfilling/booking lesson requests"""
class Meta:
Expand Down
2 changes: 2 additions & 0 deletions lessons/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ def present_or_past_date(value):

class Transfer(models.Model):
"""Models a transfer completed by a student"""
class Meta:
ordering = ['-date_received']

# The date and time when the transfer was received
date_received = models.DateTimeField(blank=False, default=timezone.now, validators=[present_or_past_date])
Expand Down
1 change: 1 addition & 0 deletions lessons/templates/admin_home.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ <h1 class="cover-heading">Admin Home</h1>
<p>
<a href="{% url 'admin_lessons' %}" class="btn btn-lg btn-secondary">
See booked lessons
</a>
</p>
<p>
<a href="{% url 'payments' %}" class="btn btn-lg btn-secondary">
Expand Down
40 changes: 40 additions & 0 deletions lessons/templates/admin_payments.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,46 @@ <h1>Students with no balance</h1>
<div class="w-25">{% include 'partials/balance_card.html' with student=student balance=balance %}</div>
{% endif %}
{% endfor %}

<h1>View payments</h1>
<div class="row">
<div class="col-8">
<h2>Transactions</h2>
<table class="table table-striped">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Date</th>
<th scope="col">Name</th>
<th scope="col">Amount</th>
</tr>
</thead>
<tbody>
{% for transfer in transfers %}
<tr class="">
<th scope="row">{{ transfer.transfer_id }}</th>
<td>{{ transfer.date_received }}</td>
<td>{{ transfer.invoice.student.full_name }}</td>
<td>£{{ transfer.invoice.price}}.00</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<div class="col-4">
<h2 class="mb-3">Outstanding balances</h2>
{% for student, balance in balances.items %}
<div class="card mb-3">
<h5 class="card-header"><img src="{{ student.mini_gravatar }}" class="rounded-circle profile-image"> {{ student.full_name }}</h5>
<div class="card-body">
<p>User has <b>£{{balance}}.00</b> outstanding</p>
<h7><a href="{% url 'student_payments' student.id %}">View user profile</a></h7>
</div>
</div>
{% empty %}
<h4>No balances to see</h4>
{% endfor %}
</div>
</div>
</div>
{% endblock %}
2 changes: 1 addition & 1 deletion lessons/templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ <h1 class="cover-heading">MSMS</h1>
<p class="cover-text">The Music School Management System</p>
<p>
<a href="{% url 'student_sign_up' %}" class="btn btn-lg btn-secondary">
Sign up
Sign up as a student
</a>
</p>
<p>
Expand Down
39 changes: 39 additions & 0 deletions lessons/templates/lesson_schedule.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{% extends 'base.html' %}
{% block body %}

{% include 'partials/navbar.html' %}

<div class="container">
<div class="row">
<div class="col-12">
{% if lessons %}
<h1>Your upcoming lessons!</h1>
<table class="table table-striped table-dark">
<thead>
<tr>
<th scope="col">Date</th>
<th scope="col">Duration</th>
<th scope="col">Teacher</th>
<th scope="col">Topic</th>
</tr>
</thead>
<tbody>
{% for lesson in lessons %}
<tr>
<td>{{ lesson.date }}</td>
<td>{{ lesson.duration }}</td>
<td>{{ lesson.teacher }}</td>
<td>{{ lesson.topic }}</td>
</tr>
{% endfor %}
</tbody>
</table>

{% else %}
<h1> There are no upcoming lessons scheduled for you yet!</h1>
{% endif %}
</div>
</div>
</div>

{% endblock %}
3 changes: 3 additions & 0 deletions lessons/templates/partials/guardian_items.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@
<li class="nav-item">
<a class="nav-link" href="{% url 'lesson_list' %}">Your Lessons</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'show_schedule' %}">Schedule</a>
</li>
3 changes: 3 additions & 0 deletions lessons/templates/partials/student_items.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@
<li class="nav-item">
<a class="nav-link" href="{% url 'show_invoices' %}">Invoices</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'show_schedule' %}">Schedule</a>
</li>
2 changes: 1 addition & 1 deletion lessons/templates/student_sign_up.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<div class="row">
<div class="col-12">
{% if guardian %}
<h1>guardian Sign up</h1>
<h1>Guardian Sign up</h1>
<form action="{% url 'guardian_sign_up' %}" method="post">
{% csrf_token %}
{% include 'partials/form.html' with form=form %}
Expand Down
15 changes: 15 additions & 0 deletions lessons/tests/fixtures/default_lesson_request.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[
{
"model": "lessons.lessonRequest",
"pk" : 1,
"fields" : {
"author": 1,
"availability": "Monday",
"lessonNum": 3,
"interval": 1,
"duration": 60,
"topic": "Piano",
"teacher": "Mr Bob"
}
}
]
71 changes: 71 additions & 0 deletions lessons/tests/forms/test_edit_lesson_form.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
from django.test import TestCase
from lessons.models import Student, Lesson, Invoice
from lessons.forms import EditLessonForm

class EditLessonFormTestCase(TestCase):
"""Unit tests for lesson edit form"""

fixtures = [
'lessons/tests/fixtures/admin_user.json',
'lessons/tests/fixtures/default_student.json',
'lessons/tests/fixtures/default_invoice.json'
]

def setUp(self):
super(TestCase, self).setUp()
self.student = Student.objects.get(email="[email protected]")
self.form_input = {
"date": "2023-12-03 12:00:00Z",
"duration": 60,
"topic": "Piano",
"teacher": "Mr Bob"
}

self.lesson = Lesson(
student = Student.objects.get(email="[email protected]"),
invoice = Invoice.objects.get(invoice_number=100),
date = "2022-12-03 12:00:00Z",
duration = 1,
topic = "Drums",
teacher = "Mr Jim"
)

def test_lesson_edit(self):
self.form_input['duration'] = 61
form = EditLessonForm(instance=self.lesson, data=self.form_input)
self.assertTrue(form.is_valid())
form.save()
self.assertEqual(61, self.lesson.duration)

def test_form_contains_fields(self):
form = EditLessonForm()
self.assertIn("date", form.fields)
self.assertIn("duration", form.fields)
self.assertIn("topic", form.fields)
self.assertIn("teacher", form.fields)

def test_accept_valid_input(self):
form = EditLessonForm(data = self.form_input)
self.assertTrue(form.is_valid())

def test_reject_blank_date(self):
self.form_input['date'] = ""
form = EditLessonForm(data = self.form_input)
self.assertFalse(form.is_valid())

def test_reject_blank_duration(self):
self.form_input['duration'] = ""
form = EditLessonForm(data = self.form_input)
self.assertFalse(form.is_valid())

def test_reject_blank_topic(self):
self.form_input['topic'] = ""
form = EditLessonForm(data = self.form_input)
self.assertFalse(form.is_valid())

def test_reject_blank_teacher(self):
self.form_input['teacher'] = ""
form = EditLessonForm(data = self.form_input)
self.assertFalse(form.is_valid())


14 changes: 4 additions & 10 deletions lessons/tests/forms/test_edit_request_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ class EditRequestFormTestCase(TestCase):

fixtures = [
'lessons/tests/fixtures/default_student.json',
'lessons/tests/fixtures/default_lesson_request.json',
]

def setUp(self):
super(TestCase, self).setUp()
self.student = Student.objects.get(email="[email protected]")
self.lessonRequest = LessonRequest.objects.get(author=1)

self.form_input = {
"availability": "Monday",
"lessonNum": 2,
Expand All @@ -20,16 +23,7 @@ def setUp(self):
"topic": "piano",
"teacher": "Mr Bob"
}

self.lessonRequest = LessonRequest(
author = self.student,
availability = "Monday",
lessonNum = 2,
interval = 1,
duration = 60,
topic = "Piano",
teacher = "bob"
)


def test_request_edit(self):
self.form_input['availability'] = "Tuesday"
Expand Down
11 changes: 2 additions & 9 deletions lessons/tests/models/test_lesson_request_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,13 @@ class LessonRequestTestCase(TestCase):

fixtures = [
'lessons/tests/fixtures/default_student.json',
'lessons/tests/fixtures/default_lesson_request.json',
]

def setUp(self):
super(TestCase, self).setUp()
self.student = Student.objects.get(email="[email protected]")
self.lessonRequest = LessonRequest(
author = self.student,
availability = "Monday",
lessonNum = 2,
interval = 1,
duration = 60,
topic = "Piano",
teacher = "bob"
)
self.lessonRequest = LessonRequest.objects.get(author=1)

def _assert_valid_request(self):
try:
Expand Down
4 changes: 3 additions & 1 deletion lessons/tests/views/test_admin_all_balances_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ def test_balance_with_invoice(self):

self.client.login(username=self.admin.email, password='Password123')
response = self.client.get(self.url)
self.assertContains(response, 'John owes')
self.assertContains(response, 'John Doe')
self.assertContains(response, 'User has')
self.assertContains(response, ' outstanding')

def test_balance_hidden_after_transfer_confirmed(self):
self.invoice.save()
Expand Down
Loading

0 comments on commit 97c3eb0

Please sign in to comment.