Skip to content

Commit

Permalink
Update Demographics model and form with new fields
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinEtchells committed Sep 6, 2024
1 parent dce43f6 commit c4c3899
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 8 deletions.
12 changes: 5 additions & 7 deletions django_app/redbox_app/redbox_core/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,16 @@ class SignInForm(forms.Form):
class DemographicsForm(forms.ModelForm):
class Meta:
model = User
fields = ("name", "ai_experience", "business_unit", "grade", "profession")
fields = ("name", "ai_experience", "info_about_user", "redbox_response_preferences")
labels: ClassVar[Mapping[str, str]] = {
"name": "Full Name",
"ai_experience": "How would you describe your level of experience with Generative AI tools?",
"business_unit": "Business unit",
"grade": "Grade",
"profession": "Profession",
"info_about_user": "What do you want Redbox to know about you?",
"redbox_response_preferences": "How do you want Redbox to respond?",
}
widgets: ClassVar[Mapping[str, forms.Widget]] = {
"name": forms.TextInput(attrs={"class": "govuk-input govuk-!-width-one-half"}),
"ai_experience": forms.RadioSelect(attrs={"class": "govuk-radios__item"}),
"business_unit": forms.Select(attrs={"class": "govuk-select govuk-!-width-one-third"}),
"grade": forms.Select(attrs={"class": "govuk-select govuk-!-width-one-third"}),
"profession": forms.Select(attrs={"class": "govuk-select govuk-!-width-one-third"}),
"info_about_user": forms.Textarea(attrs={"class": "govuk-textarea govuk-!-width-one-half"}),
"redbox_response_preferences": forms.Textarea(attrs={"class": "govuk-textarea govuk-!-width-one-half"}),
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 5.1.1 on 2024-09-05 15:57

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('redbox_core', '0041_alter_aisettings_chat_backend'),
]

operations = [
migrations.AddField(
model_name='user',
name='info_about_user',
field=models.CharField(blank=True, help_text='user entered info from profile overlay', null=True),
),
migrations.AddField(
model_name='user',
name='redbox_response_preferences',
field=models.CharField(blank=True, help_text='user entered info from profile overlay, to be used in custom prompt', null=True),
),
]
18 changes: 18 additions & 0 deletions django_app/redbox_app/redbox_core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@ class AIExperienceLevel(models.TextChoices):
name = models.CharField(null=True, blank=True)
ai_experience = models.CharField(null=True, blank=True, max_length=25, choices=AIExperienceLevel)
profession = models.CharField(null=True, blank=True, max_length=4, choices=Profession)
info_about_user = models.CharField(null=True, blank=True, help_text="user entered info from profile overlay")
redbox_response_preferences = models.CharField(null=True, blank=True, help_text="user entered info from profile overlay, to be used in custom prompt")
ai_settings = models.ForeignKey(AISettings, on_delete=models.SET_DEFAULT, default="default", to_field="label")
is_developer = models.BooleanField(null=True, blank=True, default=False, help_text="is this user a developer?")
objects = BaseUserManager()
Expand All @@ -257,6 +259,22 @@ def get_bearer_token(self) -> str:
user_uuid = str(self.id)
bearer_token = jwt.encode({"user_uuid": user_uuid}, key=settings.SECRET_KEY)
return f"Bearer {bearer_token}"

def get_initials(self) -> str:
try:
if self.name:
if " " in self.name:
first_name, last_name = self.name.split(" ")
else:
first_name = self.name
last_name = " "
else:
name_part = self.email.split("@")[0]
first_name, last_name = name_part.split(".")
initials = first_name[0].upper() + last_name[0].upper()
return initials
except (IndexError, AttributeError, ValueError):
return ""


class StatusEnum(models.TextChoices):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class CheckDemographicsView(View):
@method_decorator(login_required)
def get(self, request: HttpRequest) -> HttpResponse:
user: User = request.user
if all([user.name, user.ai_experience, user.grade, user.business_unit, user.profession]):
if all([user.name, user.ai_experience]):
return redirect("chats")
else:
return redirect("demographics")
Expand Down

0 comments on commit c4c3899

Please sign in to comment.