Skip to content

Commit b69911a

Browse files
authored
Water restrictions in UW (#962)
* default implant weight is 0 and not None * temporarily set django below version 6 #963 * make sure current subject is always available in restriction form * fix tests when we can't get current object from request * update alyx version number - changelog
1 parent f2bc6be commit b69911a

File tree

8 files changed

+26
-12
lines changed

8 files changed

+26
-12
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,5 @@ alyx/alyx_full.sql.gz
4848
alyx/.idea/
4949

5050
alyx.log
51+
52+
alyx/data/management/commands/create_public_links.py

CHANGELOG.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [3.3.3] 2025-12-04
9+
10+
### Fixed
11+
- default implant weight is 0 and not none to allow plotting of water curves.
12+
- water restriction admin form makes sure the current subject is selectable even if it is not alive anymore.
813

914
## [3.3.2] 2025-11-26
1015

1116
### Fixed
12-
1317
- water history plots: the weight thresholds is `(w - iw) / (ew - iw)`, where `w` is the measured weight, `iw` the implant weight and `ew` the expected weight. Expected weight is `(ew = (rw * a + zw *b) + iw` (weighted sum of reference weight and zscore weight + implant weight). The display was computing thresholds according to `w/ew` , not taking into account the implant weight and is now fixed.
1418

1519

@@ -18,7 +22,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1822
### Changed
1923

2024
- The documentation endpoint `/docs` is only for the browser and uses openapiv3. The database schemes are accessed through `/api/schema`. For compatibility, if the headers require `coreapi`, the endpoint returns a frozen set of endpoint to the client. [#929](https://github.com/cortex-lab/alyx/pull/929)
21-
2225
- narrative template is now available on the base action instead of only for surgeries [#938](https://github.com/cortex-lab/alyx/pull/938)
2326

2427

alyx/actions/admin.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -348,11 +348,20 @@ class Meta:
348348
class WaterRestrictionAdmin(BaseActionAdmin):
349349
def formfield_for_foreignkey(self, db_field, request, **kwargs):
350350
if db_field.name == 'subject':
351+
obj = None
351352
kwargs['queryset'] = Subject.objects.filter(cull__isnull=True).order_by('nickname')
352-
subject_id = self._get_last_subject(request)
353-
if subject_id:
354-
subject = Subject.objects.get(id=subject_id)
355-
kwargs['initial'] = subject
353+
# here if the form is of an existing water restriction, get the subject
354+
if request.resolver_match is not None:
355+
object_id = request.resolver_match.kwargs.get('object_id')
356+
obj = self.get_object(request, object_id) if object_id else None
357+
if obj is not None:
358+
kwargs['queryset'] = (kwargs['queryset'] | Subject.objects.filter(pk=obj.subject.pk)).order_by('nickname')
359+
kwargs['initial'] = obj.subject
360+
else:
361+
subject_id = self._get_last_subject(request)
362+
if subject_id:
363+
subject = Subject.objects.get(id=subject_id)
364+
kwargs['initial'] = subject
356365
return super(BaseActionAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs)
357366

358367
def get_form(self, request, obj=None, **kwargs):

alyx/actions/water_control.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ def last_implant_weight_before(self, date=None, return_date=False):
294294
weights_before = (
295295
(d, w) for (d, w) in reversed(self.implant_weights) if d.date() <= date.date()
296296
)
297-
w = next(weights_before, None)
297+
w = next(weights_before, 0)
298298
return w[1] if (w and not return_date) else w
299299

300300
def last_weighing_before(self, date=None):

alyx/alyx/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
VERSION = __version__ = '3.3.2'
1+
VERSION = __version__ = '3.3.3'

deploy/docker-compose-postgres-gunicorn.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ services:
44
container_name: alyx_apache
55
ports:
66
- "8000:8000"
7-
env_file: ../alyx/alyx/.env_local
7+
env_file: ../alyx/alyx/.env
88
command: >
99
bash -c "python /var/www/alyx/alyx/manage.py collectstatic --noinput &&
1010
gunicorn --workers 2 -b 0.0.0.0:8000 alyx.gunicorn_wsgi:application"
@@ -19,7 +19,7 @@ services:
1919
postgres:
2020
image: postgres:17
2121
container_name: alyx_postgres
22-
env_file: ../alyx/alyx/.env_local
22+
env_file: ../alyx/alyx/.env
2323
volumes:
2424
- alyx_postgres:/var/lib/postgresql/data
2525
expose:

deploy/docker-compose-postgres.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ services:
22
postgres:
33
image: postgres:17
44
container_name: alyx_postgres
5-
env_file: ../alyx/alyx/.env
5+
env_file: ../alyx/alyx/.env_prod
66
volumes:
77
- alyx_postgres:/var/lib/postgresql/data
88
ports:

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
boto3
22
colorlog
3-
django>=5.2.2
3+
django>=5.2.9,<6 # see issue #963
44
django-admin-list-filter-dropdown
55
django-admin-rangefilter
66
django-autocomplete-light

0 commit comments

Comments
 (0)