Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Django5 #829

Merged
merged 4 commits into from
Jan 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions alyx/actions/views.py
Original file line number Diff line number Diff line change
@@ -66,7 +66,7 @@ class Meta:
exclude = []
filter_overrides = {
JSONField: {
'filter_class': CharFilter,
'filterset_class': CharFilter,
},
}

@@ -365,7 +365,7 @@ class SessionAPIList(generics.ListCreateAPIView):
queryset = SessionListSerializer.setup_eager_loading(queryset)
permission_classes = rest_permission_classes()

filter_class = SessionFilter
filterset_class = SessionFilter

def get_serializer_class(self):
if not self.request:
@@ -394,7 +394,7 @@ class WeighingAPIListCreate(generics.ListCreateAPIView):
serializer_class = WeighingDetailSerializer
queryset = Weighing.objects.all()
queryset = WeighingDetailSerializer.setup_eager_loading(queryset)
filter_class = WeighingFilter
filterset_class = WeighingFilter


class WeighingAPIDetail(generics.RetrieveDestroyAPIView):
@@ -421,7 +421,7 @@ class WaterAdministrationAPIListCreate(generics.ListCreateAPIView):
serializer_class = WaterAdministrationDetailSerializer
queryset = WaterAdministration.objects.all()
queryset = WaterAdministrationDetailSerializer.setup_eager_loading(queryset)
filter_class = WaterAdministrationFilter
filterset_class = WaterAdministrationFilter


class WaterAdministrationAPIDetail(generics.RetrieveUpdateDestroyAPIView):
@@ -458,7 +458,7 @@ class WaterRestrictionList(generics.ListAPIView):
queryset = WaterRestriction.objects.all().order_by('-end_time', '-start_time')
serializer_class = WaterRestrictionListSerializer
permission_classes = rest_permission_classes()
filter_class = WaterRestrictionFilter
filterset_class = WaterRestrictionFilter


class LabLocationList(generics.ListAPIView):
@@ -497,7 +497,7 @@ class SurgeriesList(generics.ListAPIView):
queryset = Surgery.objects.all().order_by('-start_time')
serializer_class = SurgerySerializer
permission_classes = rest_permission_classes()
filter_class = SurgeriesFilter
filterset_class = SurgeriesFilter


class SurgeriesAPIDetail(generics.RetrieveUpdateAPIView):
10 changes: 5 additions & 5 deletions alyx/actions/water_control.py
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@
from django.urls import reverse
from django.utils.html import format_html
from django.http import HttpResponse
from django.utils import timezone
import django.utils.timezone

import numpy as np

@@ -27,7 +27,7 @@


def today():
return timezone.now()
return django.utils.timezone.now()


def to_date(s):
@@ -110,16 +110,16 @@ def return_figure(f):

def tzone_convert(date_t, tz):
assert isinstance(date_t, datetime)
date_t = timezone.make_aware(date_t, timezone.get_default_timezone(), is_dst=False)
return timezone.make_naive(date_t, tz)
date_t = django.utils.timezone.make_aware(date_t, django.utils.timezone.get_default_timezone())
return django.utils.timezone.make_naive(date_t, tz)


class WaterControl(object):
def __init__(self, nickname=None, birth_date=None, sex=None,
implant_weight=None, subject_id=None,
reference_weight_pct=0.,
zscore_weight_pct=0.,
timezone=timezone.get_default_timezone(),
timezone=django.utils.timezone.get_default_timezone(),
):
assert nickname, "Subject nickname not provided"
self.nickname = nickname
2 changes: 1 addition & 1 deletion alyx/alyx/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION = __version__ = '1.17.0'
VERSION = __version__ = '1.18.0'
13 changes: 7 additions & 6 deletions alyx/alyx/base.py
Original file line number Diff line number Diff line change
@@ -7,9 +7,9 @@
import pytz
import uuid
from collections import OrderedDict
from rest_framework import serializers
import one.alf.spec
from datetime import datetime
import traceback

from django import forms
from django.db import models
@@ -23,9 +23,9 @@
from django.utils import termcolors, timezone
from django.test import TestCase
from django_filters import CharFilter
from django_filters.rest_framework import FilterSet
from django_filters import rest_framework as filters
from rest_framework.views import exception_handler

from rest_framework import serializers
from rest_framework import permissions
from dateutil.parser import parse
from reversion.admin import VersionAdmin
@@ -457,7 +457,7 @@ def patch(self, *args, **kwargs):
return self.client.patch(*args, **kwargs, content_type='application/json')


