mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-06 11:13:21 +02:00
wip but not working, adding in pk
This commit is contained in:
parent
aa5b574d01
commit
f9249f88cd
6 changed files with 114 additions and 23 deletions
|
@ -179,7 +179,7 @@ urlpatterns = [
|
|||
name="domain-users-add",
|
||||
),
|
||||
path(
|
||||
"user-profile",
|
||||
"user-profile/<int:pk>",
|
||||
views.UserProfileView.as_view(),
|
||||
name="user-profile",
|
||||
),
|
||||
|
|
54
src/registrar/forms/user_profile.py
Normal file
54
src/registrar/forms/user_profile.py
Normal file
|
@ -0,0 +1,54 @@
|
|||
from django import forms
|
||||
|
||||
from registrar.models.contact import Contact
|
||||
|
||||
from django.core.validators import MaxLengthValidator
|
||||
from phonenumber_field.widgets import RegionalPhoneNumberWidget
|
||||
|
||||
class UserProfileForm(forms.ModelForm):
|
||||
"""Form for updating user profile."""
|
||||
|
||||
class Meta:
|
||||
model = Contact
|
||||
fields = ["first_name", "middle_name", "last_name", "title", "email", "phone"]
|
||||
widgets = {
|
||||
"first_name": forms.TextInput,
|
||||
"middle_name": forms.TextInput,
|
||||
"last_name": forms.TextInput,
|
||||
"title": forms.TextInput,
|
||||
"email": forms.EmailInput,
|
||||
"phone": RegionalPhoneNumberWidget,
|
||||
}
|
||||
|
||||
# the database fields have blank=True so ModelForm doesn't create
|
||||
# required fields by default. Use this list in __init__ to mark each
|
||||
# of these fields as required
|
||||
required = ["first_name", "last_name", "title", "email", "phone"]
|
||||
|
||||
# def __init__(self, *args, **kwargs):
|
||||
# super().__init__(*args, **kwargs)
|
||||
# # take off maxlength attribute for the phone number field
|
||||
# # which interferes with out input_with_errors template tag
|
||||
# self.fields["phone"].widget.attrs.pop("maxlength", None)
|
||||
|
||||
# # Define a custom validator for the email field with a custom error message
|
||||
# email_max_length_validator = MaxLengthValidator(320, message="Response must be less than 320 characters.")
|
||||
# self.fields["email"].validators.append(email_max_length_validator)
|
||||
|
||||
# for field_name in self.required:
|
||||
# self.fields[field_name].required = True
|
||||
|
||||
# # Set custom form label
|
||||
# self.fields["middle_name"].label = "Middle name (optional)"
|
||||
|
||||
# # Set custom error messages
|
||||
# self.fields["first_name"].error_messages = {"required": "Enter your first name / given name."}
|
||||
# self.fields["last_name"].error_messages = {"required": "Enter your last name / family name."}
|
||||
# self.fields["title"].error_messages = {
|
||||
# "required": "Enter your title or role in your organization (e.g., Chief Information Officer)"
|
||||
# }
|
||||
# self.fields["email"].error_messages = {
|
||||
# "required": "Enter your email address in the required format, like name@example.com."
|
||||
# }
|
||||
# self.fields["phone"].error_messages["required"] = "Enter your phone number."
|
||||
# self.domainInfo = None
|
|
@ -158,7 +158,7 @@
|
|||
</li>
|
||||
<li class="usa-nav__primary-item display-flex flex-align-center margin-left-2">
|
||||
<span class="text-base"> | </span>
|
||||
<a href="{% url 'user-profile' %}"><span class="text-primary">Your profile</span></a>
|
||||
<a href="{% url 'user-profile' pk=user.contact.id %}"><span class="text-primary">Your profile</span></a>
|
||||
</li>
|
||||
<li class="usa-nav__primary-item display-flex flex-align-center margin-left-2">
|
||||
<span class="text-base"> | </span>
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
{% extends 'base.html' %}
|
||||
|
||||
|
||||
{% block title %}
|
||||
Edit your User Profile |
|
||||
{% endblock title %}
|
||||
{% load static url_helpers %}
|
||||
{% load field_helpers %}
|
||||
|
||||
{% block content %}
|
||||
<main id="main-content" class="grid-container">
|
||||
|
@ -23,12 +25,26 @@ Edit your User Profile |
|
|||
<p>Review the details below and update any required information. Note that editing this information won’t affect your Login.gov account information.</p>
|
||||
{% include "includes/required_fields.html" %}
|
||||
|
||||
<form class="usa-form usa-form--large" method="post" enctype="multipart/form-data">
|
||||
<form class="usa-form usa-form--large" method="post" novalidate>
|
||||
{% csrf_token %}
|
||||
<fieldset class="usa-fieldset">
|
||||
{% for field in profile_form %}
|
||||
<label class="usa-label" for="id_{{ field.name }}">{{ field.label }}</label>
|
||||
{{ field }}
|
||||
{% endfor %}
|
||||
|
||||
{% input_with_errors form.first_name %}
|
||||
|
||||
{% input_with_errors form.middle_name %}
|
||||
|
||||
{% input_with_errors form.last_name %}
|
||||
|
||||
{% input_with_errors form.title %}
|
||||
|
||||
{% input_with_errors form.email %}
|
||||
|
||||
{% with add_class="usa-input--medium" %}
|
||||
{% input_with_errors form.phone %}
|
||||
{% endwith %}
|
||||
|
||||
|
||||
|
||||
</fieldset>
|
||||
<button type="submit" class="usa-button">Save</button>
|
||||
</form>
|
||||
|
|
|
@ -4,17 +4,10 @@
|
|||
|
||||
import logging
|
||||
|
||||
from django.contrib import messages
|
||||
from django.contrib.messages.views import SuccessMessageMixin
|
||||
from django.db import IntegrityError
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.shortcuts import redirect
|
||||
from django.urls import reverse
|
||||
from django.views.generic.edit import FormMixin
|
||||
from django.conf import settings
|
||||
|
||||
from registrar.forms.user_profile import UserProfileForm
|
||||
from registrar.models import (
|
||||
User,
|
||||
Contact,
|
||||
)
|
||||
from registrar.views.utility.permission_views import UserProfilePermissionView
|
||||
|
||||
|
@ -29,8 +22,33 @@ class UserProfileView(UserProfilePermissionView):
|
|||
and setting the domain in cache
|
||||
"""
|
||||
|
||||
model = Contact
|
||||
template_name = "profile.html"
|
||||
form_class = UserProfileForm
|
||||
|
||||
# Override get_object to return the logged-in user
|
||||
def get_object(self, queryset=None):
|
||||
return self.request.user # Returns the logged-in user
|
||||
# def get(self, request, *args, **kwargs):
|
||||
# logger.info("in get")
|
||||
# return super().get(request, *args, **kwargs)
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
logger.info("in get()")
|
||||
self.object = self.get_object()
|
||||
context = self.get_context_data(object=self.object)
|
||||
logger.info(context)
|
||||
return self.render_to_response(context)
|
||||
|
||||
# def get_context_data(self, **kwargs):
|
||||
# logger.info("in get_context_data")
|
||||
# kwargs.setdefault("view", self)
|
||||
# if self.extra_context is not None:
|
||||
# kwargs.update(self.extra_context)
|
||||
# return kwargs
|
||||
|
||||
# # Override get_object to return the logged-in user
|
||||
# def get_object(self, queryset=None):
|
||||
# logger.info("in get_object")
|
||||
# user = self.request.user # get the logged in user
|
||||
# if hasattr(user, 'contact'): # Check if the user has a contact instance
|
||||
# logger.info(user.contact)
|
||||
# return user.contact
|
||||
# return None
|
|
@ -5,6 +5,7 @@ import abc # abstract base class
|
|||
from django.contrib.auth import get_user_model
|
||||
from django.views.generic import DetailView, DeleteView, TemplateView
|
||||
from registrar.models import Domain, DomainRequest, DomainInvitation, User
|
||||
from registrar.models.contact import Contact
|
||||
from registrar.models.user_domain_role import UserDomainRole
|
||||
|
||||
from .mixins import (
|
||||
|
@ -153,10 +154,12 @@ class UserProfilePermissionView(UserProfilePermission, DetailView, abc.ABC):
|
|||
`template_name`.
|
||||
"""
|
||||
|
||||
# DetailView property for what model this is viewing
|
||||
model = get_user_model()
|
||||
# variable name in template context for the model object
|
||||
context_object_name = "user"
|
||||
# # DetailView property for what model this is viewing
|
||||
# model = get_user_model()
|
||||
# # variable name in template context for the model object
|
||||
# context_object_name = "user"
|
||||
model = Contact
|
||||
context_object_name = "contact"
|
||||
|
||||
# Abstract property enforces NotImplementedError on an attribute.
|
||||
@property
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue