From 983529e5cf9d3b54d03fb9d1538ecfe6eb51b66e Mon Sep 17 00:00:00 2001 From: Nishant Nayak Date: Fri, 5 Jan 2024 23:54:59 +0530 Subject: [PATCH 1/7] Modify startup script and update image spacing Signed-off-by: Nishant Nayak --- corpus/start_dev.sh | 2 +- corpus/templates/pages/index.html | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/corpus/start_dev.sh b/corpus/start_dev.sh index f1b3b5af..f88b6fe0 100755 --- a/corpus/start_dev.sh +++ b/corpus/start_dev.sh @@ -4,5 +4,5 @@ export DJANGO_SUPERUSER_PASSWORD=admin python manage.py migrate --no-input python manage.py loaddata config_db.json -python manage.py createsuperuser --no-input --username admin --email admin@example.com +python manage.py createsuperuser --no-input --email admin@example.com python manage.py runserver 0.0.0.0:8000 diff --git a/corpus/templates/pages/index.html b/corpus/templates/pages/index.html index b086a954..e59357ce 100644 --- a/corpus/templates/pages/index.html +++ b/corpus/templates/pages/index.html @@ -106,16 +106,16 @@

Piston

Societies

-
+
{% for society in societies %} {% if society.dark_image %} + alt="{{ society.name }} Logo" class="dark-logo h-14 lg:h-24 inline mx-5" /> + alt="{{ society.name }} Logo" class="light-logo h-14 lg:h-24 inline mx-5" /> {% else %} {{ society.name }} Logo + class="h-14 lg:h-24 inline mx-5" /> {% endif %} {% empty %}

There should be some societies here. Did you import the DB dump using @@ -123,16 +123,16 @@

Societies

{% endfor %}
-
+
{% for society in societies %} {% if society.dark_image %} + alt="{{ society.name }} Logo" class="dark-logo h-14 lg:h-24 inline mx-5" /> + alt="{{ society.name }} Logo" class="light-logo h-14 lg:h-24 inline mx-5" /> {% else %} {{ society.name }} Logo + class="h-14 lg:h-24 inline mx-5" /> {% endif %} {% empty %}

