Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
8d1361c
add student folder
wanguimbutu Dec 22, 2022
99fa961
Merge pull request #1 from AxleBee/mbutu
wanguimbutu Dec 22, 2022
4fbbde7
Adds employer's dashboard file
danielevans-999 Dec 22, 2022
e3d6043
Merge pull request #2 from AxleBee/daniel/antony
AxleBee Dec 22, 2022
bb14c62
Add file via upload
Amiratul008 Dec 22, 2022
9181bed
Adds application files
danielevans-999 Dec 23, 2022
baa6195
Adds backend files
danielevans-999 Dec 23, 2022
05260c1
Adds the User model
danielevans-999 Dec 23, 2022
97f7147
Registers the app and install the rest_framework
danielevans-999 Dec 23, 2022
3430edc
adds login and register serializers classes
danielevans-999 Dec 23, 2022
8ef4e44
Adds Login and Register API view
danielevans-999 Dec 23, 2022
f2809a5
Change user type
danielevans-999 Dec 23, 2022
7538f3d
Adds routing module
danielevans-999 Dec 23, 2022
318c338
Registers the app url to the project
danielevans-999 Dec 23, 2022
533f204
Specifies the user auth model
danielevans-999 Dec 23, 2022
06b2b93
Implement register and Login endpoints
danielevans-999 Dec 26, 2022
fc627dc
Add login required
danielevans-999 Dec 26, 2022
4841c3b
Registers users
danielevans-999 Dec 26, 2022
0673cf8
Adds models
danielevans-999 Dec 28, 2022
be7a6ce
Add class method
danielevans-999 Dec 28, 2022
4c43706
Adds the logout and login api endpoints
danielevans-999 Dec 28, 2022
a19740e
Adds the logout and login api views
danielevans-999 Dec 28, 2022
cb9e163
Adds the media path
danielevans-999 Dec 28, 2022
f9b8e77
Initial commit
danielevans-999 Dec 28, 2022
ba88241
Changes
danielevans-999 Dec 28, 2022
c46fc2a
Adds templates
danielevans-999 Dec 30, 2022
40d85cd
Adds forms for registaration
danielevans-999 Dec 30, 2022
e60ca05
Adds static folder for static files
danielevans-999 Dec 30, 2022
1c80b2e
Adds a user_type field
danielevans-999 Dec 30, 2022
d0b56aa
Adds views
danielevans-999 Dec 30, 2022
017afb5
Adds routes
danielevans-999 Dec 30, 2022
3b65a15
styles the registration page
danielevans-999 Dec 30, 2022
98b310b
Updates the logout url
danielevans-999 Dec 30, 2022
14d4c41
Adds register and login forms
danielevans-999 Dec 30, 2022
245b285
Updates the login and logout views
danielevans-999 Dec 30, 2022
7f3d1c2
Styles the login and registeration forms
danielevans-999 Dec 30, 2022
72de06d
Stages changes
danielevans-999 Dec 31, 2022
bd3fa19
Changes the query key for student and attachment models
danielevans-999 Dec 31, 2022
9c88d46
Adds the add-attachment view
danielevans-999 Jan 1, 2023
5eadd06
Adds add-attachment and student-profile urls
danielevans-999 Jan 1, 2023
481f3f2
Adds the students views
danielevans-999 Jan 4, 2023
8d302f4
Adds studentst templates
danielevans-999 Jan 4, 2023
8a7eaa0
Styles the student's profile page
danielevans-999 Jan 4, 2023
a73b7cf
Adds the media url settings
danielevans-999 Jan 4, 2023
5e1fd9a
Adds supervisor dashboard templater
danielevans-999 Jan 4, 2023
8a1fedb
Adds the supervisor css file
danielevans-999 Jan 4, 2023
46d291d
Adds the comments and Employer models
danielevans-999 Jan 9, 2023
e22c70b
Adds the supervisor and employer routes
danielevans-999 Jan 9, 2023
228cf62
Adds the supervisor and Employer views
danielevans-999 Jan 9, 2023
c6081df
Adds html templates for Student, Employer and Supervisor views
danielevans-999 Jan 9, 2023
cb8aaee
Adds styling for the templates
danielevans-999 Jan 9, 2023
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
5 changes: 5 additions & 0 deletions backend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/venv
app/__pycache__/
attachment/__pycache__/
app/migrations/
zbackup.txt
Empty file added backend/app/__init__.py
Empty file.
Binary file added backend/app/__pycache__/__init__.cpython-37.pyc
Binary file not shown.
Binary file added backend/app/__pycache__/admin.cpython-37.pyc
Binary file not shown.
Binary file added backend/app/__pycache__/apps.cpython-37.pyc
Binary file not shown.
Binary file added backend/app/__pycache__/models.cpython-37.pyc
Binary file not shown.
Binary file not shown.
Binary file added backend/app/__pycache__/urls.cpython-37.pyc
Binary file not shown.
Binary file added backend/app/__pycache__/views.cpython-37.pyc
Binary file not shown.
3 changes: 3 additions & 0 deletions backend/app/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
6 changes: 6 additions & 0 deletions backend/app/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class AppConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'app'
53 changes: 53 additions & 0 deletions backend/app/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
from django import forms
from django.contrib.auth.forms import UserCreationForm
from .models import *


