Skip to content

Commit

Permalink
Merge pull request #335 from payerle/allocation_parent_resource_ordering
Browse files Browse the repository at this point in the history
Allow site-level control of how Resources ordered within an Allocation
  • Loading branch information
aebruno committed Jan 11, 2022
2 parents 001913d + 48c3935 commit 0c65d1e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
13 changes: 11 additions & 2 deletions coldfront/core/allocation/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
'ALLOCATION_ATTRIBUTE_VIEW_LIST', [])
ALLOCATION_FUNCS_ON_EXPIRE = import_from_settings(
'ALLOCATION_FUNCS_ON_EXPIRE', [])
ALLOCATION_RESOURCE_ORDERING = import_from_settings(
'ALLOCATION_RESOURCE_ORDERING',
['-is_allocatable', 'name'])


class AllocationStatusChoice(TimeStampedModel):
Expand Down Expand Up @@ -131,14 +134,20 @@ def get_information(self):

@property
def get_resources_as_string(self):
return ', '.join([ele.name for ele in self.resources.all().order_by('-is_allocatable')])
return ', '.join([ele.name for ele in self.resources.all().order_by(
*ALLOCATION_RESOURCE_ORDERING)])

@property
def get_parent_resource(self):
if self.resources.count() == 1:
return self.resources.first()
else:
return self.resources.filter(is_allocatable=True).first()
parent = self.resources.order_by(
*ALLOCATION_RESOURCE_ORDERING).first()
if parent:
return parent
# Fallback
return self.resources.first()

def get_attribute(self, name, expand=True, typed=True,
extra_allocations=[]):
Expand Down
1 change: 1 addition & 0 deletions docs/pages/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ The following settings are ColdFront specific settings related to the core appli
| ALLOCATION_ENABLE_CHANGE_REQUESTS_BY_DEFAULT | Enable or disable allocation change requests. Default True |
| ALLOCATION_CHANGE_REQUEST_EXTENSION_DAYS | List of days users can request extensions in an allocation change request. Default 30,60,90 |
| ALLOCATION_ACCOUNT_ENABLED | Allow user to select account name for allocation. Default False |
| ALLOCATION_RESOURCE_ORDERING | Controls the ordering of parent resources for an allocation (if allocation has multiple resources). Should be a list of field names suitable for Django QuerySet order_by method. Default is ['-is_allocatable', 'name']; i.e. prefer Resources with is_allocatable field set, ordered by name of the Resource.|
| INVOICE_ENABLED | Enable or disable invoices. Default True |
| ONDEMAND_URL | The URL to your Open OnDemand installation |
| LOGIN_FAIL_MESSAGE | Custom message when user fails to login. Here you can paint a custom link to your user account portal |
Expand Down

0 comments on commit 0c65d1e

Please sign in to comment.