Skip to content

Commit

Permalink
feat: removing djangoapp demographics, step 1 (#35182)
Browse files Browse the repository at this point in the history
* feat: removing djangoapp `demographics`, step 1

This step removes the models, the references to the models, and adds a
migration to drop both tables  (`HistoricalUserDemographics`  didn't
have a corresponding model but was still a valid table).

Once this has deployed, this will be removed from `INSTALLED_APPS` and
completely removed.

No other apps  in the repository currently reference this djangoapp  in
code or tables.

FIXES: APER-3560
  • Loading branch information
deborahgu authored Jul 25, 2024
1 parent 6b5d812 commit 12569b4
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 178 deletions.
19 changes: 0 additions & 19 deletions openedx/core/djangoapps/demographics/admin.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,3 @@
"""
Django admin page for demographics
"""

from django.contrib import admin

from openedx.core.djangoapps.demographics.models import UserDemographics


class UserDemographicsAdmin(admin.ModelAdmin):
"""
Admin for UserDemographics Model
"""
list_display = ('id', 'user', 'show_call_to_action')
readonly_fields = ('user',)
search_fields = ('id', 'user__username')

class Meta:
model = UserDemographics


admin.site.register(UserDemographics, UserDemographicsAdmin)
13 changes: 3 additions & 10 deletions openedx/core/djangoapps/demographics/api/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
Python API for Demographics Status
"""

from openedx.features.enterprise_support.utils import is_enterprise_learner
from openedx.core.djangoapps.programs.api import is_user_enrolled_in_program_type
from openedx.core.djangoapps.demographics.models import UserDemographics
from openedx.features.enterprise_support.utils import is_enterprise_learner


def show_user_demographics(user, enrollments=None, entitlements=None):
Expand All @@ -13,10 +12,7 @@ def show_user_demographics(user, enrollments=None, entitlements=None):
to MicroBachlors Programs' learners who aren't part of an enterprise.
"""
is_user_in_microbachelors_program = is_user_enrolled_in_program_type(
user,
"microbachelors",
enrollments=enrollments,
entitlements=entitlements
user, "microbachelors", enrollments=enrollments, entitlements=entitlements
)
return is_user_in_microbachelors_program and not is_enterprise_learner(user)

Expand All @@ -26,7 +22,4 @@ def show_call_to_action_for_user(user):
Utility method to determine if a user should be shown the Demographics call to
action.
"""
try:
return UserDemographics.objects.get(user=user).show_call_to_action
except UserDemographics.DoesNotExist:
return True
return False
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 4.2.14 on 2024-07-25 15:19

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('demographics', '0004_alter_historicaluserdemographics_options'),
]

operations = [
migrations.RemoveField(
model_name='userdemographics',
name='user',
),
migrations.DeleteModel(
name='HistoricalUserDemographics',
),
migrations.DeleteModel(
name='UserDemographics',
),
]
27 changes: 0 additions & 27 deletions openedx/core/djangoapps/demographics/models.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,3 @@
"""
Demographics models
"""

from django.contrib.auth import get_user_model
from django.db import models
from model_utils.models import TimeStampedModel
from simple_history.models import HistoricalRecords

User = get_user_model()


class UserDemographics(TimeStampedModel):
"""
A Users Demographics platform related data in support of the Demographics
IDA and features
.. no_pii:
"""
user = models.OneToOneField(User, on_delete=models.CASCADE)
show_call_to_action = models.BooleanField(default=True)
history = HistoricalRecords(app='demographics')

class Meta:
app_label = "demographics"
verbose_name = "user demographic"
verbose_name_plural = "user demographic"

def __str__(self):
return f'UserDemographics for {self.user}'
30 changes: 5 additions & 25 deletions openedx/core/djangoapps/demographics/rest_api/v1/views.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
# lint-amnesty, pylint: disable=missing-module-docstring
from rest_framework import permissions, status
from rest_framework import permissions
from rest_framework.response import Response
from rest_framework.views import APIView

from openedx.core.djangoapps.demographics.api.status import (
show_user_demographics, show_call_to_action_for_user,
)
from openedx.core.djangoapps.demographics.models import UserDemographics
from openedx.core.djangoapps.demographics.api.status import show_call_to_action_for_user, show_user_demographics


class DemographicsStatusView(APIView):
Expand All @@ -16,7 +13,8 @@ class DemographicsStatusView(APIView):
The API will return whether or not to display the Demographics UI based on
the User's status in the Platform
"""
permission_classes = (permissions.IsAuthenticated, )

permission_classes = (permissions.IsAuthenticated,)

def _response_context(self, user, user_demographics=None):
"""
Expand All @@ -26,10 +24,7 @@ def _response_context(self, user, user_demographics=None):
show_call_to_action = user_demographics.show_call_to_action
else:
show_call_to_action = show_call_to_action_for_user(user)
return {
'display': show_user_demographics(user),
'show_call_to_action': show_call_to_action
}
return {"display": show_user_demographics(user), "show_call_to_action": show_call_to_action}

def get(self, request):
"""
Expand All @@ -39,18 +34,3 @@ def get(self, request):
"""
user = request.user
return Response(self._response_context(user))

def patch(self, request):
"""
PATCH /api/user/v1/accounts/demographics/status
This is a Web API to update fields that are dependent on user interaction.
"""
show_call_to_action = request.data.get('show_call_to_action')
user = request.user
if not isinstance(show_call_to_action, bool):
return Response(status.HTTP_400_BAD_REQUEST)
(user_demographics, _) = UserDemographics.objects.get_or_create(user=user)
user_demographics.show_call_to_action = show_call_to_action
user_demographics.save()
return Response(self._response_context(user, user_demographics))
Empty file.
16 changes: 0 additions & 16 deletions openedx/core/djangoapps/demographics/tests/factories.py

This file was deleted.

81 changes: 0 additions & 81 deletions openedx/core/djangoapps/demographics/tests/test_status.py

This file was deleted.

0 comments on commit 12569b4

Please sign in to comment.