There should be some societies here. Did you import the DB dump using From 504d12562c6d57c6446c43fca0846a2fda17a943 Mon Sep 17 00:00:00 2001 From: Nishant Nayak Date: Sat, 6 Jan 2024 12:59:56 +0530 Subject: [PATCH 2/7] Copy SIG model from SIG Pages PR and fix Gender list scoping --- corpus/accounts/forms.py | 5 ++--- corpus/accounts/models.py | 14 +++++++------- corpus/config/models.py | 20 ++++++++++++++++++++ 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/corpus/accounts/forms.py b/corpus/accounts/forms.py index 3a12b014..3f89abf0 100644 --- a/corpus/accounts/forms.py +++ b/corpus/accounts/forms.py @@ -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" @@ -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 diff --git a/corpus/accounts/models.py b/corpus/accounts/models.py index 1f98fe7c..5b9b6ddd 100644 --- a/corpus/accounts/models.py +++ b/corpus/accounts/models.py @@ -5,13 +5,6 @@ # Create your models here. -GENDERS = [ - ("M", "Male"), - ("F", "Female"), - ("O", "Other"), - ("N", "Prefer not to disclose"), -] - class UserManager(BaseUserManager): def create_user(self, email, password, **kwargs): @@ -40,6 +33,13 @@ 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) diff --git a/corpus/config/models.py b/corpus/config/models.py index a5eb9722..bd2993a4 100644 --- a/corpus/config/models.py +++ b/corpus/config/models.py @@ -3,6 +3,25 @@ DATETIME_FORMAT = "%d-%m-%Y %H:%M:%S" +class SIG(models.Model): + """ + SIG Model. + Defines all SIGs that are part of IEEE NITK. + """ + + name = models.CharField(verbose_name="Name", max_length=10, unique=True) + about = models.TextField(verbose_name="About Us", default="") + what_we_do = models.TextField(verbose_name="What We Do", default="") + slug = models.SlugField(unique=True, null=True) # Added SlugField for url access + + def __str__(self): + return str(self.name) + + class Meta: + verbose_name = "SIG" + verbose_name_plural = "SIGs" + + class Society(models.Model): """ Society Model. @@ -61,6 +80,7 @@ class Society(models.Model): verbose_name="Dark Image", upload_to="img/logo/", blank=True, null=True ) description = models.TextField(verbose_name="Description") + sigs = models.ManyToManyField(SIG, related_name="societies") def __str__(self): return self.get_name_display() From 3e0efd962c47b4924bf3cea86c0cf6baa30a7d23 Mon Sep 17 00:00:00 2001 From: Nishant Nayak Date: Sat, 6 Jan 2024 15:32:01 +0530 Subject: [PATCH 3/7] Run pre-commit hooks on all files Signed-off-by: Nishant Nayak --- README.md | 2 ++ corpus/pages/views.py | 2 +- corpus/templates/static/img/symbols/arrow_down.svg | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7c48b123..a926c4fd 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/corpus/pages/views.py b/corpus/pages/views.py index da01fdfc..364ddf0b 100644 --- a/corpus/pages/views.py +++ b/corpus/pages/views.py @@ -24,4 +24,4 @@ def about_us(request): { "socieites": societies, }, - ) \ No newline at end of file + ) diff --git a/corpus/templates/static/img/symbols/arrow_down.svg b/corpus/templates/static/img/symbols/arrow_down.svg index 8acdf606..2de42af0 100644 --- a/corpus/templates/static/img/symbols/arrow_down.svg +++ b/corpus/templates/static/img/symbols/arrow_down.svg @@ -9,4 +9,4 @@ d="M11 15.675C10.7937 15.675 10.6219 15.6062 10.45 15.4687L2.54374 7.69998C2.23436 7.3906 2.23436 6.90935 2.54374 6.59998C2.85311 6.2906 3.33436 6.2906 3.64374 6.59998L11 13.7844L18.3562 6.53123C18.6656 6.22185 19.1469 6.22185 19.4562 6.53123C19.7656 6.8406 19.7656 7.32185 19.4562 7.63123L11.55 15.4C11.3781 15.5719 11.2062 15.675 11 15.675Z" fill="currentColor" /> - \ No newline at end of file + From c518b9e8a7c5dac7958a931520de57713e0d5494 Mon Sep 17 00:00:00 2001 From: Nishant Nayak Date: Sat, 6 Jan 2024 23:29:42 +0530 Subject: [PATCH 4/7] Add Executive Member Model Signed-off-by: Nishant Nayak --- corpus/accounts/admin.py | 34 ++++ ...ail_alter_user_phone_no_executivemember.py | 146 ++++++++++++++++++ corpus/accounts/models.py | 96 +++++++++++- corpus/accounts/validators.py | 56 +++++++ .../migrations/0004_sig_society_sigs.py | 43 ++++++ corpus/templates/accounts/signup.html | 2 +- corpus/templates/pages/index.html | 6 +- 7 files changed, 375 insertions(+), 8 deletions(-) create mode 100644 corpus/accounts/migrations/0002_alter_user_email_alter_user_phone_no_executivemember.py create mode 100644 corpus/accounts/validators.py create mode 100644 corpus/config/migrations/0004_sig_society_sigs.py diff --git a/corpus/accounts/admin.py b/corpus/accounts/admin.py index 5a5022a6..c5f61419 100644 --- a/corpus/accounts/admin.py +++ b/corpus/accounts/admin.py @@ -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. @@ -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) diff --git a/corpus/accounts/migrations/0002_alter_user_email_alter_user_phone_no_executivemember.py b/corpus/accounts/migrations/0002_alter_user_email_alter_user_phone_no_executivemember.py new file mode 100644 index 00000000..ca624aa5 --- /dev/null +++ b/corpus/accounts/migrations/0002_alter_user_email_alter_user_phone_no_executivemember.py @@ -0,0 +1,146 @@ +# Generated by Django 4.2.7 on 2024-01-06 17:44 +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(auto_now_add=True)), + ( + "sig", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, to="config.sig" + ), + ), + ], + ), + ] diff --git a/corpus/accounts/models.py b/corpus/accounts/models.py index 5b9b6ddd..52ef4df8 100644 --- a/corpus/accounts/models.py +++ b/corpus/accounts/models.py @@ -1,9 +1,15 @@ +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. +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): @@ -41,14 +47,96 @@ class User(AbstractUser): ] 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") 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, + 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(auto_now_add=True) + + def __str__(self): + return f"{self.user.first_name} {self.user.last_name} [{self.sig.name}]" diff --git a/corpus/accounts/validators.py b/corpus/accounts/validators.py new file mode 100644 index 00000000..3f1f4623 --- /dev/null +++ b/corpus/accounts/validators.py @@ -0,0 +1,56 @@ +from django.core.exceptions import ValidationError +from django.core.validators import EmailValidator +from django.core.validators import RegexValidator + + +def validate_phone_number(value): + if len(value) == 10: + validator = RegexValidator(regex=r"^[0-9]{10}$") + validator(value) + elif len(value) == 12 and value.startswith("91"): + validator = RegexValidator(regex=r"^91[0-9]{10}$") + validator(value) + elif len(value) == 13 and value.startswith("+91"): + validator = RegexValidator(regex=r"^\+91[0-9]{10}$") + validator(value) + + +def validate_nitk_email(value): + email_validator = EmailValidator(message="Email must end with @nitk.edu.in") + if not value.endswith("@nitk.edu.in"): + raise ValidationError("Email must end with @nitk.edu.in") + email_validator(value) + + +def validate_roll_number(value): + NITK_ROLL_NUMBER_REGEX = r"^[1-9][0-9]{2}[A-Z]{2}[0-9]{3}$" + roll_number_validator = RegexValidator( + regex=NITK_ROLL_NUMBER_REGEX, + message="Roll number should follow the format: 201XX123", + ) + roll_number_validator(value) + + +def validate_reg_number(value): + NITK_REG_NUMBER_REGEX = r"^[0-9]{6,}$" + reg_number_validator = RegexValidator( + regex=NITK_REG_NUMBER_REGEX, + message="Registration number should follow the format: 2010723", + ) + reg_number_validator(value) + + +def validate_ieee_number(value): + IEEE_NUMBER_REGEX = r"^[0-9]{8,}$" + ieee_number_validator = RegexValidator( + regex=IEEE_NUMBER_REGEX, + message="IEEE Membership number should follow the format: 97240288", + ) + ieee_number_validator(value) + + +def validate_ieee_email(value): + email_validator = EmailValidator(message="Email must end with @ieee.org") + if not value.endswith("@ieee.org"): + raise ValidationError("Email must end with @ieee.org") + email_validator(value) diff --git a/corpus/config/migrations/0004_sig_society_sigs.py b/corpus/config/migrations/0004_sig_society_sigs.py new file mode 100644 index 00000000..9bca0b41 --- /dev/null +++ b/corpus/config/migrations/0004_sig_society_sigs.py @@ -0,0 +1,43 @@ +# Generated by Django 4.2.7 on 2024-01-06 17:44 +from django.db import migrations +from django.db import models + + +class Migration(migrations.Migration): + + dependencies = [ + ("config", "0003_moduleconfiguration"), + ] + + operations = [ + migrations.CreateModel( + name="SIG", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ( + "name", + models.CharField(max_length=10, unique=True, verbose_name="Name"), + ), + ("about", models.TextField(default="", verbose_name="About Us")), + ("what_we_do", models.TextField(default="", verbose_name="What We Do")), + ("slug", models.SlugField(null=True, unique=True)), + ], + options={ + "verbose_name": "SIG", + "verbose_name_plural": "SIGs", + }, + ), + migrations.AddField( + model_name="society", + name="sigs", + field=models.ManyToManyField(related_name="societies", to="config.sig"), + ), + ] diff --git a/corpus/templates/accounts/signup.html b/corpus/templates/accounts/signup.html index 8617dcf7..84ac8a93 100644 --- a/corpus/templates/accounts/signup.html +++ b/corpus/templates/accounts/signup.html @@ -75,7 +75,7 @@

