Skip to content

Commit

Permalink
Merge pull request #439 from onaio/print-cover-updates
Browse files Browse the repository at this point in the history
Add usernames to print covers and fix audit and clearance review pending states
  • Loading branch information
JohnMwashuma authored Nov 15, 2024
2 parents ab2cb17 + 9139e6b commit 624e4c7
Show file tree
Hide file tree
Showing 15 changed files with 401 additions and 238 deletions.
Binary file modified locale/ar/LC_MESSAGES/django.mo
Binary file not shown.
304 changes: 185 additions & 119 deletions locale/ar/LC_MESSAGES/django.po

Large diffs are not rendered by default.

22 changes: 0 additions & 22 deletions tally_ho/apps/tally/forms/recon_form.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from django import forms
from django.forms import ModelForm
from tally_ho.apps.tally.models import ReconciliationForm
from django.utils.translation import gettext_lazy as _


disable_copy_input = {
Expand Down Expand Up @@ -54,23 +52,3 @@ def __init__(self, *args, **kwargs):
class_str,
self.fields[field].widget.attrs.get('class'))
self.fields[field].widget.attrs['class'] = class_str
def clean(self):
"""Verify that the total of field number_cancelled_ballots and
field number_ballots_inside_box match the value of field
total_of_cancelled_ballots_and_ballots_inside_box
"""
if self.is_valid():
cleaned_data = super(ReconForm, self).clean()
number_cancelled_ballots =\
cleaned_data.get('number_cancelled_ballots')
number_ballots_inside_box =\
cleaned_data.get('number_ballots_inside_box')
total_of_cancelled_ballots_and_ballots_inside_box =\
cleaned_data.get(
'total_of_cancelled_ballots_and_ballots_inside_box')

if (number_cancelled_ballots + number_ballots_inside_box) !=\
total_of_cancelled_ballots_and_ballots_inside_box:
raise forms.ValidationError(
_('Total of fied 5 and 7 is incorrect'))
return cleaned_data
58 changes: 38 additions & 20 deletions tally_ho/apps/tally/management/commands/import_staff_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from django.core.management.base import BaseCommand
from django.utils.translation import gettext_lazy

from tally_ho.apps.tally.models.tally import Tally
from tally_ho.libs.permissions import groups
from tally_ho.apps.tally.models.user_profile import UserProfile

Expand Down Expand Up @@ -41,42 +42,51 @@


def unicode_csv_reader(unicode_csv_data, dialect=csv.excel, **kwargs):
# csv.py doesn't do Unicode; encode temporarily as UTF-8:
csv_reader = csv.reader(utf_8_encoder(unicode_csv_data),
dialect=dialect, **kwargs)
csv_reader = csv.reader(unicode_csv_data, dialect=dialect, **kwargs)
for row in csv_reader:
# decode UTF-8 back to Unicode, cell by cell:
yield [str(cell, 'utf-8') for cell in row]
yield row


def utf_8_encoder(unicode_csv_data):
for line in unicode_csv_data:
yield line.encode('utf-8')


def add_row(command, name, username, role, admin=None):
def add_row(command, name, username, role, admin=None, tally_id=None):
try:
# Parse the name into first and last name
first_name, last_name = assign_names(name)
user = create_user(first_name, last_name, username)

tally = None
if tally_id:
try:
tally = Tally.objects.get(id=tally_id)
except Tally.DoesNotExist:
command.stdout.write(command.style.ERROR(
f"Tally with id '{tally_id}' does not exist."
))
return # Exit function if the Tally is not found

user = create_user(first_name, last_name, username, tally)

permission = True if admin == 'Yes' else False
user.is_superuser = user.is_staff = permission
user.save()

except Exception as e:
command.stdout.write(command.style.ERROR(
"User '%s' not created! '%s'" % (username, e)))
f"User '{username}' not created! '{e}'"
))
else:
system_role = STAFF_ROLE_DICT.get(role.upper().strip())

if system_role:
group = Group.objects.get_or_create(
name=system_role)[0]
group = Group.objects.get_or_create(name=system_role)[0]
user.groups.add(group)
else:
command.stdout.write(command.style.ERROR(
"Unable to add user %s to unknown group '%s'."
% (username, role)))
f"Unable to add user {username} to unknown group '{role}'."
))


def assign_names(name):
Expand All @@ -91,22 +101,27 @@ def assign_names(name):
return first_name, last_name


