Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def edit_redirect():
record = None
# Find out where we wanted to go to. We need to chop off the leading
# /admin on this URL as this is where the admin thinks it's placed.
path = extract_path_info(request.url_root.rstrip('/').rsplit('/', 1)[0],
request.args.get('path', '/'))
if path is not None:
record = g.admin_context.pad.resolve_url_path(path, alt_fallback=False)
if record is None:
abort(404)
path = fs_path_to_url_path(record.path.split('@')[0])
if record.alt != PRIMARY_ALT:
path += '+' + record.alt
return redirect(url_for('dash.edit', path=path))
def _get_cache_key(self, record_or_path, alt=PRIMARY_ALT,
virtual_path=None):
if isinstance(record_or_path, string_types):
path = record_or_path.strip('/')
else:
path, virtual_path = split_virtual_path(record_or_path.path)
path = path.strip('/')
virtual_path = virtual_path or None
alt = record_or_path.alt
return (path, alt, virtual_path)
def _iter_filename_choices(fn_base, alts, config, fallback=True):
"""Returns an iterator over all possible filename choices to .lr files
below a base filename that matches any of the given alts.
"""
# the order here is important as attachments can exist without a .lr
# file and as such need to come second or the loading of raw data will
# implicitly say the record exists.
for alt in alts:
if alt != PRIMARY_ALT and config.is_valid_alternative(alt):
yield os.path.join(fn_base, 'contents+%s.lr' % alt), alt, False
if fallback or PRIMARY_ALT in alts:
yield os.path.join(fn_base, 'contents.lr'), PRIMARY_ALT, False
for alt in alts:
if alt != PRIMARY_ALT and config.is_valid_alternative(alt):
yield fn_base + '+%s.lr' % alt, alt, True
if fallback or PRIMARY_ALT in alts:
yield fn_base + '.lr', PRIMARY_ALT, True
def get_fs_path(self, alt=PRIMARY_ALT):
"""The path to the record file on the file system."""
base = self.pad.db.to_fs_path(self.path)
suffix = '.lr'
if alt != PRIMARY_ALT:
suffix = '+%s%s' % (alt, suffix)
if self.is_attachment:
return base + suffix
return os.path.join(base, 'contents' + suffix)
def find_files(self, query, alt=PRIMARY_ALT, lang=None, limit=50,
types=None):
"""Returns a list of files that match the query. This requires that
the source info is up to date and is primarily used by the admin to
show files that exist.
"""
return find_files(self, query, alt, lang, limit, types)
def get_fs_path(self, alt=PRIMARY_ALT):
"""The path to the record file on the file system."""
base = self.pad.db.to_fs_path(self.path)
suffix = '.lr'
if alt != PRIMARY_ALT:
suffix = '+%s%s' % (alt, suffix)
if self.is_attachment:
return base + suffix
return os.path.join(base, 'contents' + suffix)
def find_files(self, query, alt=PRIMARY_ALT, lang=None, limit=50,
types=None):
"""Returns a list of files that match the query. This requires that
the source info is up to date and is primarily used by the admin to
show files that exist.
"""
return find_files(self, query, alt, lang, limit, types)
def _find_best_info(infos, alt, lang):
for _alt, _lang in [(alt, lang), (PRIMARY_ALT, lang),
(alt, 'en'), (PRIMARY_ALT, 'en')]:
rv = _find_info(infos, _alt, _lang)
if rv is not None:
return rv
return None
def to_json(self, pad, record=None, alt=PRIMARY_ALT):
return {
'name': self.name,
'label': self.label,
'label_i18n': self.label_i18n,
'hide_label': bool_from_string(self.options.get('hide_label'),
default=False),
'description_i18n': self.description_i18n,
'type': self.type.to_json(pad, record, alt),
'default': self.default,
}