def title(self, *args, **kwargs): record = self.record critRecord = self.critRecord withEvidence = H.icon( N.missing if self.field(N.evidence).isBlank() else N.check) status = H.span(f"""evidence{NBSP}{withEvidence}""", cls="right small") seq = G(record, N.seq, default=Q) scoreRep = self.field(N.score).wrapBare() return H.span( [ H.span([f"""{seq}{DOT}{NBSP}""", critRecord.title()], cls="col1"), H.span(scoreRep, cls="col2"), status, ], cls=f"centrytitle criteria", )
"""The datetime type.""" import re from datetime import datetime as dt from config import Config as C, Names as N from control.utils import now, E from control.html import HtmlElements as H from control.typ.base import TypeBase CW = C.web QQ = H.icon(CW.unknown[N.generic]) Qq = H.icon(CW.unknown[N.generic], asChar=True) dtTrim = re.compile(r"""[^0-9 T/:.-]+""") dtSep = re.compile(r"""[ T/:.-]+""") def getDefaultDate(): today = now() return ( today.year, today.month, today.day, today.hour, today.minute, today.second, )
from config import Config as C, Names as N from control.utils import pick as G from control.html import HtmlElements as H from control.typ.master import Master CW = C.web Qn = H.icon(CW.unknown[N.number], asChar=True) Qq = H.icon(CW.unknown[N.generic], asChar=True) class ReviewEntry(Master): """Type class for review entries.""" def __init__(self, context): super().__init__(context) def titleStr(self, record): """The title is a sequence number plus the short criterion text.""" context = self.context types = context.types seq = H.he(G(record, N.seq)) or Qn eid = G(record, N.criteria) title = Qq if eid is None else types.criteria.title(eid=eid) return f"""{seq}. {title}"""
def wrap(self): """Wrap it all up.""" context = self.context auth = context.auth eppn = G(auth.user, N.eppn) if auth.authenticated() else N.public eppnRep = H.span(eppn, cls="mono") (identityRep, accessRep) = auth.credentials() login = (E if auth.authenticated() else ( auth.wrapTestUsers() if auth.isDevel else H. a(G(LOGIN, N.text), G(LOGIN, N.url), cls="button small loginout"))) logout = (H.join([ H.a(G(LOGOUT, N.text), G(LOGOUT, N.url), cls="button small loginout"), H.a( G(SLOGOUT, N.text), G(SLOGOUT, N.url), cls="button small loginout", title=G(SLOGOUT, N.title), ), ]) if auth.authenticated() else E) techdoc = (H.a( G(TECH, N.text), G(TECH, N.url), target=N._blank, cls="button medium help", title=G(TECH, N.title), )) userhelp = (H.a( G(HELP, N.text), G(HELP, N.url), target=N._blank, cls="button medium help", title=G(HELP, N.title), )) return H.div( [ H.div( [ H.icon(N.devel) if auth.isDevel else E, H.details(identityRep, eppnRep, "usereppn", cls="user"), H.div(accessRep, cls="access"), login, logout, ], cls="headlinestart", ), H.div( [ techdoc, userhelp, ], cls="headlineend", ), H.img( G(LOGO, N.src), href=G(LOGO, N.url), target=N._blank, title=G(LOGO, N.text), imgAtts=dict(height=G(LOGO, N.height)), id="logo", ), ], cls="headline", )
def title( self, eid=None, record=None, markup=False, clickable=False, multiple=False, active=None, hideInActual=False, hideBlockedUsers=False, ): if record is None and eid is None: return (QQ, QQ) if markup else Qq table = self.name if record is None: context = self.context record = context.getItem(table, eid) titleStr = self.titleStr(record) titleHint = self.titleHint(record) if markup: if eid is None: eid = G(record, N._id) isActive = eid in (active or []) if multiple else eid == active baseCls = ( ("button " if multiple or not isActive else "label ") if clickable else "tag " ) activeCls = "active " if isActive else E inActualCls = self.inActualCls(record=record) hidden = ( hideInActual and inActualCls and not isActive or hideBlockedUsers and table == N.user and not G(record, N.mayLogin) ) if hidden: return (E, E) atts = dict(cls=f"{baseCls}{activeCls}medium {inActualCls}") if clickable and eid is not None: atts[N.eid] = str(eid) if titleHint: atts[N.title] = titleHint titleIcon = ( (NBSP + H.icon(N.cross if isActive else N.add, cls="small")) if multiple else E ) titleFormatted = H.span( [titleStr, titleIcon], lab=titleStr.lower(), **atts, ) return (titleStr, titleFormatted) else: return titleStr
SYSTEM, ) CB = C.base CW = C.web DEBUG = CB.debug DEBUG_AUTH = G(DEBUG, N.auth) TRANSPORT_ATTRIBUTES = CB.transportAttributes SHIB_KEY = CB.shibKey ATTRIBUTES = CB.attributes LIMITS = CW.limits LIMIT_JSON = G(LIMITS, N.json, default=1000000) Qc = H.icon(CW.unknown[N.country], asChar=True) Qu = H.icon(CW.unknown[N.user], asChar=True) Qg = H.icon(CW.unknown[N.group], asChar=True) class Auth: """Deal with user Authentication. Facilitates the login/logout process of users. Maintains the attributes that the DARIAH Identity Provider supplies about users. """ def __init__(self, db, regime): """## Initialization Include a handle to `control.db.Db` into the
def deleteButton(self): """Show the delete button and/or the number of dependencies. Check the permissions in order to not show a delete button if the user cannot delete the record. Returns ------- string(html) """ mayDelete = self.mayDelete if not mayDelete: return E record = self.record table = self.table itemSingle = self.itemLabels[0] dependencies = self.getDependencies() nCas = G(dependencies, N.cascade, default=0) cascadeMsg = (H.span( f"""{nCas} detail record{E if nCas == 1 else S}""", title="""Detail records will be deleted with the master record""", cls="label small warning-o right", ) if nCas else E) cascadeMsgShort = ( f""" and {nCas} dependent record{E if nCas == 1 else S}""" if nCas else E) nRef = G(dependencies, N.reference, default=0) if nRef: plural = E if nRef == 1 else S return H.span([ H.icon( N.chain, cls="medium right", title= f"""Cannot delete because of {nRef} dependent record{plural}""", ), H.span( f"""{nRef} dependent record{plural}""", cls="label small warning-o right", ), ]) if table in TO_MASTER: masterTable = G(TO_MASTER, table) masterId = G(record, masterTable) else: masterTable = None masterId = None url = ( f"""/api/{table}/{N.delete}/{G(record, N._id)}""" if masterTable is None or masterId is None else f"""/api/{masterTable}/{masterId}/{table}/{N.delete}/{G(record, N._id)}""" ) return H.span([ cascadeMsg, H.iconx( N.delete, cls="medium right warning", deleteurl=url, title=f"""delete this {itemSingle}{cascadeMsgShort}""", ), ])
from config import Config as C, Names as N from control.html import HtmlElements as H from control.utils import pick as G, E, DOT from control.record import Record CW = C.web MESSAGES = CW.messages Qu = H.icon(CW.unknown[N.user], asChar=True) class ReviewEntryR(Record): """Logic for reviewEntry records. Review entry records have a customised title, showing when the entry was made and by whom. There is also a `compact` method to present these records, just the title and the comments entered by the reviewer. !!! hint If the `reviewEntry` record is not part of the workflow, the behaviour of this class falls back to the base class `control.record.Record`. """ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) def title(self, *args, **kwargs): uid = self.uid record = self.record
from config import Config as C, Names as N from control.html import HtmlElements as H from control.utils import pick as G, E, NBSP from control.typ.value import Value CW = C.web Qq = H.icon(CW.unknown[N.generic], asChar=True) QQ = H.icon(CW.unknown[N.generic]) Qn = H.icon(CW.unknown[N.number], asChar=True) Qc = H.icon(CW.unknown[N.country], asChar=True) class Decision(Value): """Type class for decisions.""" def __init__(self, context): super().__init__(context) def titleStr(self, record): """The title string is a suitable icon plus the participle field.""" decision = G(record, N.participle) if decision is None: return Qq sign = G(record, N.sign) decision = f"""{sign}{NBSP}{decision}""" return decision def title( self, eid=None, record=None,
def toDisplay(self, val, markup=True): values = G(BOOLEAN_TYPES, self.name) noneValue = False if len(values) == 2 else None valueBare = G(values, val, default=G(values, noneValue)) return H.icon(valueBare, cls="medium", asChar=not markup)
from config import Config as C, Names as N from control.utils import pick as G, shiftRegional from control.html import HtmlElements as H from control.typ.value import Value CW = C.web Qq = H.icon(CW.unknown[N.generic], asChar=True) Qc = H.icon(CW.unknown[N.country], asChar=True) class Country(Value): """Type class for countries.""" def __init__(self, context): super().__init__(context) def titleStr(self, record): """Puts the 2-letter iso code plus the flag characters in the title.""" iso = H.he(G(record, N.iso)) return iso + shiftRegional(iso) if iso else Qc def titleHint(self, record): """Provides the full country name as a tooltip on the interface.""" return G(record, N.name) or Qc