From 1602d83163d1651d9e43e6e156ff5e45025afac3 Mon Sep 17 00:00:00 2001 From: Corentin Date: Sat, 2 Nov 2024 00:09:32 +0100 Subject: [PATCH] Tested and fix some bugs: One bug found not fixed: pub/sub crashing sometimes. Revert refactor? --- README.md | 6 ++++++ redis_app/utils/model.py | 21 +++++++++++++++++++-- redis_app/views.py | 16 ++++++++++------ 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 3d1cc63..eb04c18 100644 --- a/README.md +++ b/README.md @@ -102,6 +102,12 @@ As a teacher, you can't manage students registered to your course. The search looks for title, description and level fo the course. There's no advanced search for the moment. +--- + +### Pub/sub + +Sometimes, I really don't know why, some message published does not appear at all to notifications page. It concerns around 20 % of all messages. + ## Bugs If you see any bugs, please tell me. I really tried my best by testing every feature every time at every change, but I can miss some tricky things. So please, feel free to mail me at corentin.lemaire@etu.uca.fr to report any bug! diff --git a/redis_app/utils/model.py b/redis_app/utils/model.py index b0ab558..54032e0 100644 --- a/redis_app/utils/model.py +++ b/redis_app/utils/model.py @@ -73,7 +73,15 @@ def register_redis(name, role): # Allows a user to login def login_redis(name, role): # We just check if the user exists - return getPersonIdNameRole(name, role) + person_id = getPersonIdNameRole(name, role) + + # Checking if the person_id is not False or "" + if not person_id: + # Not a person id + return False + + # Getting the person associating with the person id + return getPerson(person_id.split(":")[1]) # Allows to change the profile of a user. person_id = current person id, name = name requested, role = role requested def changeProfile_redis(person_id, name, role): @@ -392,9 +400,18 @@ def get_message(*courses_id): # Listening for new messages for message in pub_sub.listen(): # Checking if the message if a message as we published - if message["type"] != 'pmessage': + if message.get("type", "") != 'pmessage': # Not a message that is interesting for us continue + + # If not a dict, continuing to avoid problems + if not isinstance(message, dict): + continue + + # When the data or channel is null + if not message.get("data", "") or not message.get("channel", ""): + # Just continuing + continue # Found an interesting message! break # Returning this message diff --git a/redis_app/views.py b/redis_app/views.py index 2569396..d1eddff 100644 --- a/redis_app/views.py +++ b/redis_app/views.py @@ -114,10 +114,13 @@ def courses(request, error_message="", success_message=""): return render(request, 'login.html', {'person': Person(name="", role=""), "error_message": "You must login!"}) # Getting up the person id (only the id part without person:) - person_id = getPersonId(person).split(":")[1] + person_id = getPersonId(person) + if not person_id: + # Person id not found + return render(request, 'courses.html', {'person': person, 'courses': courses, 'error_message': 'Person id not found.'}) # Getting all courses of the person (if he's a teacher, taking all courses where he's teacher ; if he's a student, taking all courses where he's registered to) - courses = getCoursesFromPerson(person_id) + courses = getCoursesFromPerson(person_id.split(":")[1]) return render(request, 'courses.html', {'person': person, 'courses': courses, 'error_message': error_message, 'success_message': success_message}) # Called after filled the update profile form @@ -285,8 +288,9 @@ def create_course_form(request): # Only handling POST request if request.method == 'POST': # Getting information from the form - course_title = request.POST['title'] - course_summary = request.POST['summary'] + # Replacing ' by ` because it breaks everything + course_title = request.POST['title'].replace('\'', '`').replace(':', '') + course_summary = request.POST['summary'].replace('\'', '`').replace(':', '') course_level = request.POST['level'] course_places = request.POST['places'] @@ -321,8 +325,8 @@ def update_course_form(request, course_id): # Only handling POST request if request.method == 'POST': # Retriving the POST information - course_title = request.POST['title'] - course_summary = request.POST['summary'] + course_title = request.POST['title'].replace('\'', '`').replace(':', '') + course_summary = request.POST['summary'].replace('\'', '`').replace(':', '') course_level = request.POST['level'] course_places = request.POST['places']