Skip to content

Commit

Permalink
Add teachers to ClassCourse and forms (#870)
Browse files Browse the repository at this point in the history
* Completed

* Tests
  • Loading branch information
Dmi4er4 authored Sep 1, 2024
1 parent f4830e8 commit 35dca20
Show file tree
Hide file tree
Showing 16 changed files with 220 additions and 115 deletions.
2 changes: 1 addition & 1 deletion apps/admission/locale/ru/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-08-27 12:24+0000\n"
"POT-Creation-Date: 2024-08-30 12:30+0000\n"
"PO-Revision-Date: 2024-07-23 17:04+0000\n"
"Last-Translator: Дмитрий Чернушевич <[email protected]>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down
12 changes: 12 additions & 0 deletions apps/courses/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,18 @@ def formfield_for_foreignkey(self, db_field, request, **kwargs):
.select_related("meta_course", "semester"))
return super().formfield_for_foreignkey(db_field, request, **kwargs)

def formfield_for_manytomany(self, db_field, request=None, **kwargs):
if db_field.name == "teachers":
qs = CourseTeacher.objects.select_related("teacher", "course")
try:
courseclass_id = request.resolver_match.kwargs['object_id']
cl = CourseClass.objects.get(pk=courseclass_id)
qs = qs.filter(course_id=cl.course_id)
except KeyError:
pass
kwargs["queryset"] = qs.order_by("course_id").distinct()
return super().formfield_for_manytomany(db_field, request, **kwargs)


class CourseNewsAdmin(admin.ModelAdmin):
date_hierarchy = 'created'
Expand Down
6 changes: 5 additions & 1 deletion apps/courses/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ class CourseClassForm(forms.ModelForm):
class Meta:
model = CourseClass
fields = ['venue', 'type', 'translation_link', 'date', 'starts_at', 'ends_at', 'time_zone', 'name',
'description', 'attachments', 'recording_link', 'materials_visibility', 'restricted_to']
'description', 'attachments', 'recording_link', 'materials_visibility', 'restricted_to',
'teachers', 'is_conducted_by_invited']

def __init__(self, locale='en', **kwargs):
course = kwargs.pop('course', None)
Expand All @@ -217,6 +218,9 @@ def __init__(self, locale='en', **kwargs):
self.fields['time_zone'].choices = CourseService.get_time_zones(course, locale=locale)
field_restrict_to = self.fields['restricted_to']
field_restrict_to.choices = StudentGroupService.get_choices(course)
self.fields['teachers'].widget = forms.widgets.CheckboxSelectMultiple()
self.fields['teachers'].queryset = get_course_teachers(course=course).select_related('teacher')
self.fields['teachers'].label_from_instance = lambda obj: obj.teacher
self.instance.course = course

def clean_date(self):
Expand Down
28 changes: 28 additions & 0 deletions apps/courses/migrations/0050_auto_20240830_0818.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 3.2.18 on 2024-08-30 08:18

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('courses', '0049_auto_20240827_1221'),
]

operations = [
migrations.AddField(
model_name='courseclass',
name='is_conducted_by_invited',
field=models.BooleanField(default=False),
),
migrations.AddField(
model_name='courseclass',
name='teachers',
field=models.ManyToManyField(blank=True, related_name='course_classes', to='courses.CourseTeacher', verbose_name='Course class teachers'),
),
migrations.AlterField(
model_name='course',
name='default_grade',
field=models.CharField(choices=[('not_graded', 'Not graded'), ('without_grade', 'Without Grade')], default='not_graded', max_length=100, verbose_name='Enrollment|default_grade'),
),
]
8 changes: 8 additions & 0 deletions apps/courses/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,14 @@ class CourseClass(TimezoneAwareMixin, TimeStampedModel):
verbose_name=_("Groups"),
related_name='course_classes',
through='learning.CourseClassGroup')
teachers = models.ManyToManyField(
CourseTeacher,
verbose_name=_("Course class teachers"),
related_name='course_classes',
blank=True)
is_conducted_by_invited = models.BooleanField(
verbose_name=_("Is conducted by invited"),
default=False)

class Meta:
ordering = ["-date", "course", "-starts_at"]
Expand Down
4 changes: 3 additions & 1 deletion apps/courses/tests/test_course_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,9 @@ def test_course_class_form_available(client, curator, settings):
"date": next_day.strftime(date_format),
"starts_at": "17:20",
"ends_at": "18:50",
"recording_link": "https://test-site.com",
"recording_link": "https://record.com",
"translation_link": "https://translate.com",
"is_conducted_by_invited": 'on',
"time_zone": course.main_branch.get_timezone(),
"materials_visibility": MaterialVisibilityTypes.PUBLIC
}
Expand Down
2 changes: 1 addition & 1 deletion apps/htmlpages/locale/ru/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ msgid ""
msgstr ""
"Project-Id-Version: django\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-08-27 12:25+0000\n"
"POT-Creation-Date: 2024-08-30 12:30+0000\n"
"PO-Revision-Date: 2015-03-18 08:34+0000\n"
"Last-Translator: Jannis Leidel <[email protected]>\n"
"Language-Team: Russian (http://www.transifex.com/projects/p/django/language/"
Expand Down
2 changes: 1 addition & 1 deletion apps/projects/locale/ru/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-08-27 12:25+0000\n"
"POT-Creation-Date: 2024-08-30 12:30+0000\n"
"PO-Revision-Date: 2022-02-21 15:24+0000\n"
"Last-Translator: Сергей Жеревчук <[email protected]>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down
2 changes: 1 addition & 1 deletion apps/surveys/locale/ru/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-08-27 12:25+0000\n"
"POT-Creation-Date: 2024-08-30 12:30+0000\n"
"PO-Revision-Date: 2019-10-31 16:30+0000\n"
"Last-Translator: b' <[email protected]>'\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down
21 changes: 21 additions & 0 deletions apps/users/migrations/0047_auto_20240830_0818.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 3.2.18 on 2024-08-30 08:18

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('users', '0046_auto_20240812_0827'),
]

