diff --git a/redis_app/templates/courses.html b/redis_app/templates/courses.html index e5e7102..de03077 100644 --- a/redis_app/templates/courses.html +++ b/redis_app/templates/courses.html @@ -10,6 +10,9 @@ Profile Search Notifications + {% if person.role == 'Teacher' %} + Publish a message + {% endif %} Logout {% endif %} diff --git a/redis_app/templates/create.html b/redis_app/templates/create.html index ef7cbe2..472b5e4 100644 --- a/redis_app/templates/create.html +++ b/redis_app/templates/create.html @@ -10,6 +10,9 @@ Profile Search Notifications + {% if person.role == 'Teacher' %} + Publish a message + {% endif %} Logout {% endif %} diff --git a/redis_app/templates/details.html b/redis_app/templates/details.html index bb5f3ca..553f672 100644 --- a/redis_app/templates/details.html +++ b/redis_app/templates/details.html @@ -10,6 +10,9 @@ Profile Search Notifications + {% if person.role == 'Teacher' %} + Publish a message + {% endif %} Logout {% endif %} diff --git a/redis_app/templates/login.html b/redis_app/templates/login.html index 0bd4d7c..0f5634a 100644 --- a/redis_app/templates/login.html +++ b/redis_app/templates/login.html @@ -10,6 +10,9 @@ Profile Search Notifications + {% if person.role == 'Teacher' %} + Publish a message + {% endif %} Logout {% endif %} diff --git a/redis_app/templates/notifications.html b/redis_app/templates/notifications.html index 6c2d9f1..85c786c 100644 --- a/redis_app/templates/notifications.html +++ b/redis_app/templates/notifications.html @@ -10,6 +10,9 @@ Profile Search Notifications + {% if person.role == 'Teacher' %} + Publish a message + {% endif %} Logout {% endif %} diff --git a/redis_app/templates/profile.html b/redis_app/templates/profile.html index e34622b..64f890c 100644 --- a/redis_app/templates/profile.html +++ b/redis_app/templates/profile.html @@ -10,6 +10,9 @@ Profile Search Notifications + {% if person.role == 'Teacher' %} + Publish a message + {% endif %} Logout {% endif %} diff --git a/redis_app/templates/publish_message.html b/redis_app/templates/publish_message.html index 603382e..564d427 100644 --- a/redis_app/templates/publish_message.html +++ b/redis_app/templates/publish_message.html @@ -10,6 +10,9 @@ Profile Search Notifications + {% if person.role == 'Teacher' %} + Publish a message + {% endif %} Logout {% endif %} diff --git a/redis_app/templates/register.html b/redis_app/templates/register.html index 0709d23..1372a2c 100644 --- a/redis_app/templates/register.html +++ b/redis_app/templates/register.html @@ -10,6 +10,9 @@ Profile Search Notifications + {% if person.role == 'Teacher' %} + Publish a message + {% endif %} Logout {% endif %} diff --git a/redis_app/templates/search.html b/redis_app/templates/search.html index d25a4be..e962813 100644 --- a/redis_app/templates/search.html +++ b/redis_app/templates/search.html @@ -10,6 +10,9 @@ Profile Search Notifications + {% if person.role == 'Teacher' %} + Publish a message + {% endif %} Logout {% endif %} diff --git a/redis_app/templates/update.html b/redis_app/templates/update.html index 61f9359..1343fde 100644 --- a/redis_app/templates/update.html +++ b/redis_app/templates/update.html @@ -21,7 +21,7 @@ {% if error_message %} {{ error_message }} {% endif %} - +


diff --git a/redis_app/views.py b/redis_app/views.py index 45e9d34..b505fd9 100644 --- a/redis_app/views.py +++ b/redis_app/views.py @@ -6,7 +6,7 @@ from redis_app.utils.index import create_index # This model only helps us the development part to set rules on objects (we do not use the django model to save objects in it) from .models import Person -DEFAULT_EXPIRE_TIME = 120 +DEFAULT_EXPIRE_TIME = 1200 EXPIRE_REFRESH_TIME = 60 messages = [] # All messages obtained with pub/sub. Will refresh the view every time a message is received @@ -228,6 +228,7 @@ def delete_course_view(request, course_id): res = delete_course(course_id) if not res: return courses(request) + publish(course_id, f"DELETE: Course:{course_id} has been deleted!") return courses(request) def create_course(course_title, course_summary, course_level, course_places, course_teacher): @@ -325,10 +326,18 @@ def update_course_form(request, course_id): course_level = request.POST['level'] course_places = request.POST['places'] course_teacher = getPersonId(person['name'], person['role']).split(":")[1] + course = redis_connection.hgetall(f"course:{course_id}") + course["id"] = course_id + course_students = course.get("students", "") + try: + if course_students and len(course_students.split(',')) >= int(course_places): + return render(request, 'update.html', {'person': person, "error_message": "There's too many students registered to decrease the number of places that much!", "course": course}) + except: + return render(request, 'update.html', {'person': person, "error_message": "The number of places has not the right format!", "course": course}) update_course(course_id, course_title, course_summary, course_level, course_places, course_teacher) return courses(request) - return render(request, 'update.html', {'person': person, "error_message": "The form has been wrongly filled!"}) + return render(request, 'update.html', {'person': person, "error_message": "The form has been wrongly filled!", "course": course}) # Test if places are not limited def course_register(course_id, person_id):