Skip to content

Commit ba39d57

Browse files
committed
Rename model and viewsets from HeaProfile to UserProfile and address PR feedback see HEA-580
1 parent e9ec6aa commit ba39d57

File tree

7 files changed

+30
-37
lines changed

7 files changed

+30
-37
lines changed

apps/common/migrations/0010_heaprofile.py renamed to apps/common/migrations/0010_userprofile.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Generated by Django 5.1.1 on 2024-11-17 15:34
1+
# Generated by Django 5.0.2 on 2024-11-22 06:07
22

33
import django.db.models.deletion
44
import django.utils.timezone
@@ -16,7 +16,7 @@ class Migration(migrations.Migration):
1616

1717
operations = [
1818
migrations.CreateModel(
19-
name="HeaProfile",
19+
name="UserProfile",
2020
fields=[
2121
(
2222
"created",
@@ -39,14 +39,11 @@ class Migration(migrations.Migration):
3939
to=settings.AUTH_USER_MODEL,
4040
),
4141
),
42-
("expert", models.BooleanField(default=False)),
43-
("skip_tour", models.BooleanField(default=False)),
44-
("tour_last_viewed", models.DateField(null=True)),
45-
("livelihood_explorer_data", models.JSONField(blank=True, default=dict, null=True)),
42+
("profile_data", models.JSONField(blank=True, default=dict, null=True)),
4643
],
4744
options={
48-
"verbose_name": "hea user profile",
49-
"verbose_name_plural": "hea user profiles",
45+
"verbose_name": "user profile",
46+
"verbose_name_plural": "user profiles",
5047
},
5148
),
5249
]

apps/common/models.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -953,21 +953,17 @@ class Meta:
953953
]
954954

955955

956-
class HeaProfile(Model):
956+
class UserProfile(Model):
957957
"""
958-
A profile to store data associated with a user to be used by the Livelihoods Explorer
959-
to create a dynamic user experience.
958+
A profile to store data associated with a user to enable a customized user experience
960959
"""
961960

962961
user = models.OneToOneField(User, on_delete=CASCADE, primary_key=True, unique=True)
963-
expert = models.BooleanField(default=False)
964-
skip_tour = models.BooleanField(default=False)
965-
tour_last_viewed = models.DateField(null=True)
966-
livelihood_explorer_data = models.JSONField(default=dict, null=True, blank=True)
962+
profile_data = models.JSONField(default=dict, null=True, blank=True)
967963

968964
def __str__(self):
969-
return f"hea_profile: {str(self.user)}"
965+
return f"user_profile: {str(self.user)}"
970966

971967
class Meta:
972-
verbose_name = _("hea user profile")
973-
verbose_name_plural = _("hea user profiles")
968+
verbose_name = _("user profile")
969+
verbose_name_plural = _("user profiles")

apps/common/serializers.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from django.contrib.auth.models import User
22
from rest_framework import serializers
33

4-
from .models import ClassifiedProduct, Country, Currency, HeaProfile, UnitOfMeasure
4+
from .models import ClassifiedProduct, Country, Currency, UnitOfMeasure, UserProfile
55

66

77
class CountrySerializer(serializers.ModelSerializer):
@@ -92,7 +92,7 @@ class Meta:
9292
]
9393

9494

95-
class HeaProfileSerializer(serializers.ModelSerializer):
95+
class UserProfileSerializer(serializers.ModelSerializer):
9696
class Meta:
97-
model = HeaProfile
98-
fields = ("user", "expert", "skip_tour", "tour_last_viewed", "livelihood_explorer_data")
97+
model = UserProfile
98+
fields = ("user", "profile_data")

apps/common/tests/factories.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ def groups(self, create, extracted, **kwargs):
6060
self.groups.add(group)
6161

6262

63-
class HeaProfileFactory(factory.django.DjangoModelFactory):
63+
class UserProfileFactory(factory.django.DjangoModelFactory):
6464
class Meta:
65-
model = "common.HeaProfile"
65+
model = "common.UserProfile"
6666
django_get_or_create = ("user",)
6767

