Skip to content

Commit

Permalink
Merge 0672840 into 431ebed
Browse files Browse the repository at this point in the history
  • Loading branch information
jazwu committed Mar 8, 2024
2 parents 431ebed + 0672840 commit 026c670
Show file tree
Hide file tree
Showing 11 changed files with 241 additions and 99 deletions.
4 changes: 3 additions & 1 deletion healthScore/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# from django.contrib import admin
from django.contrib import admin
from .models import User

# Register your models here.
admin.site.register(User)
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Generated by Django 4.2 on 2024-03-08 12:53

import datetime
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("healthScore", "0004_user_groups_user_is_superuser_user_last_login_and_more"),
]

operations = [
migrations.AddField(
model_name="user",
name="date_joined",
field=models.DateTimeField(
default=datetime.datetime(
2024, 3, 8, 12, 53, 46, 829675, tzinfo=datetime.timezone.utc
)
),
),
migrations.AddField(
model_name="user",
name="is_active",
field=models.BooleanField(default=True),
),
migrations.AddField(
model_name="user",
name="is_staff",
field=models.BooleanField(default=False),
),
migrations.AlterField(
model_name="user",
name="email",
field=models.EmailField(max_length=254, unique=True),
),
migrations.AlterField(
model_name="user",
name="gender",
field=models.TextField(blank=True, default=""),
),
migrations.AlterField(
model_name="user",
name="is_superuser",
field=models.BooleanField(default=False),
),
migrations.AlterField(
model_name="user",
name="last_login",
field=models.DateTimeField(blank=True, null=True),
),
migrations.AlterField(
model_name="user",
name="name",
field=models.TextField(blank=True, default="", max_length=255),
),
]
17 changes: 17 additions & 0 deletions healthScore/migrations/0006_remove_user_date_joined.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 4.2 on 2024-03-08 13:40

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("healthScore", "0005_user_date_joined_user_is_active_user_is_staff_and_more"),
]

operations = [
migrations.RemoveField(
model_name="user",
name="date_joined",
),
]
27 changes: 27 additions & 0 deletions healthScore/migrations/0007_alter_user_options_user_date_joined.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Generated by Django 4.2 on 2024-03-08 13:51

import datetime
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("healthScore", "0006_remove_user_date_joined"),
]

operations = [
migrations.AlterModelOptions(
name="user",
options={"verbose_name": "User", "verbose_name_plural": "Users"},
),
migrations.AddField(
model_name="user",
name="date_joined",
field=models.DateTimeField(
default=datetime.datetime(
2024, 3, 8, 13, 51, 13, 776202, tzinfo=datetime.timezone.utc
)
),
),
]
17 changes: 17 additions & 0 deletions healthScore/migrations/0008_remove_user_date_joined.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 4.2 on 2024-03-08 13:55

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("healthScore", "0007_alter_user_options_user_date_joined"),
]

operations = [
migrations.RemoveField(
model_name="user",
name="date_joined",
),
]
67 changes: 44 additions & 23 deletions healthScore/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


# Create your models here.
class hospital(models.Model): # Viewed by healthScoreAdmin and hospitalAdmin
class Hospital(models.Model): # Viewed by healthScoreAdmin and hospitalAdmin
id = models.AutoField(primary_key=True)
name = models.TextField(null=False)
address = models.TextField(null=False)
Expand All @@ -25,7 +25,7 @@ class hospital(models.Model): # Viewed by healthScoreAdmin and hospitalAdmin
status = models.TextField(choices=STATUS_CHOICES, default="pending")


class hospitalStaff(models.Model): # Viewed by hospitalAdmin
class HospitalStaff(models.Model): # Viewed by hospitalAdmin
id = models.AutoField(primary_key=True)
hospitalID = models.ForeignKey("hospital", to_field="id", on_delete=models.CASCADE)
admin = models.BooleanField(default=False) # True = hospitalAdmin, False = Doctor
Expand All @@ -43,43 +43,53 @@ class hospitalStaff(models.Model): # Viewed by hospitalAdmin


class CustomUserManager(BaseUserManager):
def create_user(self, email, username, password=None, **extra_fields):
def _create_user(self, email, password, **extra_fields):
if not email:
raise ValueError("Users must have an email address")
user = self.model(
email=self.normalize_email(email), username=username, **extra_fields
)
raise ValueError("You have not provided a valid e-mail address")
user = self.model(email=self.normalize_email(email), **extra_fields)
user.set_password(password)
user.save(using=self._db)
return user

