本文整理汇总了Python中genshi.filters.Transformer.attr方法的典型用法代码示例。如果您正苦于以下问题:Python Transformer.attr方法的具体用法?Python Transformer.attr怎么用?Python Transformer.attr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类genshi.filters.Transformer
的用法示例。
在下文中一共展示了Transformer.attr方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: filter_stream
# 需要导入模块: from genshi.filters import Transformer [as 别名]
# 或者: from genshi.filters.Transformer import attr [as 别名]
def filter_stream(self, req, method, filename, stream, data):
"""
Reformat the ``branch`` field of a ticket to show the history of the
linked branch.
"""
if filename == 'ticket.html':
ticket = data.get('ticket')
if ticket and ticket.exists:
branch = ticket['branch']
if branch:
error = None
if not self._is_valid_branch_name(branch):
error = "not a valid branch name"
elif not self._is_existing_branch(branch):
error = "branch does not exist"
else:
try:
master = self._dereference_head(MASTER_BRANCH)
branch = self._dereference_head(branch)
common_ancestor = self._common_ancestor(master,branch)
if branch == common_ancestor:
# the trac log page does not work if the revisions are equal
error = "no commits on branch yet"
else:
filter = Transformer('//td[@headers="h_branch"]/text()')
stream |= filter.wrap(tag.a(href=req.href.log(revs="%s-%s"%(common_ancestor,branch))))
except GitError:
error = "failed to determine common ancestor with %s branch"%MASTER_BRANCH
if error:
filter = Transformer('//td[@headers="h_branch"]')
stream |= filter.attr("title",error)
return stream
示例2: filter_stream
# 需要导入模块: from genshi.filters import Transformer [as 别名]
# 或者: from genshi.filters.Transformer import attr [as 别名]
def filter_stream(self, req, method, filename, stream, data):
"""
Quick and dirty solution - modify page on the fly to inject special field. It would be
nicer if we can do it by creating custom field as this depends on page structure.
"""
#embed(header='Ticket Stream Filter')
if filename == 'ticket.html':
# Disable any direct bounty input
filter = Transformer('.//input[@id="field-bounty"]')
stream |= filter.attr("disabled", "disabled")
ticket = data.get('ticket')
if ticket and ticket.exists:
identifier = ticket.id
user = req.authname if req.authname != 'anonymous' else None
request = self.call_api('GET', '/issue/%s' % identifier)
fragment = tag()
sponsorships = {}
status = self.convert_status(ticket.values['status'])
owner = ticket.values['owner']
tooltip = None
if request != None and (request.status_code == 200 or request.status_code == 404):
sponsorships = self.get_sponsorships(identifier)
pledged_amount = sum_amounts(sponsorships.values())
user_sponsorship = sponsorships.get(user, Sponsorship())
# Bounty
tooltip = u"Pledged: %d\u20ac" % pledged_amount
if status == 'STARTED' or status == 'COMPLETED':
confirmed_amount = sum_amounts(sponsorships.values(), ('CONFIRMED', 'VALIDATED', 'REJECTED', 'TRANSFERRED', 'REFUNDED'))
tooltip += u" \nConfirmed: %d\u20ac" % confirmed_amount
if status == 'COMPLETED':
validated_amount = sum_amounts(sponsorships.values(), 'VALIDATED')
tooltip += u" \nValidated: %d\u20ac" % validated_amount
# Action
action = None
if (((status == 'STARTED' or status == 'COMPLETED')
and user_sponsorship.status == 'PLEDGED')
or (status == 'STARTED' and user != None and user != owner
and user_sponsorship.status == None)):
response = self.call_api('GET', '/config/payment_gateways')
gateways = response.json().get('gateways')
gateway_tags = []
if 'DUMMY' in gateways:
gateway_tags.append(tag.input(type="submit", value="Payment Card", name='DUMMY'))
if 'PAYPAL_STANDARD' in gateways:
gateway_tags.append(tag.input(type="submit", value="PayPal", name='PAYPAL_STANDARD'))
if 'PAYPAL_ADAPTIVE' in gateways:
gateway_tags.append(tag.input(type="submit", value="PayPal", name='PAYPAL_ADAPTIVE'))
if user_sponsorship.status == 'PLEDGED':
action = tag.form(
tag.input(type="button", name="confirm", value=u"Confirm %d\u20ac" % user_sponsorship.amount, id="confirm-button"),
tag.span(gateway_tags, id="confirm-options"),
tag.input(type="submit", name="delete", value="Delete"),
method="post", action=req.href.ticket(identifier, "confirm"))
else:
#TODO: should be separate action
action = tag.form(
tag.input(name="amount", type="text", size="3", value="0", pattern="[0-9]*", title="money amount"),
tag.input(type="button", value="Pledge & Confirm", id="confirm-button"),
tag.span(gateway_tags, id="confirm-options"),
method="post", action=req.href.ticket(identifier, "confirm"))
elif status == 'COMPLETED' and user_sponsorship.status in ('CONFIRMED', 'REJECTED', 'VALIDATED'):
action = tag.form(method="post", action=req.href.ticket(identifier, "validate"))
if user_sponsorship.status == 'CONFIRMED' or user_sponsorship.status == 'REJECTED':
action.append(tag.input(type="submit", name='validate', value=u"Validate %d\u20ac" % user_sponsorship.amount))
if user_sponsorship.status == 'CONFIRMED' or user_sponsorship.status == 'VALIDATED':
action.append(tag.input(type="submit", name='reject', value="Reject"))
elif (status == 'READY' and user != None):
if user_sponsorship.status == None:
action = tag.form(tag.input(name="amount", type="text", size="3", value=user_sponsorship.amount, pattern="[0-9]*", title="money amount"), tag.input(type="submit", value="Pledge"), method="post", action=req.href.ticket(identifier, "sponsor"))
elif user_sponsorship.status == 'PLEDGED':
action = tag.form(tag.input(name="amount", type="text", size=3, value=user_sponsorship.amount, pattern="[0-9]*", title="money amount"), tag.input(type="submit", name="update", value="Update"), tag.input(type="submit", name="delete", value="Delete"), method="post", action=req.href.ticket(identifier, "update_sponsorship"))
elif (user == None):
action = tag.span(u"\u00A0", tag.a("Login", href=req.href.login()), " or ", tag.a("Register", href=req.href.register()), " to sponsor")
if action != None:
fragment.append(" ")
fragment.append(action)
else:
error = "Connection error"
if request:
error = request.json().get("error", "Unknown error")
fragment.append(tag.span("[BountyFunding Error]", title=error))
#chrome = Chrome(self.env)
#chrome.add_jquery_ui(req)
add_stylesheet(req, 'htdocs/styles/bountyfunding.css')
add_script(req, 'htdocs/scripts/bountyfunding.js')
if tooltip != None:
filter = Transformer('.//td[@headers="h_bounty"]/text()')
stream |= filter.wrap(tag.span(title=tooltip))
#.........这里部分代码省略.........