Skip to content

Commit 3041f9a

Browse files
last temp
1 parent 3f24d5c commit 3041f9a

File tree

14 files changed

+274
-17
lines changed

14 files changed

+274
-17
lines changed

api/academics/urls.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
from academics.views import MarksViewSet, AttendanceViewSet
1+
from academics.views import MarksViewSet, AttendanceViewSet, get_branch_names
22

33
from django.urls import path
44

55
urlpatterns = [
6+
path('metadata/branches', get_branch_names, name='get_branch_names'),
67
path('marks/', MarksViewSet.as_view({
78
'get': 'list',
89
'post': 'create'

api/academics/views.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
1-
from rest_framework import viewsets
2-
from academics.models import Marks, Attendance
1+
from rest_framework.decorators import api_view
2+
from rest_framework import viewsets, status
3+
from academics.models import Marks, Attendance, Branch
34
from academics.serializers import MarksSerializer, AttendanceSerializer
45
from rest_framework.response import Response
56
from django.shortcuts import get_object_or_404
67
from core.permissions import isAdmin, isStaff, isOwner
78

89

10+
@api_view(['GET'])
11+
def get_branch_names(request):
12+
branches = Branch.objects.all()
13+
branches = [(branch.code, branch.name) for branch in branches]
14+
return Response(branches, status.HTTP_200_OK)
15+
16+
917
class MarksViewSet(viewsets.ModelViewSet):
1018
queryset = Marks.objects.all()
1119
serializer_class = MarksSerializer

api/api/settings.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,4 +159,9 @@
159159
EMAIL_HOST_PASSWORD = secrets.EMAIL_HOST_PASSWORD
160160

161161
MEDIA_ROOT = Path(BASE_DIR) / 'media'
162-
MEDIA_URL = '/media/'
162+
MEDIA_URL = '/media/'
163+
164+
165+
# Client URLs to be sent in verification and password reset emails
166+
CHANGE_PASSWORD_URL = 'http://localhost:8000/type/forgot-password'
167+
RESET_PASSWORD_URL = 'http://localhost:8000/type/reset-password'

api/core/views.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,19 +101,17 @@ def core_change_password(request, user_type='Admin'):
101101

102102

103103
# send email
104-
# change_password_url = request.get_host() + reverse(f"{self.basename}-{self.change_password.url_name}")
105-
# reset_password_url = request.get_host() + reverse(f"{self.basename}-{self.password_reset.url_name}")
106-
change_password_url = 'dummy'
107-
reset_password_url = 'dummy'
104+
change_password_url = settings.CHANGE_PASSWORD_URL.replace('type', user.user_type.lower())
105+
reset_password_url = f"{settings.RESET_PASSWORD_URL.replace('type', user.user_type.lower())}?token={req.key}"
108106

109107
send_mail(
110108
f"BIT Online Portal password account verification" if first_time else f"BIT Online Portal password reset",
111109
f'''An account has been created for you in the {user_type} Portal of the BIT website.\n\n
112-
Please click on the following link to verify the account by setting your password: {reset_password_url}?token={req.key}\n\n
110+
Please click on the following link to verify the account by setting your password: {reset_password_url}\n\n
113111
This link is only valid for the next 48 hours. In order to issue a password-reset request again, visit {change_password_url}
114112
If you are not {user.name}, then please ignore this email.'''.replace('\t\t', '') if first_time else
115113
f'''We have received a request to reset the password for your account in the {user_type} Portal of the BIT website.
116-
Please click on the following link to reset your password: {reset_password_url}?token={req.key}\n\n
114+
Please click on the following link to reset your password: {reset_password_url}\n\n
117115
This link is only valid for the next 30 minutes. In order to issue a password-reset request again, visit {change_password_url}
118116
If you did not request a password reset, please ignore this email.'''.replace('\t\t', ''),
119117
"superuser.bit@gmail.com",

api/db.sqlite3

8 KB
Binary file not shown.

api/staff/views.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,12 @@ def update(self, request, *args, **kwargs):
9595

9696
def destroy(self, request, *args, **kwargs):
9797
instance = self.get_object()
98+
user_id = instance.user.id
99+
98100
self.perform_destroy(instance.user)
99101
self.perform_destroy(instance)
100-
return Response(status=status.HTTP_200_OK)
102+
103+
return Response({'success': f"User {user_id} deleted successfully."}, status=status.HTTP_200_OK)
101104

102105
def get_serializer_class(self):
103106
if self.action == 'update' or self.action == 'partial_update':

api/student/views.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,12 @@ def update(self, request, *args, **kwargs):
111111

112112
def destroy(self, request, *args, **kwargs):
113113
instance = self.get_object()
114+
user_id = instance.user.id
115+
114116
self.perform_destroy(instance.user)
115117
self.perform_destroy(instance)
116-
return Response({'success': f"User {instance.user.id} deleted successfully."}, status=status.HTTP_200_OK)
118+
119+
return Response({'success': f"User {user_id} deleted successfully."}, status=status.HTTP_200_OK)
117120

118121
def get_serializer_class(self):
119122
if self.action == 'update' or self.action == 'partial_update':

client/common.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,11 @@ def delete_atendance(token, student_id, subject_id):
6666
response = requests.delete(headers={'Authorization': 'Token ' + token}, url=f"{root}/atendance/{student_id}-{subject_id}/")
6767
dict = json.loads(response.text)
6868
return dict, response.status_code
69+
70+
71+
72+
# Metadata:
73+
def get_branch_names():
74+
response = requests.get(url=f"{root}/metadata/branches")
75+
dict = json.loads(response.text)
76+
return dict, response.status_code

todo.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ Permissions:
1212

1313

1414
WEBSITE:
15-
- create student, send verification email after
1615
- create content blocks in templates
1716
- logout button
18-
- student and staff portals
17+
- create user button
18+
- student and staff portals
19+
- batch create users

website/admin/forms.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,31 @@ class LoginForm(forms.Form):
1010
widget=forms.PasswordInput(render_value = True, attrs={'placeholder': 'Enter your password'}),
1111
label='Password')
1212

13+
14+
class CreateStudentForm(forms.Form):
15+
def __init__(self, *args, **kwargs):
16+
choices = kwargs.pop('branch_choices', ())
17+
super().__init__(*args, **kwargs)
18+
self.fields['branch'].choices = choices
19+
20+
id = forms.CharField(max_length=15, label='USN')
21+
email = forms.EmailField(max_length = 254, label='Email')
22+
name = forms.CharField(max_length=100, label='Name')
23+
branch = forms.ChoiceField(choices=(), label='Branch')
24+
current_sem = forms.IntegerField(initial=1, min_value=1, label='Student Semester')
25+
26+
class CreateStaffForm(forms.Form):
27+
def __init__(self, *args, **kwargs):
28+
choices = kwargs.pop('branch_choices', ())
29+
super().__init__(*args, **kwargs)
30+
self.fields['branch'].choices = choices
31+
32+
id = forms.CharField(max_length=15, label='USN')
33+
email = forms.EmailField(max_length = 254, label='Email')
34+
name = forms.CharField(max_length=100, label='Name')
35+
branch = forms.ChoiceField(choices=(), label='Branch')
36+
37+
1338
class EditStudentForm(forms.Form):
1439
name = forms.CharField(max_length=254, label='Name')
1540
# email = forms.EmailField(max_length=254, label='Email')
@@ -19,6 +44,7 @@ class EditStudentForm(forms.Form):
1944
branch = forms.CharField(max_length=64, label='Branch')
2045
current_sem = forms.IntegerField(label='Current Semester')
2146

47+
2248
class EditStaffForm(forms.Form):
2349
name = forms.CharField(max_length=254, label='Name')
2450
branch = forms.CharField(max_length=64, label='Branch')

0 commit comments

Comments
 (0)