Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@jinja2.contextfunction
def collection_listing_items(context, collections, field=None):
c = dict(context.items())
c.update(collections=collections, field=field)
return c
@jinja2.contextfunction
def is_watching(context, obj, user=None):
if not user:
user = context['request'].user
if not hasattr(user, 'email'):
return False
return check_watch(obj.__class__, obj.pk, user.email)
@jinja2.contextfunction
def queue_tabnav(context):
"""
Returns tuple of tab navigation for the queue pages.
Each tuple contains three elements: (named_url. tab_code, tab_text)
"""
request = context['request']
counts = context['queue_counts']
apps_reviewing = AppsReviewing(request).get_apps()
# Apps.
if acl.action_allowed(request, 'Apps', 'Review'):
rv = [
('reviewers.apps.queue_pending', 'pending',
_('Apps ({0})', counts['pending']).format(counts['pending'])),
@jinja2.contextfunction
def include_external_base64(ctx, name):
with open(os.path.abspath(name), "rb") as f:
encoded_string = base64.b64encode(f.read())
return jinja2.Markup(encoded_string.decode())
@contextfunction
def get_list_value(self, context, model, name):
if name in ['start_date', 'end_date']:
original = getattr(model, name, None)
if original:
return utc_time_zone.localize(original).astimezone(
app_time_zone).strftime(DATETIME_FORMAT_SPEC)
return original
return super(EventAdminView, self).get_list_value(context, model, name)
@jinja2.contextfunction
def impala_addon_listing_header(context, url_base, sort_opts=None,
selected=None, extra_sort_opts=None,
search_filter=None):
if sort_opts is None:
sort_opts = {}
if extra_sort_opts is None:
extra_sort_opts = {}
if search_filter:
selected = search_filter.field
sort_opts = search_filter.opts
if hasattr(search_filter, 'extras'):
extra_sort_opts = search_filter.extras
# When an "extra" sort option becomes selected, it will appear alongside
# the normal sort options.
old_extras = extra_sort_opts
sort_opts, extra_sort_opts = list(sort_opts), []
else:
nation = pytz.timezone('Europe/Rome')
nation_time = utc_time.astimezone(nation)
return str(nation_time.day) + ' ' + dict_month[g.lan][nation_time.month] + ' ' + str(nation_time.year)
else:
return value.strftime(format)
def split_word_format(value, letters=30):
if len(value) > (letters * 2):
return value[:letters] + '<br>' + value[letters:(letters*2)] + '<br>' + value[(letters*2):]
if len(value) > letters:
return value[:letters] + '<br>' + value[letters:]
return value
# add some functions to jinja
app.jinja_env.globals['sorted'] = contextfunction(sorted_thing)
app.jinja_env.globals['int'] = contextfunction(int_thing)
app.jinja_env.globals['str'] = contextfunction(str_thing)
app.jinja_env.globals['unicode'] = contextfunction(unicode_thing)
app.jinja_env.globals['type'] = contextfunction(type_thing)
app.jinja_env.globals['len'] = contextfunction(len_thing)
app.jinja_env.globals['enumerate'] = contextfunction(enumerate_thing)
app.jinja_env.filters['date'] = date_time_format
app.jinja_env.filters['split_word'] = split_word_format
app.jinja_env.filters['msg'] = msg_status
class RegexConverter(BaseConverter):
def __init__(self, url_map, *items):
super(RegexConverter, self).__init__(url_map)
self.regex = items[0]
@jinja2.contextfunction
def filter_box_toggle(context, label=''):
return new_context(**locals())
@contextfunction
def capdl_declare_ipc_buffer(context, cap_symbol, symbol):
return TutorialFunctions.capdl_declare_frame(context, cap_symbol, symbol)
@contextfunction
def full_url(context, path, safe=None):
"""
Returns the full url given a partial path.
"""
return context['site'].full_url(path, safe)