-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #279 from City-of-Helsinki/develop
Merge develop to master
- Loading branch information
Showing
16 changed files
with
487 additions
and
65 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
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
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,73 @@ | ||
# Generated by Django 2.2.12 on 2020-04-28 10:28 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('metarecord', '0043_add_name_and_help_text_to_attribute_value'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='action', | ||
name='_created_by', | ||
field=models.CharField(blank=True, editable=False, max_length=200, verbose_name='created by (text)'), | ||
), | ||
migrations.AddField( | ||
model_name='action', | ||
name='_modified_by', | ||
field=models.CharField(blank=True, editable=False, max_length=200, verbose_name='modified by (text)'), | ||
), | ||
migrations.AddField( | ||
model_name='bulkupdate', | ||
name='_approved_by', | ||
field=models.CharField(blank=True, editable=False, max_length=200, verbose_name='approved by (text)'), | ||
), | ||
migrations.AddField( | ||
model_name='bulkupdate', | ||
name='_created_by', | ||
field=models.CharField(blank=True, editable=False, max_length=200, verbose_name='created by (text)'), | ||
), | ||
migrations.AddField( | ||
model_name='bulkupdate', | ||
name='_modified_by', | ||
field=models.CharField(blank=True, editable=False, max_length=200, verbose_name='modified by (text)'), | ||
), | ||
migrations.AddField( | ||
model_name='function', | ||
name='_created_by', | ||
field=models.CharField(blank=True, editable=False, max_length=200, verbose_name='created by (text)'), | ||
), | ||
migrations.AddField( | ||
model_name='function', | ||
name='_modified_by', | ||
field=models.CharField(blank=True, editable=False, max_length=200, verbose_name='modified by (text)'), | ||
), | ||
migrations.AddField( | ||
model_name='metadataversion', | ||
name='_modified_by', | ||
field=models.CharField(blank=True, editable=False, max_length=200, verbose_name='modified by (text)'), | ||
), | ||
migrations.AddField( | ||
model_name='phase', | ||
name='_created_by', | ||
field=models.CharField(blank=True, editable=False, max_length=200, verbose_name='created by (text)'), | ||
), | ||
migrations.AddField( | ||
model_name='phase', | ||
name='_modified_by', | ||
field=models.CharField(blank=True, editable=False, max_length=200, verbose_name='modified by (text)'), | ||
), | ||
migrations.AddField( | ||
model_name='record', | ||
name='_created_by', | ||
field=models.CharField(blank=True, editable=False, max_length=200, verbose_name='created by (text)'), | ||
), | ||
migrations.AddField( | ||
model_name='record', | ||
name='_modified_by', | ||
field=models.CharField(blank=True, editable=False, max_length=200, verbose_name='modified by (text)'), | ||
), | ||
] |
79 changes: 79 additions & 0 deletions
79
metarecord/migrations/0045_populate_persistent_user_name_fields.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,79 @@ | ||
# Generated by Django 2.2.12 on 2020-04-30 08:11 | ||
|
||
from django.db import migrations | ||
from django.db.models import OuterRef, Subquery, Value as V | ||
from django.db.models.functions import Coalesce, Concat, Trim | ||
|
||
|
||
def populate_user_name_field(apps, field_name, model_class): | ||
""" | ||
Populate related user's full name to equivalent char field prefixed with | ||
single underscore. The char field is expected to be in the same table as | ||
the foreign key. | ||
""" | ||
User = apps.get_model('users', 'User') | ||
char_field_name = '_%s' % field_name | ||
|
||
full_name = ( | ||
User.objects | ||
.filter(pk=OuterRef(field_name)) | ||
.annotate(full_name=Trim(Concat('first_name', V(' '), 'last_name'))) | ||
.values_list('full_name')[:1] | ||
) | ||
|
||
model_class.objects.exclude( | ||
**{field_name: None} | ||
).update( | ||
**{char_field_name: Subquery(full_name)} | ||
) | ||
|
||
|
||
def populate_function_user_name_fields(apps, schema_editor): | ||
Function = apps.get_model('metarecord', 'Function') | ||
populate_user_name_field(apps, 'created_by', Function) | ||
populate_user_name_field(apps, 'modified_by', Function) | ||
|
||
|
||
def populate_phase_user_name_fields(apps, schema_editor): | ||
Phase = apps.get_model('metarecord', 'Phase') | ||
populate_user_name_field(apps, 'created_by', Phase) | ||
populate_user_name_field(apps, 'modified_by', Phase) | ||
|
||
|
||
def populate_action_user_name_fields(apps, schema_editor): | ||
Action = apps.get_model('metarecord', 'Action') | ||
populate_user_name_field(apps, 'created_by', Action) | ||
populate_user_name_field(apps, 'modified_by', Action) | ||
|
||
|
||
def populate_record_user_name_fields(apps, schema_editor): | ||
Record = apps.get_model('metarecord', 'Record') | ||
populate_user_name_field(apps, 'created_by', Record) | ||
populate_user_name_field(apps, 'modified_by', Record) | ||
|
||
|
||
def populate_bulk_update_user_name_fields(apps, schema_editor): | ||
BulkUpdate = apps.get_model('metarecord', 'BulkUpdate') | ||
populate_user_name_field(apps, 'approved_by', BulkUpdate) | ||
populate_user_name_field(apps, 'created_by', BulkUpdate) | ||
populate_user_name_field(apps, 'modified_by', BulkUpdate) | ||
|
||
|
||
def populate_metadata_version_user_name_fields(apps, schema_editor): | ||
MetadataVersion = apps.get_model('metarecord', 'MetadataVersion') | ||
populate_user_name_field(apps, 'modified_by', MetadataVersion) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
('metarecord', '0044_user_relation_texts'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(populate_function_user_name_fields, migrations.RunPython.noop), | ||
migrations.RunPython(populate_phase_user_name_fields, migrations.RunPython.noop), | ||
migrations.RunPython(populate_action_user_name_fields, migrations.RunPython.noop), | ||
migrations.RunPython(populate_record_user_name_fields, migrations.RunPython.noop), | ||
migrations.RunPython(populate_bulk_update_user_name_fields, migrations.RunPython.noop), | ||
migrations.RunPython(populate_metadata_version_user_name_fields, migrations.RunPython.noop), | ||
] |
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
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
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.