本文整理汇总了Python中trac.util.compat.sorted函数的典型用法代码示例。如果您正苦于以下问题:Python sorted函数的具体用法?Python sorted怎么用?Python sorted使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sorted函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: render_cloud
def render_cloud(env, req, cloud, renderer=None):
"""Render a tag cloud
:cloud: Dictionary of {object: count} representing the cloud.
:param renderer: A callable with signature (tag, count, percent) used to
render the cloud objects.
"""
min_px = 10.0
max_px = 30.0
scale = 1.0
if renderer is None:
def default_renderer(tag, count, percent):
href = get_resource_url(env, Resource('tag', tag), req.href)
return builder.a(tag, rel='tag', title='%i' % count, href=href,
style='font-size: %ipx' %
int(min_px + percent * (max_px - min_px)))
renderer = default_renderer
# A LUT from count to n/len(cloud)
size_lut = dict([(c, float(i)) for i, c in
enumerate(sorted(set([r for r in cloud.values()])))])
if size_lut:
scale = 1.0 / len(size_lut)
ul = builder.ul(class_='tagcloud')
last = len(cloud) - 1
for i, (tag, count) in enumerate(sorted(cloud.iteritems())):
percent = size_lut[count] * scale
li = builder.li(renderer(tag, count, percent))
if i == last:
li(class_='last')
li()
ul(li)
return ul
开发者ID:okamototk,项目名称:kanonconductor,代码行数:35,代码来源:macros.py
示例2: get_months_authors_categories
def get_months_authors_categories(self, from_dt=None, to_dt=None,
user=None, perm=None):
""" Returns a structure of post metadata:
([ ((year1, month1), count), ((year1, month2), count) ], # newest first
[ (author1, count), (author2, count) ], # alphabetical
[ (category1, count), (category2, count) ], # alphabetical
total) # num of posts
* Use 'from_dt' and 'to_dt' (datetime objects) to restrict search to
posts with a publish_time within the intervals (None means ignore).
* If user and perm is provided, the list is also filtered for permissions.
* Note also that it only fetches from most recent version. """
blog_posts = get_blog_posts(self.env, from_dt=from_dt, to_dt=to_dt)
a_dict = {}
c_dict = {}
m_dict = {}
total = 0
for post in blog_posts:
if user and perm:
# Check permissions
bp = BlogPost(self.env, post[0], post[1])
if not 'BLOG_VIEW' in perm(bp.resource):
continue # Skip this post
post_time = post[2]
m_dict[(post_time.year, post_time.month)] = m_dict.get(
(post_time.year, post_time.month), 0) + 1
author = post[3]
a_dict[author] = a_dict.get(author, 0) + 1
categories = post[6] # a list
for category in set(categories):
c_dict[category] = c_dict.get(category, 0) + 1
total += 1
return ([(m, m_dict.get(m, 0)) for m in sorted(m_dict.keys(), reverse=True)],
[(a, a_dict.get(a, 0)) for a in sorted(a_dict.keys())],
[(c, c_dict.get(c, 0)) for c in sorted(c_dict.keys())],
total)
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:35,代码来源:core.py
示例3: post_process_request
def post_process_request(self, req, template, data, content_type):
if req.path_info.startswith('/ticket/'):
# In case of an invalid ticket, the data is invalid
if not data:
return template, data, content_type
tkt = data['ticket']
links = TicketLinks(self.env, tkt)
for i in links.blocked_by:
if Ticket(self.env, i)['status'] != 'closed':
add_script(req, 'mastertickets/disable_resolve.js')
break
# Add link to depgraph if needed
if links:
add_ctxtnav(req, 'Depgraph', req.href.depgraph(tkt.id))
for change in data.get('changes', {}):
if not change.has_key('fields'):
continue
for field, field_data in change['fields'].iteritems():
if field in self.fields:
if field_data['new'].strip():
new = set([int(n) for n in field_data['new'].split(',')])
else:
new = set()
if field_data['old'].strip():
old = set([int(n) for n in field_data['old'].split(',')])
else:
old = set()
add = new - old
sub = old - new
elms = tag()
if add:
elms.append(
tag.em(u', '.join([unicode(n) for n in sorted(add)]))
)
elms.append(u' added')
if add and sub:
elms.append(u'; ')
if sub:
elms.append(
tag.em(u', '.join([unicode(n) for n in sorted(sub)]))
)
elms.append(u' removed')
field_data['rendered'] = elms
#add a link to generate a dependency graph for all the tickets in the milestone
if req.path_info.startswith('/milestone/'):
if not data:
return template, data, content_type
milestone=data['milestone']
add_ctxtnav(req, 'Depgraph', req.href.depgraph('milestone', milestone.name))
return template, data, content_type
开发者ID:pierrejean-coudert,项目名称:trac-mastertickets,代码行数:56,代码来源:web_ui.py
示例4: render_cloud
def render_cloud(self, req, cloud, renderer=None, caseless_sort=False,
mincount=None):
"""Render a tag cloud.
:cloud: Dictionary of {object: count} representing the cloud.
:param renderer: A callable with signature (tag, count, percent)
used to render the cloud objects.
:param caseless_sort: Boolean, whether tag cloud should be sorted
case-sensitive.
:param mincount: Integer threshold to hide tags with smaller count.
"""
min_px = 10.0
max_px = 30.0
scale = 1.0
if renderer is None:
def default_renderer(tag, count, percent):
href = self.get_href(req, tag=Resource('tag', tag))
return builder.a(tag, rel='tag', title='%i' % count,
href=href, style='font-size: %ipx'
% int(min_px + percent * (max_px - min_px)))
renderer = default_renderer
# A LUT from count to n/len(cloud)
size_lut = dict([(c, float(i)) for i, c in
enumerate(sorted(set([r for r in cloud.values()])))])
if size_lut:
scale = 1.0 / len(size_lut)
if caseless_sort:
# Preserve upper-case precedence within similar tags.
items = reversed(sorted(cloud.iteritems(),
key=lambda t: t[0].lower(), reverse=True))
else:
items = sorted(cloud.iteritems())
ul = li = None
for i, (tag, count) in enumerate(items):
percent = size_lut[count] * scale
if mincount and count < as_int(mincount, 1):
# Tag count is too low.
continue
if ul:
# Found new tag for cloud; now add previously prepared one.
ul('\n', li)
else:
# Found first tag for cloud; now create the list.
ul = builder.ul(class_='tagcloud')
# Prepare current tag entry.
li = builder.li(renderer(tag, count, percent))
if li:
# All tags checked; mark latest tag as last one (no tailing colon).
li(class_='last')
ul('\n', li, '\n')
return ul and ul or _("No tags found")
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:54,代码来源:macros.py
示例5: get_months_authors_categories
def get_months_authors_categories(self, from_dt=None, to_dt=None,
user=None, perm=None):
""" Returns a structure of post metadata:
([ ((year1, month1), count), ((year1, month2), count) ], # newest first
[ (author1, count), (author2, count) ], # alphabetical
[ (category1, count), (category2, count) ], # alphabetical
total) # num of posts
* Use 'from_dt' and 'to_dt' (datetime objects) to restrict search to
posts with a publish_time within the intervals (None means ignore).
* If user and perm is provided, the list is also filtered for permissions.
* Note also that it only fetches from most recent version. """
# cache_months_authors_categories= self.env.project_name + "_months_authors_categories"
cache_months_authors_categories = self.env.project_name + '_blog_posts_months'
# if user:
# cache_months_authors_categories += "_user_" + user
if from_dt:
s_from_dt = str(from_dt)
cache_months_authors_categories += s_from_dt.replace(" ", "").replace(":", "").replace("-", "").replace("+", "")
if to_dt:
s_to_dt= str(to_dt)
cache_months_authors_categories += s_to_dt.replace(" ", "").replace(":", "").replace("-", "").replace("+", "")
if cache.c(cache_months_authors_categories):
self.env.log.debug("%r found Cache ,return Cache...318......." % cache_months_authors_categories)
return cache.c(cache_months_authors_categories)
else:
self.env.log.debug("%r not found. Cacheing.. 322." % cache_months_authors_categories)
blog_posts = get_all_blog_posts(self.env, from_dt=from_dt, to_dt=to_dt)
a_dict = {}
c_dict = {}
m_dict = {}
total = 0
for post in blog_posts:
if user and perm:
# Check permissions
bp = BlogPost(self.env, post[0], post[1])
if not 'BLOG_VIEW' in perm(bp.resource):
continue # Skip this post
post_time = post[2]
m_dict[(post_time.year, post_time.month)] = m_dict.get(
(post_time.year, post_time.month), 0) + 1
author = post[3]
a_dict[author] = a_dict.get(author, 0) + 1
categories = post[6] # a list
for category in set(categories):
c_dict[category] = c_dict.get(category, 0) + 1
total += 1
return cache.c(cache_months_authors_categories,([(m, m_dict.get(m, 0)) for m in sorted(m_dict.keys(), reverse=True)],
[(a, a_dict.get(a, 0)) for a in sorted(a_dict.keys())],
[(c, c_dict.get(c, 0)) for c in sorted(c_dict.keys())],
total))
开发者ID:renwofei423,项目名称:tracfullblog,代码行数:52,代码来源:core.py
示例6: render_admin_panel
def render_admin_panel(self, req, cat, page, path_info):
assert req.perm.has_permission('TRAC_ADMIN')
excludes_match = self._patterns_match(self.excludes)
if page not in self._get_sections_set(excludes_match):
raise TracError("Invalid section %s" % page)
options = sorted(
[option for (section, name), option
in Option.registry.iteritems()
if section == page and \
not excludes_match('%s:%s' % (section, name))],
key=lambda opt: opt.name)
# Apply changes
if req.method == 'POST':
modified = False
for name, value in req.args.iteritems():
if any(name == opt.name for opt in options):
if self.config.get(page, name) != value:
self.config.set(page, name, value)
modified = True
if modified:
self.log.debug("Updating trac.ini")
self.config.save()
req.redirect(req.href.admin(cat, page))
add_stylesheet(req, 'iniadmin/css/iniadmin.css')
password_match = self._patterns_match(self.passwords)
options_data = []
for option in options:
doc = self._get_doc(option)
value = self.config.get(page, option.name)
# We assume the classes all end in "Option"
type = option.__class__.__name__.lower()[:-6] or 'text'
if type == 'list' and not isinstance(value,basestring):
value = unicode(option.sep).join(list(value))
option_data = {'name': option.name, 'default': option.default,
'doc': doc, 'value': value, 'type': type}
if type == 'extension':
option_data['options'] = sorted(
impl.__class__.__name__
for impl in option.xtnpt.extensions(self))
elif type == 'text' and \
password_match('%s:%s' % (option.section, option.name)):
option_data['type'] = 'password'
options_data.append(option_data)
data = {'iniadmin': {'section': page, 'options': options_data}}
return 'iniadmin.html', data
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:51,代码来源:iniadmin.py
示例7: post_process_request
def post_process_request(self, req, template, origData, content_type):
if req.path_info.startswith('/newticket'):
mode = 'new'
elif req.path_info.startswith('/ticket/'):
mode = 'view'
else:
return template, origData, content_type
fieldData = {}
fieldData['condfields'] = {}
all_fields = []
standard_fields = set()
for f in TicketSystem(self.env).get_ticket_fields():
all_fields.append(f['name'])
if not f.get('custom'):
standard_fields.add(f['name'])
if 'owner' in all_fields:
curr_idx = all_fields.index('owner')
if 'cc' in all_fields:
insert_idx = all_fields.index('cc')
else:
insert_idx = len(all_fields)
if curr_idx < insert_idx:
all_fields.insert(insert_idx, all_fields[curr_idx])
del all_fields[curr_idx]
for t in self.types:
fieldData['condfields'][t] = self.get_fields(t, all_fields, standard_fields)
# fields = set(getattr(self, t+'_fields'))
# if self.include_std:
# fields.update(standard_fields)
# fields.update(self.forced_fields)
# fieldData['condfields'][t] = dict([
# (f, f in fields) for f in all_fields
# ])
self.log.debug(all_fields)
self.log.info(standard_fields)
fieldData['mode'] = mode
fieldData['all_fields'] = list(all_fields)
fieldData['ok_view_fields'] = sorted(set(all_fields) - self.forced_fields,
key=lambda x: all_fields.index(x))
fieldData['ok_new_fields'] = sorted((set(all_fields) - self.forced_fields) - set(['owner']),
key=lambda x: all_fields.index(x))
add_script_data(req, fieldData)
add_script(req, '/condfields.js')
return template, origData, content_type
开发者ID:creswick,项目名称:trac-condfields,代码行数:50,代码来源:web_ui.py
示例8: post_process_request
def post_process_request(self, req, template, data, content_type):
if req.path_info.startswith('/ticket/'):
tkt = data['ticket']
links = TicketLinks(self.env, tkt)
for i in links.blocked_by:
if Ticket(self.env, i)['status'] != 'closed':
add_script(req, 'mastertickets/disable_resolve.js')
break
data['mastertickets'] = {
'field_values': {
'blocking': linkify_ids(self.env, req, links.blocking),
'blockedby': linkify_ids(self.env, req, links.blocked_by),
},
}
# Add link to depgraph if needed
if links:
add_ctxtnav(req, 'Depgraph', req.href.depgraph(tkt.id))
for change in data.get('changes', []):
for field, field_data in change['fields'].iteritems():
if field in self.fields:
if field_data['new'].strip():
new = set([int(n) for n in field_data['new'].split(',')])
else:
new = set()
if field_data['old'].strip():
old = set([int(n) for n in field_data['old'].split(',')])
else:
old = set()
add = new - old
sub = old - new
elms = tag()
if add:
elms.append(
tag.em(u', '.join([unicode(n) for n in sorted(add)]))
)
elms.append(u' added')
if add and sub:
elms.append(u'; ')
if sub:
elms.append(
tag.em(u', '.join([unicode(n) for n in sorted(sub)]))
)
elms.append(u' removed')
field_data['rendered'] = elms
return template, data, content_type
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:50,代码来源:web_ui.py
示例9: get_all_status
def get_all_status(self):
"""Returns a sorted list of all the states all of the action
controllers know about."""
valid_states = set()
for controller in self.action_controllers:
valid_states.update(controller.get_all_status())
return sorted(valid_states)
开发者ID:twisted-infra,项目名称:twisted-trac-source,代码行数:7,代码来源:api.py
示例10: to_ranges
def to_ranges(revs):
"""Converts a list of revisions to a minimal set of ranges.
>>> to_ranges([2, 12, 3, 6, 9, 1, 5, 11])
'1-3,5-6,9,11-12'
>>> to_ranges([])
''
"""
ranges = []
begin = end = None
def store():
if end == begin:
ranges.append(str(begin))
else:
ranges.append('%d-%d' % (begin, end))
for rev in sorted(revs):
if begin is None:
begin = end = rev
elif rev == end + 1:
end = rev
else:
store()
begin = end = rev
if begin is not None:
store()
return ','.join(ranges)
开发者ID:wiraqutra,项目名称:photrackjp,代码行数:26,代码来源:__init__.py
示例11: prepare_to_cumulate
def prepare_to_cumulate(sorted_events):
dhist = {}
for date, date_events in groupby(sorted_events, lambda (t, events): to_datetime(t).date()):
evset = {'Enter': set(), 'Leave': set(), 'Finish': set()}
dhist[date] = evset
date_events_list = list(date_events)
for (t, events) in date_events_list:
for k, ids in events.iteritems():
evset[k] |= ids
# resolve Enter / Leave conflicts
enter_leave_ids = evset['Enter'] & evset['Leave']
if enter_leave_ids:
evs = {'Enter': None, 'Leave': None}
last = {'Enter': None, 'Leave': None}
for k in ('Enter', 'Leave'):
evs[k] = sorted([(t, evs['Enter']) for (t, evs) in date_events_list],
key=lambda (t, ids): t)
for id in enter_leave_ids:
for k in ('Enter', 'Leave'):
last[k] = 0
for t, ids in reversed(evs[k]):
if id in ids:
last[k] = t
break
to_del = (last['Enter'] > last['Leave']) and 'Leave' or 'Enter'
evset[to_del].remove(id)
开发者ID:lexqt,项目名称:EduTracMetrix,代码行数:26,代码来源:mdashboard.py
示例12: _build_graph
def _build_graph(self, req, tkt_id):
links = TicketLinks(self.env, tkt_id)
g = graphviz.Graph()
node_default = g['node']
node_default['style'] = 'filled'
edge_default = g['edge']
edge_default['style'] = ''
# Force this to the top of the graph
g[tkt_id]
links = sorted(links.walk(), key=lambda link: link.tkt.id)
for link in links:
tkt = link.tkt
node = g[tkt.id]
node['label'] = u'#%s'%tkt.id
node['fillcolor'] = tkt['status'] == 'closed' and 'green' or 'red'
node['URL'] = req.href.ticket(tkt.id)
node['alt'] = u'Ticket #%s'%tkt.id
node['tooltip'] = tkt['summary']
for n in link.blocking:
node > g[n]
return g
开发者ID:ryepup,项目名称:trac-mastertickets,代码行数:28,代码来源:web_ui.py
示例13: _build_graph
def _build_graph(self, req, tkt_ids, label_summary=0):
g = graphviz.Graph()
g.label_summary = label_summary
g.attributes['rankdir'] = self.graph_direction
node_default = g['node']
node_default['style'] = 'filled'
edge_default = g['edge']
edge_default['style'] = ''
# Force this to the top of the graph
for id in tkt_ids:
g[id]
links = TicketLinks.walk_tickets(self.env, tkt_ids)
links = sorted(links, key=lambda link: link.tkt.id)
for link in links:
tkt = link.tkt
node = g[tkt.id]
if label_summary:
node['label'] = u'#%s %s' % (tkt.id, tkt['summary'])
else:
node['label'] = u'#%s'%tkt.id
node['fillcolor'] = tkt['status'] == 'closed' and self.closed_color or self.opened_color
node['URL'] = req.href.ticket(tkt.id)
node['alt'] = u'Ticket #%s'%tkt.id
node['tooltip'] = tkt['summary']
for n in link.blocking:
node > g[n]
return g
开发者ID:pierrejean-coudert,项目名称:trac-mastertickets,代码行数:34,代码来源:web_ui.py
示例14: _page_tags
def _page_tags(self, req):
pagename = req.args.get('page', 'WikiStart')
tag_system = TagSystem(self.env)
resource = Resource('wiki', pagename)
tags = sorted(tag_system.get_tags(req, resource))
return tags
开发者ID:okamototk,项目名称:kanonconductor,代码行数:7,代码来源:wiki.py
示例15: render_admin_panel
def render_admin_panel(self, req, cat, page, version):
req.perm.require("TAGS_ADMIN")
data = {}
tag_system = TagSystem(self.env)
if req.method == "POST":
# Replace Tag
allow_delete = req.args.get("allow_delete")
new_tag = req.args.get("tag_new_name").strip()
new_tag = not new_tag == u"" and new_tag or None
if not (allow_delete or new_tag):
data["error"] = _(
"""Selected current tag(s) and either
new tag or delete approval are required"""
)
else:
comment = req.args.get("comment", u"")
old_tags = req.args.get("tag_name")
if old_tags:
# Provide list regardless of single or multiple selection.
old_tags = isinstance(old_tags, list) and old_tags or [old_tags]
tag_system.replace_tag(req, old_tags, new_tag, comment, allow_delete)
data["selected"] = new_tag
all_tags = sorted(tag_system.get_all_tags(req, "-dummy"))
data["tags"] = all_tags
try:
Chrome(self.env).add_textarea_grips(req)
except AttributeError:
# Element modifiers unavailable before Trac 0.12, skip gracefully.
pass
return "admin_tag_change.html", data
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:31,代码来源:admin.py
示例16: get_timeline_events
def get_timeline_events(self, req, start, stop, filters):
if "blog" in filters:
blog_realm = Resource("blog")
if not "BLOG_VIEW" in req.perm(blog_realm):
return
add_stylesheet(req, "tracfullblog/css/fullblog.css")
# Blog posts
blog_posts = get_blog_posts(self.env, from_dt=start, to_dt=stop, all_versions=True)
for name, version, time, author, title, body, category_list in blog_posts:
bp_resource = blog_realm(id=name, version=version)
if "BLOG_VIEW" not in req.perm(bp_resource):
continue
bp = BlogPost(self.env, name, version=version)
yield ("blog", bp.version_time, bp.version_author, (bp_resource, bp, None))
# Attachments (will be rendered by attachment module)
for event in AttachmentModule(self.env).get_timeline_events(req, blog_realm, start, stop):
yield event
# Blog comments
blog_comments = get_blog_comments(self.env, from_dt=start, to_dt=stop)
blog_comments = sorted(blog_comments, key=itemgetter(4), reverse=True)
for post_name, number, comment, author, time in blog_comments:
bp_resource = blog_realm(id=post_name)
if "BLOG_VIEW" not in req.perm(bp_resource):
continue
bp = BlogPost(self.env, post_name)
bc = BlogComment(self.env, post_name, number=number)
yield ("blog", time, author, (bp_resource, bp, bc))
开发者ID:kzhamaji,项目名称:TracFullBlogPlugin,代码行数:27,代码来源:web_ui.py
示例17: render_table
def render_table(items, colspec, render_item, colspace=1):
try:
columns = max(int(colspec), 1)
except Exception:
columns = 3
nbsp = Markup(' ')
# hdr = [tag.th(nbsp, 'Display'), tag.th('Markup', nbsp)]
spacer_style = 'width:%dem;border:none' % colspace
# Find max width to make value cols equally wide
width = 0
for i in items:
if (isinstance(i, str) or isinstance(i, unicode)) and len(i) > width:
width = len(i)
value_style = 'border:none'
#noinspection PyUnusedLocal
value_style += ';width:%dem' % (width*2/3) if width else '' # empirical...
def render_def(s):
rendered = s and render_item(s) or None
if isinstance(s, str):
s = Markup(s.replace('&', '&'))
return [tag.td(rendered, nbsp, style='border:none'),
tag.td(tag.kbd(s), style=value_style)]
return tag.table(#tag.tr((hdr + [tag.td(style=spacer_style)]) *
# (columns-1) + hdr),
[tag.tr([render_def(s) + [tag.td(style=spacer_style)]
for s in row[:-1]] + render_def(row[-1]))
for row in group_over(sorted(items), columns)],
class_='wiki', style='border:none')
开发者ID:arielnetworks,项目名称:wikiextrasplugin,代码行数:31,代码来源:util.py
示例18: test_mixed_case_group
def test_mixed_case_group(self):
db = self.env.get_db_cnx()
cursor = db.cursor()
cursor.executemany("INSERT INTO permission VALUES (%s,%s)", [
('Dev', 'WIKI_MODIFY'), ('Dev', 'REPORT_ADMIN'),
('Admin', 'Dev'), ('john', 'Admin')])
self.assertEquals(['REPORT_ADMIN', 'WIKI_MODIFY'],
sorted(self.store.get_user_permissions('john')))
开发者ID:gdgkyoto,项目名称:kyoto-gtug,代码行数:8,代码来源:perm.py
示例19: get_comments
def get_comments(self):
""" Returns a list of used comment numbers attached to the post.
It instantiates BlogComment objects for comments attached to the
current BlogPost, and returns them in a list sorted by number. """
comments = sorted(get_blog_comments(self.env, post_name=self.name),
key=itemgetter(1))
return [BlogComment(self.env, comment[0],
comment[1]) for comment in comments]
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:8,代码来源:model.py
示例20: sections
def sections(self):
"""Return a list of section names."""
sections = set([to_unicode(s) for s in self.parser.sections()])
if self.parent:
sections.update(self.parent.sections())
else:
sections.update(self.defaults().keys())
return sorted(sections)
开发者ID:gdgkyoto,项目名称:kyoto-gtug,代码行数:8,代码来源:config.py
注:本文中的trac.util.compat.sorted函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论