-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add permissions and client-side subvertical loading
- Loading branch information
1 parent
0bc2e88
commit 30f3ec1
Showing
10 changed files
with
137 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from django.http import HttpResponseForbidden | ||
from django.conf import settings | ||
|
||
|
||
class VerticalTaggingAdministratorPermissionRequiredMixin: | ||
""" | ||
A mixin to enforce permission on VERTICALS_MANAGEMENT_GROUPS for the class-based views. | ||
""" | ||
|
||
def dispatch(self, request, *args, **kwargs): | ||
if not request.user.is_authenticated: | ||
return HttpResponseForbidden("You need to be logged in to access this page.") | ||
|
||
is_in_group = request.user.groups.filter( | ||
name__in=settings.VERTICALS_MANAGEMENT_GROUPS | ||
).exists() | ||
|
||
if not request.user.is_superuser and not is_in_group: | ||
return HttpResponseForbidden("You do not have permission to access this page.") | ||
|
||
return super().dispatch(request, *args, **kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 0 additions & 50 deletions
50
course_discovery/apps/tagging/templates/tagging/course_detail.html
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
course_discovery/apps/tagging/templates/tagging/course_tagging_detail.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
{% extends "tagging/base.html" %} | ||
|
||
{% block content %} | ||
<div class="container mt-5"> | ||
<h1 class="mb-4">Course: {{ course.title }}</h1> | ||
<h2>Key: {{ course.key }}</h2> | ||
|
||
<h3>Assign or Edit Vertical and Sub-Vertical</h3> | ||
<form method="post" action="" | ||
hx-post="" | ||
hx-target="#message-container" | ||
hx-swap="innerHTML"> | ||
{% csrf_token %} | ||
|
||
<div class="form-group"> | ||
<label for="vertical">Vertical</label> | ||
<select name="vertical" id="vertical" class="form-control" | ||
hx-trigger="change" | ||
hx-on="change: filterSubVerticals(event)"> | ||
<option value="">-- Select Vertical --</option> | ||
{% for vertical in verticals %} | ||
<option value="{{ vertical.slug }}" | ||
{% if course.vertical and course.vertical.vertical.slug == vertical.slug %}selected{% endif %}> | ||
{{ vertical.name }} | ||
</option> | ||
{% endfor %} | ||
</select> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<label for="sub_vertical">Sub-Vertical</label> | ||
<select name="sub_vertical" id="sub_vertical" class="form-control"> | ||
<option value="">-- Select Sub-Vertical --</option> | ||
{% for sub_vertical in all_sub_verticals %} | ||
<option value="{{ sub_vertical.slug }}" | ||
data-vertical="{{ sub_vertical.vertical.slug }}" | ||
{% if course.vertical and course.vertical.sub_vertical and course.vertical.sub_vertical.slug == sub_vertical.slug %}selected{% endif %} | ||
{% if course.vertical and not course.vertical.sub_vertical and sub_vertical.vertical.slug != course.vertical.vertical.slug %}style="display: none;"{% endif %} | ||
{% if not course.vertical or sub_vertical.vertical.slug != course.vertical.vertical.slug %}style="display: none;"{% endif %}> | ||
{{ sub_vertical.name }} | ||
</option> | ||
{% endfor %} | ||
</select> | ||
</div> | ||
|
||
<button type="submit" class="btn btn-primary">Save</button> | ||
</form> | ||
|
||
<!-- Message container for success/error --> | ||
<div id="message-container" class="mt-3"></div> | ||
</div> | ||
|
||
<script> | ||
function filterSubVerticals(event) { | ||
const selectedVertical = event.target.value; | ||
const subVerticalSelect = document.getElementById('sub_vertical'); | ||
const options = subVerticalSelect.querySelectorAll('option[data-vertical]'); | ||
|
||
// Clear sub-vertical selection only when vertical is changed to no selection | ||
if (!selectedVertical) { | ||
subVerticalSelect.value = ""; // Reset sub-vertical selection | ||
} | ||
|
||
// Hide or show sub-vertical options based on selected vertical | ||
options.forEach(option => { | ||
if (selectedVertical && option.getAttribute('data-vertical') === selectedVertical) { | ||
option.style.display = ""; // Show relevant sub-vertical | ||
} else { | ||
option.style.display = "none"; // Hide irrelevant sub-vertical | ||
} | ||
}); | ||
|
||
// Automatically clear sub-vertical selection if no matching options are visible | ||
const selectedSubVertical = subVerticalSelect.value; | ||
const matchingOption = Array.from(options).find(option => option.value === selectedSubVertical && option.style.display !== "none"); | ||
if (!matchingOption) { | ||
subVerticalSelect.value = ""; // Clear selection if no valid options remain | ||
} | ||
} | ||
|
||
document.addEventListener("DOMContentLoaded", function () { | ||
const selectedVertical = document.getElementById('vertical'); | ||
filterSubVerticals({ target: selectedVertical }); | ||
}); | ||
</script> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters