diff --git a/.gitignore b/.gitignore index 6a0812a..b49796e 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,9 @@ __pycache__/ # C extensions *.so +# Ignore migrations +migrations + # Distribution / packaging .Python build/ diff --git a/README.md b/README.md index 3a28f06..44ae75f 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,23 @@ pip install [package_name] ``` If you find an external Python library which you think you can use for this project, you can install it in your virtualenv using this command. Don't forget to add the library and the version you installed to the requirements.txt so that other collaborators can also install the dependency in their virtualenvs. +### Postgres + +Make sure that you've already installed Postgres on your computer. The Postgres details (username, password, database name, etc.) is found in the .env file, so your Postgres configuration MUST match the ones found in the .env. That means that the username, password and database name you create must be the same as the ones in the .env file. To configure your Postgres, follow the instructions in this [website](https://www.a2hosting.com/kb/developer-corner/postgresql/managing-postgresql-databases-and-users-from-the-command-line). Here's a summary of the steps: + +Creating a Postgres user +1. `createuser --interactive --pwprompt` - creates a user with prompt +2. At the "Enter name of role to add:" prompt, type the user's name. +3. At the "Enter password for new role:" prompt, type a password for the user. +4. At the "Enter it again:" prompt, retype the password. +5. At the "Shall the new role be a superuser?" prompt, type y to grant superuser access. +6. At the "Shall the new role be allowed to create databases?" prompt, type y to grant database creation access. +7. At the "Shall the new role be allowed to create more new roles?" prompt, type y to grant role creation access. + +Creating a Postgres database +1. `createdb -O [USER_NAME] [DB_NAME]` - creates a database. Make sure to replace the `[USER_NAME]` and `[DB_NAME]` with your username and database name, respectively. +2. Run `psql -U [USER_NAME] [DB_NAME]` to run your Postgres shell as the user you created. +3. `GRANT ALL ON DATABASE [DB_NAME] TO [USER_NAME];` - makes sure that your user has permissions to do any action to the database. ### Github Workflow [Very helpful interactive tutorial on the Git workflow](https://learngitbranching.js.org/) @@ -157,21 +174,21 @@ v.[field_name]_set.create(parameters…) ``` - creates objects and adds to the related set -### MySQL +### PostgreSQL ``` -mysql -u root -p +psql -U [USER_NAME] [DB_NAME] ``` - - opens shell of MySQL + - logs in your postgres user and in your database -#### In the MySQL shell: +#### In the PostgreSQL shell: ``` DROP DATABASE tanong_db; ``` - - deletes the database named tanong_database + - deletes the database named tanong_db ``` CREATE DATABASE tanong_db; ``` - - creates database named tanong_database + - creates database named tanong_db -**Note that the username and password of your MySQL configuration, as well as the name of the database you made, must match the ones in the .env file.** +**Note that the username and password of your PostgreSQL configuration, as well as the name of the database you made, must match the ones in the .env file.** diff --git a/database/models.py b/database/models.py index 71a8362..efc7cf0 100644 --- a/database/models.py +++ b/database/models.py @@ -1,3 +1,54 @@ from django.db import models +from django.contrib.auth import get_user_model + +User = get_user_model() # Create your models here. +class Request(models.Model): + user_access_ID= models.CharField(max_length=255) + request_time = models.DateTimeField(max_length=100,auto_now_add=True) + +class Adviser(models.Model): + first_name = models.CharField(max_length=255) + middle_name = models.CharField(max_length=255) + last_name = models.CharField(max_length=255) + user = models.OneToOneField(User, on_delete=models.CASCADE) + +class SchoolYear(models.Model): + years = models.CharField(max_length=5) + +class Section(models.Model): + year_level = models.IntegerField() + name = models.CharField(max_length=255) + Adviser = models.ManyToManyField(Adviser) + schoolyear = models.ForeignKey(SchoolYear, on_delete=models.CASCADE) + +class Student(models.Model): + first_name = models.CharField(max_length=255) + middle_name = models.CharField(max_length=255) + last_name = models.CharField(max_length=255) + birthdate = models.DateField() + sex_choices =[('MALE','male'),('FEMALE','female')] + sex = models.CharField(max_length=10, choices=sex_choices,default='MALE') + LRN = models.IntegerField(blank=True, null=True) + +class Enrollment(models.Model): + quarter = models.IntegerField() + school_days = models.IntegerField() + days_absent = models.IntegerField() + student_id = models.ForeignKey(Student, on_delete=models.CASCADE) + section_id = models.ForeignKey(Section, on_delete=models.CASCADE) + +class Subject(models.Model): + name = models.CharField(max_length=255) + subject_type = models.CharField(max_length=255) + +class Grade(models.Model): + student_id = models.ForeignKey(Student, on_delete=models.CASCADE) + subject_id = models.ForeignKey(Subject, on_delete=models.CASCADE) + numerical_grade = models.IntegerField() + remark = models.CharField(max_length=100, blank='true',null='true') + +class CoreValues(models.Model): + behavior_statement = models.CharField(max_length=100) + mark = models.CharField(max_length=50) diff --git a/database/static/database/css/main.css b/database/static/database/css/main.css new file mode 100644 index 0000000..94d87ce --- /dev/null +++ b/database/static/database/css/main.css @@ -0,0 +1,185 @@ +/* CSS FOR THE LOGIN SCREEN */ +/* for vertically aligning everything in innerdiv */ +.divmain{ + display: table; + position: absolute; + top: 0;left: 0; + height: 100%; + width: 100%; +} +.innerdiv{ + display: table-cell; + vertical-align: middle; +} +.centerRoboto{ + text-align: center; + font-family: 'Roboto', sans-serif; +} +.logininputdiv{ + width: 16.6rem; + margin: auto; +} +.loginform{ + padding-top: 1.6rem; + text-align: left; + font-size: 1rem; +} +.robotoFont{ + font-family: 'Roboto', sans-serif; +} +.loginInput{ + float: right; + width: 12.5em; +} +.topMargin10{ + margin-top: 0.7rem; +} +.buttonDiv{ + margin-top: 2.5em; + text-align:center; +} +.buttonStyle{ + min-width:3.2em; + min-height:1.rem; + background-color: #E3E3E3;; + width:7.5em; + font-family: 'Roboto', sans-serif; +} +.leftMargin15{ + margin-left: 0.9rem; +} +.leftMargin10{ + margin-left: 0.6rem; +} + +/* overwrite Bootstrap's striped table colors */ +.table-striped>tbody>tr:nth-child(even)>td, +.table-striped>tbody>tr:nth-child(even)>th { + background-color:#6EA37D; + }.table-striped>tbody>tr:nth-child(odd)>td, + .table-striped>tbody>tr:nth-child(odd)>th { + background-color:#F2F2F2; + } + +/* overwrite color of borders for the table */ +.table-bordered > tbody > tr > td, .table-bordered > tbody > tr > th, +.table-bordered > tfoot > tr > td, .table-bordered > tfoot > tr > th, +.table-bordered > thead > tr > td, .table-bordered > thead > tr > th { + border: 1px solid rgba(201, 200, 200, 0.5); +} + +.navstyle{ + background-color:#3DBF61; + height:4rem; + margin-bottom: 0.9rem; +} +.navbrand{ + color:black; + margin-left: 0.9rem; +} +.navbuttons{ + text-align:right; + float: right; + margin-right: 0.9rem; +} +.headerbuttons{ + background-color:#E3E3E3; + width:9.4em; +} +.screenhead{ + margin-left: 2.2rem; + width: 25rem; + margin-bottom: 1.25rem; +} +.filtersdiv{ + margin-top: 0.63rem; + text-align: center; + width: 64.38rem; + margin-left: auto; + margin-right: auto; +} +.filterlabel{ + margin-right: 0.9em; + float: left; + margin-top: 0.13em; +} +.selectstyle{ + background-color: #E5E5E5; + color:#494949; + float:left; + width: 11.06em; + height:2.2em; + border-color:#E5E5E5; +} +.leftMargin20{ + margin-left: 1.25rem; +} +.filterbuttons{ + background-color: #E3E3E3; + margin-left: 1.43em; + font-size: 0.875rem; + float: left; +} +.alignitems{ + align-items:center; +} +.inline{ + margin-top: 1.25em; + display: inline-block; +} +.searchlabels{ + float: left; + margin-top:0.188em +} +.searchinputs{ + width: 12.5em; + margin-left: 0.9em; + float: left; + height:2.2em; + background-color: #E5E5E5; +} +.hrstyle{ + margin-top: 0.9rem; + width:80.125rem; +} +.tablestyle{ + margin: auto; + margin-top: 1.5625rem; + width: 95%; + margin-bottom: 1.5625rem; + border-style: hidden; +} +.thstyle{ + text-align: center; + color:white; + font-family: 'Roboto', sans-serif; + font-weight: normal; +} +.width80{ + width: 4em; +} +.width140{ + width: 8.75em; +} +.width130{ + width: 8.125em; +} +.width250{ + width: 15em; +} +.width120{ + width: 5em; +} +.width160{ + width: 10em; +} +.table-striped>tbody>tr:nth-child(even)>td>div>.tablebuttons{ + background-color:#F2F2F2; + }.table-striped>tbody>tr:nth-child(odd)>td>div>.tablebuttons{ + background-color:rgb(211, 211, 211); + } +.tablebuttons{ + /* background-color: #E7E7E7; */ + font-size: 0.875em; + min-width: 5em; +} \ No newline at end of file diff --git a/database/templates/base.html b/database/templates/base.html new file mode 100644 index 0000000..1ca8628 --- /dev/null +++ b/database/templates/base.html @@ -0,0 +1,20 @@ +{% load static %} + + + + + + {% block title %}{% endblock %} + + + + + + + + + + {% block body %} + {% endblock %} + + \ No newline at end of file diff --git a/database/templates/database/login.html b/database/templates/database/login.html new file mode 100644 index 0000000..79ccd37 --- /dev/null +++ b/database/templates/database/login.html @@ -0,0 +1,40 @@ +{% extends 'base.html' %} + {% block title %}Login Page{% endblock %} + {% block body %} +
+
+