def create_superuser(self, email, username, password=None, **extra_fields):
extra_fields.setdefault("is_superuser", True)
extra_fields.setdefault("is_staff", True)
def create_user(self, email=None, password=None, **extra_fields):
extra_fields.setdefault("is_staff", False)
extra_fields.setdefault("is_superuser", False)
return self._create_user(email, password, **extra_fields)

return self.create_user(email, username, password, **extra_fields)
def create_superuser(self, email=None, password=None, **extra_fields):
extra_fields.setdefault("is_staff", True)
extra_fields.setdefault("is_superuser", True)
return self.create_user(email, password, **extra_fields)


class user(AbstractBaseUser, PermissionsMixin): # Viewed by User
class User(AbstractBaseUser, PermissionsMixin): # Viewed by User
id = models.AutoField(primary_key=True)
email = models.EmailField(null=False)
name = models.TextField(null=False)
email = models.EmailField(unique=True)
password = models.TextField(null=False)
username = models.CharField(null=False, max_length=50, unique=True)
dob = models.DateField(null=False)

is_active = models.BooleanField(default=True)
is_superuser = models.BooleanField(default=False)
is_staff = models.BooleanField(default=False)

last_login = models.DateTimeField(blank=True, null=True)

username = models.CharField(max_length=50, unique=True)
name = models.TextField(blank=True, max_length=255, default="")
dob = models.DateField()
contactInfo = models.TextField(default="", max_length=10)
address = models.TextField(null=False)
proofOfIdentity = models.TextField(
null=False
) # Convert image to base64 string and store it here
address = models.TextField(null=False)

securityQues = models.TextField(
default=""
) # If we not doing email resetting password
securityAns = models.TextField(
default=""
) # If we not doing email resetting password
gender = models.TextField(
default=""
blank=True, default=""
) # Can be updated to a choice field later on, if needed
profilePic = models.TextField(
null=True
Expand All @@ -90,13 +100,24 @@ class user(AbstractBaseUser, PermissionsMixin): # Viewed by User
) # Will store data in this form: [{ requestedBy: '', dateTime:'', status:''}]. Will have
# the data of all the requests that have been done to view the user's records

USERNAME_FIELD = "username"
REQUIRED_FIELDS = ["email"]
USERNAME_FIELD = "email"
EMAIL_FIELD = "email"
REQUIRED_FIELDS = ["username"]

objects = CustomUserManager()

class Meta:
verbose_name = "User"
verbose_name_plural = "Users"

def get_full_name(self):
return self.name

def get_short_name(self):
return self.username


class healthRecord(models.Model): # Viewed by User and hospitalStaff who are doctors
class HealthRecord(models.Model): # Viewed by User and hospitalStaff who are doctors
id = models.AutoField(primary_key=True)
doctorID = models.IntegerField(null=False)
userID = models.ForeignKey("user", to_field="id", on_delete=models.CASCADE)
Expand All @@ -110,7 +131,7 @@ class healthRecord(models.Model): # Viewed by User and hospitalStaff who are do
healthDocuments = models.JSONField(null=True)


class appointment(models.Model): # Viewed by User and hospitalStaff who are doctors
class Appointment(models.Model): # Viewed by User and hospitalStaff who are doctors
id = models.AutoField(primary_key=True)
name = models.TextField(null=False)
properties = models.JSONField(null=True)
Expand All @@ -121,7 +142,7 @@ class appointment(models.Model): # Viewed by User and hospitalStaff who are doc
# }


class communityInteraction(models.Model):
class CommunityInteraction(models.Model):
userID = models.ForeignKey("user", to_field="id", on_delete=models.CASCADE)
postID = models.AutoField(primary_key=True)
postTitle = models.TextField(null=False)
Expand Down
4 changes: 2 additions & 2 deletions healthScore/templates/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ <h2>Sign in to Your Health Score Account</h2>
</div>
{% endif %}
<div class="form-group">
<label for="username">Username:</label>
<input type="text" class="form-control" id="username" name="username" placeholder="Username">
<label for="email">Email:</label>
<input type="email" class="form-control" id="email" name="email" placeholder="Email">
</div>
<div class="form-group">
<label for="password">Password:</label>
Expand Down

0 comments on commit 026c670

Please sign in to comment.