class DomainSchema(Schema): if_key_missing = None DMAP_ID = validators.IDValidator(not_empty=True) DefaultCulture = validators.ActiveCulture(not_empty=True) CICViewType = validators.IDValidator() VOLViewType = validators.IDValidator() SecondaryName = validators.Bool() GoogleMapsAPIKeyCIC = validators.String(max=100) GoogleMapsClientIDCIC = validators.UnicodeString(max=100) GoogleMapsChannelCIC = validators.UnicodeString(max=100) GoogleMapsAPIKeyVOL = validators.String(max=100) GoogleMapsClientIDVOL = validators.UnicodeString(max=100) GoogleMapsChannelVOL = validators.UnicodeString(max=100)
def edit(self): request = self.request user = request.user if not user.SuperUserGlobal: self._security_failure() model_state = request.model_state model_state.validators = { "PageName": ciocvalidators.String(max=255, not_empty=True) } model_state.method = None if not model_state.validate(): # XXX invalid PageName self._go_to_route("admin_pagetitle_index", _query=[("ErrMsg", _("Invalid ID", request))]) PageName = model_state.form.data.get("PageName") edit_values = self._get_edit_info(PageName) model_state.form.data["descriptions"] = edit_values.descriptions title = _("Manage Page Titles", request) return self._create_response_namespace(title, title, edit_values._asdict(), no_index=True)
class MappingSystemBaseSchema(Schema): if_key_missing = None NewWindow = validators.Bool() DefaultProvince = ciocvalidators.String(min=2, max=2, if_empty=None, not_empty=True) DefaultCountry = ciocvalidators.UnicodeString(max=50, not_empty=True)
class PageTitleSchema(Schema): allow_extra_fields = True filter_extra_fields = True if_key_missing = None pre_validators = [viewbase.cull_extra_cultures("descriptions")] PageName = ciocvalidators.String(max=255, not_empty=True) descriptions = ciocvalidators.CultureDictSchema( PageTitleDescriptionSchema(), record_cultures=True, delete_empty=False)
class MenuItemSchema(Schema): if_key_missing = None delete = validators.Bool() MenuID = Any(ciocvalidators.IDValidator(), validators.OneOf(["NEW"])) Link = ciocvalidators.String(max=150) Display = ciocvalidators.UnicodeString(max=200) MenuGroup = ciocvalidators.Int(min=1, max=3) chained_validators = [ ciocvalidators.RequireIfAny("Display", present=("Link", )), ciocvalidators.RequireIfAny("Link", present=("Display", )), ]
class GeneralHeadingBaseSchema(Schema): if_key_missing = None Used = validators.DictConverter(UsedOptions, if_emtpy=False, if_missing=False) NonPublic = validators.StringBool() DisplayOrder = validators.Int(min=0, max=validators.MAX_TINY_INT, if_empty=0) HeadingGroup = validators.IDValidator() TaxonomyRestrict = validators.Bool() TaxonomyName = validators.Bool() IconNameFull = validators.String(max=65)
class HeadingGroupBaseSchema(Schema): if_key_missing = None GroupID = Any(validators.IDValidator(), validators.OneOf(["NEW"])) DisplayOrder = validators.Int(min=0, max=256, not_empty=True) Descriptions = validators.CultureDictSchema( HeadingGroupDescriptionSchema(), allow_extra_fields=True, fiter_extra_fields=False, ) IconNameFull = validators.String(max=65) delete = validators.Bool()
class AIRSExportOptionsSchema(validators.RootSchema): allow_extra_fields = True if_key_missing = None version = validators.OneOf(["3_1", "3_0", "3_0_Testing"], if_empty="3_0") DST = validators.UnicodeString(max=20, not_empty=True) IncludeDeleted = validators.Bool() IncludeSiteAgency = validators.Bool() PartialDate = validators.ISODateConverter() PubCodeSync = validators.Bool() FileSuffix = validators.String(max=100) LabelLangOverride = validators.Int(min=0, max=validators.MAX_TINY_INT) AnyLanguageChange = validators.Bool()
class TemplateBaseSchema(Schema): if_key_missing = None Owner = ciocvalidators.AgencyCodeValidator() BannerRepeat = validators.Bool() BannerHeight = validators.Int(min=10, max=255) BodyTagExtras = ciocvalidators.String(max=150) FontFamily = validators.String(max=100) ExtraCSS = ciocvalidators.UnicodeString() HeaderLayout = ciocvalidators.IDValidator(not_empty=True) FooterLayout = ciocvalidators.IDValidator(not_empty=True) SearchLayoutCIC = ciocvalidators.IDValidator() SearchLayoutVOL = ciocvalidators.IDValidator() HeaderSearchLink = validators.Bool() HeaderSearchIcon = validators.Bool() HeaderSuggestLink = validators.Bool() HeaderSuggestIcon = validators.Bool() ContainerFluid = validators.Bool() ContainerContrast = validators.Bool() SmallTitle = validators.Bool() cornerRadius = ciocvalidators.String(max=10) fsDefault = ciocvalidators.String(max=10) UseFontAwesome = validators.Bool() PreviewTemplate = validators.Bool() chained_validators = [ ciocvalidators.RequireIfAny("SearchLayoutCIC", missing="SearchLayoutVOL"), ciocvalidators.RequireIfAny("SearchLayoutVOL", missing="SearchLayoutCIC"), ]
class SearchValidators(Schema): allow_extra_fields = True filter_extra_fields = True if_key_missing = None Step = validators.Int(min=1, max=6, if_invalid=None) AgeGroup = ciocvalidators.IDValidator(if_invalid=None) LNID = ciocvalidators.IDValidator(if_invalid=None) CMID = ForEach(ciocvalidators.IDValidator(if_invalid=None)) CMType = ciocvalidators.String(if_invalid=None) GHID = ForEach(ciocvalidators.IDValidator(), if_invalid=None) GHType = validators.String(if_invalid=None) GHID_GRP = ForEach(ciocvalidators.IDValidator(), if_invalid=None) GHID_2 = ForEach(ciocvalidators.IDValidator(), if_invalid=None) GHType_2 = validators.String(if_invalid=None) GHID_GRP_2 = ForEach(ciocvalidators.IDValidator(), if_invalid=None)
class EmailListSchema(ciocvalidators.RootSchema): ignore_key_missing = True if_key_missing = None EmailAddress = ciocvalidators.All( validators=[ ciocvalidators.String(max=1000), ciocvalidators.EmailListRegexValidator(not_empty=True), ] ) AccessURL = AccessURLValidator(not_empty=True, if_missing=None) PDF = ciocvalidators.Bool() Subject = ciocvalidators.UnicodeString(max=255, not_empty=True) ReplyTo = ciocvalidators.Bool(if_missing=True, accept_iterator=True) BodyPrefix = ciocvalidators.UnicodeString() BodySuffix = ciocvalidators.UnicodeString()
def new(self): request = self.request user = request.user if not user.SuperUser: self._security_failure() valdict = { "AreaCode": validators.String(max=20, if_invalid=None, if_empty=None, if_missing=None), "DM": viewbase.domain_validator, } model_state = request.model_state model_state.validators = valdict model_state.method = None model_state.validate() AreaCode = model_state.value("AreaCode") DM = model_state.value("DM") with request.connmgr.get_connection("admin") as conn: areas = conn.execute("EXEC sp_GBL_Admin_Area_l ?, NULL", request.dboptions.MemberID).fetchall() if AreaCode: AdminAreaID = [ x.AdminAreaID for x in areas if x.AreaCode == AreaCode and (DM is None or x.Domain == DM.id) ] if AdminAreaID: request.model_state.form.data["AdminAreaID"] = str( AdminAreaID[0]) title = _("New Admin Notice", request) return self._create_response_namespace(title, title, dict(areas=areas), no_index=True)
class QuickSearchBaseSchema(Schema): if_key_missing = None QuickSearchID = Any(ciocvalidators.IDValidator(), validators.OneOf(["NEW"])) DisplayOrder = validators.Int(min=0, max=255, not_empty=True) PageName = validators.OneOf(search_pages) PromoteToTab = validators.Bool() QueryParameters = ciocvalidators.String(max=1000, not_empty=True) delete = validators.Bool() Descriptions = ciocvalidators.CultureDictSchema( QuickSearchDescriptionSchema(), allow_extra_fields=True, fiter_extra_fields=False, chained_validators=[ ciocvalidators.FlagRequiredIfNoCulture( QuickSearchDescriptionSchema) ], )
def __call__(self): request = self.request user = request.user passvars = request.passvars # noqa if not user: return make_401_error("Access Denied") if "airsexport" not in user.cic.ExternalAPIs: return make_401_error("Insufficient Permissions") model_state = modelstate.ModelState(request) model_state.schema = AIRSExportOptionsSchema( Field=validators.String(max=10, not_empty=True)) model_state.form.method = None # I don't think that version is relevant, just ignore it del model_state.schema.fields["version"] del model_state.schema.fields["DST"] del model_state.schema.fields["PartialDate"] del model_state.schema.fields["IncludeDeleted"] del model_state.schema.fields["IncludeSiteAgency"] if not model_state.validate(params=request.params): if model_state.is_error("Field"): msg = "Invalid Field" else: msg = "An unknown error occurred:\n" msg += "\n".join( str(x) for x in model_state.renderer.all_errors()) return make_internal_server_error(msg) try: data = request.json_body except: return make_internal_server_error( "Error getting request body as JSON") counts = ET.Element("root") for num, count in data["counts"].items(): ET.SubElement(counts, "row", {"num": num, "count": str(count)}) sent = ET.Element("sent") for num in data["sent"]: ET.SubElement(sent, "row", {"num": num}) field = "EXTRA_" + model_state.value("Field").upper() + "FILECOUNT" datefield = "EXTRA_DATE_" + model_state.value( "Field").upper() + "LASTSENT" if request.language.Culture != "en-CA": datefield += request.language.Culture.split("-")[0].upper() log.debug("Date Field: %s %s", datefield, request.language.Culture) with request.connmgr.get_connection("admin") as conn: cursor = conn.execute( """ DECLARE @ErrMsg as nvarchar(500), @RC as int EXEC @RC = sp_GBL_AIRS_Export_u_Counts ?, @@LANGID, ?, ?, ?, ?, @ErrMsg=@ErrMsg OUTPUT SELECT @RC AS [Return], @ErrMsg AS ErrMsg """, request.viewdata.cic.ViewType, field, datefield, ET.tostring(counts, encoding="unicode"), ET.tostring(sent, encoding="unicode"), ) result = cursor.fetchone() if result.Return: log.debug("Error: %s", result.ErrMsg) return make_internal_server_error( _("Unable to save: ") + result.ErrMsg) response = request.response response.content_type = "text/plain" return "success"
class UploadSchema(validators.RootSchema): ImportFile = validators.FieldStorageUploadConverter(not_empty=True) DisplayName = validators.String(max=255, if_empty=None)
class VerifySchema(StartSchema): allow_extra_fields = True filter_extra_fields = True ChallengeSig = ciocvalidators.String(not_empty=True) AuthVersion = ciocvalidators.Int(max=2, not_empty=False)
def save(self): request = self.request user = request.user chk_type = self.request.context.chk_type all_values = not self.request.dboptions.OtherMembersActive shared_values = not not ( all_values or not self.request.matched_route.name.endswith("_local")) SuperUserGlobal = self._check_security( chk_type, chk_type.Shared == "full" or shared_values) if shared_values and not SuperUserGlobal: self._security_failure() if chk_type.ShowAdd: extra_validators = { chk_type.ID: Any(ciocvalidators.IDValidator(), validators.OneOf(["NEW"])) } else: extra_validators = { chk_type.ID: ciocvalidators.IDValidator(not_empty=chk_type.CanDelete) } if chk_type.CodeTitle: if not chk_type.CodeValidator: extra_validators[chk_type.CodeField] = ciocvalidators.String( max=chk_type.CodeMaxLength) else: extra_validators[chk_type.CodeField] = chk_type.CodeValidator if chk_type.DisplayOrder: extra_validators["DisplayOrder"] = validators.Int(min=0, max=256, if_empty=0) if chk_type.ShowOnForm: extra_validators["ShowOnForm"] = validators.Bool() for field in chk_type.ExtraFields or []: extra_validators[field["field"]] = field["validator"] extra_name_validators = {} for field in chk_type.ExtraNameFields or []: extra_name_validators[field["field"]] = field["validator"] base_schema = make_checklist_base_schema(extra_name_validators, **extra_validators) schema_params = {"chkitem": foreach.ForEach(base_schema)} schema = PostSchema(**schema_params) model_state = request.model_state model_state.form.state.chk_type = chk_type model_state.schema = schema model_state.form.variable_decode = True domain, shown_cultures = viewbase.get_domain_and_show_cultures( request.params) if model_state.validate(): # valid. Save changes and redirect root = ET.Element("CHECKLIST") for i, chkitem in enumerate(model_state.form.data["chkitem"]): if should_skip_item(chk_type, chkitem): continue chk_el = ET.SubElement(root, "CHK") ET.SubElement(chk_el, "CNT").text = str(i) for key, value in chkitem.items(): if key == chk_type.ID and value == "NEW": value = -1 elif isinstance(value, bool): value = int(value) if key != "Descriptions": if value is not None: ET.SubElement(chk_el, key).text = str(value) continue descs = ET.SubElement(chk_el, "DESCS") for culture, data in value.items(): culture = culture.replace("_", "-") if culture not in shown_cultures: continue desc = ET.SubElement(descs, "DESC") ET.SubElement(desc, "Culture").text = culture for key, value in data.items(): if value: ET.SubElement(desc, key).text = value args = [ request.dboptions.MemberID, user.Mod, ET.tostring(root, encoding="unicode"), ] with request.connmgr.get_connection("admin") as conn: sql = chk_type.UpdateSQL(shared_values) log.debug("sql: %s", sql) log.debug("args: %s", args) cursor = conn.execute(sql, *args) result = cursor.fetchone() cursor.close() if not result.Return: self._go_to_route( request.matched_route.name, _query=( ( "InfoMsg", _("The record(s) were successfully updated.", request), ), ("ShowCultures", shown_cultures), ("chk", chk_type.FieldCode), ), ) ErrMsg = _("Unable to save: ") + result.ErrMsg else: ErrMsg = _("There were validation errors.") chkitems, chkusage = self._get_edit_info( chk_type, not all_values and not shared_values, not all_values and shared_values, not SuperUserGlobal, ) record_cultures = syslanguage.active_record_cultures() chkitems = variabledecode.variable_decode(request.POST)["chkitem"] model_state.form.data["chkitem"] = chkitems type_name = "" if chk_type.Shared == "partial" and not all_values: if shared_values: type_name = _("Shared", self.request) else: type_name = _("Local", self.request) title_template = _(chk_type.PageTitleTemplate, self.request) % { "type": type_name } title = (chk_type.CheckListName if request.viewdata.PrintMode else title_template.format(chk_type.CheckListName)) return self._create_response_namespace( title, title, dict( chkitems=chkitems, record_cultures=record_cultures, shown_cultures=shown_cultures, SuperUserGlobal=SuperUserGlobal, chkusage=chkusage, chk_type=chk_type, ErrMsg=ErrMsg, ), no_index=True, )