本文整理汇总了Python中tipfy.get_config函数的典型用法代码示例。如果您正苦于以下问题:Python get_config函数的具体用法?Python get_config怎么用?Python get_config使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_config函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, app, request):
self.app = app
self.request = request
# Alias.
self.current_user = self.auth_current_user
area_name = self.get_area_name()
if area_name not in ("docs", "www"):
# TODO instead of 404, redirect to a page to create the area,
# if the are doesn't exist.
# For now, only 404 is allowed.
abort(404)
self.area = Area.get_by_key_name(area_name)
if self.area is None:
self.area = Area.get_or_insert(key_name=area_name, name=area_name)
# Get sitename from config or use host minus port as default
# sitename.
sitename = self.request.host.rsplit(":", 1)[0]
# Add some common stuff to context.
self.context = self.request.context = {
"area": self.area,
"current_url": self.request.url,
"sitename": get_config("moe", "sitename", sitename),
"analytics_code": get_config("moe", "analytics_code", None),
"dev": get_config("tipfy", "dev"),
"apps_installed": get_config("tipfy", "apps_installed"),
}
示例2: __init__
def __init__(self, app, request):
self.app = app
self.request = request
area_name = self.get_area_name()
if area_name not in ('docs', 'www'):
# TODO instead of 404, redirect to a page to create the area,
# if the are doesn't exist.
# For now, only 404 is allowed.
abort(404)
self.area = Area.get_by_key_name(area_name)
if self.area is None:
self.area = Area.get_or_insert(key_name=area_name, name=area_name)
# Get sitename from config or use host minus port as default
# sitename.
sitename = self.request.host.rsplit(':', 1)[0]
# Add some common stuff to context.
self.context = self.request.context = {
'area': self.area,
'current_url': self.request.url,
'sitename': get_config('moe', 'sitename', sitename),
'analytics_code': get_config('moe', 'analytics_code', None),
'dev': get_config('tipfy', 'dev'),
'apps_installed': get_config('tipfy', 'apps_installed'),
}
示例3: get_rules
def get_rules():
"""Returns a list of URL rules for the application. The list can be
defined entirely here or in separate ``urls.py`` files. Here we show an
example of joining all rules from the ``apps_installed`` listed in
config.
"""
entry_points = get_config('tipfy', 'apps_entry_points')
if get_config('moe', 'use_subdomain', False):
kwargs = {'subdomain': '<area_name>'}
else:
kwargs = {'defaults': {'area_name': 'www'}}
rules = [
# This is a dummy rule pointing to wiki start page. Replace it by
# one pointing to a homepage handler.
Rule('/', endpoint='home/index', handler='moe.wiki.handlers.WikiViewHandler', **kwargs),
]
for app_module in get_config('tipfy', 'apps_installed'):
try:
# Get the rules from each app installed and extend our rules.
app_rules = import_string('%s.urls.get_rules' % app_module)()
entry_point = entry_points.get(app_module)
if entry_point:
# Submount using the entry point.
rules.append(Submount(entry_point, app_rules))
else:
# Just append the rules.
rules.extend(app_rules)
except ImportError:
pass
return rules
示例4: set_translations_from_request
def set_translations_from_request():
"""Sets a translations object for the current request.
It will use the configuration for ``locale_request_lookup`` to search for
a key in ``GET``, ``POST``, cookie or keywords in the current URL rule.
The configuration defines the search order. If no locale is set in any of
these, uses the default locale set in config.
By default it gets the locale from a ``lang`` GET parameter, and if not
set tries to get it from a cookie. This is represented by the default
configuration value ``[('args', 'lang'), ('cookies', 'tipfy.locale')]``.
:returns:
None.
"""
locale = None
request = Tipfy.request
for method, key in get_config(__name__, 'locale_request_lookup'):
if method in ('args', 'form', 'cookies'):
# Get locale from GET, POST or cookies.
locale = getattr(request, method).get(key, None)
elif method == 'rule_args':
# Get locale from current URL rule keywords.
locale = request.rule_args.get(key, None)
if locale is not None:
break
else:
locale = get_config(__name__, 'locale')
set_translations(locale)
示例5: get_rules
def get_rules():
# A protected path (by default '/pages') is used by everything related to
# the wiki operation. Everything else is considered a wiki content page.
protected_path = '/' + get_config('moe.wiki', 'protected_path')
# Take the area name from the subdomain if they are in use. Otherwise
# assume that this will be used in a single domain.
if get_config('moe', 'use_subdomain', False):
kwargs = {'subdomain': '<area_name>'}
else:
kwargs = {'defaults': {'area_name': 'www'}}
rules = [
# Initial page.
Rule('/', endpoint='wiki/index', handler='moe.wiki.handlers.WikiViewHandler', **kwargs),
Submount(protected_path, [
# Base for the internal pages.
Rule('/', endpoint='wiki/pages', handler='moe.wiki.handlers.WikiOverviewHandler', **kwargs),
# Lists all pages.
Rule('/list', endpoint='wiki/list', handler='moe.wiki.handlers.WikiPageListHandler', **kwargs),
# Lists all child pages for a given page.
Rule('/list/<path:page_path>', endpoint='wiki/list', handler='moe.wiki.handlers.WikiPageListHandler', **kwargs),
# Lists all pages (Atom format).
Rule('/list-atom', endpoint='wiki/list-atom', handler='moe.wiki.handlers.WikiPageListFeedHandler', **kwargs),
# Lists all child pages for a given page (Atom format).
Rule('/list-atom/<path:page_path>', endpoint='wiki/list-atom', handler='moe.wiki.handlers.WikiPageListFeedHandler', **kwargs),
# Lists all changes.
Rule('/changes', endpoint='wiki/changes', handler='moe.wiki.handlers.WikiChangesHandler', **kwargs),
# Lists all changes for a given page.
Rule('/changes/<path:page_path>', endpoint='wiki/changes', handler='moe.wiki.handlers.WikiPageChangesHandler', **kwargs),
# Lists all changes (Atom format).
Rule('/changes-atom', endpoint='wiki/changes-atom', handler='moe.wiki.handlers.WikiChangesFeedHandler', **kwargs),
# Lists all changes for a given page (Atom format).
Rule('/changes-atom/<path:page_path>', endpoint='wiki/changes-atom', handler='moe.wiki.handlers.WikiPageChangesFeedHandler', **kwargs),
# Edition overview.
Rule('/edit/', endpoint='wiki/edit', handler='moe.wiki.handlers.WikiEditOverviewHandler', **kwargs),
# Edits a page.
Rule('/edit/<path:page_path>', endpoint='wiki/edit', handler='moe.wiki.handlers.WikiEditHandler', **kwargs),
# Diffs overview.
Rule('/diff/', endpoint='wiki/diff', handler='moe.wiki.handlers.WikiDiffOverviewHandler', **kwargs),
# Show diffs for a page revision.
Rule('/diff/<path:page_path>', endpoint='wiki/diff', handler='moe.wiki.handlers.WikiDiffHandler', **kwargs),
# Reparse all pages.
# Rule('/reparse/', endpoint='wiki/reparse', handler='moe.wiki.handlers.WikiReparseHandler', **kwargs),
]),
# A wiki page.
Rule('/<path:page_path>', endpoint='wiki/index', handler='moe.wiki.handlers.WikiViewHandler', **kwargs),
]
return rules
示例6: is_default_locale
def is_default_locale():
"""Returns ``True`` if locale is set to the default locale.
:return:
``True`` if locale is set to the default locale, ``False`` otherwise.
"""
return getattr(local, 'locale', None) == get_config(__name__, 'locale')
示例7: get
def get(self, board, page=0):
if page > self.PAGES:
raise NotFound()
if page == 0:
cache = models.Cache.load("board", board)
if cache:
return Response(cache.data)
data = {}
data['threads'] = get_threads(board,page=page) # last threads
data['show_captcha'] = True
data['reply'] = True
data['board_name'] = self.NAMES.get(board) or "Woooo???"
data['board'] = board # board name
data['boards'] = get_config("aib", "boardlist")
data['pages'] = range(self.PAGES)
data['overlay'] = board in self.OVER
html = render_template("board.html", **data)
if page == 0:
cache = models.Cache.create("board", board)
cache.data = html
cache.put()
return Response(html)
示例8: handle_exception
def handle_exception(self, e, handler=None):
if get_config('tipfy', 'dev'):
# Always raise the exception in dev, so we can debug it.
raise
return ExceptionHandler(Tipfy.app, Tipfy.request).dispatch('get',
exception=e)
示例9: option_modsign
def option_modsign(request, data):
if data.get('name') != get_config("aib.ib", "mod_name"):
return
user = users.get_current_user()
if users.is_current_user_admin():
data['typ'] = 'modpost'
示例10: user_model
def user_model(self):
"""Returns the configured user model.
:return:
A :class:`tipfy.ext.auth.model.User` class.
"""
return import_string(get_config(__name__, 'user_model'))
示例11: get_threads
def get_threads(board, page=0, fmt_name="page"):
_fmt = "thread_" + fmt_name
if _fmt in globals():
fmt = globals()[_fmt]
else:
fmt = thread_plain
threads = []
board_db = Board.get_by_key_name(board)
if board_db:
threads = board_db.linked
if not threads:
threads = [ (board, th) for th in board_db.thread]
per_page = get_config('aib.ib', 'thread_per_page')
threads = threads[per_page*page:per_page*(page+1)]
logging.info("threadlist in %r : %r" % (board, threads))
# grab data from cache
data = Thread.load_list(threads)
return [ fmt(th) for th in data if th ]
示例12: _validate_recaptcha
def _validate_recaptcha(self, challenge, response, remote_addr):
"""Performs the actual validation."""
private_key = get_config('tipfy.ext.wtforms', 'recaptcha_private_key')
result = urlfetch.fetch(url=RECAPTCHA_VERIFY_SERVER,
method=urlfetch.POST,
headers={'Content-Type': 'application/x-www-form-urlencoded'},
payload=url_encode({
'privatekey': private_key,
'remoteip': remote_addr,
'challenge': challenge,
'response': response
}))
if result.status_code != 200:
return False
rv = [l.strip() for l in result.content.splitlines()]
if rv and rv[0] == 'true':
return True
if len(rv) > 1:
error = rv[1]
if error in self._error_codes:
raise RuntimeError(self._error_codes[error])
return False
示例13: get_rules
def get_rules():
"""Returns a list of URL rules for the application. The list can be defined
entirely here or in separate ``urls.py`` files. Here we show an example of
joining all rules from the ``apps_installed`` listed in config.
"""
rules = [
tipfy.Rule('/', endpoint='home', handler='home.HomeHandler'),
tipfy.Rule('/submit', endpoint='submit', handler='submit.SubmitHandler'),
tipfy.Rule('/review', endpoint='review-start', handler='review.ReviewStartHandler'),
tipfy.Rule('/review/<int:id>', endpoint='review-quote', handler='review.ReviewQuoteHandler'),
tipfy.Rule('/review/remind', endpoint='review-remind', handler='review.ReviewRemindHandler'),
tipfy.Rule('/quote/<int:id>', endpoint='quote-view', handler='quote.QuoteViewHandler'),
tipfy.Rule('/random', endpoint='random-quote', handler='random_quote.RandomQuoteHandler'),
tipfy.Rule('/atom', endpoint='atom-view', handler='atom.AtomViewHandler'),
]
for app_module in tipfy.get_config('tipfy', 'apps_installed'):
try:
# Load the urls module from the app and extend our rules.
app_rules = tipfy.import_string('%s.urls' % app_module)
rules.extend(app_rules.get_rules())
except ImportError:
pass
return rules
示例14: get_roles_and_rules
def get_roles_and_rules(cls, area, user, roles_map, roles_lock):
"""Returns a tuple (roles, rules) for a given user in a given area."""
res = None
cache_key = cls.get_key_name(area, user)
if cache_key in _rules_map:
res = _rules_map[cache_key]
else:
res = memcache.get(cache_key, namespace=cls.__name__)
if res is not None:
lock, roles, rules = res
if res is None or lock != roles_lock or get_config("tipfy", "dev"):
entity = cls.get_by_key_name(cache_key)
if entity is None:
res = (roles_lock, [], [])
else:
rules = []
# Apply role rules.
for role in entity.roles:
rules.extend(roles_map.get(role, []))
# Extend with rules, eventually overriding some role rules.
rules.extend(entity.rules)
# Reverse everything, as rules are checked from last to first.
rules.reverse()
# Set results for cache, applying current roles_lock.
res = (roles_lock, entity.roles, rules)
cls.set_cache(cache_key, res)
return (res[1], res[2])
示例15: __init__
def __init__(self, area, user, roles_map=None, roles_lock=None):
"""Loads access privileges and roles for a given user in a given area.
:param area:
An area identifier, as a string.
:param user:
An user identifier, as a string.
:param roles_map:
A dictionary of roles mapping to a list of rule tuples.
:param roles_lock:
Roles lock string to validate cache. If not set, uses the
application version id.
"""
if roles_map is not None:
self.roles_map = roles_map
if roles_lock is not None:
self.roles_lock = roles_lock
elif self.roles_lock is None:
# Set roles_lock default.
self.roles_lock = get_config("tipfy", "version_id")
if area and user:
self._roles, self._rules = AclRules.get_roles_and_rules(area, user, self.roles_map, self.roles_lock)
else:
self.reset()