diff --git a/.gitignore b/.gitignore index 3c577cc..47a6826 100644 --- a/.gitignore +++ b/.gitignore @@ -129,6 +129,7 @@ dmypy.json .pyre/ # Custome +staticfiles/ datadump.json local_note.txt docs/ diff --git a/accounts/migrations/0017_alter_departmenthead_options_alter_parent_options_and_more.py b/accounts/migrations/0017_alter_departmenthead_options_alter_parent_options_and_more.py new file mode 100644 index 0000000..f1dbe29 --- /dev/null +++ b/accounts/migrations/0017_alter_departmenthead_options_alter_parent_options_and_more.py @@ -0,0 +1,29 @@ +# Generated by Django 4.0.8 on 2023-12-31 07:50 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('accounts', '0016_alter_user_managers'), + ] + + operations = [ + migrations.AlterModelOptions( + name='departmenthead', + options={'ordering': ('-user__date_joined',)}, + ), + migrations.AlterModelOptions( + name='parent', + options={'ordering': ('-user__date_joined',)}, + ), + migrations.AlterModelOptions( + name='student', + options={'ordering': ('-student__date_joined',)}, + ), + migrations.AlterModelOptions( + name='user', + options={'ordering': ('-date_joined',)}, + ), + ] diff --git a/accounts/models.py b/accounts/models.py index a0875ef..5196b87 100644 --- a/accounts/models.py +++ b/accounts/models.py @@ -71,6 +71,9 @@ class User(AbstractUser): objects = CustomUserManager() + class Meta: + ordering = ("-date_joined",) + @property def get_full_name(self): full_name = self.username @@ -140,6 +143,9 @@ class Student(models.Model): objects = StudentManager() + class Meta: + ordering = ("-student__date_joined",) + def __str__(self): return self.student.get_full_name @@ -168,6 +174,9 @@ class Parent(models.Model): # the parent (i.e. father, mother, brother, sister) relation_ship = models.TextField(choices=RELATION_SHIP, blank=True) + class Meta: + ordering = ("-user__date_joined",) + def __str__(self): return self.user.username @@ -176,5 +185,8 @@ class DepartmentHead(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE) department = models.ForeignKey(Program, on_delete=models.CASCADE, null=True) + class Meta: + ordering = ("-user__date_joined",) + def __str__(self): return "{}".format(self.user) diff --git a/app/views.py b/app/views.py index 75feb6c..e06dc3c 100644 --- a/app/views.py +++ b/app/views.py @@ -294,33 +294,37 @@ def semester_delete_view(request, pk): return redirect("semester_list") -# ######################################################## - - -# from django.shortcuts import render_to_response -# from django.template import RequestContext - -# def handler404(request, exception, template_name="common/404.html"): -# response = render_to_response("common/404.html") -# response.status_code = 404 -# return response - - -# def handler500(request, *args, **argv): -# response = render_to_response('common/500.html', {}, context_instance=RequestContext(request)) -# response.status_code = 500 - -# return response - - -# def handler400(request, exception, template_name="common/400.html"): -# response = render_to_response('common/400.html', context_instance=RequestContext(request)) -# response.status_code = 400 - -# return response - - @login_required @admin_required def dashboard_view(request): return render(request, "app/dashboard.html") + + +# ######################################################## + + +def handler404(request, exception, template_name="common/404.html"): + response = render(request, "common/404.html") + response.status_code = 404 + return response + + +def handler500(request, *args, **argv): + response = render(request, "common/500.html") + response.status_code = 500 + + return response + + +def handler400(request, exception, template_name="common/400.html"): + response = render(request, "common/400.html") + response.status_code = 400 + + return response + + +def handler403(request, exception, template_name="common/403.html"): + response = render(request, "common/403.html") + response.status_code = 403 + + return response diff --git a/config/settings.py b/config/settings.py index d549969..218b5e7 100644 --- a/config/settings.py +++ b/config/settings.py @@ -11,7 +11,6 @@ https://docs.djangoproject.com/en/2.2/ref/settings/ """ import os -import posixpath from decouple import config # Build paths inside the project like this: os.path.join(BASE_DIR, ...) @@ -24,9 +23,9 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) SECRET_KEY = "o!ld8nrt4vc*h1zoey*wj48x*q0#ss12h=+zh)kk^6b3aygg=!" # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True +DEBUG = config("DEBUG", default=True, cast=bool) -ALLOWED_HOSTS = [] +ALLOWED_HOSTS = ["*"] # change the default user models to our custom model AUTH_USER_MODEL = "accounts.User" @@ -164,12 +163,21 @@ USE_TZ = True # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/2.2/howto/static-files/ +# https://docs.djangoproject.com/en/dev/ref/settings/#static-url STATIC_URL = "/static/" +# https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#std:setting-STATICFILES_DIRS STATICFILES_DIRS = [ os.path.join(BASE_DIR, "static"), ] +# https://docs.djangoproject.com/en/dev/ref/settings/#static-root STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles") +# https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#staticfiles-finders +STATICFILES_FINDERS = [ + "django.contrib.staticfiles.finders.FileSystemFinder", + "django.contrib.staticfiles.finders.AppDirectoriesFinder", +] +# Media files config MEDIA_URL = "/media/" MEDIA_ROOT = os.path.join(BASE_DIR, "media") @@ -203,3 +211,27 @@ REST_FRAMEWORK = { # Strip payment config STRIPE_SECRET_KEY = config("STRIPE_SECRET_KEY", default="") STRIPE_PUBLISHABLE_KEY = config("STRIPE_PUBLISHABLE_KEY", default="") + +# LOGGING +# ------------------------------------------------------------------------------ +# https://docs.djangoproject.com/en/dev/ref/settings/#logging +# See https://docs.djangoproject.com/en/dev/topics/logging for +# more details on how to customize your logging configuration. +LOGGING = { + "version": 1, + "disable_existing_loggers": False, + "formatters": { + "verbose": { + "format": "%(levelname)s %(asctime)s %(module)s " + "%(process)d %(thread)d %(message)s" + } + }, + "handlers": { + "console": { + "level": "DEBUG", + "class": "logging.StreamHandler", + "formatter": "verbose", + } + }, + "root": {"level": "INFO", "handlers": ["console"]}, +} diff --git a/config/urls.py b/config/urls.py index d31414a..1becddc 100644 --- a/config/urls.py +++ b/config/urls.py @@ -1,10 +1,10 @@ from django.contrib import admin from django.urls import path, include -from django.conf.urls import handler404, handler500, handler400 from django.conf import settings from django.conf.urls.static import static +from django.views import defaults as default_views -admin.site.site_header = "Django LMS Admin" +admin.site.site_header = "Dj-LMS Admin" urlpatterns = [ path("jet/", include("jet.urls", "jet")), # Django JET URLS @@ -26,6 +26,28 @@ if settings.DEBUG: urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) -# handler404 = 'app.views.handler404' -# handler500 = 'app.views.handler500' -# handler400 = 'app.views.handler400' +if settings.DEBUG: + # This allows the error pages to be debugged during development, just visit + # these url in browser to see how these error pages look like. + urlpatterns += [ + path( + "400/", + default_views.bad_request, + kwargs={"exception": Exception("Bad Request!")}, + ), + path( + "403/", + default_views.permission_denied, + kwargs={"exception": Exception("Permission Denied")}, + ), + path( + "404/", + default_views.page_not_found, + kwargs={"exception": Exception("Page not Found")}, + ), + path("500/", default_views.server_error), + ] + +handler404 = "app.views.handler404" +handler500 = "app.views.handler500" +handler400 = "app.views.handler400" diff --git a/quiz/migrations/0004_alter_question_figure_alter_quiz_description.py b/quiz/migrations/0004_alter_question_figure_alter_quiz_description.py new file mode 100644 index 0000000..52d7af1 --- /dev/null +++ b/quiz/migrations/0004_alter_question_figure_alter_quiz_description.py @@ -0,0 +1,23 @@ +# Generated by Django 4.0.8 on 2023-12-31 07:50 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('quiz', '0003_rename_essay_question_essayquestion'), + ] + + operations = [ + migrations.AlterField( + model_name='question', + name='figure', + field=models.ImageField(blank=True, help_text="Add an image for the question if it's necessary.", null=True, upload_to='uploads/%Y/%m/%d', verbose_name='Figure'), + ), + migrations.AlterField( + model_name='quiz', + name='description', + field=models.TextField(blank=True, help_text='A detailed description of the quiz', verbose_name='Description'), + ), + ] diff --git a/templates/common/400.html b/templates/common/400.html new file mode 100644 index 0000000..b70ce22 --- /dev/null +++ b/templates/common/400.html @@ -0,0 +1,9 @@ +{% extends 'common/_base.html' %} + +{% block content %} +
+

