utils
main.utils
¤
General utilities for ProCAT.
Classes¤
Functions:¤
create_HoRSE_group(apps, *args)
¤
Create HoRSE group.
Source code in main/utils.py
62 63 64 65 | |
create_RSETeam_group(apps, *args)
¤
Create RSETeam group and add permissions.
Source code in main/utils.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | |
create_analysis(*args)
¤
Create default analysis codes.
Source code in main/utils.py
49 50 51 52 53 | |
days_to_fte(start_date, end_date, days)
¤
Convert a number of days of effort into an FTE value over a date range.
The period is measured in seconds internally, so fractional days (e.g. if
start_date/end_date are datetimes with a time component) are handled
correctly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start_date
|
date
|
The start of the period over which the effort is spread. |
required |
end_date
|
date
|
The end of the period over which the effort is spread. |
required |
days
|
float
|
The number of (working) days of effort within that period. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The FTE (full-time-equivalent) value equivalent to |
float
|
over the period from |
Source code in main/utils.py
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 | |
destroy_HoRSE_group(apps, *args)
¤
Delete HoRSE group.
Source code in main/utils.py
68 69 70 71 | |
destroy_RSETeam_group(apps, *args)
¤
Delete RSETeam group.
Note that this deletes the group but does not delete the permissions associated with the group, so it is not truly reversible.
Source code in main/utils.py
92 93 94 95 96 97 98 99 | |
destroy_analysis(*args)
¤
Delete default analysis codes.
Source code in main/utils.py
56 57 58 59 | |
format_currency(value)
¤
Format a float value as a GBP currency with two decimal places.
Source code in main/utils.py
281 282 283 | |
fte_to_days(start_date, end_date, fte)
¤
Convert an FTE value over a date range into a number of days of effort.
The period is measured in seconds internally, so fractional days (e.g. if
start_date/end_date are datetimes with a time component) are handled
correctly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start_date
|
date
|
The start of the period over which the FTE is spread. |
required |
end_date
|
date
|
The end of the period over which the FTE is spread. |
required |
fte
|
float
|
The FTE (full-time-equivalent) value. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The number of (working) days of effort equivalent to |
float
|
the period from |
Source code in main/utils.py
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 | |
get_budget_status(date=None)
¤
Get the budget status of a funding.
Source code in main/utils.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 | |
get_calendar_year_dates()
¤
Get the start and end dates for the current calendar year.
Source code in main/utils.py
261 262 263 264 265 266 | |
get_current_and_last_month(date=None)
¤
Get the start of the last month and current month, and their names.
Source code in main/utils.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | |
get_financial_year_dates()
¤
Get the start and end dates for the current financial year.
Source code in main/utils.py
269 270 271 272 273 274 275 276 277 278 | |
get_head_email()
¤
Get the emails of the HoRSE group users.
Source code in main/utils.py
149 150 151 152 153 154 155 | |
get_logged_hours(entries)
¤
Calculate total logged hours from time entries.
Source code in main/utils.py
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | |
get_month_dates_for_previous_years()
¤
Get the start and end date of each month for the previous 3 years.
Source code in main/utils.py
185 186 187 188 189 190 191 192 193 194 195 196 197 198 | |
get_projects_with_days_used_exceeding_days_left()
¤
Get projects whose time entries exceed the total effort of the project.
Source code in main/utils.py
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 | |
order_queryset_by_property(queryset, property, is_descending)
¤
Orders a queryset according to a specified Model property.
Creates a Django conditional expression to assign the position of the model in a queryset according to its model ID (using a custom ordering). The conditional expression is then provided to the QuerySet.order_by() function. This can be used to update the ordering of a queryset column in a Table.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
queryset
|
QuerySet[Any]
|
a model queryset for ordering |
required |
property
|
str
|
the name of the model property with which to order the queryset |
required |
is_descending
|
bool
|
bool to indicate whether the property should be sorted by descending (or ascending) order |
required |
Returns:
| Type | Description |
|---|---|
QuerySet[Any]
|
The queryset ordered according to the property. |
Source code in main/utils.py
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 | |
style_fraction_badge(value, size_class='fs-5')
¤
Render a number/percentage pair as a colour-graded Bootstrap badge.
Used for metrics where the percentage indicates how much of a resource is left (e.g. days or weeks remaining): green when comfortably placed, amber when getting low, and red when critical. If there is no value to show (e.g. the metric isn't relevant for the project's current status), a neutral grey 'N/A' badge is returned instead.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
tuple[float, float] | None
|
A tuple of (absolute number, percentage), or None if not applicable. |
required |
size_class
|
str
|
The Bootstrap font-size utility class to use for the badge text (e.g. 'fs-5', the default used in the Project list table, or 'fs-4' for the bigger badges on the Project detail page). |
'fs-5'
|
Returns:
| Type | Description |
|---|---|
SafeString
|
Safe HTML string with the appropriate Bootstrap badge styling. |
Source code in main/utils.py
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 | |
style_plain_badge(value, formatter, size_class='fs-5')
¤
Render a single value as a neutral 'big badge' span.
Used for metrics that don't have a good/bad fraction associated with them
(e.g. total funding, total effort), so they are always styled the same,
neutral colour instead of the red/amber/green grading used by
style_fraction_badge.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
float | None
|
The value to display inside the badge, or None if not applicable. |
required |
formatter
|
Callable[[float], str]
|
A function that turns |
required |
size_class
|
str
|
The Bootstrap font-size utility class to use for the badge text (e.g. 'fs-5', the default, or 'fs-4' for the bigger badges on the Project detail page). |
'fs-5'
|
Returns:
| Type | Description |
|---|---|
SafeString
|
Safe HTML string with the appropriate Bootstrap badge styling. |
Source code in main/utils.py
371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 | |