Skip to content

Commit

Permalink
Merge branch 'master' of github.com:nursix/eden-asp
Browse files Browse the repository at this point in the history
  • Loading branch information
nursix committed Jul 13, 2022
2 parents 23128e3 + dfa43e3 commit 106d2d7
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 25 deletions.
6 changes: 3 additions & 3 deletions modules/core/aaa/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -4297,7 +4297,7 @@ def s3_assign_role(self, user_id, group_id, for_pe=None, system=False):
self.s3_set_roles()

# -------------------------------------------------------------------------
def s3_remove_role(self, user_id, group_id, for_pe=None):
def s3_remove_role(self, user_id, group_id, for_pe=DEFAULT):
"""
Removes a role assignment from a user account
Expand All @@ -4309,7 +4309,7 @@ def s3_remove_role(self, user_id, group_id, for_pe=None):
- None: only remove for the default realm
- 0: only remove for the site-wide realm
- X: only remove for entity X
- []: remove for any realms
- []: remove for any realms (=default)
Note:
strings are assumed to be role UIDs
Expand Down Expand Up @@ -4347,7 +4347,7 @@ def s3_remove_role(self, user_id, group_id, for_pe=None):
unrestrictable = [str(sr.ADMIN),
str(sr.ANONYMOUS),
str(sr.AUTHENTICATED)]
if for_pe != []:
if for_pe is not DEFAULT and for_pe != []:
query &= ((mtable.pe_id == for_pe) | \
(mtable.group_id.belongs(unrestrictable)))
memberships = db(query).select()
Expand Down
3 changes: 2 additions & 1 deletion modules/core/formats/pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,8 @@ def build(self):

item = [ruler]
for rfield in rfields:
if rfield.ftype != "id":
represent = rfield.field.represent if rfield.field else None
if rfield.ftype != "id" or represent or rfield.join:
item.extend(formatted(rfield, row[rfield.colname]))
if index == 0:
flowables.extend(item)
Expand Down
63 changes: 58 additions & 5 deletions modules/core/formats/xlsx.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,9 @@ def write_rows(cls, ws, batch, lfields, types, column_widths):
column_widths: mutable array of column widths
"""

# Date/Time formats from L10N deployment settings
settings = current.deployment_settings

# Date/Time formats from L10N settings
date_format = settings.get_L10n_date_format()
date_format_str = str(date_format)

Expand Down Expand Up @@ -268,16 +269,16 @@ def write_rows(cls, ws, batch, lfields, types, column_widths):

if ftype == "integer":
try:
value = int(value)
except (ValueError, TypeError):
value = to_int(value)
except ValueError:
pass
else:
num_format = "0"

elif ftype == "double":
try:
value = float(value)
except (ValueError, TypeError):
value = to_float(value)
except ValueError:
pass
else:
num_format = "0.00"
Expand Down Expand Up @@ -1150,4 +1151,56 @@ def dt_format_translate(pyfmt):

return xlfmt.replace(PERCENT, "%")

# =============================================================================
def to_int(string):
"""
Convert a string representation of an integer back into an int
- takes thousands-separator into account
- strips any leading/trailing blanks
Args:
string: the string representation
Returns:
integer value
Raises:
ValueError if the string cannot be converted
"""

sep = current.deployment_settings.get_L10n_thousands_separator()

try:
value = int(string.strip().replace(sep, ""))
except (ValueError, TypeError, AttributeError):
raise ValueError("not an integer number")
return value

# =============================================================================
def to_float(string):
"""
Convert a string representation of a float back into an float
- takes thousands-/decimal-separators into account
- strips any leading/trailing blanks
Args:
string: the string representation
Returns:
floating point value
Raises:
ValueError if the string cannot be converted
"""

settings = current.deployment_settings
tsep = settings.get_L10n_thousands_separator()
dsep = settings.get_L10n_decimal_separator()

try:
value = float(string.strip().replace(tsep, "").replace(dsep, "."))
except (ValueError, TypeError, AttributeError):
raise ValueError("not a floating point number")
return value

# END =========================================================================
2 changes: 1 addition & 1 deletion modules/core/tools/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -1019,7 +1019,7 @@ def query(self, table, fields=None, dd=None):

