本文整理汇总了Python中trac.web.chrome.add_notice函数的典型用法代码示例。如果您正苦于以下问题:Python add_notice函数的具体用法?Python add_notice怎么用?Python add_notice使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了add_notice函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: render_admin_panel
def render_admin_panel(self, req, cat, page, path_info):
wikipages = urllib.unquote_plus(req.args.get('wikipages',''));
parts = wikipages.splitlines();
data = {
'find': urllib.unquote_plus(req.args.get('find','')),
'replace': urllib.unquote_plus(req.args.get('replace','')),
'wikipages': parts,
'redir': req.args.get('redirect','') == '1',
}
if req.method == 'POST':
# Check that required fields are filled in.
if not data['find']:
add_warning(req, 'The Find field was empty. Nothing was changed.')
if not data['wikipages'] or not data['wikipages'][0]:
add_warning(req, 'The Wiki pages field was empty. Nothing was changed.')
# Replace the text if the find and wikipages fields have been input.
if data['find'] and data['wikipages'] and data['wikipages'][0]:
add_notice(req, 'Replaced "%s" with "%s". See the timeline for modified pages.'
% (data['find'], data['replace']))
wiki_text_replace(self.env, data['find'], data['replace'], data['wikipages'],
req.authname, req.remote_addr, debug=self.log.debug)
# Reset for the next display
data['find'] = ''
data['replace'] = ''
data['wikipages'] = ''
return 'admin_wikireplace.html', data
示例2: _select_login_action
def _select_login_action(self, req, remote_user):
"""
Select login action based on user status.
- If user is expired, error msg is shown
- If user is active, user will be logged in
- If user is inactive, legal process is started
- Otherwise user has no way of logging in (is banned or disabled)
"""
user_store = get_userstore()
user = user_store.getUser(remote_user)
if not user:
# This may happen if authentication method is case-insensitive
add_notice(req, _("Incorrect username or password - please try again"))
return self._show_login(req)
# Check if expired
if user.expires and user.expires <= datetime.utcnow():
author = user_store.get_user_author(user)
if author:
add_warning(req, _('Account expired. Contact {0} for extension'.format(author.getDisplayName())))
else:
add_warning(req, _('Account expired. Contact service support for extension'))
return self._show_login(req)
# User is authentic but can not log in before knowing he is not banned or disabled or activation required
if user.status == user.STATUS_INACTIVE and self.env.config.getbool('multiproject', 'login_requires_agreed_terms'):
return self._request_legal_approval(req, remote_user)
if user.status in (user.STATUS_ACTIVE, user.STATUS_INACTIVE):
return self._login_success(req, remote_user)
add_warning(req, _("User status is '%s'. Can not log in." % user_store.USER_STATUS_LABELS[user.status]))
return self._show_login(req)
示例3: changePassword
def changePassword(self, req):
userstore = get_userstore()
user = userstore.getUser(req.authname)
oldpw = req.args.get('oldpassword')
newpw = req.args.get('newpassword')
if not oldpw or not userstore.userExists(req.authname, oldpw):
add_warning(req, _('Old password is invalid'))
return user
if not newpw or len(newpw) < 7:
add_warning(req, _('New password should be at least 7 characters long'))
return user
if newpw != req.args.get('confirmpw'):
add_warning(req, _('Passwords do not match'))
return user
if not userstore.updatePassword(user, newpw):
add_warning(req, _('Failed to change the password'))
return user
add_notice(req, _('Password changed'))
return user
示例4: _render_editor
def _render_editor(self, req, milestone):
# Suggest a default due time of 18:00 in the user's timezone
now = datetime.now(req.tz)
default_due = datetime(now.year, now.month, now.day, 18)
if now.hour > 18:
default_due += timedelta(days=1)
default_due = to_datetime(default_due, req.tz)
data = {
'milestone': milestone,
'datetime_hint': get_datetime_format_hint(req.lc_time),
'default_due': default_due,
'milestone_groups': [],
}
if milestone.exists:
req.perm(milestone.resource).require('MILESTONE_MODIFY')
milestones = [m for m in Milestone.select(self.env)
if m.name != milestone.name
and 'MILESTONE_VIEW' in req.perm(m.resource)]
data['milestone_groups'] = group_milestones(milestones,
'TICKET_ADMIN' in req.perm)
else:
req.perm(milestone.resource).require('MILESTONE_CREATE')
if milestone.name:
add_notice(req, _("Milestone %(name)s does not exist. You can"
" create it here.", name=milestone.name))
chrome = Chrome(self.env)
chrome.add_jquery_ui(req)
chrome.add_wiki_toolbars(req)
return 'milestone_edit.html', data, None
示例5: save
def save(self, req, id, fields=None, redirect=True):
req.perm.require('CLOUD_MODIFY')
self.log.debug('Saving data bag item %s/%s..' % (self.name,id))
item = self.chefapi.resource(self.crud_resource, id, self.name)
# prepare modify data
self.cloudapi.modify_rds_instance(id,
allocated_storage = req.args.get('allocated_storage'),
instance_class = req.args.get('instance_class'),
multi_az = req.args.get('multi_az'),
apply_immediately = req.args.get('cmd_apply_now'))
# prepare fields; remove command fields
if fields is None:
fields = self.fields.get_list('crud_edit', filter=r"cmd_.*")
for field in fields:
field.set(item, req)
item['multi_az'] = item['multi_az'] in ('1','true')
item.save()
self.log.info('Saved data bag item %s/%s' % (self.name,id))
if redirect:
# show the view
add_notice(req, _('%(label)s %(id)s has been saved.',
label=self.label, id=id))
req.redirect(req.href.cloud(self.name, id))
示例6: post_process_request
def post_process_request(self, req, template, data, content_type):
if template is None or not req.session.authenticated:
# Don't start the email verification procedure on anonymous users.
return template, data, content_type
email = req.session.get('email')
# Only send verification if the user entered an email address.
if self.verify_email and self.email_enabled is True and email and \
email != req.session.get('email_verification_sent_to') and \
'ACCTMGR_ADMIN' not in req.perm:
req.session['email_verification_token'] = self._gen_token()
req.session['email_verification_sent_to'] = email
try:
AccountManager(self.env)._notify(
'email_verification_requested',
req.authname,
req.session['email_verification_token']
)
except NotificationError, e:
chrome.add_warning(req, _(
"Error raised while sending a change notification."
) + _("You should report that issue to a Trac admin."))
self.log.error('Unable to send registration notification: %s',
exception_to_unicode(e, traceback=True))
else:
# TRANSLATOR: An email has been sent to <%(email)s>
# with a token to ... (the link label for following message)
link = tag.a(_("verify your new email address"),
href=req.href.verify_email())
# TRANSLATOR: ... verify your new email address
chrome.add_notice(req, tag_(
"An email has been sent to <%(email)s> with a token to "
"%(link)s.", email=tag(email), link=link))
示例7: _process_changes
def _process_changes(self, req, protos, scm_type):
scm_protos = dav_protos = set([])
allowed_scm_schemes = protos.allowed_protocols(scm_type)
allowed_dav_schemes = protos.allowed_protocols('dav')
if 'scm_proto' in req.args:
scm_protos = set(self._to_list(req.args['scm_proto']))
if 'dav_proto' in req.args:
dav_protos = set(self._to_list(req.args['dav_proto']))
if not self._validate(scm_protos, dav_protos):
msg = 'Changes not stored, make sure that at least one protocol for each ' \
'section is selected. If you want to disable any section, configure ' \
'the appropriate permissions in the "Groups" page'
add_warning(req, msg)
return
try:
# Change scm protocols
protos.disallow_protocols(allowed_scm_schemes - scm_protos, scm_type)
protos.allow_protocols(scm_protos - allowed_scm_schemes, scm_type)
# Change dav protocols
protos.disallow_protocols(allowed_dav_schemes - dav_protos, 'dav')
protos.allow_protocols(dav_protos - allowed_dav_schemes, 'dav')
except:
raise TracError("Server error. Try again later.")
add_notice(req, "Changes saved")
示例8: _process_add
def _process_add(self, req, ticket):
if req.method == "POST" and self._validate_add(req):
if req.args.get('reminder_type') == 'interval':
time = clear_time(to_datetime(None))
delta = _time_intervals[req.args.get('unit')](req.args.get('interval'))
time += delta
time = to_utimestamp(time)
else:
time = to_utimestamp(parse_date(req.args.get('date')))
origin = to_utimestamp(to_datetime(None))
self.env.db_transaction("""
INSERT INTO ticketreminder
(ticket, time, author, origin, reminded, description)
VALUES (%s, %s, %s, %s, 0, %s)
""", (ticket.id, time, get_reporter_id(req, 'author'),
origin, req.args.get('description')))
add_notice(req, "Reminder has been added.")
req.redirect(get_resource_url(self.env, ticket.resource, req.href) + "#reminders")
add_script(req, 'ticketreminder/js/ticketreminder.js')
data = {
'ticket': ticket,
'date_hint': get_date_format_hint(),
}
return ("ticket_reminder_add.html", data, None)
示例9: _process_delete
def _process_delete(self, req, ticket):
reminder_id = req.args.get('reminder')
redirect_url = get_resource_url(self.env, ticket.resource, req.href)
with self.env.db_transaction as db:
for reminder in db("""
SELECT id, time, author, origin, description
FROM ticketreminder WHERE id=%s
""", (reminder_id,)):
break
else:
add_warning(req, "Could not find reminder to delete.")
req.redirect(redirect_url)
if req.method == "POST":
db("""
DELETE FROM ticketreminder WHERE id=%s
""", (reminder_id,))
if req.method == "POST":
add_notice(req, "Reminder has been deleted.")
req.redirect(redirect_url + "#reminders")
kwargs = {'delete_button': False}
data = {
'ticket': ticket,
'formatted_reminder':
self._format_reminder(req, ticket, *reminder, **kwargs),
}
return "ticket_reminder_delete.html", data, None
示例10: _do_account
def _do_account(self, req):
if not req.authname or req.authname == 'anonymous':
req.redirect(req.href.wiki())
action = req.args.get('action')
delete_enabled = AccountManager(self.env).supports('delete_user')
data = {'delete_enabled': delete_enabled}
force_change_password = req.session.get('force_change_passwd', False)
if req.method == 'POST':
if action == 'save':
data.update(self._do_change_password(req))
if force_change_password:
del(req.session['force_change_passwd'])
req.session.save()
chrome.add_notice(req, Markup(tag(
"Thank you for taking the time to update your password."
)))
force_change_password = False
elif action == 'delete' and delete_enabled:
data.update(self._do_delete(req))
else:
data.update({'error': 'Invalid action'})
if force_change_password:
chrome.add_warning(req, Markup(tag(
"You are required to change password because of a recent "
"password change request. ",
tag.b("Please change your password now."))))
return data
示例11: edit_category
def edit_category(self, req):
req.perm.require('TRAC_ADMIN')
category_id = req.args.get('edited_category_id', '')
if category_id.isdigit():
category = self.categorystore.get_category_by_id(category_id)
if not category_id or not category:
add_warning(req, _('Invalid category id provided.'))
return
category_name = req.args.get('edited_category_name', '')
category_description = req.args.get('edited_category_description', '')
if len(category_description.split("#")) == 2:
category_name = category_name + "#" + category_description.split("#")[1]
if not category_name or not category_description:
add_warning(req, _('Category name and description cannot be empty. "%s" "%s"'%(category_name, category_description)))
return
if category.name == category_name and category.description == category_description:
add_warning(req, _('Category name and description are already as requested.'))
return
try:
self.categorystore.edit_category(category.category_id, category_name, category_description)
add_notice(req, _('Category has been edited.'))
except Exception as e:
add_warning(req, _('Category was not edited. ') + _(str(e)))
示例12: render_module
def render_module(self, req, cat, page, path_info):
global db_conn
testaction = test_action.TestAction(self.env, db_conn, req=req)
templates = 'iTest_NewTest.html'
if gl.gl_b_submittest in req.args \
or gl.gl_b_saveandstarttest in req.args:
testtype = req.args.get(gl.gl_test_type_mode)
if testtype == gl.gl_HSIT:
testtype = gl.gl_psit
name = req.args.get(gl.gl_name, '')
name = utils.name_filter_dirty_symbol(self.env, str(name))
if testtype == gl.gl_rdit:
rditPlatform = req.args.get('rditPlatform')
pre_name = name
if rditPlatform == 'T2W1' \
or rditPlatform == 'T2(9810)W1':#两个单子
#1-- 'W1'
name = pre_name + '_' + 'W1'
name += '_' + utils._get_current_time_str()
ret = testaction.B_Save2start(req, testtype=testtype, name=name, rditPlatform=rditPlatform)
#2-- 'W1'
if rditPlatform == 'T2W1':
name = pre_name + '_' + 'T2'
name += '_' + utils._get_current_time_str()
ret = testaction.B_Save2start(req, testtype=testtype, name=name, rditPlatform=rditPlatform)
elif rditPlatform == 'T2(9810)W1':
name = pre_name + '_' + 'T2_9810'
name += '_' + utils._get_current_time_str()
ret = testaction.B_Save2start(req, testtype=testtype, name=name, rditPlatform=rditPlatform)
else:#单个
if rditPlatform == gl.gl_T2_9810:
name += '_T2_9810'
elif rditPlatform == gl.gl_T2_8810:
name += '_T2_8810'
elif rditPlatform == gl.gl_T2_8501c:
name += '_T2_8501c'
else:
name += '_' + rditPlatform
name += '_' + utils._get_current_time_str()
ret = testaction.B_Save2start(req, testtype=testtype, name=name, rditPlatform=rditPlatform)
else:
time_string = utils.curtime_string()
time_string = re.sub('[\D]', '', time_string)
self.log.debug('NewTest: time_string,%s', time_string)
name += '_' + time_string
ret = testaction.B_Save2start(req, testtype=testtype, name=name)
if ret == True:
templates = 'iTest_Server_Manager.html'
data = itest_mmi_data.iTest_Server_Manager(self.env, req)
else:
add_notice(req, "Error, Plz Check.")
data = test_action.iTest_NewTest(self.env,req)
elif gl.gl_b_uploadcaselist_txt in req.args:
txt_file = test_action.iTest_UploadCaselist(self.env, req)
data = test_action.iTest_NewTest(self.env, req, txt_file_name=txt_file)
else:
data = test_action.iTest_NewTest(self.env,req)
return templates, data
示例13: save
def save(self, req, id):
req.perm.require('CLOUD_MODIFY')
self.log.debug('Saving data bag item %s/%s..' % (self.name,id))
item = self.chefapi.resource(self.crud_resource, id, self.name)
# check to attach and/or detach volume to/from instance(s)
new_instance_id = req.args.get('instance_id','')
if 'instance_id' not in item or item['instance_id'] != new_instance_id:
# check if attaching or detaching
if 'instance_id' in item and item['instance_id']: # detach
req.args['status'] = self.cloudapi.detach_ebs_volume(id,
item['instance_id'], item['device'])
if new_instance_id: # attach
req.args['status'] = self.cloudapi.attach_ebs_volume(id,
new_instance_id, req.args.get('device',''))
else:
req.args['device'] = ''
# prepare fields; remove command fields
fields = self.fields.get_list('crud_edit', filter=r"cmd_.*")
for field in fields:
field.set(item, req)
item.save()
self.log.info('Saved data bag item %s/%s' % (self.name,id))
# show the view
add_notice(req, _('%(label)s %(id)s has been saved.',
label=self.label, id=id))
req.redirect(req.href.cloud(self.name, id))
示例14: render_admin_panel
def render_admin_panel(self, req, cat, page, svnhooks_name):
req.perm.require('REPOSITORY_ADMIN')
data = {}
obj = SVNHooksModel(self.env)
if req.method == 'POST':
if req.args.get('add') :
hook = req.args.get('hook').strip()
path = req.args.get('path').strip()
validate_path=obj.validate(path,hook)
if validate_path > 0:
add_warning(req,_('Already exists'))
else:
obj.insert( path, hook)
add_notice(req, _('Added SVN hook "%s" for path :%s successfully' %(self._hooks_info()[hook], path)))
elif req.args.get('remove'):
sel = req.args.get('sel')
if not sel:
raise TracError(_('No hook selected'))
if not isinstance(sel, list):
sel = [sel]
for id in sel:
path, hook = obj.get_by_id(id)
obj.delete(id)
add_notice(req, _('Hooks "%s" for path :%s deleted successfully' %(self._hooks_info()[hook], path)))
req.redirect(req.href.admin(cat, page))
add_stylesheet(req, 'svnhooks/css/svnhooks.css')
add_javascript(req, 'svnhooks/js/svnhooks.js')
data['svnhooks'] = obj.getall()
data['svnhook_names'] = self._hooks_info(type='name')
data['svnhook_descriptions'] = self._hooks_info(type='description')
return 'admin-svnhooks.html', data
示例15: _do_account
def _do_account(self, req):
assert(req.authname and req.authname != 'anonymous')
action = req.args.get('action')
delete_enabled = self.acctmgr.supports('delete_user') and \
self.acctmgr.allow_delete_account
data = {'delete_enabled': delete_enabled,
'delete_msg_confirm': _(
"Are you sure you want to delete your account?"),
}
force_change_password = req.session.get('force_change_passwd', False)
if req.method == 'POST':
if action == 'save':
data.update(self._do_change_password(req))
if force_change_password:
del(req.session['force_change_passwd'])
req.session.save()
chrome.add_notice(req, Markup(tag.span(tag_(
"Thank you for taking the time to update your password."
))))
force_change_password = False
elif action == 'delete' and delete_enabled:
data.update(self._do_delete(req))
else:
data.update({'error': 'Invalid action'})
if force_change_password:
chrome.add_warning(req, Markup(tag.span(_(
"You are required to change password because of a recent "
"password change request. "),
tag.b(_("Please change your password now.")))))
return data