Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ExecutiveMember model #87

Merged
merged 8 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# IEEE NITK Corpus

[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/IEEE-NITK/corpus/main.svg)](https://results.pre-commit.ci/latest/github/IEEE-NITK/corpus/main)

A Django based web application to manage all things IEEE NITK.

## Setup Instructions
Expand Down
34 changes: 34 additions & 0 deletions corpus/accounts/admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin

from .models import ExecutiveMember
from .models import User

# Register your models here.
Expand Down Expand Up @@ -49,4 +50,37 @@ class CorpusUserAdmin(UserAdmin):
ordering = ("email",)


class ExecutiveMemberAdmin(admin.ModelAdmin):
fieldsets = (
(None, {"fields": ("user", "sig")}),
(
"NITK Related Details",
{
"fields": (
"edu_email",
"roll_number",
"reg_number",
"minor_branch",
"is_nep",
)
},
),
(
"IEEE Related Details",
{"fields": ("ieee_number", "ieee_email")},
),
("Socials", {"fields": ("linkedin", "github")}),
)
list_display = ("user", "sig", "roll_number", "edu_email", "ieee_number", "is_nep")
search_fields = (
"roll_number",
"reg_number",
"edu_email",
"ieee_number",
"ieee_email",
)
ordering = ("user",)


admin.site.register(User, CorpusUserAdmin)
admin.site.register(ExecutiveMember, ExecutiveMemberAdmin)
5 changes: 2 additions & 3 deletions corpus/accounts/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
from django.contrib.auth.forms import UserChangeForm
from django.contrib.auth.forms import UserCreationForm

from .models import GENDERS
from .models import User


class CorpusCreationForm(UserCreationForm):
phone_no = forms.CharField(required=True, max_length=10)
gender = forms.ChoiceField(choices=GENDERS, required=True)
gender = forms.ChoiceField(choices=User.GENDERS, required=True)
first_name = forms.CharField(max_length=30, required=True, help_text="Required.")

error_css_class = "text-sm text-error"
Expand All @@ -36,7 +35,7 @@ def __init__(self, *args, **kwargs):

class CorpusChangeForm(UserChangeForm):
phone_no = forms.CharField(required=True)
gender = forms.ChoiceField(choices=GENDERS, required=True)
gender = forms.ChoiceField(choices=User.GENDERS, required=True)

class Meta:
model = User
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
# Generated by Django 4.2.7 on 2024-01-08 16:02
import datetime

import accounts.validators
import django.db.models.deletion
from django.conf import settings
from django.db import migrations
from django.db import models


class Migration(migrations.Migration):

dependencies = [
("config", "0004_sig_society_sigs"),
("accounts", "0001_initial"),
]

operations = [
migrations.AlterField(
model_name="user",
name="email",
field=models.EmailField(
max_length=254, unique=True, verbose_name="Personal Email"
),
),
migrations.AlterField(
model_name="user",
name="phone_no",
field=models.CharField(
max_length=15,
unique=True,
validators=[accounts.validators.validate_phone_number],
verbose_name="Phone Number",
),
),
migrations.CreateModel(
name="ExecutiveMember",
fields=[
(
"user",
models.OneToOneField(
on_delete=django.db.models.deletion.CASCADE,
primary_key=True,
serialize=False,
to=settings.AUTH_USER_MODEL,
),
),
(
"edu_email",
models.EmailField(
max_length=254,
unique=True,
validators=[accounts.validators.validate_nitk_email],
verbose_name="NITK EDU Email",
),
),
(
"roll_number",
models.CharField(
max_length=8,
unique=True,
validators=[accounts.validators.validate_roll_number],
verbose_name="NITK Roll Number",
),
),
(
"reg_number",
models.CharField(
max_length=10,
unique=True,
validators=[accounts.validators.validate_reg_number],
verbose_name="NITK Registration Number",
),
),
(
"minor_branch",
models.CharField(
blank=True,
choices=[
("WO", "Water Resources and Ocean Engineering"),
("CH", "Chemical Engineering"),
("CM", "Chemistry"),
("CV", "Civil Engineering"),
("CS", "Computer Science and Engineering"),
("EE", "Electrical and Electronics Engineering"),
("EC", "Electronics and Communication Engineering"),
("IT", "Information Technology"),
("MA", "Mathematical and Computational Sciences"),
("ME", "Mechanical Engineering"),
("MT", "Metallurgical and Materials Engineering"),
("MN", "Mining Engineering"),
("PS", "Physics"),
(
"SM",
"School of Humanities, Social Sciences and Management",
),
],
max_length=2,
null=True,
verbose_name="Minor Branch",
),
),
(
"ieee_number",
models.CharField(
blank=True,
max_length=10,
null=True,
validators=[accounts.validators.validate_ieee_number],
verbose_name="IEEE Membership Number",
),
),
(
"ieee_email",
models.EmailField(
blank=True,
max_length=254,
null=True,
validators=[accounts.validators.validate_ieee_email],
verbose_name="IEEE Email",
),
),
(
"linkedin",
models.URLField(
blank=True, null=True, verbose_name="Linkedin Profile URL"
),
),
(
"github",
models.CharField(
blank=True, null=True, verbose_name="GitHub Username"
),
),
(
"is_nep",
models.BooleanField(default=False, verbose_name="Is NEP Member?"),
),
(
"date_joined",
models.DateTimeField(
default=datetime.datetime(2024, 1, 8, 21, 32, 24, 610176),
verbose_name="Date Joined",
),
),
(
"sig",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE, to="config.sig"
),
),
],
),
]
119 changes: 108 additions & 11 deletions corpus/accounts/models.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
from datetime import datetime

