diff --git a/SMS/asgi.py b/SMS/asgi.py new file mode 100644 index 0000000..83459d0 --- /dev/null +++ b/SMS/asgi.py @@ -0,0 +1,13 @@ +import os + +import django +from channels.http import AsgiHandler +from channels.routing import ProtocolTypeRouter + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'SMS.settings') +django.setup() + +application = ProtocolTypeRouter({ + "http": AsgiHandler(), + # Just HTTP for now. (We can add other protocols later.) +}) diff --git a/SMS/settings.py b/SMS/settings.py index a955754..d4a278b 100644 --- a/SMS/settings.py +++ b/SMS/settings.py @@ -46,6 +46,7 @@ INSTALLED_APPS = [ # custom apps 'app.apps.AppConfig', 'accounts.apps.AccountsConfig', + 'coursemanagement', 'course.apps.CourseConfig', 'result.apps.ResultConfig', 'search.apps.SearchConfig', @@ -54,6 +55,7 @@ INSTALLED_APPS = [ 'crispy_forms', 'rest_framework', + 'channels', ] MIDDLEWARE = [ @@ -91,18 +93,32 @@ TEMPLATES = [ WSGI_APPLICATION = 'SMS.wsgi.application' +ASGI_APPLICATION = "SMS.asgi.application" + # Database # https://docs.djangoproject.com/en/2.2/ref/settings/#databases +# DATABASES = { +# 'default': { +# 'ENGINE': 'django.db.backends.sqlite3', +# 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), +# } +# } + +# connect to postgresql database + DATABASES = { 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + 'ENGINE': 'django.db.backends.postgresql_psycopg2', + 'NAME': 'django_sms_data', + 'USER': 'postgres', + 'PASSWORD': 'testing321', + 'HOST': 'localhost', + 'POST': '', } } - # Password validation # https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators diff --git a/SMS/urls.py b/SMS/urls.py index 04e39bd..c26fb12 100644 --- a/SMS/urls.py +++ b/SMS/urls.py @@ -7,7 +7,6 @@ from django.conf.urls.static import static urlpatterns = [ - path('accounts/', include('django.contrib.auth.urls')), url(r'^', include('app.urls')), url(r'^accounts/', include('accounts.urls')), url(r'^programs/', include('course.urls')), diff --git a/accounts/forms.py b/accounts/forms.py index 218a717..2402080 100644 --- a/accounts/forms.py +++ b/accounts/forms.py @@ -66,6 +66,7 @@ class StudentAddForm(UserCreationForm): attrs={ 'type': 'text', 'class': 'form-control', + 'id': 'username_id' } ), label="Username", diff --git a/accounts/migrations/0011_auto_20210823_0825.py b/accounts/migrations/0011_auto_20210823_0825.py new file mode 100644 index 0000000..61d2468 --- /dev/null +++ b/accounts/migrations/0011_auto_20210823_0825.py @@ -0,0 +1,29 @@ +# Generated by Django 3.1.3 on 2021-08-23 05:25 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('course', '0004_auto_20200822_2238'), + ('accounts', '0010_auto_20210401_1718'), + ] + + operations = [ + migrations.AddField( + model_name='user', + name='is_dep_head', + field=models.BooleanField(default=False), + ), + migrations.CreateModel( + name='DepHead', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('department', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='course.program')), + ('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), + ], + ), + ] diff --git a/accounts/models.py b/accounts/models.py index 882b1a5..8b607ab 100644 --- a/accounts/models.py +++ b/accounts/models.py @@ -56,6 +56,7 @@ class User(AbstractUser): is_student = models.BooleanField(default=False) is_lecturer = models.BooleanField(default=False) is_parent = models.BooleanField(default=False) + is_dep_head = models.BooleanField(default=False) phone = models.CharField(max_length=60, blank=True, null=True) address = models.CharField(max_length=60, blank=True, null=True) picture = models.ImageField(upload_to='profile_pictures/%y/%m/%d/', default='default.png', null=True) @@ -159,3 +160,15 @@ class Parent(models.Model): def __str__(self): return self.user.username + +class DepHead(models.Model): + user = models.OneToOneField(User, on_delete=models.CASCADE) + department = models.ForeignKey(Program, on_delete=models.CASCADE, null=True) + + def __str__(self): + return "{}".format(self.user) + + # def save(self, *args, **kwarg): + # pass + # dep + # diff --git a/accounts/templates/registration/login.html b/accounts/templates/registration/login.html index ac67259..6d476d5 100644 --- a/accounts/templates/registration/login.html +++ b/accounts/templates/registration/login.html @@ -2,20 +2,19 @@ {% block title %}DjangoSMS - Login{% endblock title %} {% load crispy_forms_tags %} {% block content %} +