6868
user = factory.SubFactory(UserFactory)

apps/common/tests/test_viewsets.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
ClassifiedProductFactory,
1010
CountryFactory,
1111
CurrencyFactory,
12-
HeaProfileFactory,
1312
UnitOfMeasureFactory,
1413
UserFactory,
14+
UserProfileFactory,
1515
)
1616

1717

@@ -212,12 +212,12 @@ def test_search_users(self):
212212
self.assertEqual(response.data[0]["first_name"], "Search")
213213

214214

215-
class HeaProfileViewSetTestCase(APITestCase):
215+
class UserProfileViewSetTestCase(APITestCase):
216216
def setUp(self):
217217
self.user = UserFactory(username="testuser", password="password123")
218-
self.profile = HeaProfileFactory(user=self.user)
218+
self.profile = UserProfileFactory(user=self.user)
219219
self.client.force_authenticate(user=self.user)
220-
self.url = reverse("heaprofile-list")
220+
self.url = reverse("userprofile-list")
221221

222222
def test_get_current_profile(self):
223223
response = self.client.get(f"{self.url}current/")
@@ -233,7 +233,7 @@ def test_superuser_access_profiles(self):
233233

234234
def test_queryset_filters(self):
235235
other_user = UserFactory(username="otheruser", password="password123")
236-
HeaProfileFactory(user=other_user)
236+
UserProfileFactory(user=other_user)
237237

238238
# Current user profile only
239239
response = self.client.get(f"{self.url}?pk=current")

apps/common/viewsets.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010

1111
from .fields import translation_fields
1212
from .filters import MultiFieldFilter
13-
from .models import ClassifiedProduct, Country, Currency, HeaProfile, UnitOfMeasure
13+
from .models import ClassifiedProduct, Country, Currency, UnitOfMeasure, UserProfile
1414
from .serializers import (
1515
ClassifiedProductSerializer,
1616
CountrySerializer,
1717
CurrencySerializer,
1818
CurrentUserSerializer,
19-
HeaProfileSerializer,
2019
UnitOfMeasureSerializer,
20+
UserProfileSerializer,
2121
UserSerializer,
2222
)
2323

@@ -368,15 +368,15 @@ def current(self, request, *args, **kwargs):
368368
return self.retrieve(request, *args, **kwargs)
369369

370370

371-
class HeaProfileViewSet(BaseModelViewSet):
372-
queryset = HeaProfile.objects.all()
373-
serializer_class = HeaProfileSerializer
371+
class UserProfileViewSet(BaseModelViewSet):
372+
queryset = UserProfile.objects.all()
373+
serializer_class = UserProfileSerializer
374374
permission_classes = [CurrentUserOnly, IsAuthenticated]
375375

376376
def get_object(self):
377377
pk = self.kwargs.get("pk")
378378
if pk == "current":
379-
return self.request.user.heaprofile if self.request.user.id else None
379+
return self.request.user.userprofile if self.request.user.id else None
380380
return super().get_object()
381381

382382
def get_queryset(self):

hea/urls.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@
4949
ClassifiedProductViewSet,
5050
CountryViewSet,
5151
CurrencyViewSet,
52-
HeaProfileViewSet,
5352
UnitOfMeasureViewSet,
5453
UserViewSet,
54+
UserProfileViewSet,
5555
)
5656
from metadata.viewsets import (
5757
HazardCategoryViewSet,
@@ -70,7 +70,7 @@
7070
router.register(r"unitofmeasure", UnitOfMeasureViewSet)
7171
router.register(r"classifiedproduct", ClassifiedProductViewSet)
7272
router.register(r"user", UserViewSet)
73-
router.register(r"heaprofile", HeaProfileViewSet)
73+
router.register(r"userprofile", UserProfileViewSet)
7474

7575
# Metadata
7676
router.register(r"livelihoodcategory", LivelihoodCategoryViewSet)

0 commit comments

Comments
 (0)