joeni

Add functionality to edit course items

Included in this commit are the new formsets for the course items, such as announcements and assignments.

Author
Maarten 'Vngngdn' Vangeneugden
Date
April 11, 2018, 6:10 p.m.
Hash
56eb93dad8d6d31a2bf667cf2960a4cbc080c858
Parent
c7c69bc69acec02658ae82a79d7a50b4004b372a
Modified files
courses/forms.py
courses/migrations/0007_course_co_titulars.py
courses/migrations/0008_remove_course_co_titulars.py
courses/migrations/0009_upload_course.py
courses/migrations/0010_auto_20180410_1652.py
courses/templates/courses/edit_course_items.djhtml
courses/templates/courses/nav.djhtml
courses/templates/courses/study_guide.djhtml

courses/forms.py

46 additions and 0 deletions.

View changes Hide changes
+
1
from django.forms import ModelForm, modelformset_factory
+
2
from . import models
+
3
+
4
class AssignmentForm(ModelForm):
+
5
    class Meta:
+
6
        model = models.Assignment
+
7
        fields = ['title',
+
8
                  'information',
+
9
                  'deadline',
+
10
                  'digital_task',
+
11
                  ]
+
12
class AnnouncementForm(ModelForm):
+
13
    class Meta:
+
14
        model = models.Announcement
+
15
        fields = ['title',
+
16
                  'text',
+
17
                  ]
+
18
class UploadForm(ModelForm):
+
19
    class Meta:
+
20
        model = models.Upload
+
21
        fields = ['comment',
+
22
                  'file',
+
23
                  ]
+
24
class CourseItemForm(ModelForm):
+
25
    class Meta:
+
26
        model = models.CourseItem
+
27
        fields = ['file',
+
28
                  'note',
+
29
                  ]
+
30
+
31
AssignmentFormSet = modelformset_factory(
+
32
    models.Assignment, fields=('title', 'information', 'deadline', 'digital_task'),
+
33
    localized_fields="__all__",
+
34
    can_delete=True,
+
35
    )
+
36
AnnouncementFormSet = modelformset_factory(
+
37
    models.Announcement, fields=('title', 'text'),
+
38
    localized_fields="__all__",
+
39
    can_delete=True,
+
40
    )
+
41
CourseItemFormSet = modelformset_factory(
+
42
    models.CourseItem, fields=('file', 'note'),
+
43
    localized_fields="__all__",
+
44
    can_delete=True,
+
45
    )
+
46

courses/migrations/0007_course_co_titulars.py

20 additions and 0 deletions.

View changes Hide changes
+
1
+
2
from django.conf import settings
+
3
from django.db import migrations, models
+
4
+
5
+
6
class Migration(migrations.Migration):
+
7
+
8
    dependencies = [
+
9
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
+
10
        ('courses', '0006_auto_20180204_1349'),
+
11
    ]
+
12
+
13
    operations = [
+
14
        migrations.AddField(
+
15
            model_name='course',
+
16
            name='co_titulars',
+
17
            field=models.ManyToManyField(blank=True, help_text='The co-titular(s) of this course, if applicable.', limit_choices_to={'is_staff': True}, related_name='co_titulars', to=settings.AUTH_USER_MODEL),
+
18
        ),
+
19
    ]
+
20

courses/migrations/0008_remove_course_co_titulars.py

17 additions and 0 deletions.

View changes Hide changes
+
1
+
2
from django.db import migrations
+
3
+
4
+
5
class Migration(migrations.Migration):
+
6
+
7
    dependencies = [
+
8
        ('courses', '0007_course_co_titulars'),
+
9
    ]
+
10
+
11
    operations = [
+
12
        migrations.RemoveField(
+
13
            model_name='course',
+
14
            name='co_titulars',
+
15
        ),
+
16
    ]
+
17

courses/migrations/0009_upload_course.py

20 additions and 0 deletions.

