diff --git a/studysite/templates/studysite/restricted/profile.html b/studysite/templates/studysite/restricted/profile.html index 7170c66..8f9fea4 100644 --- a/studysite/templates/studysite/restricted/profile.html +++ b/studysite/templates/studysite/restricted/profile.html @@ -29,9 +29,15 @@
Friends:
Courses:
{% if courses %} {% endif %}
diff --git a/studysite/urls.py b/studysite/urls.py index e53bc3e..3154f43 100644 --- a/studysite/urls.py +++ b/studysite/urls.py @@ -33,4 +33,5 @@ path('accept_friend_request//', views.accept_friend_request, name="accept friend request"), path('buddies/', views.BuddyView.as_view(), name='buddy-finder'), path('notifications/', views.NotifView.as_view(), name='notifications'), + path('/profile/', views.deleteCourseFromUser, name='delete-course'), ] diff --git a/studysite/views.py b/studysite/views.py index 9c84151..fa4e195 100644 --- a/studysite/views.py +++ b/studysite/views.py @@ -117,6 +117,28 @@ def addCourseToUser(request, pk, pku): 'courses_list': Course.objects.order_by('course_subject'), }) +def deleteCourseFromUser(request, uid, pk): + course = get_object_or_404(Course, pk=pk) + try: + selected_course = Course.objects.get(pk=pk) + except (KeyError, User.DoesNotExist): + # Redisplay the question voting form. + print("Website doesn't exist") + return render(request, 'studysite/restricted/profile.html', { + 'courses_list': User.objects.get(id=uid).course_set.all(), + }) + else: + selected_course.course_roster.remove(uid) + print(selected_course.course_roster.all()) + #ProfileView.request.user.pk + selected_course.save() + # Always return an HttpResponseRedirect after successfully dealing + # with POST data. This prevents data from being posted twice if a + # user hits the Back button. + return render(request, 'studysite/restricted/profile.html', { + 'courses_list': User.objects.get(id=uid).course_set.all(), + }) + def send_friend_request(request, uid): fromu = request.user tou = User.objects.get(id=uid)