mirror of
https://github.com/Southampton-RSG/breccia-mapper.git
synced 2026-03-03 03:17:07 +00:00
@@ -25,7 +25,7 @@ class PersonForm(forms.ModelForm):
|
||||
'organisation',
|
||||
'organisation_started_date',
|
||||
'job_title',
|
||||
'discipline',
|
||||
'disciplines',
|
||||
'role',
|
||||
'themes',
|
||||
]
|
||||
|
||||
61
people/migrations/0021_refactor_person_disciplines.py
Normal file
61
people/migrations/0021_refactor_person_disciplines.py
Normal file
@@ -0,0 +1,61 @@
|
||||
# Generated by Django 2.2.10 on 2020-06-24 14:19
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
def migrate_forward(apps, schema_editor):
|
||||
Person = apps.get_model('people', 'Person')
|
||||
|
||||
for person in Person.objects.all():
|
||||
try:
|
||||
person.disciplines = person.discipline.name
|
||||
person.save()
|
||||
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
|
||||
def migrate_backward(apps, schema_editor):
|
||||
Person = apps.get_model('people', 'Person')
|
||||
Discipline = apps.get_model('people', 'Discipline')
|
||||
|
||||
for person in Person.objects.all():
|
||||
try:
|
||||
discipline_str = person.disciplines.split(',')[0]
|
||||
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
else:
|
||||
# Returns None if not found - doesn't raise exception
|
||||
discipline = Discipline.objects.filter(name=discipline_str).first()
|
||||
|
||||
if not discipline:
|
||||
discipline = Discipline.objects.create(
|
||||
name=discipline_str,
|
||||
code=discipline_str
|
||||
if len(discipline_str) < 15 else discipline_str[:15])
|
||||
|
||||
person.discipline = discipline
|
||||
person.save()
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('people', '0020_person_organisation_started_date'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='person',
|
||||
name='disciplines',
|
||||
field=models.CharField(blank=True, max_length=255, null=True),
|
||||
),
|
||||
migrations.RunPython(migrate_forward, migrate_backward),
|
||||
migrations.RemoveField(
|
||||
model_name='person',
|
||||
name='discipline',
|
||||
),
|
||||
migrations.DeleteModel(name='Discipline', ),
|
||||
]
|
||||
@@ -19,7 +19,6 @@ __all__ = [
|
||||
'User',
|
||||
'Organisation',
|
||||
'Role',
|
||||
'Discipline',
|
||||
'Theme',
|
||||
'Person',
|
||||
]
|
||||
@@ -82,19 +81,6 @@ class Role(models.Model):
|
||||
return self.name
|
||||
|
||||
|
||||
class Discipline(models.Model):
|
||||
"""
|
||||
Discipline within which a :class:`Person` works.
|
||||
"""
|
||||
name = models.CharField(max_length=255, blank=False, null=False)
|
||||
|
||||
#: Short code using system such as JACS 3
|
||||
code = models.CharField(max_length=15, blank=True, null=False)
|
||||
|
||||
def __str__(self) -> str:
|
||||
return self.name
|
||||
|
||||
|
||||
class Theme(models.Model):
|
||||
"""
|
||||
Project theme within which a :class:`Person` works.
|
||||
@@ -179,12 +165,8 @@ class Person(models.Model):
|
||||
#: Job title this person holds within their organisation
|
||||
job_title = models.CharField(max_length=255, blank=True, null=False)
|
||||
|
||||
#: Discipline within which this person works
|
||||
discipline = models.ForeignKey(Discipline,
|
||||
on_delete=models.PROTECT,
|
||||
related_name='people',
|
||||
blank=True,
|
||||
null=True)
|
||||
#: Discipline(s) within which this person works
|
||||
disciplines = models.CharField(max_length=255, blank=True, null=True)
|
||||
|
||||
#: Role this person holds within the project
|
||||
role = models.ForeignKey(Role,
|
||||
|
||||
@@ -55,9 +55,9 @@
|
||||
<dd>{{ person.role }}</dd>
|
||||
{% endif %}
|
||||
|
||||
{% if person.dispipline %}
|
||||
<dt>Discipline</dt>
|
||||
<dd>{{ person.discipline }}</dd>
|
||||
{% if person.disciplines %}
|
||||
<dt>Discipline(s)</dt>
|
||||
<dd>{{ person.disciplines }}</dd>
|
||||
{% endif %}
|
||||
|
||||
{% if person.themes.exists %}
|
||||
|
||||
Reference in New Issue
Block a user