operations = [
migrations.AlterModelOptions(
name='studentacademicdisciplinelog',
options={'ordering': ['-changed_at', '-pk'], 'verbose_name_plural': 'Student Academic Discipline Log'},
),
migrations.AlterModelOptions(
name='studentstatuslog',
options={'ordering': ['-changed_at', '-pk'], 'verbose_name_plural': 'Student Status Log'},
),
]
2 changes: 1 addition & 1 deletion compscicenter_ru/locale/ru/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-08-27 12:25+0000\n"
"POT-Creation-Date: 2024-08-30 12:30+0000\n"
"PO-Revision-Date: 2020-02-03 16:52+0000\n"
"Last-Translator: b' <[email protected]>'\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down
2 changes: 1 addition & 1 deletion compsciclub_ru/locale/ru/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-08-27 12:25+0000\n"
"POT-Creation-Date: 2024-08-30 12:30+0000\n"
"PO-Revision-Date: 2020-09-09 04:43+0000\n"
"Last-Translator: b' <[email protected]>'\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down
4 changes: 3 additions & 1 deletion lms/jinja2/lms/courses/course_class_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ <h2>
</tr>
<tr>
<td>{% trans %}Where{% endtrans %}:</td>
<td><a href="{{ course_class.venue.location.get_absolute_url() }}">{{ course_class.venue.full_name }}</a></td>
<td>{{ course_class.venue.full_name }}{% if course_class.translation_link %}, <a href="{{ course_class.translation_link }}">{%
trans %}translation{% endtrans %}</a>{% endif %}
</td>
</tr>
{% if course_class.slides and can_view_course_class_materials %}
<tr>
Expand Down
7 changes: 7 additions & 0 deletions lms/jinja2/lms/courses/course_class_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ <h2 class="content-title mb-20">
</div>
</fieldset>
{{ forms.field(form['name']) }}
<label for="{{ form['teachers'].id_for_label }}" class="control-label"> {{ form['teachers'].label }} </label>
{% for checkbox in form['teachers'] %}
<div class="checkbox-item" style="font-weight: normal;">
{{ checkbox }}
</div>
{% endfor %}
{{ forms.field(form['is_conducted_by_invited'], is_boolean=True) }}
{{ forms.field(form['description']) }}
{{ forms.field(form['recording_link']) }}
<fieldset>
Expand Down
15 changes: 15 additions & 0 deletions lms/jinja2/lms/courses/course_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ <h4>{{ review.course.semester|title }}, {{ review.course.main_branch.name }}</h4
<th>{% trans %}Class|Name{% endtrans %}</th>
<th style="min-width: 140px;">{% trans %}Venue|short{% endtrans %}</th>
<th style="width: 110px;">{% trans %}Materials{% endtrans %}</th>
<th>{% trans %}Teachers{% endtrans %}</th>
</tr>
</thead>
{% for course_class in tab.tab_panel.context['items'] %}
Expand Down Expand Up @@ -145,6 +146,19 @@ <h4>{{ review.course.semester|title }}, {{ review.course.main_branch.name }}</h4
{% endwith %}
{% endif %}
</td>
<td>
{% if course_class.is_conducted_by_invited %}
{% trans %}Is conducted by invited{% endtrans %}{% if course_class.teachers.exists() %},<br>{% endif %}
{% endif %}
{% for course_teacher in course_class.teachers.all() %}
{% with teacher = course_teacher.teacher %}
<a href="{{ teacher.teacher_profile_url() }}">{{ teacher }}</a>{% if not loop.last %},<br>{% endif %}
{% endwith %}
{% endfor %}
{% if not course_class.is_conducted_by_invited and not course_class.teachers.exists() %}
{% trans %}No{% endtrans %}
{% endif %}
</td>
</tr>
{% endfor %}
</table>
Expand Down Expand Up @@ -273,6 +287,7 @@ <h4>{{ news.title }}{% if user.is_curator or user.is_teacher and is_actual_teach
</div>
{% endif %}
{% if teachers.lecturer or teachers.seminar %}
<br>
<div class="o-users-vlist">
<h4 class="text-center">{% trans %}Teachers{% endtrans %}</h4>
<ul class="list-unstyled">
Expand Down
Loading

0 comments on commit 35dca20

Please sign in to comment.