Skip to content

Commit

Permalink
ubccr#294: Created a data migration file so that existing ColdFront i…
Browse files Browse the repository at this point in the history
…nstances, can get the allocation change status choices loaded into their application automatically
  • Loading branch information
brisco17 committed Nov 17, 2021
1 parent fc4cc37 commit 43f9c4b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
20 changes: 20 additions & 0 deletions coldfront/core/allocation/migrations/0005_auto_20211117_1413.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 2.2.24 on 2021-11-17 19:13

from django.db import migrations


def create_status_choices(apps, schema_editor):
AllocationChangeStatusChoice = apps.get_model('allocation', "AllocationChangeStatusChoice")
for choice in ('Pending', 'Approved', 'Denied',):
AllocationChangeStatusChoice.objects.get_or_create(name=choice)


class Migration(migrations.Migration):

dependencies = [
('allocation', '0004_auto_20211102_1017'),
]

operations = [
migrations.RunPython(create_status_choices),
]
7 changes: 7 additions & 0 deletions coldfront/core/allocation/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,13 @@ class AllocationChangeRequest(TimeStampedModel):
notes = models.CharField(max_length=512, blank=True, null=True)
history = HistoricalRecords()

@property
def get_parent_resource(self):
if self.allocation.resources.count() == 1:
return self.allocation.resources.first()
else:
return self.allocation.resources.filter(is_allocatable=True).first()

def __str__(self):
return "%s (%s)" % (self.get_parent_resource.name, self.allocation.project.pi)

Expand Down

0 comments on commit 43f9c4b

Please sign in to comment.