本文整理匯總了Python中announcer.model.Subscription.find_by_sid_and_distributor方法的典型用法代碼示例。如果您正苦於以下問題:Python Subscription.find_by_sid_and_distributor方法的具體用法?Python Subscription.find_by_sid_and_distributor怎麽用?Python Subscription.find_by_sid_and_distributor使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類announcer.model.Subscription
的用法示例。
在下文中一共展示了Subscription.find_by_sid_and_distributor方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _get_preferred_format
# 需要導入模塊: from announcer.model import Subscription [as 別名]
# 或者: from announcer.model.Subscription import find_by_sid_and_distributor [as 別名]
def _get_preferred_format(self, realm, sid, authenticated):
if authenticated is None:
authenticated = 0
# Format is unified for all subscriptions of a user.
result = Subscription.find_by_sid_and_distributor(
self.env, sid, authenticated, 'email')
if result:
chosen = result[0]['format']
self.log.debug("EmailDistributor determined the preferred format"
" for '%s (%s)' is: %s", sid, authenticated and
'authenticated' or 'not authenticated', chosen)
return chosen
else:
return self._get_default_format()
示例2: render_preference_panel
# 需要導入模塊: from announcer.model import Subscription [as 別名]
# 或者: from announcer.model.Subscription import find_by_sid_and_distributor [as 別名]
def render_preference_panel(self, req, panel, path_info=None):
if req.method == 'POST':
method_arg = req.args.get('method', '')
m = re.match('^([^_]+)_(.+)', method_arg)
if m:
method, arg = m.groups()
method_func = self.post_handlers.get(method)
if method_func:
method_func(arg, req)
else:
pass
else:
pass
req.redirect(req.href.prefs('subscriptions'))
data = {'rules':{}, 'subscribers':[]}
desc_map = {}
data['formatters'] = ('text/plain', 'text/html')
data['selected_format'] = {}
data['adverbs'] = ('always', 'never')
for i in self.subscribers:
if not i.description():
continue
if not req.session.authenticated and i.requires_authentication():
continue
data['subscribers'].append({
'class': i.__class__.__name__,
'description': i.description()
})
desc_map[i.__class__.__name__] = i.description()
for i in self.distributors:
for j in i.transports():
data['rules'][j] = []
for r in Subscription.find_by_sid_and_distributor(self.env,
req.session.sid, req.session.authenticated, j):
if desc_map.get(r['class']):
data['rules'][j].append({
'id': r['id'],
'adverb': r['adverb'],
'description': desc_map[r['class']],
'priority': r['priority']
})
data['selected_format'][j] = r['format']
data['default_rules'] = {}
defaults = []
for i in self.default_subscribers:
defaults.extend(i.default_subscriptions())
for r in sorted(defaults, key=itemgetter(2)):
klass, dist, _, adverb = r
if not data['default_rules'].get(dist):
data['default_rules'][dist] = []
if desc_map.get(klass):
data['default_rules'][dist].append({
'adverb': adverb,
'description': desc_map.get(klass)
})
add_stylesheet(req, 'announcer/css/announcer_prefs.css')
return "prefs_announcer_manage_subscriptions.html", dict(data=data)