class CustomUserCreationForm(UserCreationForm):
class Meta:
model = User
fields = [ 'user_type', 'email', 'username']

USER_TYPES = (

('employer', "Employer"),
('supervisor', "Supervisor"),
('student', "Student"),
)
user_type = forms.ChoiceField(widget=forms.Select(attrs={
'class': "input-field",
}
), choices=USER_TYPES)

email = forms.Field(widget=forms.EmailInput(attrs={
'class': "input-field",
"placeholder": "Enter Email",
}), label='')
username = forms.Field(widget=forms.TextInput(attrs={
'class': "input-field",
"placeholder": "Enter username"
}), label='')
password1 = forms.Field(widget=forms.PasswordInput(attrs={
'class': "input-field",
"placeholder": "Enter password",
}), label='')
password2 = forms.Field(widget=forms.PasswordInput(attrs={
'class': "input-field",
"placeholder": "confirm password",

}), label='')


def clean_password2(self):
password1 = self.cleaned_data.get("password1")
password2 = self.cleaned_data.get("password2")
if password1 and password2 and password1 != password2:
raise forms.ValidationError("Passwords don't match")
return password2

def save(self, commit=True):
user = super().save(commit=False)
user.set_password(self.cleaned_data["password1"])
if commit:
user.save()
return user
30 changes: 30 additions & 0 deletions backend/app/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Generated by Django 3.2.16 on 2022-12-27 07:46

from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='User',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('password', models.CharField(max_length=128, verbose_name='password')),
('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
('email', models.EmailField(max_length=100, unique=True)),
('username', models.CharField(max_length=100)),
('user_type', models.CharField(max_length=10)),
('is_active', models.BooleanField(default=True)),
('is_admin', models.BooleanField(default=False)),
],
options={
'abstract': False,
},
),
]
Empty file.
Binary file not shown.
Binary file not shown.
158 changes: 158 additions & 0 deletions backend/app/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
from django.db import models
import datetime
from django.contrib.auth.models import (BaseUserManager, AbstractBaseUser)
# Create your models here.


class UserManager(BaseUserManager):

def create_user(self, username, email, user_type, password=None):
if username is None:
raise TypeError('Users must have a username')
if email is None:
raise TypeError('Users must have a Email')

user = self.model(

username=username,
user_type=user_type,
email=self.normalize_email(email)

)
user.set_password(password)
user.save()
return user

def create_superuser(self, email, user_type, username, password=None):

user = self.create_user(

email,
user_type=user_type,
username=username,
password=password,

)

user.is_admin = True
user.is_superuser = True
user.is_staff = True
user.save(using=self._db)
return user


class User(AbstractBaseUser):

USER_TYPE_CHOICES = (

('employer', "Employer"),
('supervisor', "Supervisor"),
('student', "Student"),
)

email = models.EmailField(max_length=100, unique=True)
username = models.CharField(max_length=100)
user_type = models.CharField(max_length=10)
is_active = models.BooleanField(default=True)
is_admin = models.BooleanField(default=False)
date_joined = models.DateTimeField(auto_now_add=True)
last_login = models.DateTimeField(auto_now_add=True)
updated_profile = models.BooleanField(default=False)
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = ['username', 'user_type']

objects = UserManager()

def __str__(self):
return self.email


class Student(models.Model):

admission_no = models.CharField(max_length=100, unique=True)
name = models.CharField(max_length=255)
course = models.CharField(max_length=255)
year = models.IntegerField(blank=True, null=True)
photo_url = models.ImageField(upload_to="images/")
assessed_by_employer = models.BooleanField(default=False)
user = models.OneToOneField(
User, primary_key=True, on_delete=models.CASCADE)