class BaseFilterSet(FilterSet):
class BaseFilterSet(filters.FilterSet):
"""
Base class for Alyx filters. Adds a custom django filter for extensible queries using
Django syntax. For example this is a query on a start_time field of a REST accessible model:
@@ -624,13 +624,14 @@ def rest_filters_exception_handler(exc, context):
REST queries
"""
response = exception_handler(exc, context)

from rest_framework.response import Response
# Now add the HTTP status code to the response.
if response is not None:
response.data['status_code'] = response.status_code
else:
data = {'status_code': 500, 'detail': str(exc)}
# we send back a long form error message in debug mode
debug_text = traceback.format_exc() if settings.DEBUG else str(exc)
data = {'status_code': 500, 'detail': debug_text}
response = Response(data, status=500)

return response
6 changes: 3 additions & 3 deletions alyx/data/views.py
Original file line number Diff line number Diff line change
@@ -220,7 +220,7 @@ class DatasetList(generics.ListCreateAPIView):
queryset = DatasetSerializer.setup_eager_loading(queryset)
serializer_class = DatasetSerializer
permission_classes = rest_permission_classes()
filter_class = DatasetFilter
filterset_class = DatasetFilter


class DatasetDetail(generics.RetrieveUpdateDestroyAPIView):
@@ -265,7 +265,7 @@ class FileRecordList(generics.ListCreateAPIView):
queryset = FileRecordSerializer.setup_eager_loading(queryset)
serializer_class = FileRecordSerializer
permission_classes = rest_permission_classes()
filter_class = FileRecordFilter
filterset_class = FileRecordFilter


class FileRecordDetail(generics.RetrieveUpdateDestroyAPIView):
@@ -595,4 +595,4 @@ class DownloadList(generics.ListAPIView):
queryset = Download.objects.all()
serializer_class = DownloadSerializer
permission_classes = rest_permission_classes()
filter_class = DownloadFilter
filterset_class = DownloadFilter
16 changes: 8 additions & 8 deletions alyx/experiments/views.py
Original file line number Diff line number Diff line change
@@ -152,7 +152,7 @@ class ProbeInsertionList(generics.ListCreateAPIView):
queryset = ProbeInsertionListSerializer.setup_eager_loading(queryset)
serializer_class = ProbeInsertionListSerializer
permission_classes = rest_permission_classes()
filter_class = ProbeInsertionFilter
filterset_class = ProbeInsertionFilter


class ProbeInsertionDetail(generics.RetrieveUpdateDestroyAPIView):
@@ -212,7 +212,7 @@ class ChronicInsertionList(generics.ListCreateAPIView):
queryset = ChronicInsertionListSerializer.setup_eager_loading(queryset)
serializer_class = ChronicInsertionListSerializer
permission_classes = rest_permission_classes()
filter_class = ChronicInsertionFilter
filterset_class = ChronicInsertionFilter


class ChronicInsertionDetail(generics.RetrieveUpdateDestroyAPIView):
@@ -259,7 +259,7 @@ class TrajectoryEstimateList(generics.ListCreateAPIView):
queryset = TrajectoryEstimate.objects.all()
serializer_class = TrajectoryEstimateSerializer
permission_classes = rest_permission_classes()
filter_class = TrajectoryEstimateFilter
filterset_class = TrajectoryEstimateFilter


class TrajectoryEstimateDetail(generics.RetrieveUpdateDestroyAPIView):
@@ -300,7 +300,7 @@ def get_serializer(self, *args, **kwargs):
queryset = Channel.objects.all()
serializer_class = ChannelSerializer
permission_classes = rest_permission_classes()
filter_class = ChannelFilter
filterset_class = ChannelFilter


class ChannelDetail(generics.RetrieveUpdateDestroyAPIView):
@@ -346,7 +346,7 @@ class BrainRegionList(generics.ListAPIView):
queryset = BrainRegion.objects.all()
serializer_class = BrainRegionSerializer
permission_classes = rest_permission_classes()
filter_class = BrainRegionFilter
filterset_class = BrainRegionFilter


class BrainRegionDetail(generics.RetrieveUpdateAPIView):
@@ -436,7 +436,7 @@ class FOVList(generics.ListCreateAPIView):
queryset = FOV.objects.all()
serializer_class = FOVSerializer
permission_classes = rest_permission_classes()
filter_class = FOVFilter
filterset_class = FOVFilter


