Skip to content

Commit

Permalink
Fix a bug in the overview where wrong numbers for subjects and users …
Browse files Browse the repository at this point in the history
…was being reported
  • Loading branch information
trevor-james-nangosha committed Dec 2, 2024
1 parent 0ff1d8d commit ad97508
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
9 changes: 9 additions & 0 deletions api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
from django.contrib.auth.models import AbstractBaseUser, BaseUserManager, PermissionsMixin

class CustomUserManager(BaseUserManager):
def get_queryset(self):
return super().get_queryset().filter(date_deleted__isnull=True, user_role=UserRole.ADMIN)

def create_user(self, email, name, password=None, user_role=None):
if not email:
raise ValueError('Users must have an email address')
Expand Down Expand Up @@ -63,7 +66,13 @@ def delete(self, *args, **kwargs):
def __str__(self):
return self.name

class SubjectManager(models.Manager):
def get_queryset(self):
return super().get_queryset().filter(date_deleted__isnull=True, user_role=UserRole.SUBJECT)

class Subject(User):
objects = SubjectManager()

class Meta:
proxy = True

Expand Down
2 changes: 1 addition & 1 deletion api/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def test_create_user(self):

# Test duplicate email
response = self.client.post('/register/user/', payload)
self.assertEqual(response.status_code, 400)
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)

class LocationTests(BaseTest):
def test_get_all_locations(self):
Expand Down
4 changes: 4 additions & 0 deletions api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ def create(self, request, *args, **kwargs):
serializer = BulkLocationSerializer(data=request.data)
if serializer.is_valid():
locations_data = serializer.validated_data['locations']

if len(locations_data) == 0:
return Response({'error': 'locations data is required'}, status=status.HTTP_400_BAD_REQUEST)

Location.objects.bulk_create(
[Location(**data) for data in locations_data]
)
Expand Down
7 changes: 0 additions & 7 deletions thea/settings/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@
BASE_DIR = os.path.dirname(os.path.abspath(__file__))

DATABASES = {
# 'default': {
# 'ENGINE': 'django.db.backends.sqlite3',
# 'NAME': 'test_db.sqlite3',
# 'TEST': {
# 'NAME': 'test_db.sqlite3',
# },
# },
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': ':memory:',
Expand Down

0 comments on commit ad97508

Please sign in to comment.