class ConferenceAdmin(admin.ModelAdmin):
exclude = ['readers', 'keywords']
search_fields = ['public_id', 'id', 'title']
+ filter_horizontal = ['professor',]
autocomplete_fields = ['docs_description',
'suggested_seminars', 'suggested_conferences']
actions = ['export_conference']
--- /dev/null
+# -*- coding: utf-8 -*-
+from django.db import migrations, models
+
+
+def copy_professor(apps, schema_editor):
+ """Move the single FK professor into the new M2M relation."""
+ Conference = apps.get_model('teleforma', 'Conference')
+ for conf in Conference.objects.exclude(professor_single__isnull=True):
+ conf.professor.add(conf.professor_single_id)
+
+
+def reverse_professor(apps, schema_editor):
+ """Keep the first M2M professor as the single FK professor."""
+ Conference = apps.get_model('teleforma', 'Conference')
+ for conf in Conference.objects.all():
+ first = conf.professor.first()
+ if first:
+ conf.professor_single = first
+ conf.save(update_fields=['professor_single'])
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('teleforma', '0026_conference_secondary_subject'),
+ ]
+
+ operations = [
+ migrations.RenameField(
+ model_name='conference',
+ old_name='professor',
+ new_name='professor_single',
+ ),
+ migrations.AddField(
+ model_name='conference',
+ name='professor',
+ field=models.ManyToManyField(blank=True, related_name='conference', to='teleforma.Professor', verbose_name='professor'),
+ ),
+ migrations.RunPython(copy_professor, reverse_professor),
+ migrations.RemoveField(
+ model_name='conference',
+ name='professor_single',
+ ),
+ ]
course = models.ForeignKey('Course', related_name='conference', verbose_name=_('course'), on_delete=models.CASCADE)
course_type = models.ForeignKey('CourseType', related_name='conference', verbose_name=_('course type'),
null=True, blank=True, on_delete=models.SET_NULL)
- professor = models.ForeignKey('Professor', related_name='conference', verbose_name=_('professor'),
- blank=True, null=True, on_delete=models.SET_NULL)
+ professor = models.ManyToManyField('Professor', related_name='conference', verbose_name=_('professor'),
+ blank=True)
session = models.CharField(_('session'), choices=session_choices,
max_length=16, default="1")
}
def __str__(self):
- if self.professor:
- list = [self.title, self.course.title,
- self.session,
- self.professor.user.first_name,
- self.professor.user.last_name,
- str(self.date_begin)]
- else:
- list = [self.title, self.course.title,
- self.session,
- str(self.date_begin)]
+ list = [self.title, self.course.title, self.session]
+ if self.pk:
+ for professor in self.professor.all():
+ list.append(professor.user.first_name)
+ list.append(professor.user.last_name)
+ list.append(str(self.date_begin))
return ' - '.join(list)
def save(self, **kwargs):
{'id':'organization','value': self.course.department.organization, 'class':'', 'label': 'Organization'},
{'id': 'department', 'value': self.course.department , 'class':'', 'label': 'Department'},
{'id': 'period', 'value': self.period, 'class':'', 'label': 'Period'},
- {'id': 'professor', 'value': self.professor, 'class':'' , 'label': 'Professor'},
+ {'id': 'professor', 'value': ', '.join(str(p) for p in self.professor.all()), 'class':'' , 'label': 'Professor'},
{'id': 'session', 'value': self.session, 'class':'' , 'label': 'Session'},
{'id': 'comment', 'value': self.comment, 'class':'' , 'label': 'Comment'},
]
return dict
def to_json_dict(self):
+ professors = self.professor.all()
data = {'id': self.public_id,
'course_code': self.course.code,
- 'professor_id': self.professor.user.username,
+ 'professor_id': professors[0].user.username if professors else '',
+ 'professor_ids': [p.user.username for p in professors],
'period': self.period.name,
'department': self.department.name,
'session': self.session,
{% for conference in course.conference.all %}
<tr {% if not forloop.counter0|divisibleby:"2" %}class="odd"{% endif %}>
<td>{{ conference.session }}</td>
-<td>{{ conference.professor.user.first_name }} {{ conference.professor.user.last_name }}</td>
+<td>{% for professor in conference.professor.all %}{{ professor.user.first_name }} {{ professor.user.last_name }}{% if not forloop.last %}, {% endif %}{% endfor %}</td>
<td>{{ conference.date_begin }}</td>
</tr>
<div class="course_content" id="media_infos">
<dl class="listing">
-{% if conference.professor %}
+{% if conference.professor.all %}
<dt>{% trans "Course" %}</dt><dd><a href="{% url 'teleforma-course-detail' course.id %}">{{ conference.course.title }} - {{ conference.course_type }}</a></dd>
<dt>{% trans "Session" %}</dt><dd>{{ conference.session }}</dd>
-<dt>{% trans "Professor" %}</dt>
- <dd><a href="{% url 'teleforma-profile-detail' conference.professor.user.username %}" target="_blank">{{ conference.professor }}</a></dd>
+<dt>{% if conference.professor.count > 1 %}{% trans "Professors" %}{% else %}{% trans "Professor" %}{% endif %}</dt>
+ <dd>{% for professor in conference.professor.all %}<a href="{% url 'teleforma-profile-detail' professor.user.username %}" target="_blank">{{ professor }}</a>{% if not forloop.last %}, {% endif %}{% endfor %}</dd>
{% endif %}
{% if conference.comment %}<dt>{% trans "Comment" %}</dt><dd>{{ conference.comment }}</dd>{% endif %}
<dt>{% trans "Begin date" %}</dt><dd>{{ conference.date_begin }}</dd>
<a href="{% url 'teleforma-conference-detail' conference.id %}" class="component_icon button icon_clap"> {% trans "Video" %}</a>
</div>
-{{ course.title }}{% if course.description %} - {{ course.description }}{% endif %} - {{ conference.session }} - {{ conference.professor }}
+{{ course.title }}{% if course.description %} - {{ course.description }}{% endif %} - {{ conference.session }} - {% for professor in conference.professor.all %}{{ professor }}{% if not forloop.last %}, {% endif %}{% endfor %}
</div>
<div class="media">
<div class="course_content" id="media_infos">
<dl class="listing">
<dt>{% trans "Title" %}</dt><dd>{{ conference.course.title }}</dd>
-<dt>{% trans "Professor" %}</dt><dd><a href="{% url 'teleforma-profile-detail' conference.professor.user.username %}" target="_blank">{{ conference.professor }}</a></dd>
+<dt>{% if conference.professor.count > 1 %}{% trans "Professors" %}{% else %}{% trans "Professor" %}{% endif %}</dt><dd>{% for professor in conference.professor.all %}<a href="{% url 'teleforma-profile-detail' professor.user.username %}" target="_blank">{{ professor }}</a>{% if not forloop.last %}, {% endif %}{% endfor %}</dd>
<dt>{% trans "Session" %}</dt><dd>{{ conference.session }}</dd>
<dt>{% trans "Room" %}</dt><dd>{{ conference.room }}</dd>
<dt>{% trans "Begin" %}</dt><dd>{{ conference.date_begin }}</dd>
{% if media.conference %}
<dt>{% trans "Course" %}</dt><dd><a href="{% url 'teleforma-course-detail' course.id %}">{{ media.course.title }} - {{ media.course_type }}</a></dd>
<dt>{% trans "Session" %}</dt><dd>{{ media.conference.session }}</dd>
-{% if media.conference.professor %}
-<dt>{% trans "Professor" %}</dt>
- <dd><a href="{% url 'teleforma-profile-detail' media.conference.professor.user.username %}" target="_blank">{{ media.conference.professor }}</a></dd>
+{% if media.conference.professor.all %}
+<dt>{% if media.conference.professor.count > 1 %}{% trans "Professors" %}{% else %}{% trans "Professor" %}{% endif %}</dt>
+ <dd>{% for professor in media.conference.professor.all %}<a href="{% url 'teleforma-profile-detail' professor.user.username %}" target="_blank">{{ professor }}</a>{% if not forloop.last %}, {% endif %}{% endfor %}</dd>
{% endif %}
{% if media.conference.comment %}<dt>{% trans "Comment" %}</dt><dd>{{ media.conference.comment }}</dd>{% endif %}
<dt>{% trans "Begin date" %}</dt><dd>{{ media.conference.date_begin }}</dd>
{% if media.conference %}
<dt>{% trans "Course" %}</dt><dd><a href="{% url 'teleforma-desk-period-course' period.id course.id %}">{{ media.course.title }} - {{ media.course_type }}</a></dd>
<dt>{% trans "Session" %}</dt><dd>{{ media.conference.session }}</dd>
-{% if media.conference.professor %}
-<dt>{% trans "Professor" %}</dt>
- <dd><a href="{% url 'teleforma-profile-detail' media.conference.professor.user.username %}" target="_blank">{{ media.conference.professor }}</a></dd>
+{% if media.conference.professor.all %}
+<dt>{% if media.conference.professor.count > 1 %}{% trans "Professors" %}{% else %}{% trans "Professor" %}{% endif %}</dt>
+ <dd>{% for professor in media.conference.professor.all %}<a href="{% url 'teleforma-profile-detail' professor.user.username %}" target="_blank">{{ professor }}</a>{% if not forloop.last %}, {% endif %}{% endfor %}</dd>
{% endif %}
{% if media.conference.comment %}<dt>{% trans "Comment" %}</dt><dd>{{ media.conference.comment }}</dd>{% endif %}
<dt>{% trans "Begin date" %}</dt><dd>{{ media.conference.date_begin }}</dd>
<div class="course_content" id="media_infos">
<dl class="listing">
- {% if conference.professor %}
+ {% if conference.professor.all %}
<dt>{% trans "Course" %}</dt>
<dd><a href="{% url 'teleforma-course-detail' course.id %}">{{ conference.course.title }}{% if conference.course_type != None %}
- {{ conference.course_type }}{% endif %}</a></dd>
<dt>Niveau</dt>
<dd>{{ conference.level }}</dd>
- <dt>{% trans "Professor" %}</dt>
- <dd><a href="{% url 'teleforma-profile-detail' conference.professor.user.username %}"
- target="_blank">{{ conference.professor }}</a></dd>
+ <dt>{% if conference.professor.count > 1 %}{% trans "Professors" %}{% else %}{% trans "Professor" %}{% endif %}</dt>
+ <dd>{% for professor in conference.professor.all %}<a href="{% url 'teleforma-profile-detail' professor.user.username %}"
+ target="_blank">{{ professor }}</a>{% if not forloop.last %}, {% endif %}{% endfor %}</dd>
{% endif %}
{% if conference.comment %}<dt>{% trans "Comment" %}</dt>
<dd>{{ conference.comment }}</dd>{% endif %}
<dl class="listing" style="font-size: 1.2em;">
<dt>{% trans "Title" %}</dt><dd>{{ stream.conference.course.title }}</dd>
<dt>{% trans "Session" %}</dt><dd>{{ stream.conference.session }}</dd>
- <dt>{% trans "Professor" %}</dt><dd><a href="{% url 'teleforma-profile-detail' stream.conference.professor.user.username %}" target="_blank">{{ stream.conference.professor }}</a></dd>
+ <dt>{% if stream.conference.professor.count > 1 %}{% trans "Professors" %}{% else %}{% trans "Professor" %}{% endif %}</dt><dd>{% for professor in stream.conference.professor.all %}<a href="{% url 'teleforma-profile-detail' professor.user.username %}" target="_blank">{{ professor }}</a>{% if not forloop.last %}, {% endif %}{% endfor %}</dd>
<dt>{% trans "Begin" %}</dt><dd>{{ stream.conference.date_begin }}</dd>
</dl>
</div>
<dl class="listing" style="font-size: 1.2em;">
<dt>{% trans "Title" %}</dt><dd>{{ media.conference.course.title }}</dd>
<dt>{% trans "Session" %}</dt><dd>{{ media.conference.session }}</dd>
- {% if media.conference.professor %}
- <dt>{% trans "Professor" %}</dt><dd><a href="{% url 'teleforma-profile-detail' media.conference.professor.user.username %}" target="_blank">{{ media.conference.professor }}</a></dd>
+ {% if media.conference.professor.all %}
+ <dt>{% if media.conference.professor.count > 1 %}{% trans "Professors" %}{% else %}{% trans "Professor" %}{% endif %}</dt><dd>{% for professor in media.conference.professor.all %}<a href="{% url 'teleforma-profile-detail' professor.user.username %}" target="_blank">{{ professor }}</a>{% if not forloop.last %}, {% endif %}{% endfor %}</dd>
{% endif %}
<dt>{% trans "Begin" %}</dt><dd>{{ media.conference.date_begin }}</dd>
{% if media.conference.comment %}
course=course, course_type=course_type)
if c:
conf.session = conference['session']
- if conference['professor_id']:
- user = User.objects.filter(username=conference['professor_id'])
+ professor_ids = conference.get('professor_ids') or []
+ if not professor_ids and conference['professor_id']:
+ professor_ids = [conference['professor_id']]
+ for professor_id in professor_ids:
+ user = User.objects.filter(username=professor_id)
if user:
- conf.professor = Professor.objects.get(user=user[0])
+ professor = Professor.objects.get(user=user[0])
else:
- user = User(username=conference['professor_id'])
+ user = User(username=professor_id)
user.save()
professor = Professor(user=user)
professor.save()
- conf.professor = professor
+ conf.professor.add(professor)
try:
organization, c = Organization.objects.get_or_create(name=conference['organization'])
conf.room, c = Room.objects.get_or_create(name=conference['room'],