View changes Hide changes
+
1
+
2
from django.db import migrations, models
+
3
import django.db.models.deletion
+
4
+
5
+
6
class Migration(migrations.Migration):
+
7
+
8
    dependencies = [
+
9
        ('courses', '0008_remove_course_co_titulars'),
+
10
    ]
+
11
+
12
    operations = [
+
13
        migrations.AddField(
+
14
            model_name='upload',
+
15
            name='course',
+
16
            field=models.ForeignKey(default=2, on_delete=django.db.models.deletion.CASCADE, to='courses.Course'),
+
17
            preserve_default=False,
+
18
        ),
+
19
    ]
+
20

courses/migrations/0010_auto_20180410_1652.py

18 additions and 0 deletions.

View changes Hide changes
+
1
+
2
from django.db import migrations, models
+
3
+
4
+
5
class Migration(migrations.Migration):
+
6
+
7
    dependencies = [
+
8
        ('courses', '0009_upload_course'),
+
9
    ]
+
10
+
11
    operations = [
+
12
        migrations.AlterField(
+
13
            model_name='study',
+
14
            name='degree_type',
+
15
            field=models.CharField(choices=[('BSc', 'Bachelor of Science'), ('MSc', 'Master of Science'), ('LL.B', 'Bachelor of Laws'), ('LL.M', 'Master of Laws'), ('ir.', 'Engineer'), ('ing.', 'Technical Engineer'), ('BA', 'Bachelor of Arts'), ('MA', 'Master of Arts')], help_text='The type of degree one obtains upon passing this study.', max_length=64),
+
16
        ),
+
17
    ]
+
18

courses/templates/courses/edit_course_items.djhtml

37 additions and 0 deletions.

View changes Hide changes
+
1
{% load static %}
+
2
{% load i18n %}
+
3
{% load joeni_org %}
+
4
+
5
{% block title %}
+
6
    {{ course.name }} | {{ block.super }}
+
7
{% endblock %}
+
8
+
9
{% block main %}
+
10
    {% include "administration/nav.djhtml" %}
+
11
    <p>
+
12
        {% blocktrans %}You can edit announcements, assignments, and course
+
13
            items on this page, mark them for deletion, and add new ones.
+
14
            When all changes are saved successfully, you will be redirected to
+
15
            the course's main page. When errors occur, you will stay on this page,
+
16
            and receive error notifications where necessary.{% endblocktrans %}
+
17
    </p>
+
18
+
19
    <form action="" method="POST">
+
20
        {% csrf_token %}
+
21
        <h2 id="{% trans "announcements" %}">{% trans "Announcements" %}</h2>
+
22
            <table>
+
23
                {{ announcements }}
+
24
            </table>
+
25
        <h2 id="{% trans "assignments" %}">{% trans "Assignments" %}</h2>
+
26
            <table>
+
27
            {{ assignments }}
+
28
            </table>
+
29
        <h2 id="{% trans "course-items" %}">{% trans "Course items" %}</h2>
+
30
            <table>
+
31
                {{ course_items }}
+
32
            </table>
+
33
        <hr />
+
34
        <input type="submit" value="{% trans "Save everything" %}" />
+
35
    </form>
+
36
{% endblock main %}
+
37

courses/templates/courses/nav.djhtml

6 additions and 0 deletions.

View changes Hide changes
+
1
{% load i18n %}
+
2
<nav>
+
3
    <a href="{% url 'courses-index' %}">{% trans "Personal settings" %}</a>
+
4
+
5
</nav>
+
6

courses/templates/courses/study_guide.djhtml

9 additions and 0 deletions.

View changes Hide changes
+
1
{% load i18n %}
+
2
+
3
{% block title %}
+
4
    {% trans "Study guide for" %} {{ course.name }} | {{ block.super }}
+
5
{% endblock %}
+
6
+
7
{% block main %}
+
8
{% endblock main %}
+
9