nwo
stringlengths 10
28
| sha
stringlengths 40
40
| path
stringlengths 11
97
| identifier
stringlengths 1
64
| parameters
stringlengths 2
2.24k
| return_statement
stringlengths 0
2.17k
| docstring
stringlengths 0
5.45k
| docstring_summary
stringlengths 0
3.83k
| func_begin
int64 1
13.4k
| func_end
int64 2
13.4k
| function
stringlengths 28
56.4k
| url
stringlengths 106
209
| project
int64 1
48
| executed_lines
list | executed_lines_pc
float64 0
153
| missing_lines
list | missing_lines_pc
float64 0
100
| covered
bool 2
classes | filecoverage
float64 2.53
100
| function_lines
int64 2
1.46k
| mccabe
int64 1
253
| coverage
float64 0
100
| docstring_lines
int64 0
112
| function_nodoc
stringlengths 9
56.4k
| id
int64 0
29.8k
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Record.pagination
|
(self)
|
return self.datamodel.pagination_config.get_pagination_controller(self)
|
Returns the pagination controller for the record.
|
Returns the pagination controller for the record.
| 372 | 376 |
def pagination(self):
"""Returns the pagination controller for the record."""
if not self.supports_pagination:
raise AttributeError()
return self.datamodel.pagination_config.get_pagination_controller(self)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L372-L376
| 40 |
[
0,
1,
2,
4
] | 80 |
[
3
] | 20 | false | 89.992532 | 5 | 2 | 80 | 1 |
def pagination(self):
if not self.supports_pagination:
raise AttributeError()
return self.datamodel.pagination_config.get_pagination_controller(self)
| 26,214 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Record.contents
|
(self)
|
return FileContents(self.source_filename)
| 379 | 380 |
def contents(self):
return FileContents(self.source_filename)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L379-L380
| 40 |
[
0
] | 50 |
[
1
] | 50 | false | 89.992532 | 2 | 1 | 50 | 0 |
def contents(self):
return FileContents(self.source_filename)
| 26,215 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Record.get_fallback_record_label
|
(self, lang)
|
return self["_id"].replace("-", " ").replace("_", " ").title()
| 382 | 385 |
def get_fallback_record_label(self, lang):
if not self["_id"]:
return "(Index)"
return self["_id"].replace("-", " ").replace("_", " ").title()
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L382-L385
| 40 |
[
0,
1,
2,
3
] | 100 |
[] | 0 | true | 89.992532 | 4 | 2 | 100 | 0 |
def get_fallback_record_label(self, lang):
if not self["_id"]:
return "(Index)"
return self["_id"].replace("-", " ").replace("_", " ").title()
| 26,216 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Record.get_record_label_i18n
|
(self)
|
return rv
| 387 | 397 |
def get_record_label_i18n(self):
rv = {}
for lang, _ in (self.datamodel.label_i18n or {}).items():
label = self.datamodel.format_record_label(self, lang)
if not label:
label = self.get_fallback_record_label(lang)
rv[lang] = label
# Fill in english if missing
if "en" not in rv:
rv["en"] = self.get_fallback_record_label("en")
return rv
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L387-L397
| 40 |
[
0,
1,
2,
3,
4,
6,
7,
8,
9,
10
] | 90.909091 |
[
5
] | 9.090909 | false | 89.992532 | 11 | 5 | 90.909091 | 0 |
def get_record_label_i18n(self):
rv = {}
for lang, _ in (self.datamodel.label_i18n or {}).items():
label = self.datamodel.format_record_label(self, lang)
if not label:
label = self.get_fallback_record_label(lang)
rv[lang] = label
# Fill in english if missing
if "en" not in rv:
rv["en"] = self.get_fallback_record_label("en")
return rv
| 26,217 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Record.record_label
|
(self)
|
return (self.get_record_label_i18n() or {}).get("en")
| 400 | 401 |
def record_label(self):
return (self.get_record_label_i18n() or {}).get("en")
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L400-L401
| 40 |
[
0,
1
] | 100 |
[] | 0 | true | 89.992532 | 2 | 2 | 100 | 0 |
def record_label(self):
return (self.get_record_label_i18n() or {}).get("en")
| 26,218 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Record.url_path
|
(self)
| 404 | 410 |
def url_path(self):
# This is redundant (it's the same as the inherited
# SourceObject.url_path) but is here to silence
# pylint ("W0223: Method 'url_path' is abstract in class
# 'SourceObject' but is not overridden (abstract-method)"),
# as well as to document that Record is an abstract class.
raise NotImplementedError()
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L404-L410
| 40 |
[
0,
1,
2,
3,
4,
5
] | 85.714286 |
[
6
] | 14.285714 | false | 89.992532 | 7 | 1 | 85.714286 | 0 |
def url_path(self):
# This is redundant (it's the same as the inherited
# SourceObject.url_path) but is here to silence
# pylint ("W0223: Method 'url_path' is abstract in class
# 'SourceObject' but is not overridden (abstract-method)"),
# as well as to document that Record is an abstract class.
raise NotImplementedError()
| 26,219 |
|||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Record._get_clean_url_path
|
(self)
|
return "/".join(reversed(bits)).strip("/")
|
The "clean" URL path, before modification to account for alt and
page_num and without any leading '/'
|
The "clean" URL path, before modification to account for alt and
page_num and without any leading '/'
| 412 | 426 |
def _get_clean_url_path(self):
"""The "clean" URL path, before modification to account for alt and
page_num and without any leading '/'
"""
bits = [self["_slug"]]
parent = self.parent
while parent is not None:
slug = parent["_slug"]
head, sep, tail = slug.rpartition("/")
if "." in tail:
# https://www.getlektor.com/docs/content/urls/#content-below-dotted-slugs
slug = head + sep + f"_{tail}"
bits.append(slug)
parent = parent.parent
return "/".join(reversed(bits)).strip("/")
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L412-L426
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14
] | 100 |
[] | 0 | true | 89.992532 | 15 | 3 | 100 | 2 |
def _get_clean_url_path(self):
bits = [self["_slug"]]
parent = self.parent
while parent is not None:
slug = parent["_slug"]
head, sep, tail = slug.rpartition("/")
if "." in tail:
# https://www.getlektor.com/docs/content/urls/#content-below-dotted-slugs
slug = head + sep + f"_{tail}"
bits.append(slug)
parent = parent.parent
return "/".join(reversed(bits)).strip("/")
| 26,220 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Record._get_url_path
|
(self, alt=None)
|
return "/" + clean_path.rstrip("/")
|
The target path where the record should end up, after adding prefix/suffix
for the specified alt (but before accounting for any page_num).
Note that some types of records (Attachments), are only
created for the primary alternative.
|
The target path where the record should end up, after adding prefix/suffix
for the specified alt (but before accounting for any page_num).
| 428 | 445 |
def _get_url_path(self, alt=None):
"""The target path where the record should end up, after adding prefix/suffix
for the specified alt (but before accounting for any page_num).
Note that some types of records (Attachments), are only
created for the primary alternative.
"""
clean_path = self._get_clean_url_path()
config = self.pad.config
if config.primary_alternative:
# alternatives are configured
if alt is None:
alt = config.primary_alternative
prefix, suffix = config.get_alternative_url_span(alt)
# XXX: 404.html with suffix -de becomes 404.html-de but should
# actually become 404-de.html
clean_path = prefix.lstrip("/") + clean_path + suffix.rstrip("/")
return "/" + clean_path.rstrip("/")
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L428-L445
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17
] | 100 |
[] | 0 | true | 89.992532 | 18 | 3 | 100 | 5 |
def _get_url_path(self, alt=None):
clean_path = self._get_clean_url_path()
config = self.pad.config
if config.primary_alternative:
# alternatives are configured
if alt is None:
alt = config.primary_alternative
prefix, suffix = config.get_alternative_url_span(alt)
# XXX: 404.html with suffix -de becomes 404.html-de but should
# actually become 404-de.html
clean_path = prefix.lstrip("/") + clean_path + suffix.rstrip("/")
return "/" + clean_path.rstrip("/")
| 26,221 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Record.path
|
(self)
|
return self["_path"]
| 448 | 449 |
def path(self):
return self["_path"]
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L448-L449
| 40 |
[
0,
1
] | 100 |
[] | 0 | true | 89.992532 | 2 | 1 | 100 | 0 |
def path(self):
return self["_path"]
| 26,222 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Record.get_sort_key
|
(self, fields)
|
return rv
|
Returns a sort key for the given field specifications specific
for the data in the record.
|
Returns a sort key for the given field specifications specific
for the data in the record.
| 451 | 468 |
def get_sort_key(self, fields):
"""Returns a sort key for the given field specifications specific
for the data in the record.
"""
rv = [None] * len(fields)
for idx, field in enumerate(fields):
if field[:1] == "-":
field = field[1:]
reverse = True
else:
field = field.lstrip("+")
reverse = False
try:
value = self[field]
except KeyError:
value = None
rv[idx] = _CmpHelper(value, reverse)
return rv
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L451-L468
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17
] | 100 |
[] | 0 | true | 89.992532 | 18 | 4 | 100 | 2 |
def get_sort_key(self, fields):
rv = [None] * len(fields)
for idx, field in enumerate(fields):
if field[:1] == "-":
field = field[1:]
reverse = True
else:
field = field.lstrip("+")
reverse = False
try:
value = self[field]
except KeyError:
value = None
rv[idx] = _CmpHelper(value, reverse)
return rv
| 26,223 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Record.__contains__
|
(self, name)
|
return name in self._data and not is_undefined(self._data[name])
| 470 | 471 |
def __contains__(self, name):
return name in self._data and not is_undefined(self._data[name])
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L470-L471
| 40 |
[
0
] | 50 |
[
1
] | 50 | false | 89.992532 | 2 | 2 | 50 | 0 |
def __contains__(self, name):
return name in self._data and not is_undefined(self._data[name])
| 26,224 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Record.__getitem__
|
(self, name)
|
return rv
| 473 | 481 |
def __getitem__(self, name):
rv = self._bound_data.get(name, Ellipsis)
if rv is not Ellipsis:
return rv
rv = self._data[name]
if hasattr(rv, "__get__"):
rv = rv.__get__(self)
self._bound_data[name] = rv
return rv
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L473-L481
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8
] | 100 |
[] | 0 | true | 89.992532 | 9 | 3 | 100 | 0 |
def __getitem__(self, name):
rv = self._bound_data.get(name, Ellipsis)
if rv is not Ellipsis:
return rv
rv = self._data[name]
if hasattr(rv, "__get__"):
rv = rv.__get__(self)
self._bound_data[name] = rv
return rv
| 26,225 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Record.__eq__
|
(self, other)
|
return self["_path"] == other["_path"]
| 483 | 488 |
def __eq__(self, other):
if self is other:
return True
if self.__class__ != other.__class__:
return False
return self["_path"] == other["_path"]
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L483-L488
| 40 |
[
0,
1,
3,
4,
5
] | 83.333333 |
[
2
] | 16.666667 | false | 89.992532 | 6 | 3 | 83.333333 | 0 |
def __eq__(self, other):
if self is other:
return True
if self.__class__ != other.__class__:
return False
return self["_path"] == other["_path"]
| 26,226 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Record.__ne__
|
(self, other)
|
return not self.__eq__(other)
| 490 | 491 |
def __ne__(self, other):
return not self.__eq__(other)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L490-L491
| 40 |
[
0
] | 50 |
[
1
] | 50 | false | 89.992532 | 2 | 1 | 50 | 0 |
def __ne__(self, other):
return not self.__eq__(other)
| 26,227 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Record.__hash__
|
(self)
|
return hash(self.path)
| 493 | 494 |
def __hash__(self):
return hash(self.path)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L493-L494
| 40 |
[
0,
1
] | 100 |
[] | 0 | true | 89.992532 | 2 | 1 | 100 | 0 |
def __hash__(self):
return hash(self.path)
| 26,228 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Record.__repr__
|
(self)
|
return "<%s model=%r path=%r%s%s>" % (
self.__class__.__name__,
self["_model"],
self["_path"],
self.alt != PRIMARY_ALT and " alt=%r" % self.alt or "",
self.page_num is not None and " page_num=%r" % self.page_num or "",
)
| 496 | 503 |
def __repr__(self):
return "<%s model=%r path=%r%s%s>" % (
self.__class__.__name__,
self["_model"],
self["_path"],
self.alt != PRIMARY_ALT and " alt=%r" % self.alt or "",
self.page_num is not None and " page_num=%r" % self.page_num or "",
)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L496-L503
| 40 |
[
0,
1
] | 25 |
[] | 0 | false | 89.992532 | 8 | 5 | 100 | 0 |
def __repr__(self):
return "<%s model=%r path=%r%s%s>" % (
self.__class__.__name__,
self["_model"],
self["_path"],
self.alt != PRIMARY_ALT and " alt=%r" % self.alt or "",
self.page_num is not None and " page_num=%r" % self.page_num or "",
)
| 26,229 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Siblings.__init__
|
(self, record, prev_page, next_page)
|
Virtual source representing previous and next sibling of 'record'.
|
Virtual source representing previous and next sibling of 'record'.
| 507 | 512 |
def __init__(self, record, prev_page, next_page):
"""Virtual source representing previous and next sibling of 'record'."""
VirtualSourceObject.__init__(self, record)
self._path = record.path + "@siblings"
self._prev_page = prev_page
self._next_page = next_page
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L507-L512
| 40 |
[
0,
1,
2,
3,
4,
5
] | 100 |
[] | 0 | true | 89.992532 | 6 | 1 | 100 | 1 |
def __init__(self, record, prev_page, next_page):
VirtualSourceObject.__init__(self, record)
self._path = record.path + "@siblings"
self._prev_page = prev_page
self._next_page = next_page
| 26,230 |
|
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Siblings.path
|
(self)
|
return self._path
| 515 | 517 |
def path(self):
# Used as a key in Context.referenced_virtual_dependencies.
return self._path
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L515-L517
| 40 |
[
0,
1,
2
] | 100 |
[] | 0 | true | 89.992532 | 3 | 1 | 100 | 0 |
def path(self):
# Used as a key in Context.referenced_virtual_dependencies.
return self._path
| 26,231 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Siblings.prev_page
|
(self)
|
return self._prev_page
| 520 | 521 |
def prev_page(self):
return self._prev_page
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L520-L521
| 40 |
[
0,
1
] | 100 |
[] | 0 | true | 89.992532 | 2 | 1 | 100 | 0 |
def prev_page(self):
return self._prev_page
| 26,232 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Siblings.next_page
|
(self)
|
return self._next_page
| 524 | 525 |
def next_page(self):
return self._next_page
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L524-L525
| 40 |
[
0,
1
] | 100 |
[] | 0 | true | 89.992532 | 2 | 1 | 100 | 0 |
def next_page(self):
return self._next_page
| 26,233 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Siblings.iter_source_filenames
|
(self)
| 527 | 530 |
def iter_source_filenames(self):
for page in self._prev_page, self._next_page:
if page:
yield page.source_filename
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L527-L530
| 40 |
[
0,
1,
2,
3
] | 100 |
[] | 0 | true | 89.992532 | 4 | 3 | 100 | 0 |
def iter_source_filenames(self):
for page in self._prev_page, self._next_page:
if page:
yield page.source_filename
| 26,234 |
|||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Siblings._file_infos
|
(self, path_cache)
| 532 | 535 |
def _file_infos(self, path_cache):
for page in self._prev_page, self._next_page:
if page:
yield path_cache.get_file_info(page.source_filename)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L532-L535
| 40 |
[
0,
1,
2,
3
] | 100 |
[] | 0 | true | 89.992532 | 4 | 3 | 100 | 0 |
def _file_infos(self, path_cache):
for page in self._prev_page, self._next_page:
if page:
yield path_cache.get_file_info(page.source_filename)
| 26,235 |
|||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Siblings.get_mtime
|
(self, path_cache)
|
return max(mtimes) if mtimes else None
| 537 | 539 |
def get_mtime(self, path_cache):
mtimes = [i.mtime for i in self._file_infos(path_cache)]
return max(mtimes) if mtimes else None
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L537-L539
| 40 |
[
0,
1,
2
] | 100 |
[] | 0 | true | 89.992532 | 3 | 2 | 100 | 0 |
def get_mtime(self, path_cache):
mtimes = [i.mtime for i in self._file_infos(path_cache)]
return max(mtimes) if mtimes else None
| 26,236 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Siblings.get_checksum
|
(self, path_cache)
|
return sums or None
| 541 | 544 |
def get_checksum(self, path_cache):
sums = "|".join(i.filename_and_checksum for i in self._file_infos(path_cache))
return sums or None
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L541-L544
| 40 |
[
0,
1,
2,
3
] | 100 |
[] | 0 | true | 89.992532 | 4 | 2 | 100 | 0 |
def get_checksum(self, path_cache):
sums = "|".join(i.filename_and_checksum for i in self._file_infos(path_cache))
return sums or None
| 26,237 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Page.path
|
(self)
|
return rv
| 558 | 562 |
def path(self):
rv = self["_path"]
if self.page_num is not None:
rv = "%s@%s" % (rv, self.page_num)
return rv
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L558-L562
| 40 |
[
0,
1,
2,
3,
4
] | 100 |
[] | 0 | true | 89.992532 | 5 | 2 | 100 | 0 |
def path(self):
rv = self["_path"]
if self.page_num is not None:
rv = "%s@%s" % (rv, self.page_num)
return rv
| 26,238 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Page.record
|
(self)
|
return self.pad.get(
self["_path"], persist=self.pad.cache.is_persistent(self), alt=self.alt
)
| 565 | 570 |
def record(self):
if self.page_num is None:
return self
return self.pad.get(
self["_path"], persist=self.pad.cache.is_persistent(self), alt=self.alt
)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L565-L570
| 40 |
[
0,
1,
2,
3
] | 66.666667 |
[] | 0 | false | 89.992532 | 6 | 2 | 100 | 0 |
def record(self):
if self.page_num is None:
return self
return self.pad.get(
self["_path"], persist=self.pad.cache.is_persistent(self), alt=self.alt
)
| 26,239 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Page.source_filename
|
(self)
|
return os.path.join(self.pad.db.to_fs_path(self["_path"]), "contents.lr")
| 573 | 578 |
def source_filename(self):
if self.alt != PRIMARY_ALT:
return os.path.join(
self.pad.db.to_fs_path(self["_path"]), "contents+%s.lr" % self.alt
)
return os.path.join(self.pad.db.to_fs_path(self["_path"]), "contents.lr")
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L573-L578
| 40 |
[
0,
1,
2,
5
] | 66.666667 |
[] | 0 | false | 89.992532 | 6 | 2 | 100 | 0 |
def source_filename(self):
if self.alt != PRIMARY_ALT:
return os.path.join(
self.pad.db.to_fs_path(self["_path"]), "contents+%s.lr" % self.alt
)
return os.path.join(self.pad.db.to_fs_path(self["_path"]), "contents.lr")
| 26,240 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Page.iter_source_filenames
|
(self)
| 580 | 583 |
def iter_source_filenames(self):
yield self.source_filename
if self.alt != PRIMARY_ALT:
yield os.path.join(self.pad.db.to_fs_path(self["_path"]), "contents.lr")
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L580-L583
| 40 |
[
0,
1,
2,
3
] | 100 |
[] | 0 | true | 89.992532 | 4 | 2 | 100 | 0 |
def iter_source_filenames(self):
yield self.source_filename
if self.alt != PRIMARY_ALT:
yield os.path.join(self.pad.db.to_fs_path(self["_path"]), "contents.lr")
| 26,241 |
|||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Page.url_path
|
(self)
|
return f"{path.rstrip('/')}/{pg.url_suffix.strip('/')}/{self.page_num:d}/"
| 586 | 601 |
def url_path(self):
pg = self.datamodel.pagination_config
path = self._get_url_path(self.alt)
_, _, last_part = path.rpartition("/")
if not pg.enabled:
if "." in last_part:
return path
return path.rstrip("/") + "/"
if "." in last_part:
raise RuntimeError(
"When file extension is provided pagination cannot be used."
)
# pagination is enabled
if self.page_num in (1, None):
return path.rstrip("/") + "/"
return f"{path.rstrip('/')}/{pg.url_suffix.strip('/')}/{self.page_num:d}/"
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L586-L601
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
12,
13,
14,
15
] | 87.5 |
[] | 0 | false | 89.992532 | 16 | 5 | 100 | 0 |
def url_path(self):
pg = self.datamodel.pagination_config
path = self._get_url_path(self.alt)
_, _, last_part = path.rpartition("/")
if not pg.enabled:
if "." in last_part:
return path
return path.rstrip("/") + "/"
if "." in last_part:
raise RuntimeError(
"When file extension is provided pagination cannot be used."
)
# pagination is enabled
if self.page_num in (1, None):
return path.rstrip("/") + "/"
return f"{path.rstrip('/')}/{pg.url_suffix.strip('/')}/{self.page_num:d}/"
| 26,242 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Page.resolve_url_path
|
(self, url_path)
|
return None
| 603 | 658 |
def resolve_url_path(self, url_path):
pg = self.datamodel.pagination_config
# If we hit the end of the url path, then we found our target.
# However if pagination is enabled we want to resolve the first
# page instead of the unpaginated version.
if not url_path:
if pg.enabled and self.page_num is None:
return pg.get_record_for_page(self, 1)
return self
# Try to resolve the correctly paginated version here.
if pg.enabled:
rv = pg.match_pagination(self, url_path)
if rv is not None:
return rv
# When we resolve URLs we also want to be able to explicitly
# target undiscoverable pages. Those who know the URL are
# rewarded.
# We also want to resolve hidden children
# here. Pad.resolve_url_path() is where the check for hidden
# records is done.
q = self.children.include_undiscoverable(True).include_hidden(True)
for idx in range(len(url_path)):
piece = "/".join(url_path[: idx + 1])
child = q.filter(F._slug == piece).first()
if child is None:
attachment = self.attachments.filter(F._slug == piece).first()
if attachment is None:
obj = self.pad.db.env.resolve_custom_url_path(self, url_path)
if obj is None:
continue
node = obj
else:
node = attachment
else:
node = child
rv = node.resolve_url_path(url_path[idx + 1 :])
if rv is not None:
return rv
if len(url_path) == 1 and url_path[0] == "index.html":
if pg.enabled or "." not in self["_slug"]:
# This page renders to an index.html. Its .url_path method returns
# a path ending with '/'. Accept explicit "/index.html" when resolving.
#
# FIXME: the code for Record (and subclass) .url_path and .resolve_url
# could use some cleanup, especially where it deals with
# slugs that contain '.'s.
return self
return None
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L603-L658
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29,
30,
31,
32,
33,
34,
37,
39,
40,
41,
42,
43,
44,
45,
46,
47,
48,
49,
50,
51,
52,
53,
54,
55
] | 94.642857 |
[
35
] | 1.785714 | false | 89.992532 | 56 | 15 | 98.214286 | 0 |
def resolve_url_path(self, url_path):
pg = self.datamodel.pagination_config
# If we hit the end of the url path, then we found our target.
# However if pagination is enabled we want to resolve the first
# page instead of the unpaginated version.
if not url_path:
if pg.enabled and self.page_num is None:
return pg.get_record_for_page(self, 1)
return self
# Try to resolve the correctly paginated version here.
if pg.enabled:
rv = pg.match_pagination(self, url_path)
if rv is not None:
return rv
# When we resolve URLs we also want to be able to explicitly
# target undiscoverable pages. Those who know the URL are
# rewarded.
# We also want to resolve hidden children
# here. Pad.resolve_url_path() is where the check for hidden
# records is done.
q = self.children.include_undiscoverable(True).include_hidden(True)
for idx in range(len(url_path)):
piece = "/".join(url_path[: idx + 1])
child = q.filter(F._slug == piece).first()
if child is None:
attachment = self.attachments.filter(F._slug == piece).first()
if attachment is None:
obj = self.pad.db.env.resolve_custom_url_path(self, url_path)
if obj is None:
continue
node = obj
else:
node = attachment
else:
node = child
rv = node.resolve_url_path(url_path[idx + 1 :])
if rv is not None:
return rv
if len(url_path) == 1 and url_path[0] == "index.html":
if pg.enabled or "." not in self["_slug"]:
# This page renders to an index.html. Its .url_path method returns
# a path ending with '/'. Accept explicit "/index.html" when resolving.
#
# FIXME: the code for Record (and subclass) .url_path and .resolve_url
# could use some cleanup, especially where it deals with
# slugs that contain '.'s.
return self
return None
| 26,243 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Page.parent
|
(self)
|
return None
|
The parent of the record.
|
The parent of the record.
| 661 | 669 |
def parent(self):
"""The parent of the record."""
this_path = self._data["_path"]
parent_path = posixpath.dirname(this_path)
if parent_path != this_path:
return self.pad.get(
parent_path, persist=self.pad.cache.is_persistent(self), alt=self.alt
)
return None
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L661-L669
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8
] | 100 |
[] | 0 | true | 89.992532 | 9 | 2 | 100 | 1 |
def parent(self):
this_path = self._data["_path"]
parent_path = posixpath.dirname(this_path)
if parent_path != this_path:
return self.pad.get(
parent_path, persist=self.pad.cache.is_persistent(self), alt=self.alt
)
return None
| 26,244 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Page.children
|
(self)
|
return Query(path=self["_path"], pad=self.pad, alt=self.alt)
|
A query over all children that are not hidden or undiscoverable.
want undiscoverable then use ``children.include_undiscoverable(True)``.
|
A query over all children that are not hidden or undiscoverable.
want undiscoverable then use ``children.include_undiscoverable(True)``.
| 672 | 679 |
def children(self):
"""A query over all children that are not hidden or undiscoverable.
want undiscoverable then use ``children.include_undiscoverable(True)``.
"""
repl_query = self.datamodel.get_child_replacements(self)
if repl_query is not None:
return repl_query.include_undiscoverable(False)
return Query(path=self["_path"], pad=self.pad, alt=self.alt)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L672-L679
| 40 |
[
0,
1,
2,
3,
4,
5,
7
] | 87.5 |
[
6
] | 12.5 | false | 89.992532 | 8 | 2 | 87.5 | 2 |
def children(self):
repl_query = self.datamodel.get_child_replacements(self)
if repl_query is not None:
return repl_query.include_undiscoverable(False)
return Query(path=self["_path"], pad=self.pad, alt=self.alt)
| 26,245 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Page.attachments
|
(self)
|
return AttachmentsQuery(path=self["_path"], pad=self.pad, alt=self.alt)
|
Returns a query for the attachments of this record.
|
Returns a query for the attachments of this record.
| 682 | 684 |
def attachments(self):
"""Returns a query for the attachments of this record."""
return AttachmentsQuery(path=self["_path"], pad=self.pad, alt=self.alt)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L682-L684
| 40 |
[
0,
1,
2
] | 100 |
[] | 0 | true | 89.992532 | 3 | 1 | 100 | 1 |
def attachments(self):
return AttachmentsQuery(path=self["_path"], pad=self.pad, alt=self.alt)
| 26,246 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Page.has_prev
|
(self)
|
return self.get_siblings().prev_page is not None
| 686 | 687 |
def has_prev(self):
return self.get_siblings().prev_page is not None
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L686-L687
| 40 |
[
0
] | 50 |
[
1
] | 50 | false | 89.992532 | 2 | 1 | 50 | 0 |
def has_prev(self):
return self.get_siblings().prev_page is not None
| 26,247 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Page.has_next
|
(self)
|
return self.get_siblings().next_page is not None
| 689 | 690 |
def has_next(self):
return self.get_siblings().next_page is not None
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L689-L690
| 40 |
[
0
] | 50 |
[
1
] | 50 | false | 89.992532 | 2 | 1 | 50 | 0 |
def has_next(self):
return self.get_siblings().next_page is not None
| 26,248 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Page.get_siblings
|
(self)
|
return siblings
|
The next and previous children of this page's parent.
Uses parent's pagination query, if any, else parent's "children" config.
|
The next and previous children of this page's parent.
| 692 | 701 |
def get_siblings(self):
"""The next and previous children of this page's parent.
Uses parent's pagination query, if any, else parent's "children" config.
"""
siblings = Siblings(self, *self._siblings)
ctx = get_ctx()
if ctx:
ctx.pad.db.track_record_dependency(siblings)
return siblings
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L692-L701
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9
] | 100 |
[] | 0 | true | 89.992532 | 10 | 2 | 100 | 3 |
def get_siblings(self):
siblings = Siblings(self, *self._siblings)
ctx = get_ctx()
if ctx:
ctx.pad.db.track_record_dependency(siblings)
return siblings
| 26,249 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Page._siblings
|
(self)
|
return prev_item, next_item
| 704 | 729 |
def _siblings(self):
parent = self.parent
pagination_enabled = parent.datamodel.pagination_config.enabled
# Don't track dependencies for this part.
with Context(pad=self.pad):
if pagination_enabled:
pagination = parent.pagination
siblings = list(pagination.config.get_pagination_query(parent))
else:
siblings = list(parent.children)
prev_item, next_item = None, None
try:
me = siblings.index(self)
except ValueError:
# Self not in parents.children or not in parents.pagination.
pass
else:
if me > 0:
prev_item = siblings[me - 1]
if me + 1 < len(siblings):
next_item = siblings[me + 1]
return prev_item, next_item
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L704-L729
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
10,
11,
12,
13,
14,
19,
20,
21,
22,
23,
24,
25
] | 80.769231 |
[
15,
17
] | 7.692308 | false | 89.992532 | 26 | 6 | 92.307692 | 0 |
def _siblings(self):
parent = self.parent
pagination_enabled = parent.datamodel.pagination_config.enabled
# Don't track dependencies for this part.
with Context(pad=self.pad):
if pagination_enabled:
pagination = parent.pagination
siblings = list(pagination.config.get_pagination_query(parent))
else:
siblings = list(parent.children)
prev_item, next_item = None, None
try:
me = siblings.index(self)
except ValueError:
# Self not in parents.children or not in parents.pagination.
pass
else:
if me > 0:
prev_item = siblings[me - 1]
if me + 1 < len(siblings):
next_item = siblings[me + 1]
return prev_item, next_item
| 26,250 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Attachment.source_filename
|
(self)
|
return self.pad.db.to_fs_path(self["_path"]) + suffix
| 738 | 743 |
def source_filename(self):
if self.alt != PRIMARY_ALT:
suffix = "+%s.lr" % self.alt
else:
suffix = ".lr"
return self.pad.db.to_fs_path(self["_path"]) + suffix
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L738-L743
| 40 |
[
0,
1,
2,
4,
5
] | 83.333333 |
[] | 0 | false | 89.992532 | 6 | 2 | 100 | 0 |
def source_filename(self):
if self.alt != PRIMARY_ALT:
suffix = "+%s.lr" % self.alt
else:
suffix = ".lr"
return self.pad.db.to_fs_path(self["_path"]) + suffix
| 26,251 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Attachment._is_considered_hidden
|
(self)
|
return parent.datamodel.attachment_config.hidden
| 745 | 752 |
def _is_considered_hidden(self):
# Attachments are only considered hidden if they have been
# configured as such. This means that even if a record itself is
# hidden, the attachments by default will not.
parent = self.parent
if parent is None:
return False
return parent.datamodel.attachment_config.hidden
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L745-L752
| 40 |
[
0,
1,
2,
3,
4,
5,
7
] | 87.5 |
[
6
] | 12.5 | false | 89.992532 | 8 | 2 | 87.5 | 0 |
def _is_considered_hidden(self):
# Attachments are only considered hidden if they have been
# configured as such. This means that even if a record itself is
# hidden, the attachments by default will not.
parent = self.parent
if parent is None:
return False
return parent.datamodel.attachment_config.hidden
| 26,252 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Attachment.record
|
(self)
|
return self
| 755 | 756 |
def record(self):
return self
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L755-L756
| 40 |
[
0,
1
] | 100 |
[] | 0 | true | 89.992532 | 2 | 1 | 100 | 0 |
def record(self):
return self
| 26,253 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Attachment.attachment_filename
|
(self)
|
return self.pad.db.to_fs_path(self["_path"])
| 759 | 760 |
def attachment_filename(self):
return self.pad.db.to_fs_path(self["_path"])
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L759-L760
| 40 |
[
0,
1
] | 100 |
[] | 0 | true | 89.992532 | 2 | 1 | 100 | 0 |
def attachment_filename(self):
return self.pad.db.to_fs_path(self["_path"])
| 26,254 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Attachment.parent
|
(self)
|
return self.pad.get(
self._data["_attachment_for"], persist=self.pad.cache.is_persistent(self)
)
|
The associated record for this attachment.
|
The associated record for this attachment.
| 763 | 767 |
def parent(self):
"""The associated record for this attachment."""
return self.pad.get(
self._data["_attachment_for"], persist=self.pad.cache.is_persistent(self)
)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L763-L767
| 40 |
[
0,
1,
2,
3,
4
] | 100 |
[] | 0 | true | 89.992532 | 5 | 1 | 100 | 1 |
def parent(self):
return self.pad.get(
self._data["_attachment_for"], persist=self.pad.cache.is_persistent(self)
)
| 26,255 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Attachment.contents
|
(self)
|
return FileContents(self.attachment_filename)
| 770 | 771 |
def contents(self):
return FileContents(self.attachment_filename)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L770-L771
| 40 |
[
0
] | 50 |
[
1
] | 50 | false | 89.992532 | 2 | 1 | 50 | 0 |
def contents(self):
return FileContents(self.attachment_filename)
| 26,256 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Attachment.get_fallback_record_label
|
(self, lang)
|
return self["_id"]
| 773 | 774 |
def get_fallback_record_label(self, lang):
return self["_id"]
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L773-L774
| 40 |
[
0,
1
] | 100 |
[] | 0 | true | 89.992532 | 2 | 1 | 100 | 0 |
def get_fallback_record_label(self, lang):
return self["_id"]
| 26,257 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Attachment.iter_source_filenames
|
(self)
| 776 | 780 |
def iter_source_filenames(self):
yield self.source_filename
if self.alt != PRIMARY_ALT:
yield self.pad.db.to_fs_path(self["_path"]) + ".lr"
yield self.attachment_filename
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L776-L780
| 40 |
[
0,
1,
2,
3,
4
] | 100 |
[] | 0 | true | 89.992532 | 5 | 2 | 100 | 0 |
def iter_source_filenames(self):
yield self.source_filename
if self.alt != PRIMARY_ALT:
yield self.pad.db.to_fs_path(self["_path"]) + ".lr"
yield self.attachment_filename
| 26,258 |
|||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Attachment.url_path
|
(self)
|
return self._get_url_path(alt=primary_alt)
| 783 | 786 |
def url_path(self):
# Attachments are only emitted for the primary alternative.
primary_alt = self.pad.config.primary_alternative or PRIMARY_ALT
return self._get_url_path(alt=primary_alt)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L783-L786
| 40 |
[
0,
1,
2,
3
] | 100 |
[] | 0 | true | 89.992532 | 4 | 2 | 100 | 0 |
def url_path(self):
# Attachments are only emitted for the primary alternative.
primary_alt = self.pad.config.primary_alternative or PRIMARY_ALT
return self._get_url_path(alt=primary_alt)
| 26,259 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Image.__init__
|
(self, pad, data, page_num=None)
| 792 | 795 |
def __init__(self, pad, data, page_num=None):
Attachment.__init__(self, pad, data, page_num)
self._image_info = None
self._exif_cache = None
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L792-L795
| 40 |
[
0,
1,
2,
3
] | 100 |
[] | 0 | true | 89.992532 | 4 | 1 | 100 | 0 |
def __init__(self, pad, data, page_num=None):
Attachment.__init__(self, pad, data, page_num)
self._image_info = None
self._exif_cache = None
| 26,260 |
|||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Image._get_image_info
|
(self)
|
return self._image_info
| 797 | 801 |
def _get_image_info(self):
if self._image_info is None:
with open(self.attachment_filename, "rb") as f:
self._image_info = get_image_info(f)
return self._image_info
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L797-L801
| 40 |
[
0,
1,
2,
3,
4
] | 100 |
[] | 0 | true | 89.992532 | 5 | 3 | 100 | 0 |
def _get_image_info(self):
if self._image_info is None:
with open(self.attachment_filename, "rb") as f:
self._image_info = get_image_info(f)
return self._image_info
| 26,261 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Image.exif
|
(self)
|
return self._exif_cache
|
Provides access to the exif data.
|
Provides access to the exif data.
| 804 | 809 |
def exif(self):
"""Provides access to the exif data."""
if self._exif_cache is None:
with open(self.attachment_filename, "rb") as f:
self._exif_cache = read_exif(f)
return self._exif_cache
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L804-L809
| 40 |
[
0,
1,
2,
3,
4,
5
] | 100 |
[] | 0 | true | 89.992532 | 6 | 3 | 100 | 1 |
def exif(self):
if self._exif_cache is None:
with open(self.attachment_filename, "rb") as f:
self._exif_cache = read_exif(f)
return self._exif_cache
| 26,262 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Image.width
|
(self)
|
return Undefined("Width of image could not be determined.")
|
The width of the image if possible to determine.
|
The width of the image if possible to determine.
| 812 | 817 |
def width(self):
"""The width of the image if possible to determine."""
rv = self._get_image_info()[1]
if rv is not None:
return rv
return Undefined("Width of image could not be determined.")
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L812-L817
| 40 |
[
0,
1,
2,
3,
4
] | 83.333333 |
[
5
] | 16.666667 | false | 89.992532 | 6 | 2 | 83.333333 | 1 |
def width(self):
rv = self._get_image_info()[1]
if rv is not None:
return rv
return Undefined("Width of image could not be determined.")
| 26,263 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Image.height
|
(self)
|
return Undefined("Height of image could not be determined.")
|
The height of the image if possible to determine.
|
The height of the image if possible to determine.
| 820 | 825 |
def height(self):
"""The height of the image if possible to determine."""
rv = self._get_image_info()[2]
if rv is not None:
return rv
return Undefined("Height of image could not be determined.")
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L820-L825
| 40 |
[
0,
1,
2,
3,
4
] | 83.333333 |
[
5
] | 16.666667 | false | 89.992532 | 6 | 2 | 83.333333 | 1 |
def height(self):
rv = self._get_image_info()[2]
if rv is not None:
return rv
return Undefined("Height of image could not be determined.")
| 26,264 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Image.format
|
(self)
|
return Undefined("The format of the image could not be determined.")
|
Returns the format of the image.
|
Returns the format of the image.
| 828 | 833 |
def format(self):
"""Returns the format of the image."""
rv = self._get_image_info()[0]
if rv is not None:
return rv
return Undefined("The format of the image could not be determined.")
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L828-L833
| 40 |
[
0,
1,
2,
3,
4
] | 83.333333 |
[
5
] | 16.666667 | false | 89.992532 | 6 | 2 | 83.333333 | 1 |
def format(self):
rv = self._get_image_info()[0]
if rv is not None:
return rv
return Undefined("The format of the image could not be determined.")
| 26,265 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Image.thumbnail
|
(self, width=None, height=None, mode=None, upscale=None, quality=None)
|
return make_image_thumbnail(
_require_ctx(self),
self.attachment_filename,
self.url_path,
width=width,
height=height,
mode=mode,
upscale=upscale,
quality=quality,
)
|
Utility to create thumbnails.
|
Utility to create thumbnails.
| 835 | 857 |
def thumbnail(self, width=None, height=None, mode=None, upscale=None, quality=None):
"""Utility to create thumbnails."""
if mode is None:
mode = ThumbnailMode.DEFAULT
else:
mode = ThumbnailMode(mode)
if width is not None:
width = int(width)
if height is not None:
height = int(height)
return make_image_thumbnail(
_require_ctx(self),
self.attachment_filename,
self.url_path,
width=width,
height=height,
mode=mode,
upscale=upscale,
quality=quality,
)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L835-L857
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22
] | 100 |
[] | 0 | true | 89.992532 | 23 | 4 | 100 | 1 |
def thumbnail(self, width=None, height=None, mode=None, upscale=None, quality=None):
if mode is None:
mode = ThumbnailMode.DEFAULT
else:
mode = ThumbnailMode(mode)
if width is not None:
width = int(width)
if height is not None:
height = int(height)
return make_image_thumbnail(
_require_ctx(self),
self.attachment_filename,
self.url_path,
width=width,
height=height,
mode=mode,
upscale=upscale,
quality=quality,
)
| 26,266 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Video.__init__
|
(self, pad, data, page_num=None)
| 879 | 881 |
def __init__(self, pad, data, page_num=None):
Attachment.__init__(self, pad, data, page_num)
self._video_info = None
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L879-L881
| 40 |
[
0,
1,
2
] | 100 |
[] | 0 | true | 89.992532 | 3 | 1 | 100 | 0 |
def __init__(self, pad, data, page_num=None):
Attachment.__init__(self, pad, data, page_num)
self._video_info = None
| 26,267 |
|||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Video._get_video_info
|
(self)
|
return self._video_info
| 883 | 890 |
def _get_video_info(self):
if self._video_info is None:
try:
self._video_info = get_video_info(self.attachment_filename)
except RuntimeError:
# A falsy value ensures we don't retry this video again
self._video_info = False
return self._video_info
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L883-L890
| 40 |
[
0,
1,
2,
3,
7
] | 62.5 |
[
4,
6
] | 25 | false | 89.992532 | 8 | 3 | 75 | 0 |
def _get_video_info(self):
if self._video_info is None:
try:
self._video_info = get_video_info(self.attachment_filename)
except RuntimeError:
# A falsy value ensures we don't retry this video again
self._video_info = False
return self._video_info
| 26,268 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Video.width
|
(self)
|
return Undefined("The width of the video could not be determined.")
|
Returns the width of the video if possible to determine.
|
Returns the width of the video if possible to determine.
| 894 | 899 |
def width(self):
"""Returns the width of the video if possible to determine."""
rv = self._get_video_info()
if rv:
return rv["width"]
return Undefined("The width of the video could not be determined.")
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L894-L899
| 40 |
[
0,
1,
2,
3,
4
] | 83.333333 |
[
5
] | 16.666667 | false | 89.992532 | 6 | 2 | 83.333333 | 1 |
def width(self):
rv = self._get_video_info()
if rv:
return rv["width"]
return Undefined("The width of the video could not be determined.")
| 26,269 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Video.height
|
(self)
|
return Undefined("The height of the video could not be determined.")
|
Returns the height of the video if possible to determine.
|
Returns the height of the video if possible to determine.
| 903 | 908 |
def height(self):
"""Returns the height of the video if possible to determine."""
rv = self._get_video_info()
if rv:
return rv["height"]
return Undefined("The height of the video could not be determined.")
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L903-L908
| 40 |
[
0,
1,
2,
3,
4
] | 83.333333 |
[
5
] | 16.666667 | false | 89.992532 | 6 | 2 | 83.333333 | 1 |
def height(self):
rv = self._get_video_info()
if rv:
return rv["height"]
return Undefined("The height of the video could not be determined.")
| 26,270 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Video.duration
|
(self)
|
return Undefined("The duration of the video could not be determined.")
|
Returns the duration of the video if possible to determine.
|
Returns the duration of the video if possible to determine.
| 912 | 917 |
def duration(self):
"""Returns the duration of the video if possible to determine."""
rv = self._get_video_info()
if rv:
return rv["duration"]
return Undefined("The duration of the video could not be determined.")
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L912-L917
| 40 |
[
0,
1,
2,
3,
4
] | 83.333333 |
[
5
] | 16.666667 | false | 89.992532 | 6 | 2 | 83.333333 | 1 |
def duration(self):
rv = self._get_video_info()
if rv:
return rv["duration"]
return Undefined("The duration of the video could not be determined.")
| 26,271 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Video.frame
|
(self, seek=None)
|
return VideoFrame(self, seek)
|
Returns a VideoFrame object that is thumbnailable like an Image.
|
Returns a VideoFrame object that is thumbnailable like an Image.
| 920 | 928 |
def frame(self, seek=None):
"""Returns a VideoFrame object that is thumbnailable like an Image."""
rv = self._get_video_info()
if not rv:
return Undefined("Unable to get video properties.")
if seek is None:
seek = rv["duration"] / 2
return VideoFrame(self, seek)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L920-L928
| 40 |
[
0,
1,
2,
3,
5,
6,
7,
8
] | 88.888889 |
[
4
] | 11.111111 | false | 89.992532 | 9 | 3 | 88.888889 | 1 |
def frame(self, seek=None):
rv = self._get_video_info()
if not rv:
return Undefined("Unable to get video properties.")
if seek is None:
seek = rv["duration"] / 2
return VideoFrame(self, seek)
| 26,272 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
VideoFrame.__init__
|
(self, video, seek)
| 938 | 949 |
def __init__(self, video, seek):
self.video = video
if not isinstance(seek, timedelta):
seek = timedelta(seconds=seek)
if seek < timedelta(0):
raise ValueError("Seek distance must not be negative")
if video.duration and seek > video.duration:
raise ValueError("Seek distance must not be outside the video duration")
self.seek = seek
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L938-L949
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
8,
10,
11
] | 83.333333 |
[
7,
9
] | 16.666667 | false | 89.992532 | 12 | 5 | 83.333333 | 0 |
def __init__(self, video, seek):
self.video = video
if not isinstance(seek, timedelta):
seek = timedelta(seconds=seek)
if seek < timedelta(0):
raise ValueError("Seek distance must not be negative")
if video.duration and seek > video.duration:
raise ValueError("Seek distance must not be outside the video duration")
self.seek = seek
| 26,273 |
|||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
VideoFrame.thumbnail
|
(self, width=None, height=None, mode=None, upscale=None, quality=None)
|
return make_video_thumbnail(
_require_ctx(video),
video.attachment_filename,
video.url_path,
seek=self.seek,
width=width,
height=height,
mode=mode,
upscale=upscale,
quality=quality,
)
|
Utility to create thumbnails.
|
Utility to create thumbnails.
| 960 | 978 |
def thumbnail(self, width=None, height=None, mode=None, upscale=None, quality=None):
"""Utility to create thumbnails."""
if mode is None:
mode = ThumbnailMode.DEFAULT
else:
mode = ThumbnailMode(mode)
video = self.video
return make_video_thumbnail(
_require_ctx(video),
video.attachment_filename,
video.url_path,
seek=self.seek,
width=width,
height=height,
mode=mode,
upscale=upscale,
quality=quality,
)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L960-L978
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18
] | 100 |
[] | 0 | true | 89.992532 | 19 | 2 | 100 | 1 |
def thumbnail(self, width=None, height=None, mode=None, upscale=None, quality=None):
if mode is None:
mode = ThumbnailMode.DEFAULT
else:
mode = ThumbnailMode(mode)
video = self.video
return make_video_thumbnail(
_require_ctx(video),
video.attachment_filename,
video.url_path,
seek=self.seek,
width=width,
height=height,
mode=mode,
upscale=upscale,
quality=quality,
)
| 26,274 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Query.__init__
|
(self, path, pad, alt=PRIMARY_ALT)
| 992 | 1,006 |
def __init__(self, path, pad, alt=PRIMARY_ALT):
self.path = path
self.pad = pad
self.alt = alt
self._include_pages = True
self._include_attachments = False
self._order_by = None
self._filters = None
self._pristine = True
self._limit = None
self._offset = None
self._include_hidden = None
self._include_undiscoverable = False
self._page_num = None
self._filter_func = None
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L992-L1006
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14
] | 100 |
[] | 0 | true | 89.992532 | 15 | 1 | 100 | 0 |
def __init__(self, path, pad, alt=PRIMARY_ALT):
self.path = path
self.pad = pad
self.alt = alt
self._include_pages = True
self._include_attachments = False
self._order_by = None
self._filters = None
self._pristine = True
self._limit = None
self._offset = None
self._include_hidden = None
self._include_undiscoverable = False
self._page_num = None
self._filter_func = None
| 26,275 |
|||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Query.self
|
(self)
|
return self.pad.get(self.path, alt=self.alt)
|
Returns the object this query starts out from.
|
Returns the object this query starts out from.
| 1,009 | 1,011 |
def self(self):
"""Returns the object this query starts out from."""
return self.pad.get(self.path, alt=self.alt)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1009-L1011
| 40 |
[
0,
1
] | 66.666667 |
[
2
] | 33.333333 | false | 89.992532 | 3 | 1 | 66.666667 | 1 |
def self(self):
return self.pad.get(self.path, alt=self.alt)
| 26,276 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Query._clone
|
(self, mark_dirty=False)
|
return rv
|
Makes a flat copy but keeps the other data on it shared.
|
Makes a flat copy but keeps the other data on it shared.
| 1,013 | 1,019 |
def _clone(self, mark_dirty=False):
"""Makes a flat copy but keeps the other data on it shared."""
rv = object.__new__(self.__class__)
rv.__dict__.update(self.__dict__)
if mark_dirty:
rv._pristine = False
return rv
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1013-L1019
| 40 |
[
0,
1,
2,
3,
4,
5,
6
] | 100 |
[] | 0 | true | 89.992532 | 7 | 2 | 100 | 1 |
def _clone(self, mark_dirty=False):
rv = object.__new__(self.__class__)
rv.__dict__.update(self.__dict__)
if mark_dirty:
rv._pristine = False
return rv
| 26,277 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Query._get
|
(self, id, persist=True, page_num=Ellipsis)
|
return self.pad.get(
"%s/%s" % (self.path, id), persist=persist, alt=self.alt, page_num=page_num
)
|
Low level record access.
|
Low level record access.
| 1,021 | 1,027 |
def _get(self, id, persist=True, page_num=Ellipsis):
"""Low level record access."""
if page_num is Ellipsis:
page_num = self._page_num
return self.pad.get(
"%s/%s" % (self.path, id), persist=persist, alt=self.alt, page_num=page_num
)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1021-L1027
| 40 |
[
0,
1,
2,
3,
4,
5,
6
] | 100 |
[] | 0 | true | 89.992532 | 7 | 2 | 100 | 1 |
def _get(self, id, persist=True, page_num=Ellipsis):
if page_num is Ellipsis:
page_num = self._page_num
return self.pad.get(
"%s/%s" % (self.path, id), persist=persist, alt=self.alt, page_num=page_num
)
| 26,278 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Query._matches
|
(self, record)
|
return True
| 1,029 | 1,039 |
def _matches(self, record):
include_hidden = self._include_hidden
if include_hidden is not None:
if not self._include_hidden and record.is_hidden:
return False
if not self._include_undiscoverable and record.is_undiscoverable:
return False
for filter in self._filters or ():
if not save_eval(filter, record):
return False
return True
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1029-L1039
| 40 |
[
0,
1,
2,
3,
5,
6,
7,
8,
9,
10
] | 90.909091 |
[
4
] | 9.090909 | false | 89.992532 | 11 | 9 | 90.909091 | 0 |
def _matches(self, record):
include_hidden = self._include_hidden
if include_hidden is not None:
if not self._include_hidden and record.is_hidden:
return False
if not self._include_undiscoverable and record.is_undiscoverable:
return False
for filter in self._filters or ():
if not save_eval(filter, record):
return False
return True
| 26,279 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Query._iterate
|
(self)
|
Low level record iteration.
|
Low level record iteration.
| 1,041 | 1,066 |
def _iterate(self):
"""Low level record iteration."""
# If we iterate over children we also need to track those
# dependencies. There are two ways in which we track them. The
# first is through the start record of the query. If that does
# not work for whatever reason (because it does not exist for
# instance).
self_record = self.pad.get(self.path, alt=self.alt)
if self_record is not None:
self.pad.db.track_record_dependency(self_record)
# We also always want to record the path itself as dependency.
ctx = get_ctx()
if ctx is not None:
ctx.record_dependency(self.pad.db.to_fs_path(self.path))
for name, _, is_attachment in self.pad.db.iter_items(self.path, alt=self.alt):
if not (
(is_attachment == self._include_attachments)
or (not is_attachment == self._include_pages)
):
continue
record = self._get(name, persist=False)
if self._matches(record):
yield record
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1041-L1066
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25
] | 100 |
[] | 0 | true | 89.992532 | 26 | 7 | 100 | 1 |
def _iterate(self):
# If we iterate over children we also need to track those
# dependencies. There are two ways in which we track them. The
# first is through the start record of the query. If that does
# not work for whatever reason (because it does not exist for
# instance).
self_record = self.pad.get(self.path, alt=self.alt)
if self_record is not None:
self.pad.db.track_record_dependency(self_record)
# We also always want to record the path itself as dependency.
ctx = get_ctx()
if ctx is not None:
ctx.record_dependency(self.pad.db.to_fs_path(self.path))
for name, _, is_attachment in self.pad.db.iter_items(self.path, alt=self.alt):
if not (
(is_attachment == self._include_attachments)
or (not is_attachment == self._include_pages)
):
continue
record = self._get(name, persist=False)
if self._matches(record):
yield record
| 26,280 |
|
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Query.filter
|
(self, expr)
|
return rv
|
Filters records by an expression.
|
Filters records by an expression.
| 1,068 | 1,075 |
def filter(self, expr):
"""Filters records by an expression."""
rv = self._clone(mark_dirty=True)
rv._filters = list(self._filters or ())
if callable(expr):
expr = _CallbackExpr(expr)
rv._filters.append(expr)
return rv
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1068-L1075
| 40 |
[
0,
1,
2,
3,
4,
6,
7
] | 87.5 |
[
5
] | 12.5 | false | 89.992532 | 8 | 3 | 87.5 | 1 |
def filter(self, expr):
rv = self._clone(mark_dirty=True)
rv._filters = list(self._filters or ())
if callable(expr):
expr = _CallbackExpr(expr)
rv._filters.append(expr)
return rv
| 26,281 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Query.get_order_by
|
(self)
|
return None
|
Returns the order that should be used.
|
Returns the order that should be used.
| 1,077 | 1,092 |
def get_order_by(self):
"""Returns the order that should be used."""
if self._order_by is not None:
return self._order_by
base_record = self.pad.get(self.path)
if base_record is not None:
if self._include_attachments and not self._include_pages:
return base_record.datamodel.attachment_config.order_by
if self._include_pages and not self._include_attachments:
return base_record.datamodel.child_config.order_by
# Otherwise the query includes either both or neither
# attachments and/nor children. I have no idea which
# value of order_by to use. We could punt and return
# child_config.order_by, but for now, just return None.
return None
return None
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1077-L1092
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
15
] | 93.75 |
[
14
] | 6.25 | false | 89.992532 | 16 | 7 | 93.75 | 1 |
def get_order_by(self):
if self._order_by is not None:
return self._order_by
base_record = self.pad.get(self.path)
if base_record is not None:
if self._include_attachments and not self._include_pages:
return base_record.datamodel.attachment_config.order_by
if self._include_pages and not self._include_attachments:
return base_record.datamodel.child_config.order_by
# Otherwise the query includes either both or neither
# attachments and/nor children. I have no idea which
# value of order_by to use. We could punt and return
# child_config.order_by, but for now, just return None.
return None
return None
| 26,282 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Query.include_hidden
|
(self, value)
|
return rv
|
Controls if hidden records should be included which will not
happen by default for queries to children.
|
Controls if hidden records should be included which will not
happen by default for queries to children.
| 1,094 | 1,100 |
def include_hidden(self, value):
"""Controls if hidden records should be included which will not
happen by default for queries to children.
"""
rv = self._clone(mark_dirty=True)
rv._include_hidden = value
return rv
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1094-L1100
| 40 |
[
0,
1,
2,
3,
4,
5,
6
] | 100 |
[] | 0 | true | 89.992532 | 7 | 1 | 100 | 2 |
def include_hidden(self, value):
rv = self._clone(mark_dirty=True)
rv._include_hidden = value
return rv
| 26,283 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Query.include_undiscoverable
|
(self, value)
|
return rv
|
Controls if undiscoverable records should be included as well.
|
Controls if undiscoverable records should be included as well.
| 1,102 | 1,113 |
def include_undiscoverable(self, value):
"""Controls if undiscoverable records should be included as well."""
rv = self._clone(mark_dirty=True)
rv._include_undiscoverable = value
# If we flip from not including undiscoverables to discoverables
# but we did not yet decide on the value of _include_hidden it
# becomes False to not include it.
if rv._include_hidden is None and value:
rv._include_hidden = False
return rv
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1102-L1113
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11
] | 100 |
[] | 0 | true | 89.992532 | 12 | 3 | 100 | 1 |
def include_undiscoverable(self, value):
rv = self._clone(mark_dirty=True)
rv._include_undiscoverable = value
# If we flip from not including undiscoverables to discoverables
# but we did not yet decide on the value of _include_hidden it
# becomes False to not include it.
if rv._include_hidden is None and value:
rv._include_hidden = False
return rv
| 26,284 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Query.request_page
|
(self, page_num)
|
return rv
|
Requests a specific page number instead of the first.
|
Requests a specific page number instead of the first.
| 1,115 | 1,119 |
def request_page(self, page_num):
"""Requests a specific page number instead of the first."""
rv = self._clone(mark_dirty=True)
rv._page_num = page_num
return rv
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1115-L1119
| 40 |
[
0,
1
] | 40 |
[
2,
3,
4
] | 60 | false | 89.992532 | 5 | 1 | 40 | 1 |
def request_page(self, page_num):
rv = self._clone(mark_dirty=True)
rv._page_num = page_num
return rv
| 26,285 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Query.first
|
(self)
|
return next(iter(self), None)
|
Return the first matching record.
|
Return the first matching record.
| 1,121 | 1,123 |
def first(self):
"""Return the first matching record."""
return next(iter(self), None)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1121-L1123
| 40 |
[
0,
1,
2
] | 100 |
[] | 0 | true | 89.992532 | 3 | 1 | 100 | 1 |
def first(self):
return next(iter(self), None)
| 26,286 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Query.all
|
(self)
|
return list(self)
|
Loads all matching records as list.
|
Loads all matching records as list.
| 1,125 | 1,127 |
def all(self):
"""Loads all matching records as list."""
return list(self)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1125-L1127
| 40 |
[
0,
1,
2
] | 100 |
[] | 0 | true | 89.992532 | 3 | 1 | 100 | 1 |
def all(self):
return list(self)
| 26,287 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Query.order_by
|
(self, *fields)
|
return rv
|
Sets the ordering of the query.
|
Sets the ordering of the query.
| 1,129 | 1,133 |
def order_by(self, *fields):
"""Sets the ordering of the query."""
rv = self._clone()
rv._order_by = fields or None
return rv
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1129-L1133
| 40 |
[
0,
1,
2,
3,
4
] | 100 |
[] | 0 | true | 89.992532 | 5 | 2 | 100 | 1 |
def order_by(self, *fields):
rv = self._clone()
rv._order_by = fields or None
return rv
| 26,288 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Query.offset
|
(self, offset)
|
return rv
|
Sets the ordering of the query.
|
Sets the ordering of the query.
| 1,135 | 1,139 |
def offset(self, offset):
"""Sets the ordering of the query."""
rv = self._clone(mark_dirty=True)
rv._offset = offset
return rv
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1135-L1139
| 40 |
[
0,
1,
2,
3,
4
] | 100 |
[] | 0 | true | 89.992532 | 5 | 1 | 100 | 1 |
def offset(self, offset):
rv = self._clone(mark_dirty=True)
rv._offset = offset
return rv
| 26,289 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Query.limit
|
(self, limit)
|
return rv
|
Sets the ordering of the query.
|
Sets the ordering of the query.
| 1,141 | 1,145 |
def limit(self, limit):
"""Sets the ordering of the query."""
rv = self._clone(mark_dirty=True)
rv._limit = limit
return rv
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1141-L1145
| 40 |
[
0,
1,
2,
3,
4
] | 100 |
[] | 0 | true | 89.992532 | 5 | 1 | 100 | 1 |
def limit(self, limit):
rv = self._clone(mark_dirty=True)
rv._limit = limit
return rv
| 26,290 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Query.count
|
(self)
|
return rv
|
Counts all matched objects.
|
Counts all matched objects.
| 1,147 | 1,152 |
def count(self):
"""Counts all matched objects."""
rv = 0
for _ in self:
rv += 1
return rv
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1147-L1152
| 40 |
[
0,
1,
2,
3,
4,
5
] | 100 |
[] | 0 | true | 89.992532 | 6 | 2 | 100 | 1 |
def count(self):
rv = 0
for _ in self:
rv += 1
return rv
| 26,291 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Query.distinct
|
(self, fieldname)
|
return rv
|
Set of unique values for the given field.
|
Set of unique values for the given field.
| 1,154 | 1,166 |
def distinct(self, fieldname):
"""Set of unique values for the given field."""
rv = set()
for item in self:
if fieldname in item._data:
value = item._data[fieldname]
if isinstance(value, (list, tuple)):
rv |= set(value)
elif not isinstance(value, Undefined):
rv.add(value)
return rv
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1154-L1166
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12
] | 100 |
[] | 0 | true | 89.992532 | 13 | 5 | 100 | 1 |
def distinct(self, fieldname):
rv = set()
for item in self:
if fieldname in item._data:
value = item._data[fieldname]
if isinstance(value, (list, tuple)):
rv |= set(value)
elif not isinstance(value, Undefined):
rv.add(value)
return rv
| 26,292 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Query.get
|
(self, id, page_num=Ellipsis)
|
return self._get(id, page_num=page_num)
|
Gets something by the local path.
|
Gets something by the local path.
| 1,168 | 1,177 |
def get(self, id, page_num=Ellipsis):
"""Gets something by the local path."""
# If we're not pristine, we need to query here
if not self._pristine:
q = self.filter(F._id == id)
if page_num is not Ellipsis:
q = q.request_page(page_num)
return q.first()
# otherwise we can load it directly.
return self._get(id, page_num=page_num)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1168-L1177
| 40 |
[
0,
1,
2,
3,
4,
5,
7,
8,
9
] | 90 |
[
6
] | 10 | false | 89.992532 | 10 | 3 | 90 | 1 |
def get(self, id, page_num=Ellipsis):
# If we're not pristine, we need to query here
if not self._pristine:
q = self.filter(F._id == id)
if page_num is not Ellipsis:
q = q.request_page(page_num)
return q.first()
# otherwise we can load it directly.
return self._get(id, page_num=page_num)
| 26,293 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Query.__bool__
|
(self)
|
return self.first() is not None
| 1,179 | 1,180 |
def __bool__(self):
return self.first() is not None
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1179-L1180
| 40 |
[
0
] | 50 |
[
1
] | 50 | false | 89.992532 | 2 | 1 | 50 | 0 |
def __bool__(self):
return self.first() is not None
| 26,294 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Query.__iter__
|
(self)
|
Iterates over all records matched.
|
Iterates over all records matched.
| 1,184 | 1,200 |
def __iter__(self):
"""Iterates over all records matched."""
iterable = self._iterate()
order_by = self.get_order_by()
if order_by:
iterable = sorted(iterable, key=lambda x: x.get_sort_key(order_by))
if self._offset is not None or self._limit is not None:
iterable = islice(
iterable,
self._offset or 0,
(self._offset or 0) + self._limit if self._limit else None,
)
for item in iterable:
yield item
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1184-L1200
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16
] | 100 |
[] | 0 | true | 89.992532 | 17 | 7 | 100 | 1 |
def __iter__(self):
iterable = self._iterate()
order_by = self.get_order_by()
if order_by:
iterable = sorted(iterable, key=lambda x: x.get_sort_key(order_by))
if self._offset is not None or self._limit is not None:
iterable = islice(
iterable,
self._offset or 0,
(self._offset or 0) + self._limit if self._limit else None,
)
for item in iterable:
yield item
| 26,295 |
|
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Query.__repr__
|
(self)
|
return "<%s %r%s>" % (
self.__class__.__name__,
self.path,
self.alt and " alt=%r" % self.alt or "",
)
| 1,202 | 1,207 |
def __repr__(self):
return "<%s %r%s>" % (
self.__class__.__name__,
self.path,
self.alt and " alt=%r" % self.alt or "",
)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1202-L1207
| 40 |
[
0
] | 16.666667 |
[
1
] | 16.666667 | false | 89.992532 | 6 | 3 | 83.333333 | 0 |
def __repr__(self):
return "<%s %r%s>" % (
self.__class__.__name__,
self.path,
self.alt and " alt=%r" % self.alt or "",
)
| 26,296 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
EmptyQuery._iterate
|
(self)
|
return iter(())
|
Low level record iteration.
|
Low level record iteration.
| 1,214 | 1,216 |
def _iterate(self):
"""Low level record iteration."""
return iter(())
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1214-L1216
| 40 |
[
0,
1
] | 66.666667 |
[
2
] | 33.333333 | false | 89.992532 | 3 | 1 | 66.666667 | 1 |
def _iterate(self):
return iter(())
| 26,297 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
AttachmentsQuery.__init__
|
(self, path, pad, alt=PRIMARY_ALT)
| 1,222 | 1,225 |
def __init__(self, path, pad, alt=PRIMARY_ALT):
Query.__init__(self, path, pad, alt=alt)
self._include_pages = False
self._include_attachments = True
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1222-L1225
| 40 |
[
0,
1,
2,
3
] | 100 |
[] | 0 | true | 89.992532 | 4 | 1 | 100 | 0 |
def __init__(self, path, pad, alt=PRIMARY_ALT):
Query.__init__(self, path, pad, alt=alt)
self._include_pages = False
self._include_attachments = True
| 26,298 |
|||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
AttachmentsQuery.images
|
(self)
|
return self.filter(F._attachment_type == "image")
|
Filters to images.
|
Filters to images.
| 1,228 | 1,230 |
def images(self):
"""Filters to images."""
return self.filter(F._attachment_type == "image")
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1228-L1230
| 40 |
[
0,
1,
2
] | 100 |
[] | 0 | true | 89.992532 | 3 | 1 | 100 | 1 |
def images(self):
return self.filter(F._attachment_type == "image")
| 26,299 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
AttachmentsQuery.videos
|
(self)
|
return self.filter(F._attachment_type == "video")
|
Filters to videos.
|
Filters to videos.
| 1,233 | 1,235 |
def videos(self):
"""Filters to videos."""
return self.filter(F._attachment_type == "video")
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1233-L1235
| 40 |
[
0,
1,
2
] | 100 |
[] | 0 | true | 89.992532 | 3 | 1 | 100 | 1 |
def videos(self):
return self.filter(F._attachment_type == "video")
| 26,300 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
AttachmentsQuery.audio
|
(self)
|
return self.filter(F._attachment_type == "audio")
|
Filters to audio.
|
Filters to audio.
| 1,238 | 1,240 |
def audio(self):
"""Filters to audio."""
return self.filter(F._attachment_type == "audio")
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1238-L1240
| 40 |
[
0,
1
] | 66.666667 |
[
2
] | 33.333333 | false | 89.992532 | 3 | 1 | 66.666667 | 1 |
def audio(self):
return self.filter(F._attachment_type == "audio")
| 26,301 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
AttachmentsQuery.documents
|
(self)
|
return self.filter(F._attachment_type == "document")
|
Filters to documents.
|
Filters to documents.
| 1,243 | 1,245 |
def documents(self):
"""Filters to documents."""
return self.filter(F._attachment_type == "document")
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1243-L1245
| 40 |
[
0,
1
] | 66.666667 |
[
2
] | 33.333333 | false | 89.992532 | 3 | 1 | 66.666667 | 1 |
def documents(self):
return self.filter(F._attachment_type == "document")
| 26,302 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
AttachmentsQuery.text
|
(self)
|
return self.filter(F._attachment_type == "text")
|
Filters to plain text data.
|
Filters to plain text data.
| 1,248 | 1,250 |
def text(self):
"""Filters to plain text data."""
return self.filter(F._attachment_type == "text")
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1248-L1250
| 40 |
[
0,
1
] | 66.666667 |
[
2
] | 33.333333 | false | 89.992532 | 3 | 1 | 66.666667 | 1 |
def text(self):
return self.filter(F._attachment_type == "text")
| 26,303 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Database.__init__
|
(self, env, config=None)
| 1,314 | 1,320 |
def __init__(self, env, config=None):
self.env = env
if config is None:
config = env.load_config()
self.config = config
self.datamodels = load_datamodels(env)
self.flowblocks = load_flowblocks(env)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1314-L1320
| 40 |
[
0,
1,
2,
3,
4,
5,
6
] | 100 |
[] | 0 | true | 89.992532 | 7 | 2 | 100 | 0 |
def __init__(self, env, config=None):
self.env = env
if config is None:
config = env.load_config()
self.config = config
self.datamodels = load_datamodels(env)
self.flowblocks = load_flowblocks(env)
| 26,304 |
|||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Database.to_fs_path
|
(self, path)
|
return os.path.join(self.env.root_path, "content", untrusted_to_os_path(path))
|
Convenience function to convert a path into an file system path.
|
Convenience function to convert a path into an file system path.
| 1,322 | 1,324 |
def to_fs_path(self, path):
"""Convenience function to convert a path into an file system path."""
return os.path.join(self.env.root_path, "content", untrusted_to_os_path(path))
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1322-L1324
| 40 |
[
0,
1,
2
] | 100 |
[] | 0 | true | 89.992532 | 3 | 1 | 100 | 1 |
def to_fs_path(self, path):
return os.path.join(self.env.root_path, "content", untrusted_to_os_path(path))
| 26,305 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Database.load_raw_data
|
(self, path, alt=PRIMARY_ALT, cls=None, fallback=True)
|
return rv
|
Internal helper that loads the raw record data. This performs
very little data processing on the data.
|
Internal helper that loads the raw record data. This performs
very little data processing on the data.
| 1,326 | 1,380 |
def load_raw_data(self, path, alt=PRIMARY_ALT, cls=None, fallback=True):
"""Internal helper that loads the raw record data. This performs
very little data processing on the data.
"""
path = cleanup_path(path)
if cls is None:
cls = dict
fn_base = self.to_fs_path(path)
rv = cls()
rv_type = None
choiceiter = _iter_filename_choices(
fn_base, [alt], self.config, fallback=fallback
)
for fs_path, source_alt, is_attachment in choiceiter:
# If we already determined what our return value is but the
# type mismatches what we try now, we have to abort. Eg:
# a page can not become an attachment or the other way round.
if rv_type is not None and rv_type != is_attachment:
break
try:
with open(fs_path, "rb") as f:
if rv_type is None:
rv_type = is_attachment
for key, lines in metaformat.tokenize(f, encoding="utf-8"):
if key not in rv:
rv[key] = "".join(lines)
except OSError as e:
if e.errno not in (errno.ENOTDIR, errno.ENOENT, errno.EINVAL):
raise
if not is_attachment or not os.path.isfile(fs_path[:-3]):
continue
# Special case: we are loading an attachment but the meta
# data file does not exist. In that case we still want to
# record that we're loading an attachment.
if is_attachment:
rv_type = True
if "_source_alt" not in rv:
rv["_source_alt"] = source_alt
if rv_type is None:
return None
rv["_path"] = path
rv["_id"] = posixpath.basename(path)
rv["_gid"] = hashlib.md5(path.encode("utf-8")).hexdigest()
rv["_alt"] = alt
if rv_type:
rv["_attachment_for"] = posixpath.dirname(path)
return rv
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1326-L1380
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29,
30,
31,
33,
34,
35,
36,
37,
38,
39,
40,
41,
42,
43,
44,
45,
46,
47,
48,
49,
50,
51,
52,
53,
54
] | 98.181818 |
[
32
] | 1.818182 | false | 89.992532 | 55 | 17 | 98.181818 | 2 |
def load_raw_data(self, path, alt=PRIMARY_ALT, cls=None, fallback=True):
path = cleanup_path(path)
if cls is None:
cls = dict
fn_base = self.to_fs_path(path)
rv = cls()
rv_type = None
choiceiter = _iter_filename_choices(
fn_base, [alt], self.config, fallback=fallback
)
for fs_path, source_alt, is_attachment in choiceiter:
# If we already determined what our return value is but the
# type mismatches what we try now, we have to abort. Eg:
# a page can not become an attachment or the other way round.
if rv_type is not None and rv_type != is_attachment:
break
try:
with open(fs_path, "rb") as f:
if rv_type is None:
rv_type = is_attachment
for key, lines in metaformat.tokenize(f, encoding="utf-8"):
if key not in rv:
rv[key] = "".join(lines)
except OSError as e:
if e.errno not in (errno.ENOTDIR, errno.ENOENT, errno.EINVAL):
raise
if not is_attachment or not os.path.isfile(fs_path[:-3]):
continue
# Special case: we are loading an attachment but the meta
# data file does not exist. In that case we still want to
# record that we're loading an attachment.
if is_attachment:
rv_type = True
if "_source_alt" not in rv:
rv["_source_alt"] = source_alt
if rv_type is None:
return None
rv["_path"] = path
rv["_id"] = posixpath.basename(path)
rv["_gid"] = hashlib.md5(path.encode("utf-8")).hexdigest()
rv["_alt"] = alt
if rv_type:
rv["_attachment_for"] = posixpath.dirname(path)
return rv
| 26,306 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Database.iter_items
|
(self, path, alt=PRIMARY_ALT)
|
Iterates over all items below a path and yields them as
tuples in the form ``(id, alt, is_attachment)``.
|
Iterates over all items below a path and yields them as
tuples in the form ``(id, alt, is_attachment)``.
| 1,382 | 1,446 |
def iter_items(self, path, alt=PRIMARY_ALT):
"""Iterates over all items below a path and yields them as
tuples in the form ``(id, alt, is_attachment)``.
"""
fn_base = self.to_fs_path(path)
if alt is None:
alts = self.config.list_alternatives()
single_alt = False
else:
alts = [alt]
single_alt = True
choiceiter = _iter_filename_choices(fn_base, alts, self.config)
for fs_path, _actual_alt, is_attachment in choiceiter:
if not os.path.isfile(fs_path):
continue
# This path is actually for an attachment, which means that we
# cannot have any items below it and will just abort with an
# empty iterator.
if is_attachment:
break
try:
dir_path = os.path.dirname(fs_path)
for filename in os.listdir(dir_path):
if not isinstance(filename, str):
try:
filename = filename.decode(fs_enc)
except UnicodeError:
continue
if filename.endswith(
".lr"
) or self.env.is_uninteresting_source_name(filename):
continue
# We found an attachment. Attachments always live
# below the primary alt, so we report it as such.
if os.path.isfile(os.path.join(dir_path, filename)):
yield filename, PRIMARY_ALT, True
# We found a directory, let's make sure it contains a
# contents.lr file (or a contents+alt.lr file).
else:
for content_alt in _iter_content_files(
os.path.join(dir_path, filename), alts
):
yield filename, content_alt, False
# If we want a single alt, we break here so
# that we only produce a single result.
# Otherwise this would also return the primary
# fallback here.
if single_alt:
break
except IOError as e:
if e.errno != errno.ENOENT:
raise
continue
# If we reach this point, we found our parent, so we can stop
# searching for more at this point.
break
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1382-L1446
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
24,
25,
26,
27,
28,
33,
34,
35,
36,
37,
38,
39,
40,
41,
42,
43,
44,
45,
46,
47,
48,
49,
50,
51,
52,
53,
54,
55,
56,
57,
63,
64
] | 84.615385 |
[
23,
29,
30,
31,
32,
58,
59,
60
] | 12.307692 | false | 89.992532 | 65 | 15 | 87.692308 | 2 |
def iter_items(self, path, alt=PRIMARY_ALT):
fn_base = self.to_fs_path(path)
if alt is None:
alts = self.config.list_alternatives()
single_alt = False
else:
alts = [alt]
single_alt = True
choiceiter = _iter_filename_choices(fn_base, alts, self.config)
for fs_path, _actual_alt, is_attachment in choiceiter:
if not os.path.isfile(fs_path):
continue
# This path is actually for an attachment, which means that we
# cannot have any items below it and will just abort with an
# empty iterator.
if is_attachment:
break
try:
dir_path = os.path.dirname(fs_path)
for filename in os.listdir(dir_path):
if not isinstance(filename, str):
try:
filename = filename.decode(fs_enc)
except UnicodeError:
continue
if filename.endswith(
".lr"
) or self.env.is_uninteresting_source_name(filename):
continue
# We found an attachment. Attachments always live
# below the primary alt, so we report it as such.
if os.path.isfile(os.path.join(dir_path, filename)):
yield filename, PRIMARY_ALT, True
# We found a directory, let's make sure it contains a
# contents.lr file (or a contents+alt.lr file).
else:
for content_alt in _iter_content_files(
os.path.join(dir_path, filename), alts
):
yield filename, content_alt, False
# If we want a single alt, we break here so
# that we only produce a single result.
# Otherwise this would also return the primary
# fallback here.
if single_alt:
break
except IOError as e:
if e.errno != errno.ENOENT:
raise
continue
# If we reach this point, we found our parent, so we can stop
# searching for more at this point.
break
| 26,307 |
|
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Database.get_datamodel_for_raw_data
|
(self, raw_data, pad=None)
|
return self.get_implied_datamodel(path, is_attachment, pad, datamodel=datamodel)
|
Returns the datamodel that should be used for a specific raw
data. This might require the discovery of a parent object through
the pad.
|
Returns the datamodel that should be used for a specific raw
data. This might require the discovery of a parent object through
the pad.
| 1,448 | 1,456 |
def get_datamodel_for_raw_data(self, raw_data, pad=None):
"""Returns the datamodel that should be used for a specific raw
data. This might require the discovery of a parent object through
the pad.
"""
path = raw_data["_path"]
is_attachment = bool(raw_data.get("_attachment_for"))
datamodel = (raw_data.get("_model") or "").strip() or None
return self.get_implied_datamodel(path, is_attachment, pad, datamodel=datamodel)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1448-L1456
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8
] | 100 |
[] | 0 | true | 89.992532 | 9 | 3 | 100 | 3 |
def get_datamodel_for_raw_data(self, raw_data, pad=None):
path = raw_data["_path"]
is_attachment = bool(raw_data.get("_attachment_for"))
datamodel = (raw_data.get("_model") or "").strip() or None
return self.get_implied_datamodel(path, is_attachment, pad, datamodel=datamodel)
| 26,308 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Database.iter_dependent_models
|
(self, datamodel)
|
return iter(seen)
| 1,458 | 1,477 |
def iter_dependent_models(self, datamodel):
seen = set()
def deep_find(datamodel):
seen.add(datamodel)
if datamodel.parent is not None and datamodel.parent not in seen:
deep_find(datamodel.parent)
for related_dm_name in (
datamodel.child_config.model,
datamodel.attachment_config.model,
):
dm = self.datamodels.get(related_dm_name)
if dm is not None and dm not in seen:
deep_find(dm)
deep_find(datamodel)
seen.discard(datamodel)
return iter(seen)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1458-L1477
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
13,
14,
15,
16,
17,
18,
19
] | 85 |
[] | 0 | false | 89.992532 | 20 | 7 | 100 | 0 |
def iter_dependent_models(self, datamodel):
seen = set()
def deep_find(datamodel):
seen.add(datamodel)
if datamodel.parent is not None and datamodel.parent not in seen:
deep_find(datamodel.parent)
for related_dm_name in (
datamodel.child_config.model,
datamodel.attachment_config.model,
):
dm = self.datamodels.get(related_dm_name)
if dm is not None and dm not in seen:
deep_find(dm)
deep_find(datamodel)
seen.discard(datamodel)
return iter(seen)
| 26,309 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Database.get_implied_datamodel
|
(
self, path, is_attachment=False, pad=None, datamodel=None
)
|
Looks up a datamodel based on the information about the parent
of a model.
|
Looks up a datamodel based on the information about the parent
of a model.
| 1,479 | 1,512 |
def get_implied_datamodel(
self, path, is_attachment=False, pad=None, datamodel=None
):
"""Looks up a datamodel based on the information about the parent
of a model.
"""
dm_name = datamodel
# Only look for a datamodel if there was not defined.
if dm_name is None:
parent = posixpath.dirname(path)
dm_name = None
# If we hit the root, and there is no model defined we need
# to make sure we do not recurse onto ourselves.
if parent != path:
if pad is None:
pad = self.new_pad()
parent_obj = pad.get(parent)
if parent_obj is not None:
if is_attachment:
dm_name = parent_obj.datamodel.attachment_config.model
else:
dm_name = parent_obj.datamodel.child_config.model
for dm_name in _iter_datamodel_choices(dm_name, path, is_attachment):
# If that datamodel exists, let's roll with it.
datamodel = self.datamodels.get(dm_name)
if datamodel is not None:
return datamodel
raise AssertionError(
"Did not find an appropriate datamodel. That should never happen."
)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1479-L1512
| 40 |
[
0,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29,
30
] | 76.470588 |
[
17,
31
] | 5.882353 | false | 89.992532 | 34 | 8 | 94.117647 | 2 |
def get_implied_datamodel(
self, path, is_attachment=False, pad=None, datamodel=None
):
dm_name = datamodel
# Only look for a datamodel if there was not defined.
if dm_name is None:
parent = posixpath.dirname(path)
dm_name = None
# If we hit the root, and there is no model defined we need
# to make sure we do not recurse onto ourselves.
if parent != path:
if pad is None:
pad = self.new_pad()
parent_obj = pad.get(parent)
if parent_obj is not None:
if is_attachment:
dm_name = parent_obj.datamodel.attachment_config.model
else:
dm_name = parent_obj.datamodel.child_config.model
for dm_name in _iter_datamodel_choices(dm_name, path, is_attachment):
# If that datamodel exists, let's roll with it.
datamodel = self.datamodels.get(dm_name)
if datamodel is not None:
return datamodel
raise AssertionError(
"Did not find an appropriate datamodel. That should never happen."
)
| 26,310 |
|
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Database.get_attachment_type
|
(self, path)
|
return self.config["ATTACHMENT_TYPES"].get(posixpath.splitext(path)[1].lower())
|
Gets the attachment type for a path.
|
Gets the attachment type for a path.
| 1,514 | 1,516 |
def get_attachment_type(self, path):
"""Gets the attachment type for a path."""
return self.config["ATTACHMENT_TYPES"].get(posixpath.splitext(path)[1].lower())
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1514-L1516
| 40 |
[
0,
1,
2
] | 100 |
[] | 0 | true | 89.992532 | 3 | 1 | 100 | 1 |
def get_attachment_type(self, path):
return self.config["ATTACHMENT_TYPES"].get(posixpath.splitext(path)[1].lower())
| 26,311 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Database.track_record_dependency
|
(self, record)
|
return record
| 1,518 | 1,539 |
def track_record_dependency(self, record):
ctx = get_ctx()
if ctx is not None:
for filename in record.iter_source_filenames():
if isinstance(record, Attachment):
# For Attachments, the actually attachment data
# does not affect the URL of the attachment.
affects_url = filename != record.attachment_filename
else:
affects_url = True
ctx.record_dependency(filename, affects_url=affects_url)
for virtual_source in record.iter_virtual_sources():
ctx.record_virtual_dependency(virtual_source)
if getattr(record, "datamodel", None) and record.datamodel.filename:
ctx.record_dependency(record.datamodel.filename)
for dep_model in self.iter_dependent_models(record.datamodel):
if dep_model.filename:
ctx.record_dependency(dep_model.filename)
# XXX: In the case that our datamodel is implied, then the
# datamodel depends on the datamodel(s) of our parent(s).
# We do not currently record that.
return record
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1518-L1539
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21
] | 95.454545 |
[] | 0 | false | 89.992532 | 22 | 9 | 100 | 0 |
def track_record_dependency(self, record):
ctx = get_ctx()
if ctx is not None:
for filename in record.iter_source_filenames():
if isinstance(record, Attachment):
# For Attachments, the actually attachment data
# does not affect the URL of the attachment.
affects_url = filename != record.attachment_filename
else:
affects_url = True
ctx.record_dependency(filename, affects_url=affects_url)
for virtual_source in record.iter_virtual_sources():
ctx.record_virtual_dependency(virtual_source)
if getattr(record, "datamodel", None) and record.datamodel.filename:
ctx.record_dependency(record.datamodel.filename)
for dep_model in self.iter_dependent_models(record.datamodel):
if dep_model.filename:
ctx.record_dependency(dep_model.filename)
# XXX: In the case that our datamodel is implied, then the
# datamodel depends on the datamodel(s) of our parent(s).
# We do not currently record that.
return record
| 26,312 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/db.py
|
Database.process_data
|
(self, data, datamodel, pad)
| 1,541 | 1,555 |
def process_data(self, data, datamodel, pad):
# Automatically fill in slugs
if not data["_slug"]:
data["_slug"] = default_slug_descriptor
else:
data["_slug"] = data["_slug"].strip("/")
# For attachments figure out the default attachment type if it's
# not yet provided.
if is_undefined(data["_attachment_type"]) and data["_attachment_for"]:
data["_attachment_type"] = self.get_attachment_type(data["_path"])
# Automatically fill in templates
if is_undefined(data["_template"]):
data["_template"] = datamodel.get_default_template_name()
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1541-L1555
| 40 |
[
0,
1,
2,
3,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14
] | 93.333333 |
[] | 0 | false | 89.992532 | 15 | 5 | 100 | 0 |
def process_data(self, data, datamodel, pad):
# Automatically fill in slugs
if not data["_slug"]:
data["_slug"] = default_slug_descriptor
else:
data["_slug"] = data["_slug"].strip("/")
# For attachments figure out the default attachment type if it's
# not yet provided.
if is_undefined(data["_attachment_type"]) and data["_attachment_for"]:
data["_attachment_type"] = self.get_attachment_type(data["_path"])
# Automatically fill in templates
if is_undefined(data["_template"]):
data["_template"] = datamodel.get_default_template_name()
| 26,313 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.