Browse Source

Update faculty with code field. And use that for matching researchers.

master
Joshua Rubingh 6 months ago
parent
commit
4ce2088005
  1. 14
      VRE/apps/api/authentication.py
  2. 190
      VRE/apps/university/fixtures/university_initial_data.json
  3. 18
      VRE/apps/university/migrations/0003_faculty_code.py
  4. 1
      VRE/apps/university/models.py

14
VRE/apps/api/authentication.py

@ -96,9 +96,10 @@ class VRE_OIDC_Researcher_Update(OIDCAuthenticationBackend): @@ -96,9 +96,10 @@ class VRE_OIDC_Researcher_Update(OIDCAuthenticationBackend):
# We cannot handle multiple faculties for now
email_domain = claims.get('schac_home_organization', '')
faculty_list = claims.get('ou', [])
faculty_code = claims.get('ou', [])
faculty_code = None if len(faculty_code) == 0 else faculty_code[0].split(',')[-1].strip() # The format is: [Department], [Faculty_Code]
if '' == email_domain or len(faculty_list) == 0:
if '' == email_domain or faculty_code is None:
return None
university = University.objects.filter(email__endswith=f'@{email_domain}').first()
@ -107,15 +108,20 @@ class VRE_OIDC_Researcher_Update(OIDCAuthenticationBackend): @@ -107,15 +108,20 @@ class VRE_OIDC_Researcher_Update(OIDCAuthenticationBackend):
return None
# Find the first available faculty based on the provided list and university
faculty = Faculty.objects.filter(name__in=faculty_list, university=university).first()
faculty = Faculty.objects.filter(code=faculty_code, university=university).first()
if faculty is None:
# Create a new faculty, as we do not know it.
faculty = Faculty.objects.create(name=faculty_list[0], university=university)
faculty = Faculty.objects.create(code=faculty_code, name=f'Unknown faculty: {faculty}', university=university)
return faculty
def __enhance_user(self, user, claims):
update_user = False
# Update user id based on university email address
if (claims.get('email', '') != '' and claims.get('email') != user.username):
user.username = claims.get('email')
update_user = True
# Update first name
if (claims.get('given_name', '') != '' and claims.get('given_name') != user.first_name):
user.first_name = claims.get('given_name')

190
VRE/apps/university/fixtures/university_initial_data.json