def create_user(first_name, last_name, username):
def create_user(first_name, last_name, username, tally=None):
try:
return UserProfile.objects.get(username=username)
except UserProfile.DoesNotExist:
return UserProfile.objects.create_user(
username, password=username,
user = UserProfile.objects.create_user(
username=username,
password=username,
first_name=first_name,
last_name=last_name)
last_name=last_name
)
if tally:
user.tally = tally
user.save()
return user


class Command(BaseCommand):
help = gettext_lazy("Import staff list.")

def handle(self, *args, **kwargs):
self.import_staff_list()
self.import_user_list()

def import_staff_list(self):
with codecs.open(STAFF_LIST_PATH, encoding='utf-8') as f:
Expand All @@ -116,12 +131,15 @@ def import_staff_list(self):
for row in reader:
try:
name, username, role, admin = row[0:4]
tally_id =\
row[4].strip()\
if len(row) > 4 and row[4].strip() else None
except Exception as e:
self.stdout.write(self.style.ERROR(
'Unable to add user in row: %s. Exception %s.' %
(row, e)))
f'Unable to add user in row: {row}. Exception: {e}.'
))
else:
add_row(self, name, username, role, admin)
add_row(self, name, username, role, admin, tally_id)

def import_user_list(self):
with codecs.open(USER_LIST_PATH, encoding='utf-8') as f:
Expand Down
4 changes: 4 additions & 0 deletions tally_ho/apps/tally/templates/audit/print_cover.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ <h2>{% trans 'Audit Case: Team Page' %}</h2>
<tr class="underline">
<td>{% trans 'Date Supervisor Modified:' %} </td><td colspan="3">{{ result_form.audit.date_supervisor_modified }}</td>
</tr>
<tr>
<td>{% trans 'Modified by:' %}</td>
<td>{{ username }}</td>
</tr>
<tr class="underline">
<td colspan="4"><h4>{% trans 'Problem' %}</h4>
<table id="problems" width="100%">
Expand Down
84 changes: 56 additions & 28 deletions tally_ho/apps/tally/templates/audit/review.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,58 @@ <h1>{% trans 'Quarantined Form' %}</h1>

<div class="row audit-form border-top">
<form name="audit" method="post" action="">
<div class="row" style="padding: 1em;">
<div class="col-md-2 col-sm-1 grid2">
{% if form.blank_reconciliation.value or form.blank_results.value or form.unclear_figures.value or form.damaged_form.value or form.other.value %}
<h3 style="margin-top: 0;">{% trans "Problem" %}</h3>
{% endif %}
{% if form.blank_reconciliation.value %}
<p><label for="id_blank_reconciliation">{% trans "Blank reconciliation" %}</label></p>
{% endif %}
{% if form.blank_results.value %}
<p><label for="id_blank_results">{% trans "Blank results" %}</label> </p>
{% endif %}
{% if form.unclear_figures.value %}
<p><label for="id_unclear_figures">{% trans "Unclear figures" %}</label> </p>
{% endif %}
{% if form.damaged_form.value %}
<p><label for="id_damaged_form">{% trans "Damaged form" %}</label> </p>
{% endif %}
{% if form.other.value %}
<p class="large"><label class="wrap_label" for="id_other">
{% trans "Other:" %}</label>{{ form.other.value }}</p>
<p>
{% endif %}

