def _get_options(self): request = self.request user = request.user validator = OptionsSchema() try: options = validator.to_python(request.params) except validators.Invalid as e: self._error_page(_("Invalid Domain: %s", self.request) % e.message) options["MR"] = not not options["MR"] options = Options(**options) if options.DM is None: self._error_page(_("No domain provided.", self.request)) if options.DM.id == const.DM_CIC: options = options._replace(MR=False) if not ((options.DM.id == const.DM_CIC and user.cic.SuperUser) or (options.DM.id == const.DM_VOL and user.vol.SuperUser)): self._security_failure() log.debug("options: %s", options) return options
def __init__(self, request): request.context = self self.request = request # required to use go_to_page init_page_info(request, const.DM_GLOBAL, const.DM_GLOBAL) user = request.user if not user.cic.SuperUser: security_failure(request) SubjID = request.params.get('SubjID') validator = validators.IDValidator() try: SubjID = validator.to_python(SubjID) except validators.Invalid: error_page(request, _('Invalid ID', request), const.DM_GLOBAL, const.DM_GLOBAL, _('Manage Subjects', request)) self.SubjID = SubjID self.is_add = not SubjID subject = None if SubjID: with request.connmgr.get_connection('admin') as conn: subject = conn.execute('EXEC dbo.sp_THS_Subject_s_Basic ?, ?', SubjID, request.dboptions.MemberID).fetchone() if SubjID and not subject: error_page(request, _('Subject Not Found', request), const.DM_GLOBAL, const.DM_GLOBAL, _('Manage Subjects', request)) self.subject = subject
def get_user_from_id(self, user_id): request = self.request try: user_id = validators.IDValidator().to_python(user_id) except validators.Invalid as error: error_page( request, _('Invalid User_ID: %s') % error.message, const.DM_GLOBAL, const.DM_GLOBAL, _('User API Credentials')) if user_id == self.request.user.User_ID: self.user = self.request.user if self.list_page: sql = 'EXEC sp_GBL_Users_APICreds_l ?, ?, ?' with request.connmgr.get_connection('admin') as conn: self.cred_list = conn.execute(sql, request.dboptions.MemberID, None, user_id).fetchall() return sql = ''' DECLARE @MemberID int = ?, @AgencyCode char(3) = ?, @User_ID int = ? EXEC sp_GBL_Users_s_APICreds @MemberID, @AgencyCode, @User_ID ''' if self.list_page: sql += 'EXEC sp_GBL_Users_APICreds_l @MemberID, @AgencyCode, @User_ID' with request.connmgr.get_connection('admin') as conn: cursor = conn.execute(sql, request.dboptions.MemberID, None if request.user.SuperUser else request.user.Agency, user_id) self.user = cursor.fetchone() if not self.user: error_page( request, _('User not found'), const.DM_GLOBAL, const.DM_GLOBAL, _('User API Credentials')) if self.list_page: cursor.nextset() self.cred_list = cursor.fetchall()
def delete(self): request = self.request user = request.user if not user.cic or user.cic.CanUpdatePubs == const.UPDATE_NONE: self._security_failure() base_params = [] num = request.params.get('NUM') if num is not None: base_params.append( ('NUM', num) ) number = request.params.get('Number') if number is not None: base_params.append( ('Number', number) ) model_state = request.model_state model_state.validators = { 'BTPBID': ciocvalidators.IDValidator(not_empty=True) } model_state.method = None if not model_state.validate(): self._error_page(_('Invalid Publication ID', request)) BTPBID = model_state.form.data.get('BTPBID') title = _('Update Publications', request) return self._create_response_namespace(title, title, dict(id_name='BTPBID', id_value=BTPBID, extra_values=base_params, route='cic_updatepubs', action='delete'), no_index=True)
def delete(self): request = self.request domain = self.get_domain() model_state = request.model_state model_state.validators = {"PageID": validators.IDValidator(not_empty=True)} model_state.method = None if not model_state.validate(): self._error_page(_("Invalid ID", request)) PageID = model_state.form.data["PageID"] request.override_renderer = "cioc.web:templates/confirmdelete.mak" extra_values = [("DM", domain.id)] title = _("Delete Page (%s)", request) % _(domain.label, request) return self._create_response_namespace( title, title, dict( id_name="PageID", id_value=PageID, route="admin_pages", action="delete", extra_values=extra_values, ), no_index=True, )
def delete(self): request = self.request user = request.user if not user.SuperUser: self._security_failure() options = self._get_options() model_state = request.model_state model_state.validators = {'EmailID': validators.IDValidator(not_empty=True)} model_state.method = None if not model_state.validate(): self._error_page(_('Invalid ID', request)) EmailID = model_state.form.data['EmailID'] request.override_renderer = 'cioc.web:templates/confirmdelete.mak' extra_values = [('DM', options.DM.id)] if options.MR: extra_values.append(('MR', '1')) title = _('Standard Email Update Text (%s)', request) % _(options.DM.label, request) return self._create_response_namespace(title, title, dict(id_name='EmailID', id_value=EmailID, route='admin_email', action='delete', extra_values=extra_values), no_index=True)
def delete(self): request = self.request user = request.user if not (user.SuperUser or user.WebDeveloper): self._security_failure() model_state = request.model_state model_state.validators = { "TemplateID": ciocvalidators.IDValidator(not_empty=True) } model_state.method = None if not model_state.validate(): self._error_page(_("Invalid ID", request)) TemplateID = model_state.form.data["TemplateID"] request.override_renderer = "cioc.web:templates/confirmdelete.mak" title = _("Manage Templates", request) return self._create_response_namespace( title, title, dict( id_name="TemplateID", id_value=TemplateID, route="admin_template", action="delete", ), no_index=True, )
def delete(self): request = self.request user = request.user if not user.vol.SuperUserGlobal: self._security_failure() model_state = request.model_state model_state.validators = {"AI_ID": validators.IDValidator(not_empty=True)} model_state.method = None if not model_state.validate(): self._error_page(_("Invalid ID", request)) AI_ID = model_state.form.data["AI_ID"] request.override_renderer = "cioc.web:templates/confirmdelete.mak" title = _("Manage Areas of Interest", request) return self._create_response_namespace( title, title, dict( id_name="AI_ID", id_value=AI_ID, route="admin_interests", action="delete", ), no_index=True, )
def _get_list_type(self): request = self.request user = request.user if not user.SuperUser: self._security_failure() list_type = request.params.get("list") if not list_type: error_page( request, _("No checklist selected", request), const.DM_GLOBAL, const.DM_GLOBAL, ) log.debug("list_types: %s", list_types) list_type = list_types.get(list_type) if not list_type: error_page( request, _("Not a valid checklist.", request), const.DM_GLOBAL, const.DM_GLOBAL, ) list_type = list_type(request) return list_type
def close(self): request = self.request user = request.user if not user.SuperUserGlobal: self._security_failure() validator = validators.IDValidator(not_empty=True) try: NoticeID = validator.to_python(request.params.get("NoticeID")) except validators.Invalid: self._error_page(_("Invalid ID", request)) with request.connmgr.get_connection("admin") as conn: notice = conn.execute("EXEC sp_GBL_Admin_Notice_s ?", NoticeID).fetchone() if not notice: self._error_page(_("Not Found", request)) domains = self._get_domains() if notice.Domain not in domains: self._security_failure() data = request.model_state.form.data data["ActionNotes"] = notice.ActionNotes data["ActionTaken"] = notice.ActionTaken title = _("Close Admin Notice", request) return self._create_response_namespace(title, title, dict(notice=notice, NoticeID=NoticeID), no_index=True)
class ListContactHonorific(ListValuesModel): Table = "GBL_Contact_Honorific" FieldCode = "ch" ID = None id_validator = validators.UnicodeString(max=20) AdminAreaCode = "HONORIFIC" NameField = "Honorific" ListName = _("Contact Honorific") ListNamePlural = _("honorifics") HasModified = False SearchLink1 = ( "~/results.asp", dict( incDel="on", Limit= "EXISTS(SELECT * FROM GBL_Contact WHERE GblNUM IS NOT NULL AND bt.NUM=GblNUM AND NAME_HONORIFIC='IDIDID')", ), ) SearchLink2 = ( "~/volunteer/results.asp", dict( incDel="on", Limit= "EXISTS(SELECT * FROM GBL_Contact WHERE VolVNUM IS NOT NULL AND vo.VNUM=VolVNUM AND NAME_HONORIFIC='IDIDID')", ), )
def delete_confirm(self): request = self.request user = request.user if not user.SuperUserGlobal: self._security_failure() CM_ID = self._get_cmid(True) with request.connmgr.get_connection('admin') as conn: sql = ''' DECLARE @ErrMsg as nvarchar(500), @RC as int EXECUTE @RC = dbo.sp_GBL_Community_d ?, @ErrMsg=@ErrMsg OUTPUT SELECT @RC as [Return], @ErrMsg AS ErrMsg ''' cursor = conn.execute(sql, CM_ID) result = cursor.fetchone() cursor.close() if not result.Return: self._go_to_route('admin_community_index', _query=[('InfoMsg', _('The Community was successfully deleted.', request))]) if result.Return == 3: self._error_page(_('Unable to delete Community: ', request) + result.ErrMsg) self._go_to_route('admin_community', action='edit', _query=[('ErrMsg', _('Unable to delete Community: ') + result.ErrMsg), ('CM_ID', CM_ID)])
def clearrecords(self): request = self.request user = request.user if not user.cic.SuperUser: self._security_failure() model_state = request.model_state model_state.method = None model_state.validators = { "PB_ID": validators.IDValidator(not_empty=True) } if not model_state.validate(): self._error_page(_("Invalid Publication ID", request)) PB_ID = model_state.form.data["PB_ID"] edit_values = self._get_edit_info(False, PB_ID) request.override_renderer = ( "cioc.web.cic:templates/publication/clearrecords.mak") title = _("Manage Publication from Records", request) return self._create_response_namespace( title, title, dict( id_name="PB_ID", id_value=PB_ID, route="cic_publication", action="clearrecords", publication=edit_values.publication, ), no_index=True, )
def delete(self): request = self.request user = request.user if not user.SuperUser: self._security_failure() domain, shown_cultures = viewbase.get_domain_and_show_cultures(request.params) if not domain: self._error_page(_('Invalid Domain', request)) if domain.id == const.DM_CIC: user_dm = user.cic if request.dboptions.UseCIC else user.vol else: user_dm = user.vol if not user_dm.SuperUser: self._security_failure() model_state = request.model_state model_state.validators = { 'ViewType': ciocvalidators.IDValidator(not_empty=True) } model_state.method = None if not model_state.validate(): self._error_page(_('Invalid ID', request)) ViewType = model_state.form.data['ViewType'] request.override_renderer = 'cioc.web:templates/confirmdelete.mak' title = _('Manage Views (%s)', request) % _(domain.label, request) return self._create_response_namespace(title, title, dict(id_name='ViewType', id_value=ViewType, route='admin_view', action='delete', domain=domain), no_index=True)
def index(self): request = self.request user = request.user if not user.SuperUser: self._security_failure() domain, shown_cultures = viewbase.get_domain_and_show_cultures(request.params) if not domain: self._error_page(_('Invalid Domain', request)) if domain.id == const.DM_CIC: user_dm = user.cic if request.dboptions.UseCIC else user.vol else: user_dm = user.vol if not user_dm.SuperUser: self._security_failure() with request.connmgr.get_connection('admin') as conn: cursor = conn.execute('EXEC sp_%s_View_l ?, ?, 1, NULL' % domain.str, request.dboptions.MemberID, user.Agency) views = cursor.fetchall() cursor.close() title = _('Manage Views (%s)', request) % _(domain.label, request) return self._create_response_namespace(title, title, dict(views=views, domain=domain), no_index=True)
def topicsearch_delete_confirm(self): request = self.request user = request.user if not user.cic.SuperUser: self._security_failure() ViewType, TopicSearchID = self._get_topicsearch_id() if not TopicSearchID: self._error_page(_('Invalid Topic Search', request)) if not ViewType: self._error_page(_('Invalid View', request)) with request.connmgr.get_connection('admin') as conn: sql = ''' DECLARE @ErrMsg as nvarchar(500), @RC as int EXECUTE @RC = dbo.sp_CIC_View_TopicSearch_d ?, ?, ?, @ErrMsg=@ErrMsg OUTPUT SELECT @RC as [Return], @ErrMsg AS ErrMsg ''' cursor = conn.execute(sql, TopicSearchID, request.dboptions.MemberID, user.Agency) result = cursor.fetchone() cursor.close() if not result.Return: self._go_to_route('admin_view', action='topicsearches', _query=[('InfoMsg', _('Topic Search Deleted', request)), ('ViewType', ViewType)]) if result.Return == 3: self._error_page(_('Unable to delete Topic Search: ', request) + result.ErrMsg) self._go_to_route('admin_view', action='topicsearch', _query=[('ErrMsg', _('Unable to delete Topic Search: ') + result.ErrMsg), ('ViewType', ViewType), ('TopicSearchID', TopicSearchID)])
def _get_topic_search_edit_info(self, ViewType, TopicSearchID): request = self.request user = request.user is_edit = not not TopicSearchID publications = [] topic_search = None descriptions = {} with request.connmgr.get_connection('admin') as conn: sql = '''EXECUTE dbo.sp_CIC_View_TopicSearch_s ?, ?, ?, ?''' cursor = conn.execute(sql, TopicSearchID, ViewType, user.Agency, request.dboptions.MemberID) view_info = cursor.fetchone() cursor.nextset() topic_search = cursor.fetchone() cursor.nextset() for lng in cursor.fetchall(): descriptions[lng.Culture] = lng cursor.nextset() publications = cursor.fetchall() cursor.close() if not view_info: return self._error_page(_('View Not Found', request)) if is_edit and not topic_search: return self._error_page(_('Topic Search Not Found', request)) return TopicSearchEditValues(ViewType, TopicSearchID, topic_search, descriptions, format_pub_list(publications, True), view_info, is_edit)
def delete(self): request = self.request user = request.user if not user.cic.SuperUserGlobal: self._security_failure() model_state = request.model_state model_state.validators = {"Code": ciocvalidators.IDValidator(not_empty=True)} model_state.method = None if not model_state.validate(): self._error_page(_("Invalid ID", request)) Code = model_state.form.data["Code"] request.override_renderer = "cioc.web:templates/confirmdelete.mak" title = _("Delete NAICS Code", request) return self._create_response_namespace( title, title, dict(id_name="Code", id_value=Code, route="admin_naics", action="delete"), no_index=True, )
def details_sidebar_parameters(request): return dumps([ "[" + _('Show Listings', request) + "]", "[" + _('Hide Listings', request) + "]", "[" + _('Show Deleted', request) + "]", "[" + _('Hide Deleted', request) + "]" ])
def close(self): request = self.request user = request.user if not user.SuperUserGlobal: self._security_failure() validator = validators.IDValidator(not_empty=True) try: NoticeID = validator.to_python(request.params.get('NoticeID')) except validators.Invalid: self._error_page(_('Invalid ID', request)) with request.connmgr.get_connection('admin') as conn: notice = conn.execute('EXEC sp_GBL_Admin_Notice_s ?', NoticeID).fetchone() if not notice: self._error_page(_('Not Found', request)) domains = self._get_domains() if notice.Domain not in domains: self._security_failure() data = request.model_state.form.data data['ActionNotes'] = notice.ActionNotes data['ActionTaken'] = notice.ActionTaken title = _('Close Admin Notice', request) return self._create_response_namespace(title, title, dict(notice=notice, NoticeID=NoticeID), no_index=True)
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)
def index(self): request = self.request ViewType, domain = self._basic_info() edit_info = self._get_edit_info(domain, ViewType) if not edit_info["viewinfo"]: # not a valid view self._error_page(_("View Not Found", request)) quicksearches = edit_info["quicksearches"] for quicksearch in quicksearches: quicksearch.Descriptions = self._culture_dict_from_xml( quicksearch.Descriptions, "DESC") request.model_state.form.data["quicksearch"] = quicksearches title = _("Quick Searches (%s)", request) % edit_info["viewinfo"].ViewName return self._create_response_namespace(title, title, edit_info, no_index=True, print_table=False)
def inrequest(self): CT = '{http://clienttracker.cioc.ca/schema/}' request = self.request if not has_been_launched(request): return {'fail': True, 'errinfo': _('Current session not associated with a Client Tracker user.', request)} vals = request.cioc_get_cookie('ctlaunched').split(':') if len(vals) != 3: return {'fail': True, 'errinfo': _('Current session not associated with a Client Tracker user.', request)} ctid, login, key = vals idstring = request.params.get('id') remove = request.params.get('RemoveItem') if not idstring: return {'fail': True, 'errinfo': _('Error: No record was chosen', request)} validator = [ciocvalidators.NumValidator(), ciocvalidators.VNumValidator()] if remove: validator.append(validators.OneOf(['all'])) validator = Any(validators=validator) try: idstring = validator.to_python(idstring) except Invalid, e: return {'fail': True, 'errinfo': _('Error: The following is an invalid ID: %s', request) % idstring}
def edit(self): chk_type = self.request.context.chk_type SuperUserGlobal = self._check_security(chk_type, chk_type.Shared == 'full') all_values = not self.request.dboptions.OtherMembersActive shared_values = not not (all_values or not self.request.matched_route.name.endswith('_local')) if shared_values and not SuperUserGlobal: self._security_failure() if chk_type.Shared == 'full' and not shared_values: self._error_page(_('This checklist does not support local values', self.request)) 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) retval = self._get_request_info(chk_type, SuperUserGlobal, not all_values and not shared_values, not all_values and shared_values, _(chk_type.PageTitleTemplate, self.request) % {'type': type_name}) request = self.request request.model_state.form.data['chkitem'] = retval['chkitems'] return retval
def _get_chk_type(self): request = self.request user = request.user if not user.SuperUser: security_failure(request) chklst = request.params.get('chk') if not chklst: error_page(request, _('No checklist selected', request), const.DM_GLOBAL, const.DM_GLOBAL) chk_type = checklists.get(chklst) if not chk_type: if chklst.startswith('exc'): chk_type = ChkExtraChecklist elif chklst.startswith('exd'): chk_type = ChkExtraDropDown elif chklst.startswith('vxc'): chk_type = ChkExtraChecklist elif chklst.startswith('vxd'): chk_type = ChkExtraDropDown else: error_page(request, _('Not a valid checklist.', request), const.DM_GLOBAL, const.DM_GLOBAL) chk_type = chk_type(request) return chk_type
class ListStreetType(ListValuesModel): Table = "GBL_StreetType" FieldCode = "st" AdminAreaCode = "STREETTYPE" NameField = "StreetType" ID = "SType_ID" ListName = _("Street Type") ListNamePlural = _("street types") ExtraFields = [ { "type": "language", "title": _("Language"), "field": "Culture", "kwargs": {}, "validator": validators.ActiveCulture(record_cultures=True), }, { "type": "checkbox", "title": _("Display After Street"), "field": "AfterName", "kwargs": {}, "validator": validators.Bool(), "element_title": _("Street Type displays after the Street Name: "), }, ]
def delete(self): request = self.request user = request.user if not user.cic or not user.cic.SuperUser: self._security_failure() model_state = request.model_state model_state.validators = {"SubjID": validators.IDValidator(not_empty=True)} model_state.method = None if not model_state.validate(): self._error_page(_("Invalid Subject ID", request)) SubjID = model_state.form.data["SubjID"] request.override_renderer = "cioc.web:templates/confirmdelete.mak" title = _("Manage Subjects", request) return self._create_response_namespace( title, title, dict( id_name="SubjID", id_value=SubjID, route="admin_thesaurus", action="delete", ), no_index=True, )
def edit(self): request = self.request domain = self.get_domain() is_add = request.matchdict.get('action') == 'add' model_state = request.model_state model_state.method = None model_state.schema = validators.RootSchema(PageID=validators.IDValidator(not_empty=not is_add), if_key_missing=None) if not model_state.validate(): self._error_page(_('Unable to load page: %s', request) % model_state.renderer.errorlist('PageID')) page_id = model_state.value('PageID') page = None with request.connmgr.get_connection('admin') as conn: cursor = conn.execute('EXEC dbo.sp_GBL_Page_s ?, ?, ?, ?', request.dboptions.MemberID, request.user.Agency, domain.id, page_id) page = cursor.fetchone() cursor.nextset() views = cursor.fetchall() if not is_add and not page: self._error_page(_('Page Not Found', request)) data = model_state.form.data data['page'] = page data['views'] = set(unicode(v.ViewType) for v in views if v.Selected) title = _('Page (%s)', request) % _(domain.label, request) return self._create_response_namespace(title, title, dict(PageID=page_id, page=page, is_add=is_add, views=views, domain=domain), no_index=True)
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)
def index(self): request = self.request ViewType, domain = self._basic_info() edit_info = self._get_edit_info(domain, ViewType) if not edit_info['viewinfo']: # not a valid view self._error_page(_('View Not Found', request)) quicksearches = edit_info['quicksearches'] for quicksearch in quicksearches: quicksearch.Descriptions = self._culture_dict_from_xml(quicksearch.Descriptions, 'DESC') request.model_state.form.data['quicksearch'] = quicksearches title = _('Quick Searches (%s)', request) % edit_info['viewinfo'].ViewName return self._create_response_namespace( title, title, edit_info, no_index=True, print_table=False )
def inrequest(self): CT = '{http://clienttracker.cioc.ca/schema/}' request = self.request if not has_been_launched(request): return {'fail': True, 'errinfo': _('Current session not associated with a Client Tracker user.', request)} vals = request.cioc_get_cookie('ctlaunched').split(':') if len(vals) != 3: return {'fail': True, 'errinfo': _('Current session not associated with a Client Tracker user.', request)} ctid, login, key = vals root = ET.Element(u'isInRequest', xmlns=u'http://clienttracker.cioc.ca/schema/') ET.SubElement(root, u'login').text = unicode(login) ET.SubElement(root, u'key').text = unicode(key) ET.SubElement(root, u'ctid').text = unicode(ctid) fd = StringIO() ET.ElementTree(root).write(fd, 'utf-8', True) xml = fd.getvalue() fd.close() url = request.dboptions.ClientTrackerRpcURL + 'is_in_request' headers = {"content-type": "application/xml; charset=utf-8"} r = requests.post(url, data=xml, headers=headers) try: r.raise_for_status() except Exception, e: log.debug('unable to contact %s: %s %s, %s', url, r.status_code, r.reason, e) return {'fail': True, 'errinfo': _('There was an error communicating with the Client Tracker server: %s', request) % e}
def sharedstate(self): chk_type = self.request.context.chk_type self._check_security(chk_type, True) request = self.request model_state = request.model_state model_state.validators = { "state": validators.OneOf(["local", "shared"], not_empty=True), "ID": ciocvalidators.IDValidator(not_empty=True), } model_state.method = None if not model_state.validate(): self._error_page(_("Invalid ID", request)) ID = model_state.form.data["ID"] title = _("Manage Publications", request) return self._create_response_namespace( title, title, dict(ID=ID, state=model_state.value("state"), chk_type=chk_type), no_index=True, )
def sharedstate(self): request = self.request user = request.user if not user.cic.SuperUserGlobal: self._security_failure() model_state = request.model_state model_state.validators = { "state": validators.OneOf(["local", "shared"], not_empty=True), "PB_ID": validators.IDValidator(not_empty=True), } model_state.method = None if not model_state.validate(): self._error_page(_("Invalid Publication ID", request)) PB_ID = model_state.form.data["PB_ID"] title = _("Manage Publications", request) return self._create_response_namespace( title, title, dict(PB_ID=PB_ID, state=model_state.value("state")), no_index=True, )
def delete(self): request = self.request user = request.user if not user.cic or user.cic.CanUpdatePubs != const.UPDATE_ALL: self._security_failure() model_state = request.model_state model_state.method = None model_state.validators = { "PB_ID": validators.IDValidator(not_empty=True) } if not model_state.validate(): self._error_page(_("Invalid Publication ID", request)) PB_ID = model_state.form.data["PB_ID"] request.override_renderer = "cioc.web:templates/confirmdelete.mak" title = _("Manage Publications", request) return self._create_response_namespace( title, title, dict( id_name="PB_ID", id_value=PB_ID, route="cic_publication", action="delete", ), no_index=True, )
def new_save(self): request = self.request user = request.user if not user.SuperUser: self._security_failure() model_state = request.model_state model_state.schema = NewSchema() if model_state.validate(): args = [user.Mod, user.User_ID, model_state.value('AdminAreaID'), model_state.value('RequestDetail')] with request.connmgr.get_connection('admin') as conn: result = conn.execute(''' DECLARE @ErrMsg nvarchar(500), @RC int EXEC @RC = sp_GBL_Admin_Notice_i ?,?,?,?, @ErrMsg OUTPUT SELECT @RC AS [Return], @ErrMsg AS ErrMsg''', *args).fetchone() if not result.Return: return self._go_to_page('~/admin/setup.asp', {'InfoMsg': _('Change request sent.')}) else: ErrMsg = _('There were validation errors.') with request.connmgr.get_connection('admin') as conn: areas = conn.execute('EXEC sp_GBL_Admin_Area_l ?, NULL', request.dboptions.MemberID).fetchall() title = _('New Admin Notice', request) return self._create_response_namespace(title, title, dict(ErrMsg=ErrMsg, areas=areas), no_index=True)
def delete(self): request = self.request model_state = request.model_state model_state.validators = { "CredID": validators.UUIDValidator(not_empty=True), } model_state.method = None if not model_state.validate(): self._error_page( _("Credential ID:", request) + model_state.renderer.errorlist("CredID") ) CredID = model_state.form.data["CredID"] title = _("Delete Heading", request) return self._create_response_namespace( title, title, dict( id_name="CredID", id_value=CredID, route="cic_generalheading", action="delete", extra_values=[("User_ID", request.context.user.User_ID)], ), no_index=True, )
def get_help_content(request, strHelpFileName): filename = "../pagehelp/" + strHelpFileName try: blame = get_git_blame(filename) last_mod_date = blame.get("committer-time") if last_mod_date: last_mod_date = datetime.fromtimestamp(int(blame["committer-time"])) else: last_mod_date = datetime.now() last_mod_date = format_date(last_mod_date, request) except SubProcException as e: log.error( "Error getting last change timestamp. Subproc returned %d: %s", e.args[1], e.args[0], ) last_mod_date = "%s" % _("Unknown") except OSError as e: log.exception("Error getting last change timestamp.") last_mod_date = "%s" % _("Unknown") return read_file(filename, "utf-8-sig").replace("$Date$", last_mod_date)
def delete_confirm(self): request = self.request user = request.user if not user.cic or not user.cic.SuperUser: self._security_failure() model_state = request.model_state model_state.validators = {"SubjID": validators.IDValidator(not_empty=True)} model_state.method = None if not model_state.validate(): self._error_page(_("Invalid Subject ID", request)) SubjID = model_state.form.data["SubjID"] with request.connmgr.get_connection("admin") as conn: sql = """ DECLARE @ErrMsg as nvarchar(500), @RC as int EXECUTE @RC = dbo.sp_THS_Subject_d ?, ?, @ErrMsg=@ErrMsg OUTPUT SELECT @RC as [Return], @ErrMsg AS ErrMsg """ cursor = conn.execute( sql, SubjID, None if request.user.cic.SuperUserGlobal else request.dboptions.MemberID, ) result = cursor.fetchone() cursor.close() if not result.Return: self._go_to_page( "~/admin/thesaurus.asp", { "InfoMsg": _( "The Subject Term has been successfully deleted.", request ) }, ) if result.Return == 3: # XXX check that this is the only #3 self._error_page(_("Unable to delete Subject:", request) + result.ErrMsg) self._go_to_route( "admin_thesaurus", action="edit", _query=[ ("ErrMsg", _("Unable to delete Subject: ") + result.ErrMsg), ("SubjID", SubjID), ], )
def add_lang(self): request = self.request user = request.user if not user.SuperUser: self._security_failure() domain, shown_cultures = viewbase.get_domain_and_show_cultures(request.params) if not domain: self._error_page(_('Invalid Domain', request)) if domain.id == const.DM_CIC: user_dm = user.cic if request.dboptions.UseCIC else user.vol else: user_dm = user.vol if not user_dm.SuperUser: self._security_failure() model_state = request.model_state model_state.validators = { 'ViewType': ciocvalidators.IDValidator(not_empty=True), 'Culture': ciocvalidators.ActiveCulture(not_empty=True) } model_state.method = None if not model_state.validate(): # XXX invalid ViewType or Culture if 'ViewType' in model_state.form.errors: self._error_page(_('Invalid ID', request)) else: self._error_page(_('Invalid Request', request)) ViewType = model_state.form.data.get('ViewType') Culture = model_state.form.data.get('Culture') LangID = syslanguage.culture_map()[Culture].LangID with request.connmgr.get_connection('admin') as conn: sql = ''' DECLARE @ErrMsg as nvarchar(500), @RC as int EXECUTE @RC = dbo.sp_%s_View_i_Lang ?, ?, ?, ?, ?, @ErrMsg=@ErrMsg OUTPUT SELECT @RC as [Return], @ErrMsg AS ErrMsg ''' % domain.str cursor = conn.execute(sql, ViewType, user.Mod, request.dboptions.MemberID, user.Agency, LangID) result = cursor.fetchone() cursor.close() query = [('ViewType', ViewType), ('DM', domain.id)] if result.Return: query.append(('ErrMsg', result.ErrMsg)) self._go_to_route('admin_view', action='edit', _query=query)
def delete_confirm(self): request = self.request user = request.user if not (user.SuperUser or user.WebDeveloper): self._security_failure() model_state = request.model_state model_state.validators = { "LayoutID": ciocvalidators.IDValidator(not_empty=True) } model_state.method = None if not model_state.validate(): self._error_page(_("Invalid ID", request)) LayoutID = model_state.form.data["LayoutID"] with request.connmgr.get_connection("admin") as conn: sql = """ DECLARE @ErrMsg as nvarchar(500), @RC as int EXECUTE @RC = dbo.sp_GBL_Template_Layout_d ?, ?, ?, @ErrMsg=@ErrMsg OUTPUT SELECT @RC as [Return], @ErrMsg AS ErrMsg """ cursor = conn.execute(sql, LayoutID, request.dboptions.MemberID, user.Agency) result = cursor.fetchone() cursor.close() if not result.Return: self._go_to_route( "admin_template_layout_index", _query=[( "InfoMsg", _("The Template Layout was successfully deleted.", request), )], ) if result.Return == 3: self._error_page( _("Unable to delete Template Layout: ", request) + result.ErrMsg) self._go_to_route( "admin_template_layout", action="edit", _query=[ ("ErrMsg", _("Unable to delete Template Layout: ") + result.ErrMsg), ("LayoutID", LayoutID), ], )
def edit(self): request = self.request user = request.user if not user.SuperUserGlobal: self._security_failure() model_state = request.model_state model_state.validators = {"MAP_ID": ciocvalidators.IDValidator()} model_state.method = None if not model_state.validate(): # XXX invalid MAP_ID self._error_page(_("Invalid ID", request)) MAP_ID = model_state.form.data.get("MAP_ID") is_add = not MAP_ID mapping = None mapping_descriptions = {} if not is_add: with request.connmgr.get_connection("admin") as conn: cursor = conn.execute("EXEC dbo.sp_GBL_MappingSystem_s ?", MAP_ID) mapping = cursor.fetchone() if mapping: cursor.nextset() for lng in cursor.fetchall(): mapping_descriptions[lng.Culture.replace("-", "_")] = lng cursor.close() if not mapping: # not found self._error_page(_("Mapping System Not Found", request)) domain, shown_cultures = viewbase.get_domain_and_show_cultures( request.params) model_state.form.data["mapping"] = mapping model_state.form.data["descriptions"] = mapping_descriptions title = _("Manage Mapping Systems", request) return self._create_response_namespace( title, title, dict( mapping=mapping, MAP_ID=MAP_ID, is_add=is_add, shown_cultures=shown_cultures, record_cultures=syslanguage.active_record_cultures(), ), no_index=True, )
def post(self): request = self.request user = request.user if not user.SuperUser: self._security_failure() model_state = request.model_state model_state.schema = DomainMapSchema() model_state.form.variable_decode = True if model_state.validate(): domains = ET.Element('Domains') for domain in model_state.value('domain') or []: if not any(domain.values()): continue el = ET.SubElement(domains, 'Domain') for key, val in domain.iteritems(): if isinstance(val, bool): ET.SubElement(el, key).text = unicode(int(val)) if val: ET.SubElement(el, key).text = unicode(val) args = [request.dboptions.MemberID, user.Mod, ET.tostring(domains)] with request.connmgr.get_connection('admin') as conn: sql = ''' DECLARE @ErrMsg as nvarchar(500), @RC as int EXECUTE @RC = dbo.sp_GBL_View_DomainMap_Analytics_u ?,?, ?, @ErrMsg=@ErrMsg OUTPUT SELECT @RC as [Return], @ErrMsg AS ErrMsg ''' cursor = conn.execute(sql, args) result = cursor.fetchone() cursor.close() if not result.Return: self.request.dboptions._invalidate() msg = _('The Google Analytics Configuration successfully updated.', request) self._go_to_route('admin_ganalytics', _query=[('InfoMsg', msg)]) else: ErrMsg = _('There were validation errors.') edit_info = self._get_edit_info()._asdict() edit_info['ErrMsg'] = ErrMsg model_state.form.data = variabledecode.variable_decode(request.POST) title = _('Manage Google Analytics Configuration', request) return self._create_response_namespace(title, title, edit_info, no_index=True)
def delete_confirm(self): request = self.request model_state = request.model_state model_state.validators = { "CredID": validators.UUIDValidator(not_empty=True), } model_state.method = None if not model_state.validate(): self._error_page( _("Credential ID:", request) + model_state.renderer.errorlist("CredID") ) CredID = model_state.form.data["CredID"] with request.connmgr.get_connection("admin") as conn: sql = """ DECLARE @ErrMsg as nvarchar(500), @RC as int EXECUTE @RC = dbo.sp_GBL_Users_APICreds_d ?, ?, ?, ?, @ErrMsg=@ErrMsg OUTPUT SELECT @RC as [Return], @ErrMsg AS ErrMsg """ result = conn.execute( sql, request.dboptions.MemberID, None if request.user.SuperUser else request.user.Agency, request.context.user.User_ID, CredID, ).fetchone() if not result.Return: self._go_to_route( "admin_userapicreds_index", _query=[ ("User_ID", request.context.user.User_ID), ( "InfoMsg", _("The API credential was successfully deleted.", request), ), ], ) self._go_to_route( "admin_userapicreds_index", _query=[ ("User_ID", request.context.user.User_ID), ( "ErrMsg", _("Unable to delete API credential: ", request) + result.ErrMsg, ), ], )
def post(self): request = self.request model_state = request.model_state model_state.schema = make_email_list_schema(request, self.get_list_validator()) if not model_state.validate(): return self.get_edit_info() with request.connmgr.get_connection("admin") as conn: record_data, access_url, out_of_view_records = self.get_rendered_records( conn ) if not record_data: ErrMsg = _("No records available for the selected view", request) return self.get_edit_info( record_data, access_url, out_of_view_records, ErrMsg ) user = request.user body = [ model_state.value("BodyPrefix"), record_data, model_state.value("BodySuffix"), ] body = "\n\n".join([x for x in body if x]) from_ = formataddr( (model_state.value("FromName"), request.context.agency_email) ) args = { "author": from_, "to": model_state.value("EmailAddress"), "subject": model_state.value("Subject"), "message": body, } if model_state.value("ReplyTo"): name = ( " ".join( [x for x in [request.user.FirstName, request.user.LastName] if x] ) or False ) args["author"] = formataddr((name, user.Email)) try: send_email(request, **args) except Exception: log.exception("Error sending email") return self._go_to_page( "~/" + self.extra_link_component + "presults.asp", {"ErrMsg": _("There was an error sending your Email", request)}, ) else: return self._go_to_page( "~/" + self.extra_link_component + "presults.asp", {"InfoMsg": _("Your Record List Email was Sent", request)}, )
def increment(self): request = self.request user = request.user if not user.cic: return { "success": False, "msg": _("Permission Denied", request), "updates": [], } model_state = request.model_state model_state.schema = IncrementSchema() if model_state.validate(): sql = """DECLARE @RC int, @ErrMsg nvarchar(500) EXEC @RC = sp_CIC_Vacancy_u_Increment ?, ?, ?, ?, ?, @ErrMsg=@ErrMsg OUTPUT SELECT @RC AS [Return], @ErrMsg AS ErrMsg """ with request.connmgr.get_connection("admin") as conn: cursor = conn.execute( sql, user.User_ID, user.Mod, request.viewdata.cic.ViewType, model_state.value("BT_VUT_ID"), model_state.value("Value"), ) new_values = cursor.fetchone() cursor.nextset() result = cursor.fetchone() cursor.close() updates = [{ "text": new_values.Text, "bt_vut_id": new_values.BT_VUT_ID }] if not result.Return: value = model_state.value("Value") if value > 0: msg = _("Success: added %d to vacancy.") % value else: msg = _("Success: removed %d from vacancy.") % abs(value) return {"success": True, "msg": msg, "updates": updates} ErrMsg = _("Unable to complete your change: %s") % result.ErrMsg else: updates = [] ErrMsg = _("Validation Error") return {"success": False, "msg": ErrMsg, "updates": updates}
def details_sidebar_parameters(request): return dumps( [ "[" + _("Show Listings", request) + "]", "[" + _("Hide Listings", request) + "]", "[" + _("Show Deleted", request) + "]", "[" + _("Hide Deleted", request) + "]", ] )
def edit(self): request = self.request user = request.user if not user.SuperUserGlobal: self._security_failure() model_state = request.model_state model_state.validators = {"SM_ID": ciocvalidators.IDValidator()} model_state.method = None if not model_state.validate(): # XXX invalid SM_ID self._error_page(_("Invalid ID", request)) SM_ID = model_state.form.data.get("SM_ID") is_add = not SM_ID socialmedia = None socialmedia_descriptions = {} if not is_add: with request.connmgr.get_connection("admin") as conn: cursor = conn.execute("EXEC dbo.sp_GBL_SocialMedia_s ?", SM_ID) socialmedia = cursor.fetchone() if socialmedia: cursor.nextset() for lng in cursor.fetchall(): socialmedia_descriptions[lng.Culture.replace( "-", "_")] = lng cursor.close() if not socialmedia: # not found self._error_page(_("Social Media Type Not Found", request)) domain, shown_cultures = viewbase.get_domain_and_show_cultures( request.params) model_state.form.data["socialmedia"] = socialmedia model_state.form.data["descriptions"] = socialmedia_descriptions title = _("Manage Social Media Types", request) return self._create_response_namespace( title, title, dict( socialmedia=socialmedia, SM_ID=SM_ID, is_add=is_add, shown_cultures=shown_cultures, record_cultures=syslanguage.active_record_cultures(), ), no_index=True, )
def delete_confirm(self): request = self.request user = request.user if not user.SuperUserGlobal: self._security_failure() model_state = request.model_state model_state.validators = { "SM_ID": ciocvalidators.IDValidator(not_empty=True) } model_state.method = None if not model_state.validate(): self._error_page(_("Invalid ID", request)) SM_ID = model_state.form.data["SM_ID"] with request.connmgr.get_connection("admin") as conn: sql = """ DECLARE @ErrMsg as nvarchar(500), @RC as int EXECUTE @RC = dbo.sp_GBL_SocialMedia_d ?, @ErrMsg=@ErrMsg OUTPUT SELECT @RC as [Return], @ErrMsg AS ErrMsg """ cursor = conn.execute(sql, SM_ID) result = cursor.fetchone() cursor.close() if not result.Return: self._go_to_route( "admin_socialmedia_index", _query=[( "InfoMsg", _("The Social Media Type was successfully deleted.", request), )], ) if result.Return == 3: self._error_page( _("Unable to delete Social Media Type: ", request) + result.ErrMsg) self._go_to_route( "admin_socialmedia", action="edit", _query=[ ("ErrMsg", _("Unable to delete Social Media Type: ") + result.ErrMsg), ("SM_ID", SM_ID), ], )
def _get_edit_info(self, chk_type, only_mine, only_shared, no_other): request = self.request chkitems = [] chkusage = {} with request.connmgr.get_connection('admin') as conn: sql = chk_type.SelectSQL(only_mine, only_shared, no_other) + (chk_type.UsageSQL or '') + (chk_type.NameSQL or '') + chk_type.OtherMemberItemsCountSQL cursor = conn.execute(sql) chkitems = cursor.fetchall() if chk_type.UsageSQL: cursor.nextset() chkusage = dict((unicode(x[0]), x) for x in cursor.fetchall()) if chk_type.NameSQL: cursor.nextset() row = cursor.fetchone() if row: chk_type.CheckListName = row[0] else: error_page(request, _('Not a valid checklist.', request), const.DM_GLOBAL, const.DM_GLOBAL) else: chk_type.CheckListName = _(chk_type.CheckListName, request) if chk_type.OtherMemberItemsCountSQL: cursor.nextset() chk_type.OtherMemberItemsCount = cursor.fetchone()[0] else: chk_type.OtherMemberItemsCount = 0 cursor.close() for chkitem in chkitems: chkitem.Descriptions = self._culture_dict_from_xml(chkitem.Descriptions, 'DESC') for field in chk_type.ExtraFields or []: fformat = field.get('format') if not fformat: continue elif not callable(fformat): format_fn = lambda x, y: format(x, fformat) else: format_fn = fformat for chkitem in chkitems: try: val = getattr(chkitem, field['field']) setattr(chkitem, field['field'], format_fn(val, request)) except AttributeError: pass return chkitems, chkusage
def increment(self): request = self.request user = request.user if not user.cic: return {'success': False, 'msg': _('Permission Denied', request), 'updates': []} model_state = request.model_state model_state.schema = IncrementSchema() if model_state.validate(): sql = '''DECLARE @RC int, @ErrMsg nvarchar(500) EXEC @RC = sp_CIC_Vacancy_u_Increment ?, ?, ?, ?, ?, @ErrMsg=@ErrMsg OUTPUT SELECT @RC AS [Return], @ErrMsg AS ErrMsg ''' with request.connmgr.get_connection('admin') as conn: cursor = conn.execute(sql, user.User_ID, user.Mod, request.viewdata.cic.ViewType, model_state.value('BT_VUT_ID'), model_state.value('Value')) new_values = cursor.fetchone() cursor.nextset() result = cursor.fetchone() cursor.close() updates = [ { 'text': new_values.Text, 'bt_vut_id': new_values.BT_VUT_ID } ] if not result.Return: value = model_state.value('Value') if value > 0: msg = _('Success: added %d to vacancy.') % value else: msg = _('Success: removed %d from vacancy.') % abs(value) return { 'success': True, 'msg': msg, 'updates': updates } ErrMsg = _('Unable to complete your change: %s') % result.ErrMsg else: updates = [] ErrMsg = _('Validation Error') return { 'success': False, 'msg': ErrMsg, 'updates': updates }
def post(self): request = self.request user = request.user if not user.cic.SuperUser or not request.dboptions.UseOfflineTools: self._security_failure() model_state = request.model_state model_state.schema = OfflineToolSchema() model_state.form.variable_decode = True if model_state.validate(): #success machines = model_state.value('machine') root = ET.Element('Data') for machine in machines: machine_id = unicode(machine['MachineID']) for sl in machine['SecurityLevels']: ET.SubElement(root, 'MachineSL', MachineID=machine_id, SL_ID=unicode(sl)) args = [user.Agency, ET.tostring(root)] with request.connmgr.get_connection('admin') as conn: sql = ''' DECLARE @ErrMsg as nvarchar(500), @RC as int EXECUTE @RC = dbo.sp_CIC_Offline_Machines_u ?, ?, @ErrMsg=@ErrMsg OUTPUT SELECT @RC as [Return], @ErrMsg AS ErrMsg ''' cursor = conn.execute(sql, *args) result = cursor.fetchone() cursor.close() if not result.Return: msg = _('The Offline Machines were successfully updated.', request) self._go_to_route('admin_offlinetools', _query=[('InfoMsg', msg)]) else: ErrMsg = _('There were validation errors.') edit_info = self._get_edit_info()._asdict() edit_info['ErrMsg'] = ErrMsg if not model_state.validate(): edit_info.data = variabledecode.variable_decode(model_state.form.data) title = _('Manage Offline Machines', request) return self._create_response_namespace(title, title, edit_info, no_index=True)
def index(self): request = self.request user = request.user if not user.cic.SuperUser: self._security_failure() with request.connmgr.get_connection('admin') as conn: cursor = conn.execute('EXEC sp_CIC_Vacancy_l_History ?', request.dboptions.MemberID) history = cursor.fetchall() cursor.close() headings = [ _('Record #', request), _('Record Name', request), _('Service Title', request), _('Service Title At Change', request), _('Vacancy Unit Type ID', request), _('Vacancy Unit Type GUID', request), _('Modified Date', request), _('Modified By', request), _('Vacancy Change', request), _('Total Vacancy', request) ] fields = [ 'NUM', 'OrgName', 'ServiceTitleNow', 'ServiceTitle', 'BT_VUT_ID', 'BT_VUT_GUID', 'MODIFIED_DATE', 'MODIFIED_BY', 'VacancyChange', 'VacancyFinal', ] getter = attrgetter(*fields) def row_getter(x): return tuple(u'' if y is None else unicode(y) for y in getter(x)) file = tempfile.TemporaryFile() with BufferedZipFile(file, 'w', zipfile.ZIP_DEFLATED) as zip: write_csv_to_zip(zip, itertools.chain([headings], itertools.imap(row_getter, history)), 'vacancy_history.csv') length = file.tell() file.seek(0) res = request.response res.content_type = 'application/zip' res.charset = None res.app_iter = FileIterator(file) res.content_length = length res.headers['Content-Disposition'] = 'attachment;filename=vacancy-history-%s.zip' % (datetime.today().isoformat('-').replace(':', '-').split('.')[0]) return res
def index(self): request = self.request domain = self.get_domain() with request.connmgr.get_connection('admin') as conn: pages = conn.execute('EXEC dbo.sp_GBL_Page_l ?, ?, ?', request.dboptions.MemberID, domain.id, request.user.Agency).fetchall() title = _('Pages (%s)', request) % _(domain.label, request) return self._create_response_namespace(title, title, dict(pages=pages, domain=domain), no_index=True)
def delete_confirm(self): request = self.request domain = self.get_domain() model_state = request.model_state model_state.validators = {"PageID": validators.IDValidator(not_empty=True)} model_state.method = None if not model_state.validate(): self._error_page(_("Invalid ID", request)) PageID = model_state.form.data["PageID"] with request.connmgr.get_connection("admin") as conn: sql = """ DECLARE @ErrMsg as nvarchar(500), @RC as int EXECUTE @RC = dbo.sp_GBL_Page_d ?, ?, ?, ?, @ErrMsg=@ErrMsg OUTPUT SELECT @RC as [Return], @ErrMsg AS ErrMsg """ cursor = conn.execute( sql, request.dboptions.MemberID, request.user.Agency, domain.id, PageID ) result = cursor.fetchone() cursor.close() query = [("DM", domain.id)] if not result.Return: self._go_to_route( "admin_pages_index", _query=[("InfoMsg", _("Page was successfully deleted.", request))] + query, ) if result.Return == 3: self._error_page(_("Unable to delete Page: ", request) + result.ErrMsg) self._go_to_route( "admin_pages", action="edit", _query=[ ("ErrMsg", _("Unable to delete Page: ") + result.ErrMsg), ("PageID", PageID), ] + query, )
def delete_confirm(self): request = self.request user = request.user if not user.SuperUser: self._security_failure() domain, shown_cultures = viewbase.get_domain_and_show_cultures(request.params) if not domain: self._error_page(_('Invalid Domain', request)) if domain.id == const.DM_CIC: user_dm = user.cic if request.dboptions.UseCIC else user.vol else: user_dm = user.vol if not user_dm.SuperUser: self._security_failure() model_state = request.model_state model_state.validators = { 'ViewType': ciocvalidators.IDValidator(not_empty=True) } model_state.method = None if not model_state.validate(): self._error_page(_('Invalid ID', request)) ViewType = model_state.form.data['ViewType'] with request.connmgr.get_connection('admin') as conn: sql = ''' DECLARE @ErrMsg as nvarchar(500), @RC as int EXECUTE @RC = dbo.sp_%s_View_d ?, ?, ?, @ErrMsg=@ErrMsg OUTPUT SELECT @RC as [Return], @ErrMsg AS ErrMsg ''' % domain.str cursor = conn.execute(sql, ViewType, request.dboptions.MemberID, user.Agency) result = cursor.fetchone() cursor.close() if not result.Return: self._go_to_route('admin_view_index', _query=[('InfoMsg', _('View Deleted', request)), ('DM', domain.id)]) if result.Return == 3: self._error_page(_('Unable to delete View: ', request) + result.ErrMsg) self._go_to_route('admin_view', action='edit', _query=[('ErrMsg', _('Unable to delete View: ') + result.ErrMsg), ('ViewType', ViewType), ('DM', domain.id)])
def edit(self): request = self.request user = request.user if not user.SuperUserGlobal: self._security_failure() model_state = request.model_state model_state.validators = { 'SM_ID': ciocvalidators.IDValidator() } model_state.method = None if not model_state.validate(): # XXX invalid SM_ID self._error_page(_('Invalid ID', request)) SM_ID = model_state.form.data.get('SM_ID') is_add = not SM_ID socialmedia = None socialmedia_descriptions = {} if not is_add: with request.connmgr.get_connection('admin') as conn: cursor = conn.execute('EXEC dbo.sp_GBL_SocialMedia_s ?', SM_ID) socialmedia = cursor.fetchone() if socialmedia: cursor.nextset() for lng in cursor.fetchall(): socialmedia_descriptions[lng.Culture.replace('-', '_')] = lng cursor.close() if not socialmedia: # not found self._error_page(_('Social Media Type Not Found', request)) domain, shown_cultures = viewbase.get_domain_and_show_cultures(request.params) model_state.form.data['socialmedia'] = socialmedia model_state.form.data['descriptions'] = socialmedia_descriptions title = _('Manage Social Media Types', request) return self._create_response_namespace( title, title, dict( socialmedia=socialmedia, SM_ID=SM_ID, is_add=is_add, shown_cultures=shown_cultures, record_cultures=syslanguage.active_record_cultures() ), no_index=True)
def close_save(self): request = self.request user = request.user if not user.SuperUserGlobal: self._security_failure() domains = self._get_domains() model_state = request.model_state model_state.schema = CloseSchema() if model_state.validate(): NoticeID = model_state.value('NoticeID') args = [NoticeID, ','.join(map(str, domains)), user.Mod, model_state.value('ActionTaken'), model_state.value('ActionNotes')] with request.connmgr.get_connection('admin') as conn: sql = ''' DECLARE @RC int, @ErrMsg nvarchar(500) EXEC @RC = dbo.sp_GBL_Admin_Notice_u ?, ?, ?, ?, ?, @ErrMsg OUTPUT SELECT @RC AS [Return], @ErrMsg AS ErrMsg ''' result = conn.execute(sql, args).fetchone() if not result.Return: self._go_to_route('reminder_index', _query=[]) else: if model_state.is_error('NoticeID'): self._error_page(_('Invalid ID', request)) NoticeID = model_state.value('NoticeID') ErrMsg = _('There were validation errors.') with request.connmgr.get_connection('admin') as conn: notice = conn.execute('EXEC sp_GBL_Admin_Notice_s ?', NoticeID).fetchone() if not notice: self._error_page(_('Not Found', request)) if notice.Domain not in domains: self._security_failure() data = request.model_state.form.data data['ActionNotes'] = notice.ActionNotes data['ActionTaken'] = notice.ActionTaken log.debug('Errors: %s', model_state.form.errors) title = _('Close Admin Notice', request) return self._create_response_namespace(title, title, dict(notice=notice, NoticeID=NoticeID, ErrMsg=ErrMsg), no_index=True)
def edit(self): request = self.request user = request.user if not user.cic or user.cic.CanUpdatePubs != const.UPDATE_ALL: self._security_failure() model_state = request.model_state model_state.validators = { "PB_ID": validators.IDValidator(not_empty=True), "GH_ID": validators.IDValidator(), } model_state.method = None if not model_state.validate(): # XXX invalid PB_ID if model_state.is_error("PB_ID"): self._error_page(_("Invalid Publication ID", request)) self._error_page(_("Invalid Heading ID", request)) PB_ID = model_state.value("PB_ID") GH_ID = model_state.value("GH_ID") is_add = not GH_ID if user.cic.LimitedView and PB_ID and PB_ID != user.cic.PB_ID: self._security_failure() edit_values = self._get_edit_info(is_add, PB_ID, GH_ID) data = model_state.form.data data["generalheading"] = edit_values.generalheading data["descriptions"] = edit_values.generalheading_descriptions data["RelatedHeadings"] = edit_values.relatedheadings data["MustMatch"] = edit_values.must_match data["MatchAny"] = edit_values.match_any if not is_add: val = edit_values.generalheading.Used data["generalheading.Used"] = RUsedOptions.get(val, val) if is_add: title = _("Add Heading", request) else: title = ( _("Edit Heading: %s", request) % edit_values.generalheading.CurrentDisplayName ) return self._create_response_namespace( title, title, edit_values._asdict(), no_index=True )
def hide(self): request = self.request user = request.user if not user.cic.SuperUser: self._security_failure() model_state = request.model_state model_state.schema = HideSchema() if model_state.validate(): with request.connmgr.get_connection("admin") as conn: result = conn.execute( """ DECLARE @RC int, @ErrMsg as nvarchar(500) EXEC @RC = dbo.sp_CIC_Publication_u_MemberInactive ?, ?, @ErrMsg OUTPUT SELECT @RC AS [Return], @ErrMsg AS ErrMsg """, request.dboptions.MemberID, ",".join(map(str, model_state.value("PubHide") or [])), ).fetchone() if not result.Return: return self._go_to_route( "cic_publication_index", _query=[( "InfoMsg", _("Publication visibility settings saved.", request), )], ) ErrMsg = (_("Unable to update Publication visibility settings: ") + result.ErrMsg) else: ErrMsg = _("There were validation errors.") pubs, shared_pubs, other_pubs = self._get_index_edit_info() title = _("Manage Publications", request) return self._create_response_namespace( title, title, dict(pubs=pubs, shared_pubs=shared_pubs, other_pubs=other_pubs, ErrMsg=ErrMsg), no_index=True, print_table=True, )
def _get_topicsearch_id(self, required=False): validator = ciocvalidators.IDValidator(not_empty=required) try: TopicSearchID = validator.to_python(self.request.params.get('TopicSearchID')) except validators.Invalid: self._error_page(_('Topic Search Not Found', self.request)) validator = ciocvalidators.IDValidator(not_empty=True) try: ViewType = validator.to_python(self.request.params.get('ViewType')) except validators.Invalid: self._error_page(_('View Not Found', self.request)) return ViewType, TopicSearchID