Skip to content

Commit

Permalink
deactivate a unit
Browse files Browse the repository at this point in the history
  • Loading branch information
backface committed Nov 22, 2024
1 parent 86d12ef commit 52df50a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions apps/classrooms/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
path(r"unit/edit/<int:pk>", views.edit_unit, name="unit_update"),
path(r"unit/delete/<int:pk>", views.delete_unit, name="unit_delete"),
path(r"unit/activate/<int:pk>", views.activate_unit, name="unit_activate"),
path(r"unit/deactivate/<int:pk>", views.deactivate_unit, name="unit_deactivate"),
path(
r"addstarter/<int:group_id>/<int:project_id>",
views.add_starter,
Expand Down
10 changes: 10 additions & 0 deletions apps/classrooms/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,16 @@ def activate_unit(request, pk):
return redirect(reverse("groups:group_detail", args=[unit.group.id]))


@login_required
def deactivate_unit(request, pk):
unit = get_object_or_404(Unit, pk=pk)
if not unit.group.is_host(request.user):
raise (PermissionDenied)
unit.group.current_unit = 0
unit.group.save()
return redirect(reverse("groups:group_detail", args=[unit.group.id]))


@login_required
def add_starter(request, group_id, project_id):
group = get_object_or_404(Group, id=group_id)
Expand Down
4 changes: 4 additions & 0 deletions templates/classrooms/group_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ <h2>Projects</h2>
<a href="{% url 'groups:unit_activate' unit.id %}">
<button type="button"><i class="icon-[ion--trash] mr-1"></i>Activate Unit</button>
</a>
{% else %}
<a href="{% url 'groups:unit_deactivate' unit.id %}">
<button type="button"><i class="icon-[ion--trash] mr-1"></i>Deactivate</button>
</a>
{% endif %}
<a href="{% url 'groups:unit_update' unit.id %}">
<button type="button"><i class="icon-[ion--edit] mr-1"></i>Edit Unit Info</button>
Expand Down

0 comments on commit 52df50a

Please sign in to comment.