Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added delete course to profile #49

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 9 additions & 3 deletions studysite/templates/studysite/restricted/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,15 @@ <h6>Friends: </h6>
<h6>Courses: </h6>
{% if courses %}
<ul class="list-group list-group-flush" >
{% for course in courses %}
<li class="list-group-item">{{ course.course_subject }} {{ course.course_number }}</li>
{% endfor %}
{% for course in courses %}
<form action="{% url 'delete-course' user.id course.pk %}" method="POST" id="delete-course-user-form">
{% csrf_token %}
<li class="list-group-item">{{ course.course_subject }} {{ course.course_number }}</li>
<div class="d-flex justify-content-end">
<input class="btn" type="submit" value="delete" style="font-size: 4.5vw;"/>
</div>
</form>
{% endfor %}
</ul>
{% endif %}
</br>
Expand Down
1 change: 1 addition & 0 deletions studysite/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@
path('accept_friend_request/<int:rid>/', 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('<str:uid>/profile/<int:pk>', views.deleteCourseFromUser, name='delete-course'),
]
22 changes: 22 additions & 0 deletions studysite/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down