initial commit

This commit is contained in:
sankalp committed 2025-01-06 20:30:30 +05:45
1 parent 275815efb2
commit 302b9d8f5d
18 files changed
+771

No files matched your search

+152
View File
@@ -0,0 +1,152 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
.python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
# Custome
staticfiles/
datadump.json
local_note.txt
docs/
!media/
media/*
!media/default.png
!media/registration_form/
media/registration_form/*
!media/registration_form/README.txt
!media/result_sheet/
media/result_sheet/*
!media/result_sheet/README.txt
# Custom
dump.rdb
*.DS_Store
+43
View File
@@ -0,0 +1,43 @@
# .pre-commit-config.yaml
repos:
# Default pre-commit hooks
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0 # Use the latest stable version
hooks:
- id: fix-byte-order-marker
- id: check-case-conflict
- id: check-symlinks
- id: debug-statements
- id: end-of-file-fixer # Ensures files end with a newline
- id: trailing-whitespace # Removes trailing whitespace
- id: mixed-line-ending # Converts mixed line endings to LF
args: ["--fix=lf"] # Set line endings to LF (Unix-style)
- id: check-added-large-files # Warns on large files being committed
args: ["--maxkb=500"] # Adjust the size limit as needed
- id: check-merge-conflict # Prevents unresolved merge conflicts
- id: check-executables-have-shebangs
- id: requirements-txt-fixer
# Ruff for linting, formatting, and import sorting
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.4
hooks:
- id: ruff
args: ["--fix"]
# Prettier for JSON, YAML, Markdown formatting
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v4.0.0-alpha.8
hooks:
- id: prettier
additional_dependencies: ["prettier@3.0.0"]
# Detect secrets in code
- repo: https://github.com/Yelp/detect-secrets
rev: v1.5.0
hooks:
- id: detect-secrets
name: Detect secrets
description: Detects high entropy strings that are likely to be passwords.
default_stages: [pre-commit]
+21
View File
@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2025 Sankalp Tharu
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
View File
Whitespace-only changes.
+78
View File
@@ -0,0 +1,78 @@
from django.contrib import admin
from main.models import (
Teacher,
Student,
Staff,
Course,
AcademicYear,
Subject,
NewsEvent,
)
# Register your models here.
class TeacherAdmin(admin.ModelAdmin):
list_display = ("first_name", "last_name", "email", "phone", "active_status")
search_fields = ("first_name", "last_name", "email")
list_filter = ("gender", "active_status")
class StudentAdmin(admin.ModelAdmin):
list_display = (
"first_name",
"last_name",
"email",
"phone",
"course",
"academic_year",
"active_status",
)
search_fields = ("first_name", "last_name", "email", "phone")
list_filter = ("gender", "course", "academic_year", "active_status")
class StaffAdmin(admin.ModelAdmin):
list_display = (
"first_name",
"last_name",
"email",
"phone",
"position",
"active_status",
)
search_fields = ("first_name", "last_name", "email", "phone")
list_filter = ("position", "active_status")
class CourseAdmin(admin.ModelAdmin):
list_display = ("name", "course_type", "duration", "academic_year")
search_fields = ("name",)
list_filter = ("course_type", "academic_year")
class AcademicYearAdmin(admin.ModelAdmin):
list_display = ("batch",)
search_fields = ("batch",)
class SubjectAdmin(admin.ModelAdmin):
list_display = ("name", "course", "semester_or_year_number")
search_fields = ("name", "course__name")
list_filter = ("course", "semester_or_year_number")
class NewsEventAdmin(admin.ModelAdmin):
list_display = ("title", "type", "created_at")
search_fields = ("title", "summary")
list_filter = ("type", "created_at")
# Register models with custom admin configurations
admin.site.register(Teacher, TeacherAdmin)
admin.site.register(Student, StudentAdmin)
admin.site.register(Staff, StaffAdmin)
admin.site.register(Course, CourseAdmin)
admin.site.register(AcademicYear, AcademicYearAdmin)
admin.site.register(Subject, SubjectAdmin)
admin.site.register(NewsEvent, NewsEventAdmin)
+6
View File
@@ -0,0 +1,6 @@
from django.apps import AppConfig
class MainConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'main'
+100
View File
@@ -0,0 +1,100 @@
# Generated by Django 5.1.4 on 2025-01-06 13:02
import django.core.validators
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
('auth', '0012_alter_user_first_name_max_length'),
]
operations = [
migrations.CreateModel(
name='AcademicYear',
fields=[
('id', models.AutoField(primary_key=True, serialize=False)),
('batch', models.CharField(max_length=255, unique=True)),
],
),
migrations.CreateModel(
name='NewsEvent',
fields=[
('id', models.BigAutoField(primary_key=True, serialize=False)),
('title', models.CharField(max_length=255)),
('summary', models.TextField()),
('type', models.CharField(choices=[('news', 'News'), ('event', 'Event')], max_length=5)),
('created_at', models.DateTimeField(auto_now_add=True)),
],
),
migrations.CreateModel(
name='Staff',
fields=[
('id', models.AutoField(primary_key=True, serialize=False)),
('first_name', models.CharField(max_length=255)),
('last_name', models.CharField(max_length=255)),
('position', models.CharField(choices=[('clerk', 'Clerk'), ('assistant', 'Assistant'), ('guard', 'Guard')], max_length=255)),
('address', models.CharField(max_length=255)),
('email', models.EmailField(max_length=255, unique=True)),
('phone', models.CharField(max_length=15, validators=[django.core.validators.RegexValidator('^\\+?1?\\d{9,15}$', 'Enter a valid phone number.')])),
('active_status', models.BooleanField(default=True)),
('username', models.CharField(blank=True, max_length=255, null=True, unique=True)),
('password', models.CharField(max_length=255)),
],
),
migrations.CreateModel(
name='Course',
fields=[
('id', models.BigAutoField(primary_key=True, serialize=False)),
('name', models.CharField(max_length=100)),
('course_type', models.CharField(choices=[('semester', 'Semester-based'), ('yearly', 'Yearly-based')], max_length=10)),
('duration', models.PositiveIntegerField(help_text='Number of semesters or years')),
('academic_year', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='main.academicyear')),
],
),
migrations.CreateModel(
name='Student',
fields=[
('id', models.AutoField(primary_key=True, serialize=False)),
('active_status', models.BooleanField(default=True)),
('first_name', models.CharField(max_length=255)),
('last_name', models.CharField(max_length=255)),
('gender', models.CharField(choices=[('M', 'Male'), ('F', 'Female')], max_length=1)),
('phone', models.CharField(max_length=10, unique=True, validators=[django.core.validators.RegexValidator('^\\d{10}$', 'Enter a valid 10-digit phone number.')])),
('email', models.EmailField(max_length=255, unique=True)),
('username', models.CharField(blank=True, max_length=255, null=True, unique=True)),
('password', models.CharField(max_length=255)),
('academic_year', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='main.academicyear')),
('course', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='main.course')),
],
),
migrations.CreateModel(
name='Subject',
fields=[
('id', models.BigAutoField(primary_key=True, serialize=False)),
('name', models.CharField(max_length=255)),
('semester_or_year_number', models.PositiveIntegerField()),
('course', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='subjects', to='main.course')),
],
),
migrations.CreateModel(
name='Teacher',
fields=[
('id', models.AutoField(primary_key=True, serialize=False)),
('first_name', models.CharField(max_length=255)),
('last_name', models.CharField(max_length=255)),
('address', models.CharField(max_length=255)),
('gender', models.CharField(choices=[('M', 'Male'), ('F', 'Female')], max_length=1)),
('email', models.EmailField(max_length=255, unique=True)),
('phone', models.CharField(max_length=15, validators=[django.core.validators.RegexValidator('^\\+?1?\\d{9,15}$', 'Enter a valid phone number.')])),
('active_status', models.BooleanField(default=True)),
('username', models.CharField(blank=True, max_length=255, null=True, unique=True)),
('password', models.CharField(max_length=255)),
('group', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='auth.group')),
],
),
]
View File
Whitespace-only changes.
+145
View File
@@ -0,0 +1,145 @@
from django.db import models
import random
from django.core.validators import RegexValidator
from django.contrib.auth.models import Group
# Create your models here.
class Teacher(models.Model):
id = models.AutoField(primary_key=True)
first_name = models.CharField(max_length=255)
last_name = models.CharField(max_length=255)
address = models.CharField(max_length=255)
gender = models.CharField(max_length=1, choices=[("M", "Male"), ("F", "Female")])
email = models.EmailField(max_length=255, unique=True)
phone = models.CharField(
max_length=15,
validators=[RegexValidator(r"^\+?1?\d{9,15}$", "Enter a valid phone number.")],
)
group = models.ForeignKey(Group, on_delete=models.SET_NULL, null=True, blank=True)
active_status = models.BooleanField(default=True)
username = models.CharField(max_length=255, unique=True, blank=True, null=True)
password = models.CharField(max_length=255)
def save(self, *args, **kwargs):
if not self.username:
random_number = random.randint(1000, 9999)
self.username = f"{self.first_name.lower()}_{random_number}"
super().save(*args, **kwargs)
def __str__(self):
return f"{self.first_name} {self.last_name}"
class Student(models.Model):
id = models.AutoField(primary_key=True)
active_status = models.BooleanField(default=True)
first_name = models.CharField(max_length=255)
last_name = models.CharField(max_length=255)
gender = models.CharField(max_length=1, choices=[("M", "Male"), ("F", "Female")])
phone = models.CharField(
max_length=10,
unique=True,
validators=[
RegexValidator(r"^\d{10}$", "Enter a valid 10-digit phone number.")
],
)
email = models.EmailField(max_length=255, unique=True)
course = models.ForeignKey("Course", on_delete=models.CASCADE)
academic_year = models.ForeignKey("AcademicYear", on_delete=models.CASCADE)
username = models.CharField(max_length=255, unique=True, blank=True, null=True)
password = models.CharField(max_length=255)
def save(self, *args, **kwargs):
if not self.username:
random_number = random.randint(1000, 9999)
self.username = f"{self.first_name.lower()}_{random_number}"
super().save(*args, **kwargs)
def __str__(self):
return f"{self.first_name} {self.last_name}"
class Staff(models.Model):
id = models.AutoField(primary_key=True)
first_name = models.CharField(max_length=255)
last_name = models.CharField(max_length=255)
position = models.CharField(
max_length=255,
choices=[("clerk", "Clerk"), ("assistant", "Assistant"), ("guard", "Guard")],
)
address = models.CharField(max_length=255)
email = models.EmailField(max_length=255, unique=True)
phone = models.CharField(
max_length=15,
validators=[RegexValidator(r"^\+?1?\d{9,15}$", "Enter a valid phone number.")],
)
active_status = models.BooleanField(default=True)
username = models.CharField(max_length=255, unique=True, blank=True, null=True)
password = models.CharField(max_length=255)
def save(self, *args, **kwargs):
if not self.username:
random_number = random.randint(1000, 9999)
self.username = f"{self.first_name.lower()}_{random_number}"
super().save(*args, **kwargs)
def __str__(self):
return f"{self.first_name} {self.last_name}"
class Course(models.Model):
id = models.BigAutoField(primary_key=True)
COURSE_TYPE_CHOICES = [
("semester", "Semester-based"),
("yearly", "Yearly-based"),
]
name = models.CharField(max_length=100)
academic_year = models.ForeignKey("AcademicYear", on_delete=models.CASCADE)
course_type = models.CharField(max_length=10, choices=COURSE_TYPE_CHOICES)
duration = models.PositiveIntegerField(help_text="Number of semesters or years")
def __str__(self):
return self.name
class AcademicYear(models.Model):
id = models.AutoField(primary_key=True)
batch = models.CharField(max_length=255, unique=True)
def __str__(self):
return f"Batch {self.batch}"
class Subject(models.Model):
id = models.BigAutoField(primary_key=True)
name = models.CharField(max_length=255)
course = models.ForeignKey(
"Course", on_delete=models.CASCADE, related_name="subjects"
)
semester_or_year_number = models.PositiveIntegerField()
def __str__(self):
return f"{self.name} (Sem/Year {self.semester_or_year_number})"
class NewsEvent(models.Model):
TYPE_CHOICES = [
("news", "News"),
("event", "Event"),
]
id = models.BigAutoField(primary_key=True)
title = models.CharField(max_length=255)
summary = models.TextField()
type = models.CharField(max_length=5, choices=TYPE_CHOICES)
created_at = models.DateTimeField(auto_now_add=True)
def __str__(self):
return f"{self.title} ({self.get_type_display()})"
USER_CHOICES = [
("staff", "Staff"),
("teacher", "Teacher"),
("student", "Student"),
]
+3
View File
@@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.
+3
View File
@@ -0,0 +1,3 @@
from django.shortcuts import render
# Create your views here.
Executable
+22
View File
@@ -0,0 +1,22 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys
def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'student_management_system.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
if __name__ == '__main__':
main()
+6
View File
@@ -0,0 +1,6 @@
asgiref==3.8.1
Django==5.1.4
django-jazzmin==3.0.1
pytz==2024.2
sqlparse==0.5.3
typing_extensions==4.12.2
Whitespace-only changes.
+16
View File
@@ -0,0 +1,16 @@
"""
ASGI config for student_management_system project.
It exposes the ASGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/5.1/howto/deployment/asgi/
"""
import os
from django.core.asgi import get_asgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'student_management_system.settings')
application = get_asgi_application()
+138
View File
@@ -0,0 +1,138 @@
"""
Django settings for student_management_system project.
Generated by 'django-admin startproject' using Django 5.1.4.
For more information on this file, see
https://docs.djangoproject.com/en/5.1/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/5.1/ref/settings/
"""
import os
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/5.1/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = "django-insecure-@+&tj2vh)c2b+aiei14s%euz*@wt)#oso1ofowr!i4r93$ose6"
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
"jazzmin",
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"main",
]
MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
]
ROOT_URLCONF = "student_management_system.urls"
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [os.path.join(BASE_DIR, "templates")],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
"django.template.context_processors.debug",
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
],
},
},
]
WSGI_APPLICATION = "student_management_system.wsgi.application"
# Database
# https://docs.djangoproject.com/en/5.1/ref/settings/#databases
DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": os.path.join(BASE_DIR, "db.sqlite3"),
}
}
# Password validation
# https://docs.djangoproject.com/en/5.1/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
},
{
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
},
{
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
},
{
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
},
]
# Internationalization
# https://docs.djangoproject.com/en/5.1/topics/i18n/
LANGUAGE_CODE = "en-us"
TIME_ZONE = "Asia/Kathmandu"
USE_I18N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/5.1/howto/static-files/
STATIC_URL = "/static/"
# STATICFILES_DIRS = [
# os.path.join(BASE_DIR, "static"),
# ]
# STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles")
#
# STATICFILES_FINDERS = [
# "django.contrib.staticfiles.finders.FileSystemFinder",
# "django.contrib.staticfiles.finders.AppDirectoriesFinder",
# ]
MEDIA_URL = "/media/"
MEDIA_ROOT = os.path.join(BASE_DIR, "media")
# Default primary key field type
# https://docs.djangoproject.com/en/5.1/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
+22
View File
@@ -0,0 +1,22 @@
"""
URL configuration for student_management_system project.
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/5.1/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
urlpatterns = [
path('admin/', admin.site.urls),
]
+16
View File
@@ -0,0 +1,16 @@
"""
WSGI config for student_management_system project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/5.1/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'student_management_system.settings')
application = get_wsgi_application()