This repository has been archived by the owner on Jun 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make staff role fields dependent on staff type
- Loading branch information
Showing
9 changed files
with
302 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
django-verdant/rca/migrations/0087_staffpage_migrate_area_data_to_roles.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.9.13 on 2017-07-06 21:26 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations | ||
from django.db.models import Count | ||
|
||
|
||
class Migration(migrations.Migration): | ||
def move_area_data(apps, schema_editor): | ||
""" | ||
Move StaffPage.area to StaffPageRole.area if the user is | ||
academic/administrative and if StaffPageRole.area is empty. | ||
""" | ||
StaffPage = apps.get_model('rca', 'StaffPage') | ||
|
||
# Move area data to roles | ||
records = StaffPage.objects \ | ||
.prefetch_related('roles') \ | ||
.annotate(roles_count=Count('roles__id')) \ | ||
.filter(staff_type__in=('administrative', 'academic')) \ | ||
.filter(area__isnull=False) \ | ||
.filter(roles_count__gt=0) | ||
|
||
for staff in records: | ||
first_role = staff.roles.filter(area__isnull=True).first() | ||
if first_role is not None: | ||
first_role.area = staff.area | ||
first_role.save() | ||
|
||
dependencies = [ | ||
('rca', '0086_schoolpageresearchlinks_allow_to_add_external_links'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(move_area_data) | ||
] |
38 changes: 38 additions & 0 deletions
38
django-verdant/rca/migrations/0088_staffpage_move_area_and_location_field_to_roles.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.9.13 on 2017-07-06 21:28 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('rca', '0087_staffpage_migrate_area_data_to_roles'), | ||
] | ||
|
||
operations = [ | ||
migrations.RemoveField( | ||
model_name='staffpage', | ||
name='area', | ||
), | ||
migrations.RemoveField( | ||
model_name='staffpage', | ||
name='staff_location', | ||
), | ||
migrations.AddField( | ||
model_name='staffpagerole', | ||
name='location', | ||
field=models.CharField(blank=True, choices=[(b'ceramicsgsmj', b'Ceramics, Glass, Metalwork & Jewellery'), (b'darwinworshops', b'Darwin Workshops'), (b'fashiontextiles', b'Fashion & Textiles'), (b'lensbasedmediaaudio', b'Lens-based Media and Audio'), (b'paintingsculpture', b'Painting & Sculpture'), (b'printmakingletterpress', b'Printmaking & Letterpress'), (b'rapidform', b'Rapidform')], help_text=b'', max_length=255), | ||
), | ||
migrations.AlterField( | ||
model_name='staffpage', | ||
name='staff_type', | ||
field=models.CharField(choices=[(b'academic', b'Academic'), (b'technical', b'Technical'), (b'administrative', b'Administrative')], help_text=b'', max_length=255), | ||
), | ||
migrations.AlterField( | ||
model_name='staffpagerole', | ||
name='title', | ||
field=models.CharField(help_text=b'', max_length=255, verbose_name=b'Job title'), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.