from config.models import SIG
from django.contrib.auth.base_user import BaseUserManager
from django.contrib.auth.models import AbstractUser
from django.db import models
from django.utils.translation import gettext_lazy as _

# Create your models here.

GENDERS = [
("M", "Male"),
("F", "Female"),
("O", "Other"),
("N", "Prefer not to disclose"),
]
from .validators import validate_ieee_email
from .validators import validate_ieee_number
from .validators import validate_nitk_email
from .validators import validate_phone_number
from .validators import validate_reg_number
from .validators import validate_roll_number


class UserManager(BaseUserManager):
Expand Down Expand Up @@ -40,15 +41,111 @@ def users(self):


class User(AbstractUser):
GENDERS = [
("M", "Male"),
("F", "Female"),
("O", "Other"),
("N", "Prefer not to disclose"),
]

username = None
phone_no = models.CharField(max_length=13, unique=True, blank=False, null=False)
gender = models.CharField(max_length=1, choices=GENDERS, blank=False, null=False)
email = models.EmailField(unique=True, blank=False, null=False)
phone_no = models.CharField(
max_length=15,
unique=True,
verbose_name="Phone Number",
validators=[validate_phone_number],
)
gender = models.CharField(max_length=1, choices=GENDERS)
email = models.EmailField(unique=True, verbose_name="Personal Email")
anirudhprabhakaran3 marked this conversation as resolved.
Show resolved Hide resolved

USERNAME_FIELD = "email"
REQUIRED_FIELDS = []

objects = UserManager()

def save(self, *args, **kwargs):
phone = str(self.phone_no)
if len(phone) == 12 and phone.startswith("91"):
self.phone_no = phone[2:]
elif len(phone) == 13 and phone.startswith("+91"):
self.phone_no = phone[3:]

super(User, self).save(*args, **kwargs)

def __str__(self):
return f"{self.first_name} {self.last_name}"


class ExecutiveMember(models.Model):
NITK_DEPARTMENTS = [
("WO", "Water Resources and Ocean Engineering"),
("CH", "Chemical Engineering"),
("CM", "Chemistry"),
("CV", "Civil Engineering"),
("CS", "Computer Science and Engineering"),
("EE", "Electrical and Electronics Engineering"),
("EC", "Electronics and Communication Engineering"),
("IT", "Information Technology"),
("MA", "Mathematical and Computational Sciences"),
("ME", "Mechanical Engineering"),
("MT", "Metallurgical and Materials Engineering"),
("MN", "Mining Engineering"),
("PS", "Physics"),
("SM", "School of Humanities, Social Sciences and Management"),
]

user = models.OneToOneField(User, on_delete=models.CASCADE, primary_key=True)
sig = models.ForeignKey(SIG, on_delete=models.CASCADE)
edu_email = models.EmailField(
unique=True, verbose_name="NITK EDU Email", validators=[validate_nitk_email]
)
roll_number = models.CharField(
max_length=8,
unique=True,
verbose_name="NITK Roll Number",
validators=[validate_roll_number],
)
reg_number = models.CharField(
max_length=10,
unique=True,
verbose_name="NITK Registration Number",
validators=[validate_reg_number],
)
minor_branch = models.CharField(
max_length=2,
choices=NITK_DEPARTMENTS,
blank=True,
null=True,
verbose_name="Minor Branch",
)
ieee_number = models.CharField(
max_length=10,
blank=True,
null=True,
anirudhprabhakaran3 marked this conversation as resolved.
Show resolved Hide resolved
verbose_name="IEEE Membership Number",
validators=[validate_ieee_number],
)
ieee_email = models.EmailField(
blank=True,
null=True,
verbose_name="IEEE Email",
validators=[validate_ieee_email],
)
linkedin = models.URLField(
blank=True, null=True, verbose_name="Linkedin Profile URL"
)

# TODO: Phase out with GitHub OAuth details
github = models.CharField(blank=True, null=True, verbose_name="GitHub Username")
is_nep = models.BooleanField(default=False, verbose_name="Is NEP Member?")
date_joined = models.DateTimeField(
default=datetime.now(), verbose_name="Date Joined"
)

def save(self, *args, **kwargs):
self.roll_number = self.roll_number.upper()

super(ExecutiveMember, self).save(*args, **kwargs)

def __str__(self):
return f"{self.user.first_name} {self.user.last_name} [{self.sig.name}]"
Loading