filter_opts = self.filter_opts

if filter_opts:
if filter_opts is not None:
if None in filter_opts:
# Needs special handling (doesn't show up in 'belongs')
_query = (table[filterby] == None)
Expand Down
24 changes: 24 additions & 0 deletions modules/s3db/pr.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ def model(self):
"pe_label",
],
onaccept = self.pr_pentity_onaccept,
ondelete = self.pr_pentity_ondelete,
referenced_by = [(auth_settings.table_membership_name, "pe_id")],
)

Expand Down Expand Up @@ -677,6 +678,29 @@ def pr_pentity_onaccept(form):
s3db.org_update_affiliations("org_site", instance)
return

# -------------------------------------------------------------------------
@staticmethod
def pr_pentity_ondelete(row):
"""
Ondelete of a PE:
- remove all role assignments for this PE
Args:
row: the deleted pr_pentity Row
"""

auth = current.auth
mtable = auth.settings.table_membership

pe_id = row.pe_id
query = (mtable.pe_id == pe_id) & \
(mtable.deleted == False)
memberships = current.db(query).select(mtable.user_id,
mtable.group_id,
)
for m in memberships:
auth.s3_remove_role(m.user_id, m.group_id, for_pe=pe_id)

# -------------------------------------------------------------------------
@staticmethod
def pr_affiliation_onaccept(form):
Expand Down
2 changes: 1 addition & 1 deletion modules/templates/DRKCM/customise/dvr.py
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ def dvr_case_activity_resource(r, tablename):
# Using sectors?
activity_use_sector = ui_options_get("activity_use_sector")

if r.interactive or r.representation in ("aadata", "json"):
if r.interactive or r.representation in ("aadata", "json", "xlsx", "pdf"):

# Fields and CRUD-Form
from core import S3SQLCustomForm, \
Expand Down
10 changes: 6 additions & 4 deletions modules/templates/RLPPTM/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2371,16 +2371,18 @@ def facility_info(r, **attr):
query &= (table.date <= end)
query &= (table.deleted == False)
total = table.tests_total.sum()
row = db(query).select(total).first()
positive = table.tests_positive.sum()
row = db(query).select(total, positive).first()
tests_total = row[total]
if not tests_total:
tests_total = 0
tests_positive = row[positive]

# Add to output
output["report"] = [start.isoformat() if start else None,
end.isoformat() if end else None,
]
output["activity"] = {"tests": tests_total}
output["activity"] = {"tests": tests_total if tests_total else 0,
"positive": tests_positive if tests_positive else 0,
}
else:
r.error(400, "Invalid report parameter format")

Expand Down
22 changes: 17 additions & 5 deletions static/scripts/S3/s3.ui.roles.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@

// Realm column
if (opts.useRealms) {
var realm = !item.u && opts.realms[assignment[1]].l || '';
let realm = !item.u && this._getRealm(assignment[1]).l || '';
$('<td>').text(realm).appendTo(row);
}

Expand Down Expand Up @@ -722,6 +722,18 @@
});
},

/**
* Look up a realm entity
*
* @param {integer} id - the entity ID
*
* @returns: the entity as object {l: "Label", t: "InstanceType"}
*/
_getRealm: function(id) {

return this.options.realms[id] || {l: '---', t: '---'};
},

/**
* Compare two assignments (for sorting)
*
Expand Down Expand Up @@ -764,8 +776,8 @@
}

var realms = this.options.realms,
aType = realms[a].t,
bType = realms[b].t,
aType = this._getRealm(a).t,
bType = this._getRealm(b).t,
realmTypeOrder = this._compareRealmTypes(aType, bType);

if (!realmTypeOrder) {
Expand All @@ -774,8 +786,8 @@
// sort all other entities by their names
if (a) {
if (b) {
var aName = realms[a].l,
bName = realms[b].l;
var aName = this._getRealm(a).l,
bName = this._getRealm(b).l;
return aName > bName && 1 || -1;
} else {
return -1;
Expand Down
10 changes: 5 additions & 5 deletions static/scripts/S3/s3.ui.roles.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 106d2d7

Please sign in to comment.