Skip to content

Commit

Permalink
Merge branch 'master' of github.com:nursix/eden
Browse files Browse the repository at this point in the history
  • Loading branch information
nursix committed Apr 12, 2019
2 parents b3f2897 + 835dbf0 commit 08af22a
Show file tree
Hide file tree
Showing 6 changed files with 405 additions and 6 deletions.
40 changes: 38 additions & 2 deletions controllers/br.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ def person():
action = s3db.pr_Contacts,
)

# ID Card Export
id_card_layout = settings.get_br_id_card_layout()
id_card_export_roles = settings.get_br_id_card_export_roles()
if id_card_layout and id_card_export_roles and \
auth.s3_has_roles(id_card_export_roles):
id_card_export = True
else:
id_card_export = False

def prep(r):

# Filter to persons who have a case registered
Expand Down Expand Up @@ -126,6 +135,21 @@ def prep(r):
insertable = insertable,
)

# Configure ID Cards
if id_card_export:
if r.representation == "card":
# Configure ID card layout
resource.configure(pdf_card_layout = id_card_layout,
#pdf_card_pagesize="A4",
)

if not r.id and not r.component:
# Add export-icon for ID cards
export_formats = list(settings.get_ui_export_formats())
export_formats.append(("card", "fa fa-id-card", T("Export ID Cards")))
settings.ui.export_formats = export_formats
s3.formats["card"] = r.url(method="")

if not r.component:

# Module-specific field and form configuration
Expand Down Expand Up @@ -431,10 +455,22 @@ def postp(r, output):
from s3 import S3AnonymizeWidget
anonymize = S3AnonymizeWidget.widget(r, _class="action-btn anonymize-btn")

# TODO ID-Card button
# ID-Card button
if id_card_export:
card_button = A(T("ID Card"),
data = {"url": URL(c="br", f="person",
args = ["%s.card" % r.id]
),
},
_class = "action-btn s3-download-button",
_script = "alert('here')",
)
else:
card_button = ""

# Render in place of the delete-button
buttons["delete_btn"] = TAG[""](anonymize,
buttons["delete_btn"] = TAG[""](card_button,
anonymize,
)
return output
s3.postp = postp
Expand Down
16 changes: 12 additions & 4 deletions modules/s3/codecs/card.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ def encode(self, resource, **attr):
return output_stream

# -------------------------------------------------------------------------
def extract(self, resource, fields, orderby=None):
@staticmethod
def extract(resource, fields, orderby=None):
"""
Extract the data items from the given resource
Expand All @@ -216,7 +217,8 @@ def extract(self, resource, fields, orderby=None):
)

# -------------------------------------------------------------------------
def get_flowables(self, layout, resource, items, labels=None, cards_per_page=1):
@staticmethod
def get_flowables(layout, resource, items, labels=None, cards_per_page=1):
"""
Get the Flowable-instances for the data items
Expand Down Expand Up @@ -354,7 +356,8 @@ def __init__(self,
)

# -------------------------------------------------------------------------
def number_of_cards(self, pagesize, cardsize, margins, spacing):
@staticmethod
def number_of_cards(pagesize, cardsize, margins, spacing):
"""
Compute the number of cards for one page dimension
Expand Down Expand Up @@ -674,7 +677,12 @@ def draw_qrcode(self, value, x, y, size=40, halign=None, valign=None):

qr_code = qr.QrCodeWidget(value)

bounds = qr_code.getBounds()
try:
bounds = qr_code.getBounds()
except ValueError:
# Value contains invalid characters
return

w = bounds[2] - bounds[0]
h = bounds[3] - bounds[1]

Expand Down
12 changes: 12 additions & 0 deletions modules/s3cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -2751,6 +2751,18 @@ def get_br_needs_org_specific(self):
"""
return self.br.get("needs_org_specific", True)

def get_br_id_card_layout(self):
"""
Layout class for beneficiary ID cards
"""
return self.br.get("id_card_layout")

def get_br_id_card_export_roles(self):
"""
User roles permitted to export beneficiary ID cards
"""
return self.br.get("id_card_export_roles")

def get_br_case_hide_default_org(self):
"""
Hide the organisation field in cases if only one allowed
Expand Down
8 changes: 8 additions & 0 deletions modules/templates/BRCMS/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#from s3 import FS, IS_ONE_OF
from s3dal import original_tablename

from templates.BRCMS.idcards import IDCardLayout

# =============================================================================
def config(settings):
"""
Expand Down Expand Up @@ -152,6 +154,12 @@ def config(settings):
# Terminology to use when referring to measures of assistance (Counseling|Assistance)
#settings.br.assistance_terminology = "Counseling"

# ID Card Layout
settings.br.id_card_layout = IDCardLayout

# Roles with permission to generate beneficiary ID cards
settings.br.id_card_export_roles = ["CASE_MANAGEMENT"]

# -------------------------------------------------------------------------
# CMS Module Settings
#
Expand Down
Loading

0 comments on commit 08af22a

Please sign in to comment.