Skip to content

Commit

Permalink
more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sainak committed Sep 23, 2024
1 parent 42a8f84 commit 4b836c9
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 19 deletions.
24 changes: 22 additions & 2 deletions care/users/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,24 @@ class UserAdmin(auth_admin.UserAdmin, ExportCsvMixin):
form = UserChangeForm
add_form = UserCreationForm
actions = ["export_as_csv"]
fieldsets = (("User", {"fields": ("user_type", "local_body", "district", "state", "phone_number", "alt_phone_number", "gender", "verified")}), *auth_admin.UserAdmin.fieldsets)
fieldsets = (
(
"User",
{
"fields": (
"user_type",
"local_body",
"district",
"state",
"phone_number",
"alt_phone_number",
"gender",
"verified",
)
},
),
*auth_admin.UserAdmin.fieldsets,
)
list_display = ["username", "is_superuser"]
search_fields = ["first_name", "last_name"]

Expand Down Expand Up @@ -73,7 +90,10 @@ class UserFlagForm(forms.ModelForm):
)

class Meta:
fields = "__all__"
fields = (
"user",
"flag",
)
model = UserFlag

form = UserFlagForm
Expand Down
19 changes: 13 additions & 6 deletions care/users/api/serializers/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ def validate(self, attrs):

return validated


MIN_USER_AGE = 16


class UserCreateSerializer(SignUpSerializer):
password = serializers.CharField(required=False)
facilities = serializers.ListSerializer(
Expand Down Expand Up @@ -127,16 +130,17 @@ def validate_date_of_birth(self, value):
return value

def validate_facilities(self, facility_ids):
if facility_ids and len(facility_ids) != Facility.objects.filter(external_id__in=facility_ids).count():

if (
facility_ids
and len(facility_ids)
!= Facility.objects.filter(external_id__in=facility_ids).count()
):
available_facility_ids = Facility.objects.filter(
external_id__in=facility_ids,
).values_list("external_id", flat=True)
not_found_ids = list(set(facility_ids) - set(available_facility_ids))
error = f"Some facilities are not available - {', '.join([str(_id) for _id in not_found_ids])}"
raise serializers.ValidationError(
error
)
raise serializers.ValidationError(error)
return facility_ids

def validate_ward(self, value):
Expand Down Expand Up @@ -196,7 +200,10 @@ def validate(self, attrs):
},
)

if self.context["created_by"].user_type in User.READ_ONLY_TYPES and validated["user_type"] not in User.READ_ONLY_TYPES:
if (
self.context["created_by"].user_type in User.READ_ONLY_TYPES
and validated["user_type"] not in User.READ_ONLY_TYPES
):
raise exceptions.ValidationError(
{
"user_type": [
Expand Down
1 change: 0 additions & 1 deletion care/users/migrations/0010_rename_skills.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ def fix_skill_name(apps, schema_editor):
Skill.objects.filter(name=old).update(name=new)



class Migration(migrations.Migration):
dependencies = [
("users", "0009_userfacilityallocation"),
Expand Down
1 change: 0 additions & 1 deletion care/users/migrations/0017_userflag.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@


class Migration(migrations.Migration):

dependencies = [
("users", "0016_upgrade_user_skills"),
]
Expand Down
1 change: 0 additions & 1 deletion care/users/migrations/0018_user_profile_picture_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

dependencies = [
("users", "0017_userflag"),
]
Expand Down
2 changes: 1 addition & 1 deletion care/users/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def test_user_can_read_all_users_within_accessible_facility(self):

def test_user_can_modify_themselves(self):
"""Test user can modify the attributes for themselves"""
password = "new_password" # noqa S105
password = "new_password" # noqa S105
username = self.user.username
response = self.client.patch(
f"/api/v1/users/{username}/",
Expand Down
4 changes: 0 additions & 4 deletions care/users/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ def setUpTestData(cls):
"""
cls.state = State.objects.create(name="kerala")


def test_object_name(self):
"""Test that the correct format is returned while printing the object"""
state = self.state
Expand All @@ -45,7 +44,6 @@ def setUpTestData(cls):
state = State.objects.create(name="uttar pradesh")
cls.district = District.objects.create(state=state, name="name")


def test_object_name(self):
"""Test that the correct format is returned while printing the object"""
district = self.district
Expand All @@ -67,7 +65,6 @@ def setUpTestData(cls):
district=district, name="blabla", body_type=1
)


def test_object_name(self):
"""Test that the correct format is returned while printing the object"""
local_body = self.local_body
Expand All @@ -93,4 +90,3 @@ def setUpTestData(cls):
gender=1,
date_of_birth=date(2005, 1, 1),
)

4 changes: 2 additions & 2 deletions config/caches.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@


class DummyCache(dummy.DummyCache):
def set(self, key, value, timeout=DEFAULT_TIMEOUT, version=None, nx=None): # noqa: ARG002
def set(self, key, value, timeout=DEFAULT_TIMEOUT, version=None, nx=None):
super().set(key, value, timeout, version)
# mimic the behavior of django_redis with setnx, for tests
return True


class LocMemCache(locmem.LocMemCache):
def set(self, key, value, timeout=DEFAULT_TIMEOUT, version=None, nx=None): # noqa: ARG002
def set(self, key, value, timeout=DEFAULT_TIMEOUT, version=None, nx=None):
super().set(key, value, timeout, version)
# mimic the behavior of django_redis with setnx, for tests
return True
2 changes: 1 addition & 1 deletion config/settings/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# WhiteNoise
# ------------------------------------------------------------------------------
# http://whitenoise.evans.io/en/latest/django.html#using-whitenoise-in-development
INSTALLED_APPS = ["whitenoise.runserver_nostatic"] + INSTALLED_APPS
INSTALLED_APPS = ["whitenoise.runserver_nostatic", *INSTALLED_APPS]

# django-silk
# ------------------------------------------------------------------------------
Expand Down

0 comments on commit 4b836c9

Please sign in to comment.