Tañong Public High School

+ +

Student Records

+ +
+ +
+ + + + + +
+ + + + + +
+ +
+ + + + Sign In + Register +
+ +
+ +
+
+
+ + {% endblock %} \ No newline at end of file diff --git a/database/templates/database/student_list.html b/database/templates/database/student_list.html new file mode 100644 index 0000000..bfa3f50 --- /dev/null +++ b/database/templates/database/student_list.html @@ -0,0 +1,205 @@ +{% extends 'base.html' %} + {% block title %}Student List{% endblock %} + {% block body %} + +

View Student Records

+ +
+ + + + + + + + + + + + + Apply Filter +
+ +
+
+ + + + + Search Database +
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
IDLRN Last Name First Name MI Level Section Status Action
+
+ View + Update +
+
+
+ View + Update +
+
+
+ View + Update +
+
+
+ View + Update +
+
+
+ View + Update +
+
+
+ View + Update +
+
+
+ View + Update +
+
+
+ View + Update +
+
+ + + + {% endblock %} \ No newline at end of file diff --git a/database/urls.py b/database/urls.py index 1434a54..801e851 100644 --- a/database/urls.py +++ b/database/urls.py @@ -1,5 +1,7 @@ from django.urls import path - +from database import views urlpatterns = [ # path('', ) + path('login/', views.login), + path('student-list/', views.student_list) ] diff --git a/database/views.py b/database/views.py index 91ea44a..99526e2 100644 --- a/database/views.py +++ b/database/views.py @@ -1,3 +1,7 @@ from django.shortcuts import render # Create your views here. +def login(request): + return render(request, 'database/login.html') +def student_list(request): + return render(request, 'database/student_list.html') \ No newline at end of file diff --git a/example.env b/example.env new file mode 100644 index 0000000..d29fd8b --- /dev/null +++ b/example.env @@ -0,0 +1,9 @@ +// Fill out secret key +SECRET_KEY= + +// Fill out user and password +DB_NAME=tanong_db +DB_USER= +DB_PASSWORD= +DB_HOST=localhost +PORT=5432 \ No newline at end of file diff --git a/old_repos/students-2/Student Database ERD.png b/old_repos/students-2/Student Database ERD.png new file mode 100644 index 0000000..f8ef9dd Binary files /dev/null and b/old_repos/students-2/Student Database ERD.png differ diff --git a/requirements.txt b/requirements.txt index cdd1b61..58789bc 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,3 @@ Django==2.2.5 -pymysql==0.9.3 python-decouple==3.1 -mysqlclient==1.4.4 \ No newline at end of file +psycopg2==2.8.4 \ No newline at end of file diff --git a/tanong_db/settings.py b/tanong_db/settings.py index f31c087..f3e97c5 100644 --- a/tanong_db/settings.py +++ b/tanong_db/settings.py @@ -77,18 +77,10 @@ DATABASES = { 'default': { - 'ENGINE': 'django.db.backends.mysql', + 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': config('DB_NAME'), 'USER': config('DB_USER'), 'PASSWORD': config('DB_PASSWORD'), - 'OPTIONS': { - # Tell MySQLdb to connect with 'utf8mb4' character set - 'charset': config('CHARSET'), - }, - 'TEST': { - 'CHARSET': config('CHARSET'), - 'COLLATION': config('COLLATION'), - }, 'HOST': config('DB_HOST'), # Or an IP Address that your DB is hosted on 'PORT': config('PORT'), } @@ -133,3 +125,6 @@ # https://docs.djangoproject.com/en/2.2/howto/static-files/ STATIC_URL = '/static/' +STATICFILES_DIRS = ( + os.path.join(BASE_DIR, "static"), +) diff --git a/tanong_db/urls.py b/tanong_db/urls.py index 1cd8f9a..c1b2bca 100644 --- a/tanong_db/urls.py +++ b/tanong_db/urls.py @@ -4,4 +4,4 @@ urlpatterns = [ path('admin/', admin.site.urls), path('', include('database.urls')) -] +] \ No newline at end of file