{% if form.action_prior_to_recommendation.value|get_audit_action_name != '----' or form.resolution_recommendation.value|get_audit_resolution_name != '----' %}
<h3>{% trans "Action Prior to Recommendation" %}</h3>
{% if form.action_prior_to_recommendation.value|get_audit_action_name != '----' %}
<p><label for="id_action_prior_to_recommendation">{% trans "Action prior to recommendation:" %}</label>
{{ form.action_prior_to_recommendation.value|get_audit_action_name }}
</p>
{% endif %}
{% if form.resolution_recommendation.value|get_audit_resolution_name != '----' %}
<p><label for="id_resolution_recommendation">{% trans "Resolution recommendation:" %}</label>
{{ form.resolution_recommendation.value|get_audit_resolution_name }}
</p>
{% endif %}
{% endif %}
</div>
<div class="col-md-2 col-sm-1 grid2 righter">
{% if form.team_comment.value %}
<p><label for="id_team_comment">{% trans "Team comment:" %}</label>
{{ form.team_comment.value }}
</p>
{% endif %}
{% if not is_clerk %}
{% if form.supervisor_comment.value %}
<p><label for="id_supervisor_comment">{% trans "Supervisor comment:" %}</label>
{{ form.supervisor_comment.value }}
</p>
{% endif %}
{% endif %}
</div>
</div>
<div class="col-md-2 col-sm-1 grid2">
<h3>{% trans "Problem" %}</h3>
<p>{{ form.blank_reconciliation }}<label for="id_blank_reconciliation">{% trans "Blank reconciliation:" %}</label></p>
Expand All @@ -34,7 +86,10 @@ <h3>{% trans "Problem" %}</h3>
<p>{{ form.damaged_form }}<label for="id_damaged_form">{% trans "Damaged form:" %}</label> </p>
<p class="large"><label class="wrap_label" for="id_other">
{% trans "Other:" %}</label>{{ form.other }}</p>
<p><button class="btn btn-primary" type="submit" name="save">{% trans "Save" %}</button></p>
<p>
<button class="btn btn-primary" type="submit" name="save">{% trans "Save" %}</button>
<a class="btn btn-danger" role="button" href="{% url 'audit' tally_id=tally_id %}">{% trans "Cancel" %}</a>
</p>
<h3>{% trans "Action Prior to Recommendation" %}</h3>
<p><label for="id_action_prior_to_recommendation">{% trans "Action prior to recommendation:" %}</label>
{{ form.action_prior_to_recommendation }}
Expand All @@ -49,34 +104,7 @@ <h3>{% trans "Action Prior to Recommendation" %}</h3>
<p><button class="btn btn-danger" type="submit" name="return">{% trans "Return to Audit Team" %}</button></p>
{% endif %}
</div>
{% if form.action_prior_to_recommendation.value|get_audit_action_name != '----' or form.action_prior_to_recommendation.value|get_audit_action_name != '----' %}
<div class="col-md-2 col-sm-1 grid2 righter">
<h3>{% trans "Action Prior to Recommendation" %}</h3>
{% if form.action_prior_to_recommendation.value|get_audit_action_name != '----' %}
<p><label for="id_action_prior_to_recommendation">{% trans "Action prior to recommendation:" %}</label>
{{ form.action_prior_to_recommendation.value|get_audit_action_name }}
</p>
{% endif %}
{% if form.action_prior_to_recommendation.value|get_audit_action_name != '----' %}
<p><label for="id_resolution_recommendation">{% trans "Resolution recommendation:" %}</label>
{{ form.resolution_recommendation.value|get_audit_resolution_name }}
</p>
{% endif %}
</div>
{% endif %}
<div class="col-md-2 col-sm-1 grid2 righter">
{% if form.team_comment.value %}
<p><label for="id_team_comment">{% trans "Team comment:" %}</label>
{{ form.team_comment.value }}
</p>
{% endif %}
{% if not is_clerk %}
{% if form.supervisor_comment.value %}
<p><label for="id_supervisor_comment">{% trans "Supervisor comment:" %}</label>
{{ form.supervisor_comment.value }}
</p>
{% endif %}
{% endif %}
{% if is_clerk %}
<p><label for="id_team_comment">{% trans "Team comment:" %}</label>
{{ form.team_comment }}
Expand Down
4 changes: 4 additions & 0 deletions tally_ho/apps/tally/templates/clearance/print_cover.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ <h2>{% trans 'Clearance Case: Team Page' %}</h2>
{% else %} {% trans 'None' %} {% endif %}
</td>
</tr>
<tr>
<td>{% trans 'Modified by:' %}</td>
<td>{{ username }}</td>
</tr>
<tr class="underline">
<td colspan="4"><h4>{% trans 'Problem' %}</h4>
<table id="problems" width="100%">
Expand Down
70 changes: 65 additions & 5 deletions tally_ho/apps/tally/templates/clearance/review.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{% extends 'base.html' %}

{% load i18n %}
{% load app_filters %}

{% block content %}

Expand All @@ -12,6 +13,66 @@ <h1>{% trans 'Clearance:' %} {{ clearance_type }}</h1>