@ -15,8 +15,9 @@ @@ -15,8 +15,9 @@
"pk": 2,
"fields": {
"created_at": "2021-04-29T09:40:00.843Z",
"updated_at": "2021-04-29T09:40:00.843Z",
"name": "Economie en Bedrijfskunde",
"updated_at": "2021-12-03T09:19:34.697Z",
"code": "FEB",
"name": "Faculteit Economie en Bedrijfskunde",
"university": 1
}
},
@ -25,8 +26,9 @@ @@ -25,8 +26,9 @@
"pk": 3,
"fields": {
"created_at": "2021-04-29T09:40:15.232Z",
"updated_at": "2021-04-29T09:59:05.168Z",
"name": "Gedrags- en Maatschappij-wetenschappen",
"updated_at": "2021-12-03T09:21:47.259Z",
"code": "GMW",
"name": "Faculteit Gedrags- en Maatschappijwetenschappen",
"university": 1
}
},
@ -35,8 +37,9 @@ @@ -35,8 +37,9 @@
"pk": 4,
"fields": {
"created_at": "2021-04-29T09:40:26.287Z",
"updated_at": "2021-04-29T09:40:26.287Z",
"name": "Godgeleerdheid en Godsdienst- wetenschap",
"updated_at": "2021-12-03T09:21:19.441Z",
"code": "GGW",
"name": "Faculteit Godgeleerdheid en Godsdienstwetenschap",
"university": 1
}
},
@ -45,8 +48,9 @@ @@ -45,8 +48,9 @@
"pk": 5,
"fields": {
"created_at": "2021-04-29T09:40:34.920Z",
"updated_at": "2021-04-29T09:40:34.920Z",
"name": "Letteren",
"updated_at": "2021-12-03T09:22:16.377Z",
"code": "LET",
"name": "Faculteit der Letteren",
"university": 1
}
},
@ -55,8 +59,9 @@ @@ -55,8 +59,9 @@
"pk": 6,
"fields": {
"created_at": "2021-04-29T09:40:43.131Z",
"updated_at": "2021-04-29T09:40:43.131Z",
"name": "Medische Wetenschappen",
"updated_at": "2021-12-03T09:25:23.027Z",
"code": "UMC",
"name": "Faculteit Medische Wetenschappen (umcg)",
"university": 1
}
},
@ -65,8 +70,9 @@ @@ -65,8 +70,9 @@
"pk": 7,
"fields": {
"created_at": "2021-04-29T09:40:51.248Z",
"updated_at": "2021-04-29T10:04:42.753Z",
"name": "Rechtsgeleerdheid",
"updated_at": "2021-12-03T09:22:03.505Z",
"code": "JUR",
"name": "Faculteit Rechtsgeleerdheid",
"university": 1
}
},
@ -75,48 +81,130 @@ @@ -75,48 +81,130 @@
"pk": 8,
"fields": {
"created_at": "2021-04-29T09:41:00.072Z",
"updated_at": "2021-04-29T09:57:18.767Z",
"name": "Ruimtelijke Wetenschappen",
"updated_at": "2021-12-03T09:20:11.745Z",
"code": "FRW",
"name": "Faculteit Ruimtelijke Wetenschappen",
"university": 1
}
},
{
"model": "university.faculty",
"pk": 9,
"pk": 10,
"fields": {
"created_at": "2021-04-29T09:41:10.777Z",
"updated_at": "2021-04-29T10:05:55.983Z",
"name": "Science and Engineering",
"created_at": "2021-04-29T09:41:17.643Z",
"updated_at": "2021-12-03T09:19:52.219Z",
"code": "FIL",
"name": "Faculteit Wijsbegeerte",
"university": 1
}
},
{
"model": "university.faculty",
"pk": 10,
"pk": 11,
"fields": {
"created_at": "2021-04-29T09:41:17.643Z",
"updated_at": "2021-04-29T10:07:00.916Z",
"name": "Wijsbegeerte",
"created_at": "2021-04-29T09:41:24.270Z",
"updated_at": "2021-12-03T09:24:48.670Z",
"code": "UCG",
"name": "University College Groningen",
"university": 1
}
},
{
"model": "university.faculty",
"pk": 11,
"pk": 13,
"fields": {
"created_at": "2021-04-29T09:41:24.270Z",
"updated_at": "2021-04-29T09:41:24.270Z",
"name": "University College Groningen",
"created_at": "2021-11-18T10:28:34.929Z",
"updated_at": "2021-12-03T09:18:25.325Z",
"code": "CIT",
"name": "Centrum voor Informatie Technologie",
"university": 1
}
},
{
"model": "university.faculty",
"pk": 12,
"pk": 14,
"fields": {
"created_at": "2021-12-03T09:19:02.363Z",
"updated_at": "2021-12-03T09:19:02.363Z",
"code": "BUR",
"name": "Bureau van de Universiteit",
"university": 1
}
},
{
"model": "university.faculty",
"pk": 15,
"fields": {
"created_at": "2021-12-03T09:19:19.215Z",
"updated_at": "2021-12-03T09:19:19.215Z",
"code": "CVB",
"name": "College van Bestuur",
"university": 1
}
},
{
"model": "university.faculty",
"pk": 16,
"fields": {
"created_at": "2021-12-03T09:20:54.557Z",
"updated_at": "2021-12-03T09:20:54.557Z",
"code": "FWN",
"name": "Faculteit Wis- en Natuurkunde",
"university": 1
}
},
{
"model": "university.faculty",
"pk": 17,
"fields": {
"created_at": "2021-12-03T09:23:29.654Z",
"updated_at": "2021-12-03T09:23:29.654Z",
"code": "PPO",
"name": "Postmaster Psychologie en Orthopedagogiek (gelieerde instelling)",
"university": 1
}
},
{
"model": "university.faculty",
"pk": 18,
"fields": {
"created_at": "2021-12-03T09:23:50.750Z",
"updated_at": "2021-12-03T09:23:50.750Z",
"code": "PTH",
"name": "Protestants Theologische Universiteit (gelieerde instelling)",
"university": 1
}
},
{
"model": "university.faculty",
"pk": 19,
"fields": {
"created_at": "2021-12-03T09:24:04.737Z",
"updated_at": "2021-12-03T09:24:04.737Z",
"code": "SRN",
"name": "SRON (gelieerde instelling)",
"university": 1
}
},
{
"model": "university.faculty",
"pk": 20,
"fields": {
"created_at": "2021-12-03T09:24:31.917Z",
"updated_at": "2021-12-03T09:24:31.917Z",
"code": "UBG",
"name": "Universiteitsbibliotheek Groningen",
"university": 1
}
},
{
"model": "university.faculty",
"pk": 21,
"fields": {
"created_at": "2021-04-29T09:41:32.065Z",
"updated_at": "2021-04-29T09:41:32.066Z",
"name": "Rijksuniversiteit Groningen/Campus Fryslân",
"created_at": "2021-12-03T09:25:03.871Z",
"updated_at": "2021-12-03T09:25:03.871Z",
"code": "UFB",
"name": "Universitair Facilitair Bedrijf",
"university": 1
}
},
@ -325,9 +413,9 @@ @@ -325,9 +413,9 @@
"pk": 21,
"fields": {
"created_at": "2021-04-29T10:03:35.592Z",
"updated_at": "2021-04-29T10:03:35.592Z",
"updated_at": "2021-11-18T10:28:53.812Z",
"name": "Effective Criminal Law",
"faculty": 7
"faculty": 13
}
},
{
@ -335,9 +423,9 @@ @@ -335,9 +423,9 @@
"pk": 22,
"fields": {
"created_at": "2021-04-29T10:03:44.191Z",
"updated_at": "2021-04-29T10:03:44.191Z",
"updated_at": "2021-11-18T10:29:02.132Z",
"name": "Law on Energy and Sustainability",
"faculty": 7
"faculty": 13
}
},
{
@ -395,39 +483,9 @@ @@ -395,39 +483,9 @@
"pk": 28,
"fields": {
"created_at": "2021-04-29T10:05:18.656Z",
"updated_at": "2021-04-29T10:05:18.656Z",
"updated_at": "2021-11-18T10:29:41.838Z",
"name": "Advanced Materials",
"faculty": 9
}
},
{
"model": "university.studyfield",
"pk": 29,
"fields": {
"created_at": "2021-04-29T10:05:25.139Z",
"updated_at": "2021-04-29T10:05:25.140Z",
"name": "Molecular Life and Health",
"faculty": 9
}
},
{
"model": "university.studyfield",
"pk": 30,
"fields": {
"created_at": "2021-04-29T10:05:31.161Z",
"updated_at": "2021-04-29T10:05:31.161Z",
"name": "Adaptive Life",
"faculty": 9
}
},
{
"model": "university.studyfield",
"pk": 31,
"fields": {
"created_at": "2021-04-29T10:05:37.997Z",
"updated_at": "2021-04-29T10:05:37.997Z",
"name": "Data Science and Systems Complexity",
"faculty": 9
"faculty": 13
}
},
{

18
VRE/apps/university/migrations/0003_faculty_code.py

@ -0,0 +1,18 @@ @@ -0,0 +1,18 @@
# Generated by Django 3.2.9 on 2021-12-03 09:17
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('university', '0002_auto_20211124_1149'),
]
operations = [
migrations.AddField(
model_name='faculty',
name='code',
field=models.CharField(default='___', help_text='The code for the faculty.', max_length=3, verbose_name='code'),
),
]

1
VRE/apps/university/models.py

@ -54,6 +54,7 @@ class Faculty(MetaDataModel): @@ -54,6 +54,7 @@ class Faculty(MetaDataModel):
verbose_name_plural = _('faculties')
ordering = ['name']
code = models.CharField(_('code'), max_length=3, help_text=_('The code for the faculty.'), default='___')
name = models.CharField(_('Name'), max_length=200, help_text=_('The name of the faculty.'))
university = models.ForeignKey(University, verbose_name=University._meta.verbose_name, on_delete=models.CASCADE, help_text=_('To which university belongs this faculty'))

Loading…
Cancel
Save