From b76325c76d8c2c0b937deef8e73b5f391192eb22 Mon Sep 17 00:00:00 2001 From: Corentin Date: Fri, 1 Nov 2024 20:06:00 +0100 Subject: [PATCH] Commenting my code except the two most important ones: views.py and model.py --- CourseMaster/settings.py | 12 +++++- CourseMaster/urls.py | 3 ++ redis_app/admin.py | 5 --- redis_app/apps.py | 2 +- redis_app/static/redis_app/style.css | 3 ++ redis_app/templates/courses.html | 50 +++++++++++++++++++++--- redis_app/templates/create.html | 8 ++++ redis_app/templates/details.html | 15 ++++++- redis_app/templates/home.html | 2 + redis_app/templates/login.html | 1 + redis_app/templates/notifications.html | 3 ++ redis_app/templates/profile.html | 2 + redis_app/templates/publish_message.html | 1 + redis_app/templates/register.html | 1 + redis_app/templates/search.html | 14 ++++++- redis_app/templates/update.html | 1 + redis_app/tests.py | 1 + redis_app/urls.py | 1 + redis_app/utils/index.py | 4 +- 19 files changed, 113 insertions(+), 16 deletions(-) diff --git a/CourseMaster/settings.py b/CourseMaster/settings.py index 105f98d..5ca8195 100644 --- a/CourseMaster/settings.py +++ b/CourseMaster/settings.py @@ -20,6 +20,7 @@ BASE_DIR = Path(__file__).resolve().parent.parent # See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! +# Fell free to get this key, I won't publish my project into a release, and I didn't want to take the time to hide it. SECRET_KEY = 'django-insecure-3ib(8=@cwv%48&0@r1c)inr_*l*-ky$q!8*f_x2&*8a(1_mxb#' # SECURITY WARNING: don't run with debug turned on in production! @@ -37,7 +38,9 @@ INSTALLED_APPS = [ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', + # My project, where all my code is defined 'redis_app', + # I love using debug toolbar 'debug_toolbar', ] @@ -52,12 +55,15 @@ MIDDLEWARE = [ 'django.middleware.clickjacking.XFrameOptionsMiddleware', ] +# Localhost website INTERNAL_IPS = [ '127.0.0.1', ] +# All my URLs are in this file, kinda Router ROOT_URLCONF = 'CourseMaster.urls' +# Declaring redis TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', @@ -80,6 +86,7 @@ WSGI_APPLICATION = 'CourseMaster.wsgi.application' # Database # https://docs.djangoproject.com/en/4.2/ref/settings/#databases +# Useless, I don't use it in my project because I'm using Redis DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', @@ -106,6 +113,7 @@ AUTH_PASSWORD_VALIDATORS = [ }, ] +# Defining the cache in redis. Not very important here, just played with it after I saw a YouTube video showcasing this feature. CACHES = { "default": { "BACKEND": "django_redis.cache.RedisCache", @@ -120,8 +128,8 @@ CACHES = { # Internationalization # https://docs.djangoproject.com/en/4.2/topics/i18n/ +# I'm telling my project that le language is french (even if all my texts are in english...) LANGUAGE_CODE = 'fr-fr' - TIME_ZONE = 'Europe/Paris' USE_I18N = True @@ -132,6 +140,8 @@ USE_TZ = True # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/4.2/howto/static-files/ + +# Allows me to use css into my templates. I followed the django docs. STATIC_URL = '/static/' # Default primary key field type diff --git a/CourseMaster/urls.py b/CourseMaster/urls.py index 69dfc5c..bca5043 100644 --- a/CourseMaster/urls.py +++ b/CourseMaster/urls.py @@ -19,7 +19,10 @@ from django.urls import path, include import debug_toolbar urlpatterns = [ + # Useless, there's no admin part in my project path('admin/', admin.site.urls), + # The main project path('redis/', include('redis_app.urls')), + # For debug toolbar path('__debug__/', include(debug_toolbar.urls)) ] diff --git a/redis_app/admin.py b/redis_app/admin.py index 6f3538b..694323f 100644 --- a/redis_app/admin.py +++ b/redis_app/admin.py @@ -1,6 +1 @@ from django.contrib import admin - -from .models import Course, Person - -admin.site.register(Course) -admin.site.register(Person) diff --git a/redis_app/apps.py b/redis_app/apps.py index 5d03691..0575ed7 100644 --- a/redis_app/apps.py +++ b/redis_app/apps.py @@ -1,6 +1,6 @@ from django.apps import AppConfig - +# Configuring redis as I saw it on the doc. class RedisAppConfig(AppConfig): default_auto_field = 'django.db.models.BigAutoField' name = 'redis_app' diff --git a/redis_app/static/redis_app/style.css b/redis_app/static/redis_app/style.css index ec83e4f..afd4b84 100644 --- a/redis_app/static/redis_app/style.css +++ b/redis_app/static/redis_app/style.css @@ -1,3 +1,6 @@ +/* I don't think commenting css would be relevant enough. My comments could litteraly only describe every line, so it would be faster to just read each part */ +/* This css is not really good, I just spent 2 hours to make it because the main part is not the UX/UI. Sorry if you thinks it's ugly :( */ + body { margin: 0; font-family: Arial, sans-serif; diff --git a/redis_app/templates/courses.html b/redis_app/templates/courses.html index 263b793..133ee9c 100644 --- a/redis_app/templates/courses.html +++ b/redis_app/templates/courses.html @@ -1,38 +1,71 @@ + {% load static %} + +
+ {% if error_message %}

