Skip to content

Commit

Permalink
Show unsubmit button to teachers only for programs of their current s…
Browse files Browse the repository at this point in the history
…tudents #5990
  • Loading branch information
boryanagoncharenko committed Dec 6, 2024
1 parent 5308864 commit 24b5f61
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 27 deletions.
27 changes: 14 additions & 13 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -1917,23 +1917,21 @@ def view_program(user, id):
student_adventure = DATABASE.store_student_adventure(
dict(id=f"{student_adventure_id}", ticked=False, program_id=id))

arguments_dict = {}
arguments_dict['program_id'] = id
arguments_dict['page_title'] = f'{result["name"]} – Hedy'
arguments_dict['level'] = result['level'] # Necessary for running
arguments_dict['initial_adventure'] = dict(result,
editor_contents=code,
)
arguments_dict['editor_readonly'] = True
arguments_dict['student_adventure'] = student_adventure
arguments_dict = {
'program_id': id,
'page_title': f'{result["name"]} – Hedy',
'level': result['level'], # Necessary for running
'initial_adventure': dict(result, editor_contents=code),
'editor_readonly': True,
'student_adventure': student_adventure,
'is_students_teacher': False
}

if "submitted" in result and result['submitted']:
arguments_dict['show_edit_button'] = False
arguments_dict['program_timestamp'] = utils.localized_date_format(result['date'])
else:
arguments_dict['show_edit_button'] = True
is_students_teacher = is_teacher(user)\
and result['username'] in DATABASE.get_teacher_students(user['username'])
arguments_dict['is_students_teacher'] = is_students_teacher

classes = DATABASE.get_student_classes_ids(result['username'])
next_classmate_adventure_id = None
Expand All @@ -1948,6 +1946,10 @@ def view_program(user, id):
next_classmate_adventure_id = next_classmate_adventure.get('program_id')
if next_classmate_adventure_id:
break
if is_teacher(user):
second_teachers = [t for t in class_.get('second_teachers', []) if t.get('role', '') == 'teacher']
all_teachers = [class_.get('teacher')] + [t.get('username', '') for t in second_teachers]
arguments_dict['is_students_teacher'] = user.get('username') in all_teachers

student_customizations = DATABASE.get_student_class_customizations(result['username'])
adventure_index = 0
Expand All @@ -1973,7 +1975,6 @@ def view_program(user, id):
lang=g.lang,
level=int(result['level']),
code=code),
is_teacher=user['is_teacher'],
class_id=student_customizations.get('id'),
next_program_id=next_program_id,
next_classmate_program_id=next_classmate_adventure_id,
Expand Down
36 changes: 22 additions & 14 deletions templates/view-program-page.html
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
{% extends "layout.html" %}
{% block full_width_content %}
<div style="height: 30px;"></div>
<div tabindex="0" class="flex-grow px-8 common-page-container">
{% if initial_adventure.submitted %}
<div class="text-center">
<h2>{{_('submitted_header')}}</h2>
<h3 class="inline-block mt-0">{{_('submission_time')}}: {{program_timestamp}}</h3>
</div>
{% if is_teacher %}
<div class="text-center">
<button class="green-btn" data-cy="unsubmit_btn" onclick="hedyApp.modal.confirm ('{{_('unsubmit_warning')}}', function () {hedyApp.unsubmit_program ('{{initial_adventure.id}}', {{ loop_index }})})">{{_('unsubmit_program')}}</button>
</div>
{% endif %}
{% endif %}
<div class="flex flex-row gap-6 items-center">
<h1>{{initial_adventure.name}}</h1>
{% if is_students_teacher %}
Expand All @@ -25,6 +13,13 @@ <h1>{{initial_adventure.name}}</h1>
{% if student_adventure.ticked %}checked{% endif %}
_="on click toggle .fa-solid .fa-check on me"
>

{% if initial_adventure.submitted %}
<div class="text-center">
<button class="green-btn" data-cy="unsubmit_btn" onclick="hedyApp.modal.confirm ('{{_('unsubmit_warning')}}', function () {hedyApp.unsubmit_program ('{{initial_adventure.id}}', {{ loop_index }})})">{{_('unsubmit_program')}}</button>
</div>
{% endif %}

<div class="flex-1"></div>
{% if next_program_id %}
<a class="green-btn" href="/hedy/{{ next_program_id }}/view">
Expand All @@ -41,10 +36,23 @@ <h1>{{initial_adventure.name}}</h1>
{% endif %}
{% endif %}
</div>
<h2 class="p-0 m-0">{{_('level_title')}} {{level}}</h2>
<div>{{_('by')}}
<div class="flex flex-row gap-6 items-center">
<h2 class="p-0 m-0">{{_('level_title')}} {{level}}</h2>
{% if initial_adventure.submitted %}
<div class="flex-1"></div>
<h2 class="p-0 m-0">{{_('submitted_header')}}</h2>
{% endif %}
</div>
<div class="flex flex-row gap-6 items-center">
{% if initial_adventure.submitted %}
<div>{{_('by')}}
<a {% if initial_adventure.public_profile %}onclick="window.open('/user/{{initial_adventure.username}}', '_self')"{% endif %} class="{% if initial_adventure.public_profile %}cursor-pointer{% else %}text-black{% endif %} no-underline">{{ initial_adventure.username }}</a>
</div>
<div class="flex-1"></div>
<h3>{{_('submission_time')}} {{program_timestamp}}</h3>
{% endif %}
</div>

{% include "incl/editor-and-output.html" %}
</div>
{% endblock %}

0 comments on commit 24b5f61

Please sign in to comment.