Skip to content

Commit

Permalink
Add group_work_allowed boolean to CourseInstance to avoid expensive l…
Browse files Browse the repository at this point in the history
…ookup on every page load

Fixes #1367
  • Loading branch information
sayravai committed May 22, 2024
1 parent 0086e01 commit 6b3d27c
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 1 deletion.
1 change: 1 addition & 0 deletions course/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class CourseInstanceAdmin(admin.ModelAdmin):
'course',
'instance_name',
'visible_to_students',
'group_work_allowed',
'starting_time',
'ending_time',
instance_url,
Expand Down
3 changes: 3 additions & 0 deletions course/api/full_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ class Meta(CourseBriefSerializer.Meta):
'starting_time',
'ending_time',
'visible_to_students',
'group_work_allowed',
# links
'exercises',
'tree',
Expand Down Expand Up @@ -148,6 +149,7 @@ class Meta(AplusModelSerializer.Meta):
'starting_time',
'ending_time',
'visible_to_students',
'group_work_allowed',
'configure_url',
'teachers',
)
Expand Down Expand Up @@ -205,6 +207,7 @@ def update(self, instance: CourseInstance, validated_data: OrderedDict) -> Cours
instance.starting_time = validated_data.get('starting_time', instance.starting_time)
instance.ending_time = validated_data.get('ending_time', instance.ending_time)
instance.visible_to_students = validated_data.get('visible_to_students', instance.visible_to_students)
instance.group_work_allowed = validated_data.get('group_work_allowed', instance.group_work_allowed)
instance.configure_url = validated_data.get('configure_url', instance.configure_url)
instance.save()
self.set_teachers(instance, self.teachers)
Expand Down
20 changes: 20 additions & 0 deletions course/migrations/0059_courseinstance_group_work_allowed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 4.2.13 on 2024-05-22 08:06

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("course", "0058_coursemodule_model_answer_and_more"),
]

operations = [
migrations.AddField(
model_name="courseinstance",
name="group_work_allowed",
field=models.BooleanField(
default=True, verbose_name="LABEL_GROUP_WORK_ALLOWED"
),
),
]
4 changes: 4 additions & 0 deletions course/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,10 @@ class CourseInstance(CourseInstanceProto, models.Model):
verbose_name=_('LABEL_VISIBLE_TO_STUDENTS'),
default=True,
)
group_work_allowed = models.BooleanField(
verbose_name=_('LABEL_GROUP_WORK_ALLOWED'),
default=True,
)
enrollment_audience = models.IntegerField(
verbose_name=_('LABEL_ENROLLMENT_AUDIENCE'),
choices=ENROLLMENT_AUDIENCE.choices,
Expand Down
2 changes: 1 addition & 1 deletion course/templates/course/_course_menu.html
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ <h4 id="course-menu-heading">{% translate "COURSE" %}</h4>
</a>
</li>

{% if instance_max_group_size > 1 %}
{% if instance.group_work_allowed %}
<li class="menu-groups">
<a href="{{ instance|url:'groups' }}">
<span class="glyphicon glyphicon-heart" aria-hidden="true"></span>
Expand Down
1 change: 1 addition & 0 deletions edit_course/course_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ class Meta:
model = CourseInstance
fields = [
'visible_to_students',
'group_work_allowed',
'instance_name',
'url',
'image',
Expand Down
4 changes: 4 additions & 0 deletions locale/en/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,10 @@ msgstr "enrolments"
msgid "LABEL_VISIBLE_TO_STUDENTS"
msgstr "visible to students"

#: course/models.py
msgid "LABEL_GROUP_WORK_ALLOWED"
msgstr "students can form groups"

#: course/models.py
msgid "MODEL_NAME_USER_TAG"
msgstr "user tag"
Expand Down
4 changes: 4 additions & 0 deletions locale/fi/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,10 @@ msgstr "ilmoittautumiset"
msgid "LABEL_VISIBLE_TO_STUDENTS"
msgstr "näkyy opiskelijoille"

#: course/models.py
msgid "LABEL_GROUP_WORK_ALLOWED"
msgstr "opiskelijat saavat luoda ryhmiä"

#: course/models.py
msgid "MODEL_NAME_USER_TAG"
msgstr "käyttäjämerkintä"
Expand Down

0 comments on commit 6b3d27c

Please sign in to comment.