<div class="row audit-form border-top">
<form name="audit" method="post" action="">
<div class="row" style="padding: 1em;">
<div class="col-md-2 col-sm-1 grid2">
{% if form.center_name_missing.value or form.center_name_mismatching.value or form.center_code_missing.value or form.center_code_mismatching.value or form.form_already_in_system.value or form.form_incorrectly_entered_into_system.value or form.other.value %}
<h3 style="margin-top: 0;">{% trans "Problem" %}</h3>
{% endif %}
{% if form.center_name_missing.value %}
<p><label
for="id_center_name_missing">{% trans 'Center name missing' %}</label> </p>
{% endif %}
{% if form.center_name_mismatching.value %}
<p><label for="id_center_name_mismatching">{% trans 'Center name mismatching' %}</label> </p>
{% endif %}
{% if form.center_code_missing.value %}
<p><label for="id_center_code_missing">{% trans 'Center code missing' %}</label></p>
{% endif %}
{% if form.center_code_mismatching.value %}
<p><label for="id_center_code_mismatching">{% trans 'Center code mismatching' %}</label></p>
{% endif %}
{% if form.form_already_in_system.value %}
<p><label for="id_form_already_in_system">{% trans 'Form already in system' %}</label></p>
{% endif %}
{% if form.form_incorrectly_entered_into_system.value %}
<p><label
for="id_form_incorrectly_entered_into_system">
{% trans 'Form incorrectly entered into system' %}</label></p>
{% endif %}
{% if form.other.value %}
<p class="large"><label class="wrap_label" for="id_other">
{% trans "Other:" %}</label>{{ form.other.value }}</p>
{% endif %}

{% if form.action_prior_to_recommendation.value|get_audit_action_name != '----' or form.resolution_recommendation.value|get_clearance_resolution_name != '----' %}
<h3>{% trans "Action Prior to Recommendation" %}</h3>
{% if form.action_prior_to_recommendation.value|get_audit_action_name != '----' %}
<p><label for="id_action_prior_to_recommendation">{% trans "Action prior to recommendation:" %}</label>
{{ form.action_prior_to_recommendation.value|get_audit_action_name }}
</p>
{% endif %}
{% if form.resolution_recommendation.value|get_clearance_resolution_name != '----' %}
<p><label for="id_resolution_recommendation">{% trans "Resolution recommendation:" %}</label>
{{ form.resolution_recommendation.value|get_clearance_resolution_name }}
</p>
{% endif %}
{% endif %}
</div>
<div class="col-md-2 col-sm-1 grid2 righter">
{% if form.team_comment.value %}
<p><label for="id_team_comment">{% trans "Team comment:" %}</label>
{{ form.team_comment.value }}
</p>
{% endif %}
{% if not is_clerk %}
{% if form.supervisor_comment.value %}
<p><label for="id_supervisor_comment">{% trans "Supervisor comment:" %}</label>
{{ form.supervisor_comment.value }}
</p>
{% endif %}
{% endif %}
</div>
</div>
<div class="col-md-2 col-sm-1 grid2">
<h3>{% trans "Problem" %}</h3>
<p>{{ form.center_name_missing }}<label
Expand All @@ -30,7 +91,10 @@ <h3>{% trans "Problem" %}</h3>
{% trans 'Form incorrectly entered into system:' %}</label></p>
<p class="large"><label class="wrap_label" for="id_other">
{% trans "Other:" %}</label>{{ form.other }}</p>
<p><button class="btn btn-primary" type="submit" name="save">{% trans "Save" %}</button></p>
<p>
<button class="btn btn-primary" type="submit" name="save">{% trans "Save" %}</button>
<a class="btn btn-danger" role="button" href="{% url 'clearance' tally_id=tally_id %}">{% trans "Cancel" %}</a>
</p>
<h3>{% trans "Action Prior to Recommendation" %}</h3>
<p><label for="id_action_prior_to_recommendation">{% trans "Action prior to recommendation:" %}</label>
{{ form.action_prior_to_recommendation }}
Expand All @@ -51,10 +115,6 @@ <h3>{% trans "Action Prior to Recommendation" %}</h3>
<p><label for="id_team_comment">{% trans "Team comment:" %}</label>
{{ form.team_comment }}
</p>
{% else %}
<p><label for="id_team_comment">{% trans "Team comment:" %}</label>
{{ form.team_comment.value }}
</p>
{% endif %}
{% if not is_clerk %}
<p><label for="id_supervisor_comment">{% trans "Supervisor comment:" %}</label>
Expand Down
Loading

0 comments on commit 624e4c7

Please sign in to comment.