{{ error_message }}

{% endif %} {% if success_message %}

{{ success_message }}

{% endif %} -
- {% if person %} - {% if person.role == "Teacher" %} + + {% if person %} + {% if person.role == "Teacher" %} + +
- {% endif %} +
{% endif %} -
+ {% endif %} +

Courses for {{ person.name }}

+ {% if courses %}
{% for course in courses %} + {{ course.title }} {% endfor %}
+ + {% else %}

No course yet

{% endif %} + + diff --git a/redis_app/templates/create.html b/redis_app/templates/create.html index 3c512a0..aadc816 100644 --- a/redis_app/templates/create.html +++ b/redis_app/templates/create.html @@ -22,7 +22,15 @@
+
+ {% csrf_token %}

Create a course

diff --git a/redis_app/templates/details.html b/redis_app/templates/details.html index f6cf2e4..7e62921 100644 --- a/redis_app/templates/details.html +++ b/redis_app/templates/details.html @@ -29,6 +29,8 @@ {% if success_message %}

{{ success_message }}

{% endif %} + + {% if course %}

Welcome in the course {{ course.title }}!

@@ -43,17 +45,28 @@

The course has been created by {{ course.teacher_name }}

+ + {% else %} -

No course found!

+

No course found!

{% endif %} + + {% if person %} + {% if person.role == "Teacher" %} Delete Update + + {% else %} + {% if register %} Unregister + + {% else %} + {% if full == False %} Register {% else %} diff --git a/redis_app/templates/home.html b/redis_app/templates/home.html index d72f444..678c8f1 100644 --- a/redis_app/templates/home.html +++ b/redis_app/templates/home.html @@ -29,6 +29,8 @@ {% if success_message %}

{{ success_message }}

{% endif %} + + {% if person != '' %}

Welcome {{ person.name }}!

{% else %} diff --git a/redis_app/templates/login.html b/redis_app/templates/login.html index 3075b0e..bc7a468 100644 --- a/redis_app/templates/login.html +++ b/redis_app/templates/login.html @@ -32,6 +32,7 @@ {% if success_message %}

{{ success_message }}

{% endif %} + diff --git a/redis_app/templates/notifications.html b/redis_app/templates/notifications.html index a9557b1..1c8d24d 100644 --- a/redis_app/templates/notifications.html +++ b/redis_app/templates/notifications.html @@ -25,8 +25,11 @@

Notifications

+ Clear notifications
+ + {% for message in messages %} {{ message.data }} {% endfor %} diff --git a/redis_app/templates/profile.html b/redis_app/templates/profile.html index 3532766..456f35d 100644 --- a/redis_app/templates/profile.html +++ b/redis_app/templates/profile.html @@ -32,10 +32,12 @@ {% if success_message %}

{{ success_message }}

{% endif %} + diff --git a/redis_app/templates/publish_message.html b/redis_app/templates/publish_message.html index 7e598d4..0e2158f 100644 --- a/redis_app/templates/publish_message.html +++ b/redis_app/templates/publish_message.html @@ -34,6 +34,7 @@

{{ success_message }}

{% endif %} + diff --git a/redis_app/templates/search.html b/redis_app/templates/search.html index f9abf26..77640c6 100644 --- a/redis_app/templates/search.html +++ b/redis_app/templates/search.html @@ -32,6 +32,14 @@ {% if success_message %}

{{ success_message }}

{% endif %} + +
@@ -39,12 +47,16 @@
+ + {% if courses %} {% for course in courses %} {{ course.title }} {% endfor %} + + {% else %} -

No course found

+

No course found.

{% endif %}
diff --git a/redis_app/templates/update.html b/redis_app/templates/update.html index 80ee575..f4a4886 100644 --- a/redis_app/templates/update.html +++ b/redis_app/templates/update.html @@ -39,6 +39,7 @@