Skip to content

Commit

Permalink
Task/wp 284 submitter listing table (#232)
Browse files Browse the repository at this point in the history
* Created path and submitter listing app, view, urls

* task/wp-284-submitter-listin-table

* -Updated get registration query to only get distinct
registration records from DB
-Made SubmittersTable a subclass of RegistrationTable

* Reused admin view modal and removed submitter view modal

Adjusted sub class parameters

Added drop down to link to form

* Changed wording per Jodie at UTH

* Link to admin style sheet rather than copying into a new one

* Changed path to correct form page

* Update apcd-cms/src/apps/submitter_renewals_listing/templates/list_submitter_registrations.html

Adjust path so reg_id is a query parameter and not a reg parameter

Co-authored-by: edmondsgarrett <[email protected]>

* Add year to query, view, and table.
Recreated submission table css since it has different columns than
admin registration

* Added back css since table has different columns
than admin registrations

* Remove coming soon from options

* Add year to registration context

* Broken link to static dir

---------

Co-authored-by: edmondsgarrett <[email protected]>
  • Loading branch information
sophia-massie and edmondsgarrett authored Oct 27, 2023
1 parent a0b9e40 commit dc31d93
Show file tree
Hide file tree
Showing 15 changed files with 247 additions and 15 deletions.
4 changes: 2 additions & 2 deletions apcd-cms/src/apps/exception/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def get_context_data(self, *args, **kwargs):

user = self.request.user.username

submitters = apcd_database.get_submitter_for_extend_or_except(user)
submitters = apcd_database.get_submitter_info(user)

file_type = self.request.GET.get('file_type')

Expand Down Expand Up @@ -127,7 +127,7 @@ def get_context_data(self, *args, **kwargs):

user = self.request.user.username

submitters = apcd_database.get_submitter_for_extend_or_except(user)
submitters = apcd_database.get_submitter_info(user)

self.request.session['submitters'] = submitters

Expand Down
2 changes: 1 addition & 1 deletion apcd-cms/src/apps/extension/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def get_context_data(self, *args, **kwargs):

user = self.request.user.username

submitters = apcd_database.get_submitter_for_extend_or_except(user)
submitters = apcd_database.get_submitter_info(user)

self.request.session['submitters'] = submitters

Expand Down
2 changes: 1 addition & 1 deletion apcd-cms/src/apps/registrations/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@

app_name = 'register'
urlpatterns = [
path('request-to-submit/', SubmissionFormView.as_view(), name='index')
path('request-to-submit/', SubmissionFormView.as_view(), name='register_table')
]
Empty file.
5 changes: 5 additions & 0 deletions apcd-cms/src/apps/submitter_renewals_listing/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class SubmitterRenewalsListingConfig(AppConfig):
name = 'submitter_renewals_listing'
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.status-filter.org-filter {
width: max-content;
}

/* SEE: https://css-tricks.com/responsive-data-tables/ */
@media (max-width: 767px) {
/* To label the cells */
/* RFE: Add `data-label` to each cell so we can use `attr(data-label)` */
.submitters-table td:nth-of-type(1):before { content: "Business Name"; }
.submitters-table td:nth-of-type(2):before { content: "Year"; }
.submitters-table td:nth-of-type(3):before { content: "Type"; }
.submitters-table td:nth-of-type(4):before { content: "Location"; }
.submitters-table td:nth-of-type(5):before { content: "Registration Status"; }
.submitters-table td:nth-of-type(6):before { content: "Actions"; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
{% extends "standard.html" %}
{% load static %}

{% block content %}

<link rel="stylesheet" href="{% static 'apcd-cms/css/table.css' %}">
<link rel="stylesheet" href="{% static 'apcd-cms/css/modal.css' %}">
<link rel="stylesheet" href="{% static 'submitter_renewals_listing/css/table.css' %}">

<div class="container">
{% include "nav_cms_breadcrumbs.html" %}

<h1>Registration Information</h1>
<hr />
<p style="margin-bottom: 30px">Current registration information on file for your organization is listed below. On the right of the screen, select the dropdown menu under “Actions” to view or renew your organization’s registration information.</p>
<hr />
<div class="filter-container">
<div class="filter-content">
<span><b>Filter by Status: </b></span>
<select id="statusFilter" class="status-filter" onchange="filterTableByStatus()">
{% for option in status_options %}
<option class="dropdown-text" {% if option == selected_status %}selected{% endif %}>{{ option }}</option>
{% endfor %}
</select>
<span><b>Filter by Organization: </b></span>
<select id="organizationFilter" class="status-filter org-filter" onchange="filterTableByOrganization()">
{% for option in org_options %}
<option class="dropdown-text" {% if option == selected_org %}selected{% endif %}>{{ option }}</option>
{% endfor %}
</select>
{% if selected_status or selected_org %}
<button onclick="clearSelections()">Clear Options</button>
{% endif %}
</div>
</div>
<table id="submittersTable" class="submitters-table">
<thead>
<tr>
{% for k in header %}
<th>{{k}}</th>
{% endfor %}
</tr>
</thead>
<tbody>
{% for r in page %}
<tr>
<td>{{r.biz_name}}</td>
<td>{{r.year}}</td>
<td>{{r.type}}</td>
<td>{{r.location}}</td>
<td>{{r.reg_status}}</td>
<td>
{% include "view_registration_modal.html" %}
<select id='actionsSubmitterDropdown_{{r.reg_id}}' class='status-filter' onchange="openAction('{{r.reg_id}}')">
<option value="">Actions</option>
<option value="viewRegistration">View Record</option>
<option value="renewRegistration">Renew Registration</option>
</select>
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% include 'paginator.html' %}
</div>
<script>
function filterTableByStatus() {
var dropdown, statusFilter, xhr, url_params, url;
dropdown = document.getElementById("statusFilter");
statusFilter = dropdown.value;
url_params = `?status=${statusFilter}`;
{% if selected_org %}
url_params += `&org={{selected_org}}`;
{% endif %}
url = `/register/list-registration-requests/${url_params}`;
xhr = new XMLHttpRequest();
xhr.open('GET', url);
xhr.send();
window.location.href = url;
window.location.load();
}
function filterTableByOrganization() {
var input, orgFilter, xhr, url_params, url;
input = document.getElementById("organizationFilter");
orgFilter = input.value.replace("&", encodeURIComponent('&'));
url_params = `?org=${orgFilter}`;
{% if selected_status %}
url_params = `?status={{selected_status}}&org=${orgFilter}`;
{% endif %}
url = `/register/list-registration-requests/${url_params}`;
xhr = new XMLHttpRequest();
xhr.open('GET', url);
xhr.send();
window.location.href = url;
window.location.load();
}
function clearSelections() {
var xhr;
xhr = new XMLHttpRequest();
xhr.open('GET', '/register/list-registration-requests/')
xhr.send()
window.location.href = '/register/list-registration-requests/';
window.location.load();
}

function openAction(reg_id) {
var actionsDropdown, selectedOption, modal_id;
actionsDropdown = document.getElementById(`actionsSubmitterDropdown_${reg_id}`);
/* grabs dropdown option number selected by user via selectedIndex,
then grabs actual value associated with that option via
options[index].value */
selectedOption = actionsDropdown.options[actionsDropdown.selectedIndex].value;
modal_id = `${selectedOption}Modal_${reg_id}`;
$(`#${modal_id}`).modal({backdrop: "static"}); /* modal appears manually */
actionsDropdown.selectedIndex = 0; /* resets dropdown to display 'Select Action' again */
if (selectedOption == "renewRegistration") {
var xhr;
xhr = new XMLHttpRequest();
xhr.open('GET', `/register/request-to-submit/?reg_id=${reg_id}`)
xhr.send()
window.location.href = `/register/request-to-submit/?reg_id=${reg_id}`;
window.location.load();
}
}
</script>

{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{% extends "standard.html" %}
{% block content %}
<div class="container">
{% include "nav_cms_breadcrumbs.html" %}

<h1>View Registations</h1>
<hr />
<p class="c-message c-message--error">
An error occurred loading your registrations. For help, <a href="/workbench/dashboard">submit a ticket</a>.
</p>
<a class="c-button c-button--primary" href="/">Back to Home</a>
</div>

{% endblock %}
10 changes: 10 additions & 0 deletions apcd-cms/src/apps/submitter_renewals_listing/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from django.urls import path
from apps.submitter_renewals_listing.views import SubmittersTable

app_name = 'register'
urlpatterns = [
path('list-registration-requests/', SubmittersTable.as_view(), name='submitter_regis_table'),
path(r'list-registration-requests/?status=(?P<status>)/', SubmittersTable.as_view(), name='submitter_regis_table'),
path(r'list-registration-requests/?org=(?P<org>)/', SubmittersTable.as_view(), name='submitter_regis_table'),
path(r'list-registration-requests/?status=(?P<status>)&org=(?P<org>)/', SubmittersTable.as_view(), name='submitter_regis_table')
]
48 changes: 48 additions & 0 deletions apcd-cms/src/apps/submitter_renewals_listing/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
from django.http import HttpResponse, HttpResponseRedirect, JsonResponse
from django.views.generic.base import TemplateView
from django.template import loader
from apps.utils.apcd_database import get_registrations, get_registration_contacts, get_submitter_info, get_registration_entities
from apps.utils.apcd_groups import is_submitter_admin
from apps.admin_regis_table.views import RegistrationsTable
import logging
import json

logger = logging.getLogger(__name__)


class SubmittersTable(RegistrationsTable):
template_name = 'list_submitter_registrations.html'

def get(self, request, *args, **kwargs):
try:
response = get_submitter_code(request.user)
submitter_code = response.content
data = json.loads(submitter_code)
submitter_code = data['submitter_code']
registrations_content = get_registrations(submitter_code=submitter_code)
registrations_entities = get_registration_entities(submitter_code=submitter_code)
registrations_contacts = get_registration_contacts(submitter_code=submitter_code)
context = self.get_context_data(registrations_content, registrations_entities, registrations_contacts, *args,**kwargs)
template = loader.get_template(self.template_name)
return HttpResponse(template.render(context, request))
except:
context = super(RegistrationsTable, self).get_context_data(*args, **kwargs)
template = loader.get_template('submitter_listing_error.html')
return HttpResponse(template.render(context, request))

def dispatch(self, request, *args, **kwargs):
if not request.user.is_authenticated or not is_submitter_admin(request.user):
return HttpResponseRedirect('/')
return super(SubmittersTable, self).dispatch(request, *args, **kwargs)

def get_context_data(self, registrations_content, registrations_entities, registrations_contacts, *args, **kwargs):
context = super().get_context_data(registrations_content, registrations_entities, registrations_contacts, *args, **kwargs)
context['header'] = ['Business Name', 'Year', 'Type', 'Location', 'Registration Status', 'Actions']
context['pagination_url_namespaces'] = 'register:submitter_regis_table'
return context

def get_submitter_code(request):
submitter = get_submitter_info(str(request))
for i in submitter:
submitter_code = i[1]
return JsonResponse(({'submitter_code' : submitter_code } if submitter_code else ""), safe=False)
26 changes: 17 additions & 9 deletions apcd-cms/src/apps/utils/apcd_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def get_user_role(user):
conn.close()


def get_registrations(reg_id=None):
def get_registrations(reg_id=None, submitter_code=None):
cur = None
conn = None
try:
Expand All @@ -139,7 +139,7 @@ def get_registrations(reg_id=None):
port=APCD_DB['port'],
sslmode='require'
)
query = f"""SELECT
query = f"""SELECT DISTINCT
registrations.registration_id,
registrations.posted_date,
registrations.applicable_period_start,
Expand All @@ -151,8 +151,11 @@ def get_registrations(reg_id=None):
registrations.mail_address,
registrations.city,
registrations.state,
registrations.zip
FROM registrations {f"WHERE registration_id = {str(reg_id)}" if reg_id is not None else ''}"""
registrations.zip,
registrations.registration_year
FROM registrations
{f"WHERE registration_id = {str(reg_id)}" if reg_id is not None else ''}
{f"LEFT JOIN submitters on registrations.registration_id = submitters.registration_id WHERE submitter_code = '{str(submitter_code)}' ORDER BY registrations.registration_id" if submitter_code is not None else ''}"""
cur = conn.cursor()
cur.execute(query)
return cur.fetchall()
Expand Down Expand Up @@ -272,7 +275,7 @@ def update_registration(form, reg_id):
if conn is not None:
conn.close()

def get_registration_entities(reg_id=None):
def get_registration_entities(reg_id=None, submitter_code=None):
cur = None
conn = None
try:
Expand Down Expand Up @@ -302,7 +305,10 @@ def get_registration_entities(reg_id=None):
registration_entities.file_mc,
registration_entities.file_pc,
registration_entities.file_dc
FROM registration_entities {f"WHERE registration_id = {str(reg_id)}" if reg_id is not None else ''}"""
FROM registration_entities
{f"WHERE registration_id = {str(reg_id)}" if reg_id is not None else ''}
{f"LEFT JOIN submitters on registration_entities.registration_id = submitters.registration_id WHERE submitter_code = '{str(submitter_code)}'" if submitter_code is not None else ''}"""

cur = conn.cursor()
cur.execute(query)
return cur.fetchall()
Expand Down Expand Up @@ -492,7 +498,7 @@ def delete_registration_entity(reg_id, ent_id):
conn.close()


def get_registration_contacts(reg_id=None):
def get_registration_contacts(reg_id=None, submitter_code=None):
cur = None
conn = None
try:
Expand All @@ -512,7 +518,9 @@ def get_registration_contacts(reg_id=None):
registration_contacts.contact_name,
registration_contacts.contact_phone,
registration_contacts.contact_email
FROM registration_contacts {f"WHERE registration_id = {str(reg_id)}" if reg_id is not None else ''}"""
FROM registration_contacts
{f"WHERE registration_id = {str(reg_id)}" if reg_id is not None else ''}
{f"LEFT JOIN submitters on registration_contacts.registration_id = submitters.registration_id WHERE submitter_code = '{str(submitter_code)}'" if submitter_code is not None else ''}"""
cur = conn.cursor()
cur.execute(query)
return cur.fetchall()
Expand Down Expand Up @@ -1236,7 +1244,7 @@ def update_extension(form):
if cur is not None:
cur.close()

def get_submitter_for_extend_or_except(user):
def get_submitter_info(user):
cur = None
conn = None
try:
Expand Down
3 changes: 3 additions & 0 deletions apcd-cms/src/apps/utils/apcd_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ def has_apcd_group(user):

def is_apcd_admin(user):
return user.groups.filter(name='APCD_ADMIN').exists()

def is_submitter_admin(user):
return user.groups.filter(name='SUBMITTER_ADMIN').exists()
1 change: 1 addition & 0 deletions apcd-cms/src/apps/utils/registrations_data_formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def _set_registration(reg, reg_ents, reg_conts):
),
'reg_status': reg[5].title(),
'reg_id': reg[0],
'year': reg[12],
'view_modal_content': _set_modal_content(reg, reg_ents, reg_conts, org_types)
}
def _set_entities(reg_ent):
Expand Down
4 changes: 2 additions & 2 deletions apcd-cms/src/taccsite_cms/custom_app_settings.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CUSTOM_APPS = ['apps.admin_regis_table', 'apps.apcd_login', 'apps.registrations', 'apps.submissions', 'apps.exception', 'apps.admin_submissions', 'apps.admin_extension', 'apps.admin_exception', 'apps.extension', 'apps.view_users', 'apps.components.paginator', 'apps.utils']
CUSTOM_APPS = ['apps.admin_regis_table', 'apps.apcd_login', 'apps.registrations', 'apps.submissions', 'apps.exception', 'apps.admin_submissions', 'apps.admin_extension', 'apps.admin_exception', 'apps.extension', 'apps.submitter_renewals_listing', 'apps.view_users', 'apps.components.paginator', 'apps.utils']
CUSTOM_MIDDLEWARE = []
STATICFILES_DIRS = ('taccsite_custom/apcd-cms', 'apps/admin_regis_table', 'apps/submissions', 'apps/exception', 'apps/extension', 'apps/view_users', 'apps/components/paginator', 'apps/utils')
STATICFILES_DIRS = ('taccsite_custom/apcd-cms', 'apps/admin_regis_table', 'apps/submissions', 'apps/exception', 'apps/extension', 'apps/submitter_renewals_listing', 'apps/view_users', 'apps/components/paginator', 'apps/utils')

1 change: 1 addition & 0 deletions apcd-cms/src/taccsite_cms/urls_custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
path('administration/', include('apps.admin_extension.urls', namespace='admin_extension')),
path('apcd-login/', include('apps.apcd_login.urls', namespace='apcd_login')),
path('register/', include('apps.registrations.urls', namespace='register')),
path('register/', include('apps.submitter_renewals_listing.urls', namespace='submitter_regis_table')),
path('submissions/', include('apps.extension.urls', namespace='extension')),
path('submissions/', include('apps.exception.urls', namespace='exception')),
path('submissions/', include('apps.submissions.urls', namespace='submissions'))
Expand Down

0 comments on commit dc31d93

Please sign in to comment.