class FOVDetail(generics.RetrieveUpdateDestroyAPIView):
@@ -475,7 +475,7 @@ class FOVLocationList(generics.ListCreateAPIView):
"""
queryset = FOVLocation.objects.all()
permission_classes = rest_permission_classes()
filter_class = FOVLocationFilter
filterset_class = FOVLocationFilter

def get_serializer_class(self):
if not self.request:
@@ -525,7 +525,7 @@ class ImagingStackList(generics.ListCreateAPIView):
queryset = ImagingStack.objects.all()
# serializer_class = ImagingStackListSerializer
permission_classes = rest_permission_classes()
filter_class = ImagingStackFilter
filterset_class = ImagingStackFilter

def get_serializer_class(self):
if not self.request or self.request.method == 'GET':
2 changes: 1 addition & 1 deletion alyx/jobs/views.py
Original file line number Diff line number Diff line change
@@ -100,7 +100,7 @@ class TaskList(generics.ListCreateAPIView):
queryset = Task.objects.all().order_by('level', '-priority', '-session__start_time')
serializer_class = TaskSerializer
permission_classes = rest_permission_classes()
filter_class = TaskFilter
filterset_class = TaskFilter


class TaskDetail(generics.RetrieveUpdateDestroyAPIView):
6 changes: 3 additions & 3 deletions alyx/misc/views.py
Original file line number Diff line number Diff line change
@@ -89,7 +89,7 @@ class UserList(generics.ListCreateAPIView):
queryset = UserSerializer.setup_eager_loading(get_user_model().objects.all())
serializer_class = UserSerializer
permission_classes = rest_permission_classes()
filter_class = UserFilter
filterset_class = UserFilter
lookup_field = 'username'


@@ -113,7 +113,7 @@ class LabList(generics.ListCreateAPIView):
serializer_class = LabSerializer
permission_classes = rest_permission_classes()
lookup_field = 'name'
filter_class = LabFilter
filterset_class = LabFilter


class LabDetail(generics.RetrieveUpdateDestroyAPIView):
@@ -138,7 +138,7 @@ class NoteList(generics.ListCreateAPIView):
queryset = Note.objects.all()
serializer_class = NoteSerializer
permission_classes = rest_permission_classes()
filter_class = BaseFilterSet
filterset_class = BaseFilterSet


class NoteDetail(generics.RetrieveUpdateDestroyAPIView):
12 changes: 6 additions & 6 deletions alyx/subjects/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import datetime
from datetime import datetime, timezone
import structlog
from operator import attrgetter
import urllib
@@ -10,7 +10,7 @@
from django.db import models
from django.db.models.signals import post_save, post_delete
from django.dispatch import receiver
from django.utils import timezone
import django.utils.timezone

from alyx.base import BaseModel, alyx_mail, modify_fields, ALF_SPEC
from actions.notifications import responsible_user_changed
@@ -284,9 +284,9 @@ def father(self):

def timezone(self):
if not self.lab:
return timezone.get_default_timezone()
return django.utils.timezone.get_default_timezone()
elif not self.lab.timezone:
return timezone.get_default_timezone()
return django.utils.timezone.get_default_timezone()
else:
try:
tz = pytz.timezone(self.lab.timezone)
@@ -369,7 +369,7 @@ def save(self, *args, **kwargs):
self.cull.save()
# Save the reduced date.
if self.reduced and _has_field_changed(self, 'reduced'):
self.reduced_date = timezone.now().date()
self.reduced_date = django.utils.timezone.now().date()
# Update subject request.
if (self.responsible_user_id and _has_field_changed(self, 'responsible_user') and
self.line is not None and
@@ -408,7 +408,7 @@ class SubjectRequest(BaseModel):
help_text="Who requested this subject.")
line = models.ForeignKey('Line', null=True, blank=True, on_delete=models.SET_NULL)
count = models.IntegerField(null=True, blank=True)
date_time = models.DateField(default=timezone.now, null=True, blank=True)
date_time = models.DateField(default=django.utils.timezone.now, null=True, blank=True)
due_date = models.DateField(null=True, blank=True)
description = models.TextField(blank=True)

2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ django-admin-list-filter-dropdown
django-admin-rangefilter
django-autocomplete-light
django-cleanup
django-filter==21.1
django-filter>=23.5
django-mptt
django-polymorphic>=3.0.0
django-reversion>=3.0.8
Loading