Sign Up

{{ form.email }} - Please use your personal email ID. + Please use your personal email ID. {% if form.email.errors %}
-
+
@@ -192,9 +192,9 @@

Stats

Events
-
34
+
34
From 150d6c3b4008591de0a209ea1db9f74975185df6 Mon Sep 17 00:00:00 2001 From: Nishant Nayak Date: Mon, 8 Jan 2024 20:16:18 +0530 Subject: [PATCH 5/7] Add logic to allow Executive Members to sign in with any unique identifier Signed-off-by: Nishant Nayak --- corpus/accounts/models.py | 5 +++++ corpus/accounts/views.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/corpus/accounts/models.py b/corpus/accounts/models.py index 52ef4df8..e9bb6964 100644 --- a/corpus/accounts/models.py +++ b/corpus/accounts/models.py @@ -138,5 +138,10 @@ class ExecutiveMember(models.Model): is_nep = models.BooleanField(default=False, verbose_name="Is NEP Member?") date_joined = models.DateTimeField(auto_now_add=True) + 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}]" diff --git a/corpus/accounts/views.py b/corpus/accounts/views.py index c8788924..e1b41435 100644 --- a/corpus/accounts/views.py +++ b/corpus/accounts/views.py @@ -1,4 +1,7 @@ +import re + from django.contrib import messages +from django.contrib.auth import authenticate from django.contrib.auth import login from django.contrib.auth import logout from django.shortcuts import redirect @@ -6,6 +9,7 @@ from .forms import CorpusCreationForm from .forms import CorpusLoginForm +from .models import ExecutiveMember # Create your views here. @@ -37,6 +41,34 @@ def signin(request): return redirect("index") else: return redirect(next) + else: + username = form.cleaned_data.get("username") + password = form.cleaned_data.get("password") + + if username.endswith("@nitk.edu.in"): + exec_member = ExecutiveMember.objects.filter(edu_email=username) + elif username.endswith("@ieee.org"): + exec_member = ExecutiveMember.objects.filter(ieee_email=username) + elif re.search(r"^[1-9][0-9]{2}[A-Za-z]{2}[0-9]{3}$", username) is not None: + exec_member = ExecutiveMember.objects.filter( + roll_number=username.upper() + ) + elif re.search(r"^[0-9]{6,}$", username) is not None: + exec_member = ExecutiveMember.objects.filter(reg_number=username) + else: + exec_member = [] + + if len(exec_member) == 1: + user = authenticate( + username=exec_member[0].user.email, password=password + ) + if user is not None: + login(request, user) + messages.success(request, "Welcome back to Corpus!") + if next == "": + return redirect("index") + else: + return redirect(next) else: form = CorpusLoginForm() From 2cf16e927685a7e309dfcda107c66953313273ed Mon Sep 17 00:00:00 2001 From: Nishant Nayak Date: Mon, 8 Jan 2024 21:33:21 +0530 Subject: [PATCH 6/7] Update Phone number validator Signed-off-by: Nishant Nayak --- ...user_email_alter_user_phone_no_executivemember.py | 12 ++++++++++-- corpus/accounts/models.py | 6 +++++- corpus/accounts/validators.py | 11 ++--------- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/corpus/accounts/migrations/0002_alter_user_email_alter_user_phone_no_executivemember.py b/corpus/accounts/migrations/0002_alter_user_email_alter_user_phone_no_executivemember.py index ca624aa5..2c88110b 100644 --- a/corpus/accounts/migrations/0002_alter_user_email_alter_user_phone_no_executivemember.py +++ b/corpus/accounts/migrations/0002_alter_user_email_alter_user_phone_no_executivemember.py @@ -1,4 +1,6 @@ -# Generated by Django 4.2.7 on 2024-01-06 17:44 +# 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 @@ -134,7 +136,13 @@ class Migration(migrations.Migration): "is_nep", models.BooleanField(default=False, verbose_name="Is NEP Member?"), ), - ("date_joined", models.DateTimeField(auto_now_add=True)), + ( + "date_joined", + models.DateTimeField( + default=datetime.datetime(2024, 1, 8, 21, 32, 24, 610176), + verbose_name="Date Joined", + ), + ), ( "sig", models.ForeignKey( diff --git a/corpus/accounts/models.py b/corpus/accounts/models.py index e9bb6964..f4269e89 100644 --- a/corpus/accounts/models.py +++ b/corpus/accounts/models.py @@ -1,3 +1,5 @@ +from datetime import datetime + from config.models import SIG from django.contrib.auth.base_user import BaseUserManager from django.contrib.auth.models import AbstractUser @@ -136,7 +138,9 @@ class ExecutiveMember(models.Model): # 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(auto_now_add=True) + date_joined = models.DateTimeField( + default=datetime.now(), verbose_name="Date Joined" + ) def save(self, *args, **kwargs): self.roll_number = self.roll_number.upper() diff --git a/corpus/accounts/validators.py b/corpus/accounts/validators.py index 3f1f4623..c322a7c8 100644 --- a/corpus/accounts/validators.py +++ b/corpus/accounts/validators.py @@ -4,15 +4,8 @@ def validate_phone_number(value): - if len(value) == 10: - validator = RegexValidator(regex=r"^[0-9]{10}$") - validator(value) - elif len(value) == 12 and value.startswith("91"): - validator = RegexValidator(regex=r"^91[0-9]{10}$") - validator(value) - elif len(value) == 13 and value.startswith("+91"): - validator = RegexValidator(regex=r"^\+91[0-9]{10}$") - validator(value) + validator = RegexValidator(regex=r"^\+?[0-9]{8,14}$") + validator(value) def validate_nitk_email(value): From b9d4689393736be7494fc6fddb45caa1b2c19df1 Mon Sep 17 00:00:00 2001 From: Nishant Nayak Date: Mon, 8 Jan 2024 22:23:41 +0530 Subject: [PATCH 7/7] Update condition check to make more Pythonic Signed-off-by: Nishant Nayak --- corpus/accounts/views.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/corpus/accounts/views.py b/corpus/accounts/views.py index e1b41435..aeefe9aa 100644 --- a/corpus/accounts/views.py +++ b/corpus/accounts/views.py @@ -56,9 +56,9 @@ def signin(request): elif re.search(r"^[0-9]{6,}$", username) is not None: exec_member = ExecutiveMember.objects.filter(reg_number=username) else: - exec_member = [] + exec_member = None - if len(exec_member) == 1: + if exec_member is not None: user = authenticate( username=exec_member[0].user.email, password=password )