@classmethod
def get_profile_info(cls, email):
profile_info = cls.objects.filter(email=email).first()
return profile_info

@classmethod
def update_profile(cls, id, admission_no, name, course):
cls.objects.filter(pk=id).update(
admission_no=admission_no, name=name, course=course)
new_name_object = cls.objects.get(admission_no=admission_no)
new_name = new_name_object.admission_no
return new_name


class Attachment(models.Model):
attachment_name = models.CharField(max_length=100)
department_name = models.CharField(max_length=100)
start_date = models.DateField(default=datetime.date.today)
end_date = models.DateField(default=datetime.date.today)
student = models.OneToOneField(
Student, primary_key=True, on_delete=models.CASCADE)

@classmethod
def get_profile_info(cls, email):
attachment_info = cls.objects.get(email=email).first()
return attachment_info


class LogBook(models.Model):
date = models.DateField(auto_now=False)
activity = models.CharField(max_length=1000)
status = models.BooleanField(default=False)
student = models.ForeignKey(Student, on_delete=models.CASCADE, )

def verify(self):
self.verified = True
return True


class Supervisor(models.Model):
name = models.CharField(max_length=255)
postion = models.CharField(max_length=255)
phone = models.CharField(max_length=20)
photo_url = models.ImageField(upload_to="images/")
user = models.OneToOneField(
User, primary_key=True, on_delete=models.CASCADE)


class Comments(models.Model):
comment = models.CharField(max_length=1000)
supervisor = models.ForeignKey(Supervisor, on_delete=models.CASCADE)
logbook = models.ForeignKey(LogBook, on_delete=models.CASCADE)

@classmethod
def get_comments(cls, id):
comments = cls.objects.filter(update__id=id)
return comments

def save_comment(self):
self.save()

def __str__(self):
return self.comment


class Employer(models.Model):
name = models.CharField(max_length=255)
organisation = models.CharField(max_length=255)
postion = models.CharField(max_length=255)
phone = models.CharField(max_length=20)
photo_url = models.ImageField(upload_to="images/")
user = models.OneToOneField(
User, primary_key=True, on_delete=models.CASCADE)


class EmployerComment(models.Model):
comment = models.CharField(max_length=1000)
student = models.OneToOneField(Student, on_delete=models.CASCADE)
94 changes: 94 additions & 0 deletions backend/app/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
from rest_framework import serializers
from .models import *
from django.contrib.auth import authenticate
from rest_framework.exceptions import AuthenticationFailed

class RegisterSerializer(serializers.ModelSerializer):

password = serializers.CharField(max_length=68, min_length=6, write_only=True)
class Meta:
model = User
fields = ['email', 'username', 'user_type', 'password']


def validate(self, attrs):
email = attrs.get('email', '')
username = attrs.get('username', '')
user_type = attrs.get('user_type', '')

if not email:
raise serializers.ValidationError('Users should have an Email.')

return attrs
def create(self, validated_data):

return User.objects.create_user(**validated_data)



class LoginSerializer(serializers.ModelSerializer):

email = serializers.EmailField(max_length=255, min_length=3 )
password=serializers.CharField(max_length=68, min_length=6, write_only=True)
username =serializers.CharField(max_length=255, min_length=3, read_only=True)
user_type =serializers.CharField(max_length=255, min_length=3, read_only=True)
authenticated = serializers.BooleanField(read_only=True)
class Meta:
model=User
fields = ['email', 'password', 'username', 'user_type', 'authenticated']

def validate(self, attrs):
email =attrs.get('email', '')
password= attrs.get('password', '')


user = authenticate(email=email, password=password)

if not user:
raise AuthenticationFailed('Invalid credetinals')

if not user.is_active:
raise AuthenticationFailed('Account disabled contact Admin.')

return {

'email': user.email,
'username': user.username,
'user_type': user.user_type,
'authenticated': user
}



class StudentSerializer(serializers.ModelSerializer):

admission_no = serializers.CharField(max_length=100)
name = serializers.CharField(max_length=255)
course = serializers.CharField(max_length=255)
department = serializers.CharField(max_length=255)
photo_url = serializers.ImageField(required=False)
user = serializers.ReadOnlyField(source='user.email')


class Meta:
model = Student
fields = ['admission_no', 'name', 'course', 'department', 'photo_url', 'user']

def validate(self, attrs):
admission =attrs.get('admission_no', '')

if not admission:
raise ValueError("Student must have admission number")

return attrs
def create(self, validated_data):
user = self.context
return Student.objects.create(**validated_data, user = user)








Loading