本文整理汇总了Python中trac.util.translation.tag_函数的典型用法代码示例。如果您正苦于以下问题:Python tag_函数的具体用法?Python tag_怎么用?Python tag_使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了tag_函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _provider_failure
def _provider_failure(self, exc, req, ep, current_filters, all_filters):
"""Raise a TracError exception explaining the failure of a provider.
At the same time, the message will contain a link to the timeline
without the filters corresponding to the guilty event provider `ep`.
"""
self.log.error('Timeline event provider failed: %s',
exception_to_unicode(exc, traceback=True))
ep_kinds = dict((f[0], f[1])
for f in ep.get_timeline_filters(req) or [])
ep_filters = set(ep_kinds.keys())
current_filters = set(current_filters)
other_filters = set(current_filters) - ep_filters
if not other_filters:
other_filters = set(all_filters) - ep_filters
args = [(a, req.args.get(a)) for a in ('from', 'format', 'max',
'daysback')]
href = req.href.timeline(args + [(f, 'on') for f in other_filters])
# TRANSLATOR: ...want to see the 'other kinds of events' from... (link)
other_events = tag.a(_('other kinds of events'), href=href)
raise TracError(tag(
tag.p(tag_("Event provider %(name)s failed for filters "
"%(kinds)s: ",
name=tag.tt(ep.__class__.__name__),
kinds=', '.join('"%s"' % ep_kinds[f] for f in
current_filters & ep_filters)),
tag.b(exception_to_unicode(exc)), class_='message'),
tag.p(tag_("You may want to see the %(other_events)s from the "
"Timeline or notify your Trac administrator about the "
"error (detailed information was written to the log).",
other_events=other_events))))
开发者ID:dafrito,项目名称:trac-mirror,代码行数:32,代码来源:web_ui.py
示例2: _render_property
def _render_property(self, name, mode, context, props):
repos, revs = props[name]
def link(rev):
chgset = repos.get_changeset(rev)
return tag.a(rev, class_="changeset",
title=shorten_line(chgset.message),
href=context.href.changeset(rev, repos.reponame))
if name == 'Parents' and len(revs) == 2: # merge
new = context.resource.id
parent_links = [
(link(rev), ' (',
tag.a('diff', title=_("Diff against this parent "
"(show the changes merged from the other parents)"),
href=context.href.changeset(new, repos.reponame,
old=rev)), ')')
for rev in revs]
return tag([(parent, ', ') for parent in parent_links[:-1]],
parent_links[-1], tag.br(),
tag.span(tag_("Note: this is a %(merge)s changeset, "
"the changes displayed below correspond "
"to the merge itself.",
merge=tag.strong('merge')),
class_='hint'), tag.br(),
# TODO: only keep chunks present in both parents
# (conflicts) or in none (extra changes)
# tag.span('No changes means the merge was clean.',
# class_='hint'), tag.br(),
tag.span(tag_("Use the %(diff)s links above to see all "
"the changes relative to each parent.",
diff=tag.tt('(diff)')),
class_='hint'))
return tag([tag(link(rev), ', ') for rev in revs[:-1]],
link(revs[-1]))
开发者ID:dokipen,项目名称:trac-hg-plugin,代码行数:33,代码来源:backend.py
示例3: _do_repositories
def _do_repositories(self, req, category, page):
# Check that the setttings have been set.
parentpath = self.config.get('svnadmin', 'parent_path')
client = self.config.get('svnadmin', 'svn_client_location')
admin = self.config.get('svnadmin', 'svnadmin_location')
if not parentpath or not client or not admin:
add_warning(req, _('You must provide settings before continuing.'))
req.redirect(req.href.admin(category, 'config'))
data = {}
svn_provider = self.env[SvnRepositoryProvider]
db_provider = self.env[DbRepositoryProvider]
if req.method == 'POST':
# Add a repository
if svn_provider and req.args.get('add_repos'):
name = req.args.get('name')
dir = os.path.join(parentpath, name)
if name is None or name == "" or not dir:
add_warning(req, _('Missing arguments to add a repository.'))
elif self._check_dir(req, dir):
try:
svn_provider.add_repository(name)
db_provider.add_repository(name, dir, 'svn')
add_notice(req, _('The repository "%(name)s" has been '
'added.', name=name))
resync = tag.tt('trac-admin $ENV repository resync '
'"%s"' % name)
msg = tag_('You should now run %(resync)s to '
'synchronize Trac with the repository.',
resync=resync)
add_notice(req, msg)
cset_added = tag.tt('trac-admin $ENV changeset '
'added "%s" $REV' % name)
msg = tag_('You should also set up a post-commit hook '
'on the repository to call %(cset_added)s '
'for each committed changeset.',
cset_added=cset_added)
add_notice(req, msg)
req.redirect(req.href.admin(category, page))
except TracError, why:
add_warning(req, str(why))
# Remove repositories
elif svn_provider and req.args.get('remove'):
sel = req.args.getlist('sel')
if sel:
for name in sel:
svn_provider.remove_repository(name)
db_provider.remove_repository(name)
add_notice(req, _('The selected repositories have '
'been removed.'))
req.redirect(req.href.admin(category, page))
add_warning(req, _('No repositories were selected.'))
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:55,代码来源:admin.py
示例4: send
def send(self, from_addr, recipients, message):
# Ensure the message complies with RFC2822: use CRLF line endings
message = fix_eol(message, CRLF)
self.log.info("Sending notification through SMTP at %s:%d to %s",
self.smtp_server, self.smtp_port, recipients)
try:
server = smtplib.SMTP(self.smtp_server, self.smtp_port)
except smtplib.socket.error as e:
raise ConfigurationError(
tag_("SMTP server connection error (%(error)s). Please "
"modify %(option1)s or %(option2)s in your "
"configuration.",
error=to_unicode(e),
option1=tag.code("[notification] smtp_server"),
option2=tag.code("[notification] smtp_port")))
# server.set_debuglevel(True)
if self.use_tls:
server.ehlo()
if 'starttls' not in server.esmtp_features:
raise TracError(_("TLS enabled but server does not support"
" TLS"))
server.starttls()
server.ehlo()
if self.smtp_user:
server.login(self.smtp_user.encode('utf-8'),
self.smtp_password.encode('utf-8'))
start = time.time()
resp = sendmail(server, from_addr, recipients, message)
t = time.time() - start
if t > 5:
self.log.warning("Slow mail submission (%.2f s), "
"check your mail setup", t)
if self.use_tls:
# avoid false failure detection when the server closes
# the SMTP connection with TLS enabled
import socket
try:
server.quit()
except socket.sslerror:
pass
else:
server.quit()
msg = email.message_from_string(message)
ticket_id = int(msg['x-trac-ticket-id'])
msgid = msg['message-id']
aws_re = r'^email-smtp\.([a-z0-9-]+)\.amazonaws\.com$'
m = re.match(aws_re, self.smtp_server)
if m:
parts = resp.split()
if len(parts) == 2 and parts[0] == 'Ok':
region = m.group(1)
msgid = '<%[email protected]%s.amazonses.com>' % (parts[1], region)
with self.env.db_transaction as db:
cursor = db.cursor()
cursor.execute("""
INSERT OR IGNORE INTO messageid (ticket,messageid)
VALUES (%s, %s)
""", (ticket_id, msgid))
开发者ID:weisslj,项目名称:trac-messageid-plugin,代码行数:60,代码来源:api.py
示例5: _do_save
def _do_save(self, req, page):
if not page.exists:
req.perm(page.resource).require('WIKI_CREATE')
else:
req.perm(page.resource).require('WIKI_MODIFY')
if 'WIKI_ADMIN' in req.perm(page.resource):
# Modify the read-only flag if it has been changed and the user is
# WIKI_ADMIN
page.readonly = int('readonly' in req.args)
try:
page.save(get_reporter_id(req, 'author'), req.args.get('comment'),
req.remote_addr)
href = req.href.wiki(page.name, action='diff',
version=page.version)
add_notice(req, tag_("Your changes have been saved in version "
"%(version)s (%(diff)s).",
version=page.version,
diff=tag.a(_("diff"), href=href)))
req.redirect(get_resource_url(self.env, page.resource, req.href,
version=None))
except TracError:
add_warning(req, _("Page not modified, showing latest version."))
return self._render_view(req, page)
开发者ID:pkdevbox,项目名称:trac,代码行数:25,代码来源:web_ui.py
示例6: __get__
def __get__(self, instance, owner):
if instance is None:
return self
order = ListOption.__get__(self, instance, owner)
components = []
implementing_classes = []
for impl in self.xtnpt.extensions(instance):
implementing_classes.append(impl.__class__.__name__)
if self.include_missing or impl.__class__.__name__ in order:
components.append(impl)
not_found = sorted(set(order) - set(implementing_classes))
if not_found:
raise ConfigurationError(
tag_("Cannot find implementation(s) of the %(interface)s "
"interface named %(implementation)s. Please check "
"that the Component is enabled or update the option "
"%(option)s in trac.ini.",
interface=tag.tt(self.xtnpt.interface.__name__),
implementation=tag(
(', ' if idx != 0 else None, tag.tt(impl))
for idx, impl in enumerate(not_found)),
option=tag.tt("[%s] %s" % (self.section, self.name))))
def compare(x, y):
x, y = x.__class__.__name__, y.__class__.__name__
if x not in order:
return int(y in order)
if y not in order:
return -int(x in order)
return cmp(order.index(x), order.index(y))
components.sort(compare)
return components
开发者ID:exocad,项目名称:exotrac,代码行数:32,代码来源:config.py
示例7: _do_delete
def _do_delete(self, req, milestone):
req.perm(milestone.resource).require('MILESTONE_DELETE')
retarget_to = req.args.get('target') or None
# Don't translate ticket comment (comment:40:ticket:5658)
retargeted_tickets = \
milestone.move_tickets(retarget_to, req.authname,
"Ticket retargeted after milestone deleted")
milestone.delete(author=req.authname)
add_notice(req, _('The milestone "%(name)s" has been deleted.',
name=milestone.name))
if retargeted_tickets:
add_notice(req, _('The tickets associated with milestone '
'"%(name)s" have been retargeted to milestone '
'"%(retarget)s".', name=milestone.name,
retarget=retarget_to))
new_values = {'milestone': retarget_to}
comment = _("Tickets retargeted after milestone deleted")
tn = BatchTicketNotifyEmail(self.env)
try:
tn.notify(retargeted_tickets, new_values, comment, None,
req.authname)
except Exception, e:
self.log.error("Failure sending notification on ticket batch "
"change: %s", exception_to_unicode(e))
add_warning(req, tag_("The changes have been saved, but an "
"error occurred while sending "
"notifications: %(message)s",
message=to_unicode(e)))
开发者ID:exocad,项目名称:exotrac,代码行数:29,代码来源:roadmap.py
示例8: notify
def notify(self, resid, subject, author=None):
self.subject = subject
config = self.config['notification']
if not config.getbool('smtp_enabled'):
return
from_email, from_name = '', ''
if author and config.getbool('smtp_from_author'):
from_email = self.get_smtp_address(author)
if from_email:
from_name = self.name_map.get(author, '')
if not from_name:
mo = self.longaddr_re.search(author)
if mo:
from_name = mo.group(1)
if not from_email:
from_email = config.get('smtp_from')
from_name = config.get('smtp_from_name') or self.env.project_name
self.replyto_email = config.get('smtp_replyto')
self.from_email = from_email or self.replyto_email
self.from_name = from_name
if not self.from_email and not self.replyto_email:
message = tag(
tag.p(_('Unable to send email due to identity crisis.')),
# convert explicitly to `Fragment` to avoid breaking message
# when passing `LazyProxy` object to `Fragment`
tag.p(to_fragment(tag_(
"Neither %(from_)s nor %(reply_to)s are specified in the "
"configuration.",
from_=tag.strong("[notification] smtp_from"),
reply_to=tag.strong("[notification] smtp_replyto")))))
raise TracError(message, _("SMTP Notification Error"))
Notify.notify(self, resid)
开发者ID:spsoft-RockWang,项目名称:project-_trac,代码行数:33,代码来源:compat.py
示例9: _render_source
def _render_source(self, context, stream, annotations, marks=None):
from trac.web.chrome import add_warning
annotators, labels, titles = {}, {}, {}
for annotator in self.annotators:
atype, alabel, atitle = annotator.get_annotation_type()
if atype in annotations:
labels[atype] = alabel
titles[atype] = atitle
annotators[atype] = annotator
annotations = [a for a in annotations if a in annotators]
if isinstance(stream, list):
stream = HTMLParser(StringIO(u'\n'.join(stream)))
elif isinstance(stream, unicode):
text = stream
def linesplitter():
for line in text.splitlines(True):
yield TEXT, line, (None, -1, -1)
stream = linesplitter()
annotator_datas = []
for a in annotations:
annotator = annotators[a]
try:
data = (annotator, annotator.get_annotation_data(context))
except TracError, e:
self.log.warning("Can't use annotator '%s': %s", a, e.message)
add_warning(context.req, tag.strong(
tag_("Can't use %(annotator)s annotator: %(error)s",
annotator=tag.em(a), error=tag.pre(e.message))))
data = (None, None)
annotator_datas.append(data)
开发者ID:Stackato-Apps,项目名称:bloodhound,代码行数:32,代码来源:api.py
示例10: _do_login
def _do_login(self, req):
"""Log the remote user in.
This function expects to be called when the remote user name
is available. The user name is inserted into the `auth_cookie`
table and a cookie identifying the user on subsequent requests
is sent back to the client.
If the Authenticator was created with `ignore_case` set to
true, then the authentication name passed from the web server
in req.remote_user will be converted to lower case before
being used. This is to avoid problems on installations
authenticating against Windows which is not case sensitive
regarding user names and domain names
"""
if not req.remote_user:
# TRANSLATOR: ... refer to the 'installation documentation'. (link)
inst_doc = tag.a(_('installation documentation'),
title=_("Configuring Authentication"),
href=req.href.wiki('TracInstall')
+ "#ConfiguringAuthentication")
raise TracError(tag_("Authentication information not available. "
"Please refer to the %(inst_doc)s.",
inst_doc=inst_doc))
remote_user = req.remote_user
if self.ignore_case:
remote_user = remote_user.lower()
if req.authname not in ('anonymous', remote_user):
raise TracError(_('Already logged in as %(user)s.',
user=req.authname))
with self.env.db_transaction as db:
# Delete cookies older than 10 days
db("DELETE FROM auth_cookie WHERE time < %s",
(int(time.time()) - 86400 * 10,))
# Insert a new cookie if we haven't already got one
cookie = None
trac_auth = req.incookie.get('trac_auth')
if trac_auth is not None:
name = self._cookie_to_name(req, trac_auth)
cookie = trac_auth.value if name == remote_user else None
if cookie is None:
cookie = hex_entropy()
db("""
INSERT INTO auth_cookie (cookie, name, ipnr, time)
VALUES (%s, %s, %s, %s)
""", (cookie, remote_user, req.remote_addr,
int(time.time())))
req.authname = remote_user
req.outcookie['trac_auth'] = cookie
req.outcookie['trac_auth']['path'] = self.auth_cookie_path \
or req.base_path or '/'
if self.env.secure_cookies:
req.outcookie['trac_auth']['secure'] = True
if sys.version_info >= (2, 6):
req.outcookie['trac_auth']['httponly'] = True
if self.auth_cookie_lifetime > 0:
req.outcookie['trac_auth']['expires'] = self.auth_cookie_lifetime
开发者ID:exocad,项目名称:exotrac,代码行数:59,代码来源:auth.py
示例11: render_timeline_event
def render_timeline_event(self, context, field, event):
url, title, desc = event[3]
if field == 'url':
return url
elif field == 'title':
return tag_('%(page)s created', page=tag.em(title))
elif field == 'description':
return tag(desc)
开发者ID:nnabeyang,项目名称:setsuden4trac,代码行数:8,代码来源:core.py
示例12: _render_source
def _render_source(self, context, stream, annotations):
from trac.web.chrome import add_warning
annotators, labels, titles = {}, {}, {}
for annotator in self.annotators:
atype, alabel, atitle = annotator.get_annotation_type()
if atype in annotations:
labels[atype] = alabel
titles[atype] = atitle
annotators[atype] = annotator
annotations = [a for a in annotations if a in annotators]
if isinstance(stream, list):
stream = HTMLParser(StringIO(u"\n".join(stream)))
elif isinstance(stream, unicode):
text = stream
def linesplitter():
for line in text.splitlines(True):
yield TEXT, line, (None, -1, -1)
stream = linesplitter()
annotator_datas = []
for a in annotations:
annotator = annotators[a]
try:
data = (annotator, annotator.get_annotation_data(context))
except TracError as e:
self.log.warning("Can't use annotator '%s': %s", a, e)
add_warning(
context.req,
tag.strong(
tag_("Can't use %(annotator)s annotator: %(error)s", annotator=tag.em(a), error=tag.pre(e))
),
)
data = None, None
annotator_datas.append(data)
def _head_row():
return tag.tr(
[tag.th(labels[a], class_=a, title=titles[a]) for a in annotations]
+ [tag.th(u"\xa0", class_="content")]
)
def _body_rows():
for idx, line in enumerate(_group_lines(stream)):
row = tag.tr()
for annotator, data in annotator_datas:
if annotator:
annotator.annotate_row(context, row, idx + 1, line, data)
else:
row.append(tag.td())
row.append(tag.td(line))
yield row
return tag.table(class_="code")(tag.thead(_head_row()), tag.tbody(_body_rows()))
开发者ID:pkdevbox,项目名称:trac,代码行数:57,代码来源:api.py
示例13: render_timeline_event
def render_timeline_event(self, context, field, event):
wiki_page, comment = event[3]
if field == 'url':
return context.href.wiki(wiki_page.id, version=wiki_page.version)
elif field == 'title':
name = tag.em(get_resource_name(self.env, wiki_page))
if wiki_page.version > 1:
return tag_('%(page)s edited', page=name)
else:
return tag_('%(page)s created', page=name)
elif field == 'description':
markup = format_to(self.env, None,
context.child(resource=wiki_page), comment)
if wiki_page.version > 1:
diff_href = context.href.wiki(
wiki_page.id, version=wiki_page.version, action='diff')
markup = tag(markup,
' (', tag.a(_('diff'), href=diff_href), ')')
return markup
开发者ID:Stackato-Apps,项目名称:bloodhound,代码行数:19,代码来源:web_ui.py
示例14: render_timeline_event
def render_timeline_event(self, context, field, event):
milestone, description = event[3]
if field == 'url':
return context.href.milestone(milestone.id)
elif field == 'title':
return tag_('Milestone %(name)s completed',
name=tag.em(milestone.id))
elif field == 'description':
return format_to(self.env, None, context.child(resource=milestone),
description)
开发者ID:nextview,项目名称:medicticket,代码行数:10,代码来源:roadmap.py
示例15: validate
def validate(self, relation):
rls = RelationsSystem(self.env)
existing_relations = rls._select_relations(resource_type=relation.type,
destination=relation.destination)
if existing_relations:
raise ValidationError(
tag_("Another resource is already related to %(destination)s "
"with %(relation)s relation.",
destination=tag.em(relation.destination),
relation=tag.b(self.render_relation_type(relation.type)))
)
开发者ID:thimalk,项目名称:bloodhound-789,代码行数:11,代码来源:validation.py
示例16: _dispatch_request
def _dispatch_request(req, env, env_error):
resp = []
# fixup env.abs_href if `[trac] base_url` was not specified
if env and not env.abs_href.base:
env._abs_href = req.abs_href
try:
if not env and env_error:
raise HTTPInternalError(env_error)
try:
dispatcher = RequestDispatcher(env)
dispatcher.dispatch(req)
except RequestDone:
pass
resp = req._response or []
except HTTPException, e:
# This part is a bit more complex than it should be.
# See trac/web/api.py for the definition of HTTPException subclasses.
if env:
env.log.warn(exception_to_unicode(e))
try:
# We try to get localized error messages here,
# but we should ignore secondary errors
title = _('Error')
if e.reason:
if title.lower() in e.reason.lower():
title = e.reason
else:
title = _('Error: %(message)s', message=e.reason)
except:
title = 'Error'
# The message is based on the e.detail, which can be an Exception
# object, but not a TracError one: when creating HTTPException,
# a TracError.message is directly assigned to e.detail
if isinstance(e.detail, Exception): # not a TracError
message = exception_to_unicode(e.detail)
elif isinstance(e.detail, Fragment): # markup coming from a TracError
message = e.detail
else:
message = to_unicode(e.detail)
data = {'title': title, 'type': 'TracError', 'message': message,
'frames': [], 'traceback': None}
if e.code == 403 and req.authname == 'anonymous':
# TRANSLATOR: ... not logged in, you may want to 'do so' now (link)
do_so = tag.a(_("do so"), href=req.href.login())
req.chrome['notices'].append(
tag_("You are currently not logged in. You may want to "
"%(do_so)s now.", do_so=do_so))
try:
req.send_error(sys.exc_info(), status=e.code, env=env, data=data)
except RequestDone:
pass
开发者ID:zjj,项目名称:trac_hack,代码行数:54,代码来源:main.py
示例17: process_request
def process_request(self, req):
req.perm.assert_permission('TICKET_BATCH_MODIFY')
comment = req.args.get('batchmod_value_comment', '')
action = req.args.get('action')
try:
new_values = self._get_new_ticket_values(req)
except TracError, e:
new_values = None
add_warning(req, tag_("The changes could not be saved: "
"%(message)s", message=to_unicode(e)))
开发者ID:dafrito,项目名称:trac-mirror,代码行数:12,代码来源:batch.py
示例18: get_existing_node
def get_existing_node(req, repos, path, rev):
try:
return repos.get_node(path, rev)
except NoSuchNode, e:
# TRANSLATOR: You can 'search' in the repository history... (link)
search_a = tag.a(_("search"),
href=req.href.log(path, rev=rev, mode='path_history'))
raise ResourceNotFound(tag(
tag.p(e.message, class_="message"),
tag.p(tag_("You can %(search)s in the repository history to see "
"if that path existed but was later removed",
search=search_a))))
开发者ID:zjj,项目名称:trac_hack,代码行数:12,代码来源:util.py
示例19: generate_prefix
def generate_prefix(prefix):
intertrac = intertracs[prefix]
if isinstance(intertrac, basestring):
yield tag.tr(tag.td(tag.strong(prefix)),
tag.td(tag_("Alias for %(name)s",
name=tag.strong(intertrac))))
else:
url = intertrac.get('url', '')
if url:
title = intertrac.get('title', url)
yield tag.tr(tag.td(tag.a(tag.strong(prefix),
href=url + '/timeline')),
tag.td(tag.a(title, href=url)))
开发者ID:exocad,项目名称:exotrac,代码行数:13,代码来源:intertrac.py
示例20: _validate
def _validate(self, req, page):
valid = True
# Validate page size
if len(req.args.get('text', '')) > self.max_size:
add_warning(req, _("The wiki page is too long (must be less "
"than %(num)s characters)",
num=self.max_size))
valid = False
# Give the manipulators a pass at post-processing the page
for manipulator in self.page_manipulators:
for field, message in manipulator.validate_wiki_page(req, page):
valid = False
if field:
add_warning(req, tag_("The Wiki page field '%(field)s'"
" is invalid: %(message)s",
field=field, message=message))
else:
add_warning(req, tag_("Invalid Wiki page: %(message)s",
message=message))
return valid
开发者ID:exocad,项目名称:exotrac,代码行数:22,代码来源:web_ui.py
注:本文中的trac.util.translation.tag_函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论