Bad request

+

Please make sure the form is correctly filled.

+ ← Return to the app +
+{% endblock %} diff --git a/templates/common/403.html b/templates/common/403.html new file mode 100644 index 0000000..4002522 --- /dev/null +++ b/templates/common/403.html @@ -0,0 +1,9 @@ +{% extends 'common/_base.html' %} + +{% block content %} +
+

403, forbidden

+

You need the proper permission to make that request.

+ ← Return to the app +
+{% endblock %} diff --git a/templates/common/404.html b/templates/common/404.html new file mode 100644 index 0000000..f4c39c0 --- /dev/null +++ b/templates/common/404.html @@ -0,0 +1,9 @@ +{% extends 'common/_base.html' %} + +{% block content %} +
+

404

+

Looks like the page you're looking for is does not exist.

+ ← Return to the app +
+{% endblock %} diff --git a/templates/common/500.html b/templates/common/500.html new file mode 100644 index 0000000..ca49985 --- /dev/null +++ b/templates/common/500.html @@ -0,0 +1,9 @@ +{% extends 'common/_base.html' %} + +{% block content %} +
+

Server error

+

Please try again later.

+ ← Return to the app +
+{% endblock %} diff --git a/templates/common/_base.html b/templates/common/_base.html new file mode 100644 index 0000000..523a520 --- /dev/null +++ b/templates/common/_base.html @@ -0,0 +1,31 @@ +{% load static %} + + + + + + + + + {% block title %}Django Learning Management System{% endblock title %} + + + + + + + + + + + +
+ +
+ {% block content %}{% endblock content %} +
+ +
+ + +