From abd4dc4f54816d81f9aea7ecedfb24ae58e8e496 Mon Sep 17 00:00:00 2001 From: Praneeth Bhandaru Date: Sun, 13 Dec 2020 13:17:48 -0500 Subject: [PATCH] Work --- site/frontend/forms.py | 2 +- site/frontend/urls.py | 3 +- site/frontend/views.py | 20 +++++ site/templates/frontend/class.html | 94 +++++++++++++++++++++- site/templates/frontend/editClassroom.html | 80 ++++++++++++++++++ site/templates/frontend/temp.html | 8 +- 6 files changed, 200 insertions(+), 7 deletions(-) create mode 100644 site/templates/frontend/editClassroom.html diff --git a/site/frontend/forms.py b/site/frontend/forms.py index 4b24724a..871b7519 100644 --- a/site/frontend/forms.py +++ b/site/frontend/forms.py @@ -10,7 +10,7 @@ class UserRegisterForm(UserCreationForm): class Meta: model = User - fields = ["username", "email", "password1", "password2"] + fields = ["username", "email", "first_name", "last_name", "password1", "password2"] def __init__(self, *args, **kwargs): super(UserRegisterForm, self).__init__(*args, **kwargs) diff --git a/site/frontend/urls.py b/site/frontend/urls.py index 91b82cdc..c58cb143 100644 --- a/site/frontend/urls.py +++ b/site/frontend/urls.py @@ -35,5 +35,6 @@ urlpatterns = [ path("create_user/", register_view, name="create_user"), path("", home_view, name="home"), path("classes", class_form_view, name="classroom_form"), - path("classes/", classroom_view, name="class") + path("classes/", classroom_view, name="class"), + path("classes//edit", classroom_edit_view, name="edit_class"), ] diff --git a/site/frontend/views.py b/site/frontend/views.py index 0dc63133..1410c087 100644 --- a/site/frontend/views.py +++ b/site/frontend/views.py @@ -60,8 +60,28 @@ def class_form_view(request): return render(request, "frontend/classroomForm.html", {"form": form}) +@login_required def classroom_view(request, id): classroom = Classroom.objects.get(id=id) if classroom.student.user.pk != request.user.pk: return HttpResponseForbidden('You do not have access to this class') return render(request, "frontend/class.html", {'class': classroom}) + + +def classroom_edit_view(request, id): + classroom = Classroom.objects.get(id=id) + if classroom.student.user.pk != request.user.pk: + return HttpResponseForbidden('You do not have access to this class') + + + if request.method == 'POST': + form = ClassroomForm(request.POST, instance=classroom) + + if form.is_valid(): + classroom = form.save() + classroom.save() + return redirect(f'out/classes/{id}') + + form = ClassroomForm(instance=classroom) + + return render(request, 'frontend/editClassroom.html', {'form': form}) \ No newline at end of file diff --git a/site/templates/frontend/class.html b/site/templates/frontend/class.html index 086c1cd2..abdf4faf 100644 --- a/site/templates/frontend/class.html +++ b/site/templates/frontend/class.html @@ -2,14 +2,39 @@ {% load static %} {% block content %} -
+
+ + + + + +
+
+
+
+ +

Welcome to your class page for {{ class.name }} +

+

+ You can view and edit your class information here!

+
+ EDIT +
+
+
+
+
+ +
+

- Your Class: {{ class.name }}

+

@@ -17,6 +42,16 @@

Teacher: {{ class.teacher }}

+



+
+

Period: {{ class.period }}

+
+



+ + +
{% endblock content %} @@ -28,5 +63,60 @@ .class_cont { text-align: center; } + + + + {% endblock %} \ No newline at end of file diff --git a/site/templates/frontend/editClassroom.html b/site/templates/frontend/editClassroom.html new file mode 100644 index 00000000..2e08b69f --- /dev/null +++ b/site/templates/frontend/editClassroom.html @@ -0,0 +1,80 @@ +{% extends 'frontend/index.html' %} +{% load static %} +{% load crispy_forms_tags %} + + + +{% block head %} + + + + + + + + + + + + + + + + + + + + + + + +{% endblock head %} + +{% block content %} +