Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KYC Config Page #35716

Merged
merged 13 commits into from
Feb 4, 2025
9 changes: 9 additions & 0 deletions corehq/apps/integration/kyc/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django.urls import re_path as url

from corehq.apps.integration.kyc.views import KycConfigurationView


urlpatterns = [
url(r'^configure/$', KycConfigurationView.as_view(),
name=KycConfigurationView.urlname),
]
69 changes: 69 additions & 0 deletions corehq/apps/integration/kyc/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
from django.urls import reverse
from django.utils.decorators import method_decorator
from django.utils.translation import gettext as _

from corehq import toggles
from corehq.apps.domain.decorators import login_required
from corehq.apps.domain.views.base import BaseDomainView
from corehq.apps.hqwebapp.decorators import use_bootstrap5
from corehq.apps.integration.kyc.forms import KycConfigureForm
from corehq.apps.integration.kyc.models import KycConfig
from corehq.util.htmx_action import HqHtmxActionMixin


@method_decorator(login_required, name='dispatch')
@method_decorator(use_bootstrap5, name='dispatch')
class KycConfigurationView(BaseDomainView, HqHtmxActionMixin):
section_name = _("Data")
urlname = 'kyc_configuration'
template_name = 'kyc/kyc_config_base.html'
page_title = _('KYC Configuration')

form_class = KycConfigureForm
form_template_partial_name = 'kyc/partials/kyc_config_form_partial.html'

@method_decorator(toggles.KYC_VERIFICATION.required_decorator())
zandre-eng marked this conversation as resolved.
Show resolved Hide resolved
def dispatch(self, request, *args, **kwargs):
return super(KycConfigurationView, self).dispatch(request, *args, **kwargs)

@property
def page_url(self):
return reverse(self.urlname, args=[self.domain])

@property
def section_url(self):
return reverse(self.urlname, args=(self.domain,))

@property
def page_context(self):
return {
'kyc_config_form': self.config_form,
}

@property
def config(self):
try:
# Currently a domain can only save one config so we shouldn't
# expect more than one per domain
return KycConfig.objects.get(domain=self.domain)
except KycConfig.DoesNotExist:
return KycConfig(domain=self.domain)

@property
def config_form(self):
if self.request.method == 'POST':
return self.form_class(self.request.POST, instance=self.config)
return self.form_class(instance=self.config)

def post(self, request, *args, **kwargs):
form = self.config_form
show_success = False
if form.is_valid():
form.save(commit=True)
Copy link
Contributor

@Charl1996 Charl1996 Feb 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I presume the fact that the form is a ModelForm will persist the model to the database with commit=True?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is correct. The save() function's help text reads "Save this form's self.instance object if commit=True...". I also verified this in my local testing by checking that the instance is actually getting saved with this function call.

show_success = True

context = {
'kyc_config_form': form,
'show_success': show_success,
}
return self.render_htmx_partial_response(request, self.form_template_partial_name, context)
1 change: 1 addition & 0 deletions urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
url(r'^case/', include('corehq.apps.case_search.urls')),
url(r'^cloudcare/', include('corehq.apps.cloudcare.urls')),
url(r'^microplanning/', include('corehq.apps.geospatial.urls')),
url(r'^kyc/', include('corehq.apps.integration.kyc.urls')),
url(r'^fixtures/', include('corehq.apps.fixtures.urls')),
url(r'^importer/', include('corehq.apps.case_importer.urls')),
url(r'^dashboard/', include('corehq.apps.dashboard.urls')),
Expand Down