repo stringlengths 7 55 | path stringlengths 4 223 | func_name stringlengths 1 134 | original_string stringlengths 75 104k | language stringclasses 1
value | code stringlengths 75 104k | code_tokens listlengths 19 28.4k | docstring stringlengths 1 46.9k | docstring_tokens listlengths 1 1.97k | sha stringlengths 40 40 | url stringlengths 87 315 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
honzajavorek/redis-collections | redis_collections/sortedsets.py | SortedSetCounter.get_score | def get_score(self, member, default=None, pipe=None):
"""
Return the score of *member*, or *default* if it is not in the
collection.
"""
pipe = self.redis if pipe is None else pipe
score = pipe.zscore(self.key, self._pickle(member))
if (score is None) and (defaul... | python | def get_score(self, member, default=None, pipe=None):
"""
Return the score of *member*, or *default* if it is not in the
collection.
"""
pipe = self.redis if pipe is None else pipe
score = pipe.zscore(self.key, self._pickle(member))
if (score is None) and (defaul... | [
"def",
"get_score",
"(",
"self",
",",
"member",
",",
"default",
"=",
"None",
",",
"pipe",
"=",
"None",
")",
":",
"pipe",
"=",
"self",
".",
"redis",
"if",
"pipe",
"is",
"None",
"else",
"pipe",
"score",
"=",
"pipe",
".",
"zscore",
"(",
"self",
".",
... | Return the score of *member*, or *default* if it is not in the
collection. | [
"Return",
"the",
"score",
"of",
"*",
"member",
"*",
"or",
"*",
"default",
"*",
"if",
"it",
"is",
"not",
"in",
"the",
"collection",
"."
] | 07ca8efe88fb128f7dc7319dfa6a26cd39b3776b | https://github.com/honzajavorek/redis-collections/blob/07ca8efe88fb128f7dc7319dfa6a26cd39b3776b/redis_collections/sortedsets.py#L237-L248 | train |
honzajavorek/redis-collections | redis_collections/sortedsets.py | SortedSetCounter.get_or_set_score | def get_or_set_score(self, member, default=0):
"""
If *member* is in the collection, return its value. If not, store it
with a score of *default* and return *default*. *default* defaults to
0.
"""
default = float(default)
def get_or_set_score_trans(pipe):
... | python | def get_or_set_score(self, member, default=0):
"""
If *member* is in the collection, return its value. If not, store it
with a score of *default* and return *default*. *default* defaults to
0.
"""
default = float(default)
def get_or_set_score_trans(pipe):
... | [
"def",
"get_or_set_score",
"(",
"self",
",",
"member",
",",
"default",
"=",
"0",
")",
":",
"default",
"=",
"float",
"(",
"default",
")",
"def",
"get_or_set_score_trans",
"(",
"pipe",
")",
":",
"pickled_member",
"=",
"self",
".",
"_pickle",
"(",
"member",
... | If *member* is in the collection, return its value. If not, store it
with a score of *default* and return *default*. *default* defaults to
0. | [
"If",
"*",
"member",
"*",
"is",
"in",
"the",
"collection",
"return",
"its",
"value",
".",
"If",
"not",
"store",
"it",
"with",
"a",
"score",
"of",
"*",
"default",
"*",
"and",
"return",
"*",
"default",
"*",
".",
"*",
"default",
"*",
"defaults",
"to",
... | 07ca8efe88fb128f7dc7319dfa6a26cd39b3776b | https://github.com/honzajavorek/redis-collections/blob/07ca8efe88fb128f7dc7319dfa6a26cd39b3776b/redis_collections/sortedsets.py#L250-L268 | train |
honzajavorek/redis-collections | redis_collections/sortedsets.py | SortedSetCounter.get_rank | def get_rank(self, member, reverse=False, pipe=None):
"""
Return the rank of *member* in the collection.
By default, the member with the lowest score has rank 0.
If *reverse* is ``True``, the member with the highest score has rank 0.
"""
pipe = self.redis if pipe is None ... | python | def get_rank(self, member, reverse=False, pipe=None):
"""
Return the rank of *member* in the collection.
By default, the member with the lowest score has rank 0.
If *reverse* is ``True``, the member with the highest score has rank 0.
"""
pipe = self.redis if pipe is None ... | [
"def",
"get_rank",
"(",
"self",
",",
"member",
",",
"reverse",
"=",
"False",
",",
"pipe",
"=",
"None",
")",
":",
"pipe",
"=",
"self",
".",
"redis",
"if",
"pipe",
"is",
"None",
"else",
"pipe",
"method",
"=",
"getattr",
"(",
"pipe",
",",
"'zrevrank'",
... | Return the rank of *member* in the collection.
By default, the member with the lowest score has rank 0.
If *reverse* is ``True``, the member with the highest score has rank 0. | [
"Return",
"the",
"rank",
"of",
"*",
"member",
"*",
"in",
"the",
"collection",
".",
"By",
"default",
"the",
"member",
"with",
"the",
"lowest",
"score",
"has",
"rank",
"0",
".",
"If",
"*",
"reverse",
"*",
"is",
"True",
"the",
"member",
"with",
"the",
"... | 07ca8efe88fb128f7dc7319dfa6a26cd39b3776b | https://github.com/honzajavorek/redis-collections/blob/07ca8efe88fb128f7dc7319dfa6a26cd39b3776b/redis_collections/sortedsets.py#L270-L280 | train |
honzajavorek/redis-collections | redis_collections/sortedsets.py | SortedSetCounter.increment_score | def increment_score(self, member, amount=1):
"""
Adjust the score of *member* by *amount*. If *member* is not in the
collection it will be stored with a score of *amount*.
"""
return self.redis.zincrby(
self.key, float(amount), self._pickle(member)
) | python | def increment_score(self, member, amount=1):
"""
Adjust the score of *member* by *amount*. If *member* is not in the
collection it will be stored with a score of *amount*.
"""
return self.redis.zincrby(
self.key, float(amount), self._pickle(member)
) | [
"def",
"increment_score",
"(",
"self",
",",
"member",
",",
"amount",
"=",
"1",
")",
":",
"return",
"self",
".",
"redis",
".",
"zincrby",
"(",
"self",
".",
"key",
",",
"float",
"(",
"amount",
")",
",",
"self",
".",
"_pickle",
"(",
"member",
")",
")"... | Adjust the score of *member* by *amount*. If *member* is not in the
collection it will be stored with a score of *amount*. | [
"Adjust",
"the",
"score",
"of",
"*",
"member",
"*",
"by",
"*",
"amount",
"*",
".",
"If",
"*",
"member",
"*",
"is",
"not",
"in",
"the",
"collection",
"it",
"will",
"be",
"stored",
"with",
"a",
"score",
"of",
"*",
"amount",
"*",
"."
] | 07ca8efe88fb128f7dc7319dfa6a26cd39b3776b | https://github.com/honzajavorek/redis-collections/blob/07ca8efe88fb128f7dc7319dfa6a26cd39b3776b/redis_collections/sortedsets.py#L282-L289 | train |
honzajavorek/redis-collections | redis_collections/sortedsets.py | SortedSetCounter.items | def items(
self,
min_rank=None,
max_rank=None,
min_score=None,
max_score=None,
reverse=False,
pipe=None,
):
"""
Return a list of ``(member, score)`` tuples whose ranking is between
*min_rank* and *max_rank* AND whose score is between *m... | python | def items(
self,
min_rank=None,
max_rank=None,
min_score=None,
max_score=None,
reverse=False,
pipe=None,
):
"""
Return a list of ``(member, score)`` tuples whose ranking is between
*min_rank* and *max_rank* AND whose score is between *m... | [
"def",
"items",
"(",
"self",
",",
"min_rank",
"=",
"None",
",",
"max_rank",
"=",
"None",
",",
"min_score",
"=",
"None",
",",
"max_score",
"=",
"None",
",",
"reverse",
"=",
"False",
",",
"pipe",
"=",
"None",
",",
")",
":",
"pipe",
"=",
"self",
".",
... | Return a list of ``(member, score)`` tuples whose ranking is between
*min_rank* and *max_rank* AND whose score is between *min_score* and
*max_score* (both ranges inclusive). If no bounds are specified, all
items will be returned. | [
"Return",
"a",
"list",
"of",
"(",
"member",
"score",
")",
"tuples",
"whose",
"ranking",
"is",
"between",
"*",
"min_rank",
"*",
"and",
"*",
"max_rank",
"*",
"AND",
"whose",
"score",
"is",
"between",
"*",
"min_score",
"*",
"and",
"*",
"max_score",
"*",
"... | 07ca8efe88fb128f7dc7319dfa6a26cd39b3776b | https://github.com/honzajavorek/redis-collections/blob/07ca8efe88fb128f7dc7319dfa6a26cd39b3776b/redis_collections/sortedsets.py#L329-L369 | train |
honzajavorek/redis-collections | redis_collections/sortedsets.py | SortedSetCounter.set_score | def set_score(self, member, score, pipe=None):
"""
Set the score of *member* to *score*.
"""
pipe = self.redis if pipe is None else pipe
pipe.zadd(self.key, {self._pickle(member): float(score)}) | python | def set_score(self, member, score, pipe=None):
"""
Set the score of *member* to *score*.
"""
pipe = self.redis if pipe is None else pipe
pipe.zadd(self.key, {self._pickle(member): float(score)}) | [
"def",
"set_score",
"(",
"self",
",",
"member",
",",
"score",
",",
"pipe",
"=",
"None",
")",
":",
"pipe",
"=",
"self",
".",
"redis",
"if",
"pipe",
"is",
"None",
"else",
"pipe",
"pipe",
".",
"zadd",
"(",
"self",
".",
"key",
",",
"{",
"self",
".",
... | Set the score of *member* to *score*. | [
"Set",
"the",
"score",
"of",
"*",
"member",
"*",
"to",
"*",
"score",
"*",
"."
] | 07ca8efe88fb128f7dc7319dfa6a26cd39b3776b | https://github.com/honzajavorek/redis-collections/blob/07ca8efe88fb128f7dc7319dfa6a26cd39b3776b/redis_collections/sortedsets.py#L371-L376 | train |
honzajavorek/redis-collections | redis_collections/sortedsets.py | GeoDB.distance_between | def distance_between(self, place_1, place_2, unit='km'):
"""
Return the great-circle distance between *place_1* and *place_2*,
in the *unit* specified.
The default unit is ``'km'``, but ``'m'``, ``'mi'``, and ``'ft'`` can
also be specified.
"""
pickled_place_1 = ... | python | def distance_between(self, place_1, place_2, unit='km'):
"""
Return the great-circle distance between *place_1* and *place_2*,
in the *unit* specified.
The default unit is ``'km'``, but ``'m'``, ``'mi'``, and ``'ft'`` can
also be specified.
"""
pickled_place_1 = ... | [
"def",
"distance_between",
"(",
"self",
",",
"place_1",
",",
"place_2",
",",
"unit",
"=",
"'km'",
")",
":",
"pickled_place_1",
"=",
"self",
".",
"_pickle",
"(",
"place_1",
")",
"pickled_place_2",
"=",
"self",
".",
"_pickle",
"(",
"place_2",
")",
"try",
"... | Return the great-circle distance between *place_1* and *place_2*,
in the *unit* specified.
The default unit is ``'km'``, but ``'m'``, ``'mi'``, and ``'ft'`` can
also be specified. | [
"Return",
"the",
"great",
"-",
"circle",
"distance",
"between",
"*",
"place_1",
"*",
"and",
"*",
"place_2",
"*",
"in",
"the",
"*",
"unit",
"*",
"specified",
"."
] | 07ca8efe88fb128f7dc7319dfa6a26cd39b3776b | https://github.com/honzajavorek/redis-collections/blob/07ca8efe88fb128f7dc7319dfa6a26cd39b3776b/redis_collections/sortedsets.py#L428-L443 | train |
honzajavorek/redis-collections | redis_collections/sortedsets.py | GeoDB.get_hash | def get_hash(self, place):
"""
Return the Geohash of *place*.
If it's not present in the collection, ``None`` will be returned
instead.
"""
pickled_place = self._pickle(place)
try:
return self.redis.geohash(self.key, pickled_place)[0]
except (A... | python | def get_hash(self, place):
"""
Return the Geohash of *place*.
If it's not present in the collection, ``None`` will be returned
instead.
"""
pickled_place = self._pickle(place)
try:
return self.redis.geohash(self.key, pickled_place)[0]
except (A... | [
"def",
"get_hash",
"(",
"self",
",",
"place",
")",
":",
"pickled_place",
"=",
"self",
".",
"_pickle",
"(",
"place",
")",
"try",
":",
"return",
"self",
".",
"redis",
".",
"geohash",
"(",
"self",
".",
"key",
",",
"pickled_place",
")",
"[",
"0",
"]",
... | Return the Geohash of *place*.
If it's not present in the collection, ``None`` will be returned
instead. | [
"Return",
"the",
"Geohash",
"of",
"*",
"place",
"*",
".",
"If",
"it",
"s",
"not",
"present",
"in",
"the",
"collection",
"None",
"will",
"be",
"returned",
"instead",
"."
] | 07ca8efe88fb128f7dc7319dfa6a26cd39b3776b | https://github.com/honzajavorek/redis-collections/blob/07ca8efe88fb128f7dc7319dfa6a26cd39b3776b/redis_collections/sortedsets.py#L445-L455 | train |
honzajavorek/redis-collections | redis_collections/sortedsets.py | GeoDB.get_location | def get_location(self, place):
"""
Return a dict with the coordinates *place*. The dict's keys are
``'latitude'`` and ``'longitude'``.
If it's not present in the collection, ``None`` will be returned
instead.
"""
pickled_place = self._pickle(place)
try:
... | python | def get_location(self, place):
"""
Return a dict with the coordinates *place*. The dict's keys are
``'latitude'`` and ``'longitude'``.
If it's not present in the collection, ``None`` will be returned
instead.
"""
pickled_place = self._pickle(place)
try:
... | [
"def",
"get_location",
"(",
"self",
",",
"place",
")",
":",
"pickled_place",
"=",
"self",
".",
"_pickle",
"(",
"place",
")",
"try",
":",
"longitude",
",",
"latitude",
"=",
"self",
".",
"redis",
".",
"geopos",
"(",
"self",
".",
"key",
",",
"pickled_plac... | Return a dict with the coordinates *place*. The dict's keys are
``'latitude'`` and ``'longitude'``.
If it's not present in the collection, ``None`` will be returned
instead. | [
"Return",
"a",
"dict",
"with",
"the",
"coordinates",
"*",
"place",
"*",
".",
"The",
"dict",
"s",
"keys",
"are",
"latitude",
"and",
"longitude",
".",
"If",
"it",
"s",
"not",
"present",
"in",
"the",
"collection",
"None",
"will",
"be",
"returned",
"instead"... | 07ca8efe88fb128f7dc7319dfa6a26cd39b3776b | https://github.com/honzajavorek/redis-collections/blob/07ca8efe88fb128f7dc7319dfa6a26cd39b3776b/redis_collections/sortedsets.py#L457-L470 | train |
honzajavorek/redis-collections | redis_collections/sortedsets.py | GeoDB.places_within_radius | def places_within_radius(
self, place=None, latitude=None, longitude=None, radius=0, **kwargs
):
"""
Return descriptions of the places stored in the collection that are
within the circle specified by the given location and radius.
A list of dicts will be returned.
Th... | python | def places_within_radius(
self, place=None, latitude=None, longitude=None, radius=0, **kwargs
):
"""
Return descriptions of the places stored in the collection that are
within the circle specified by the given location and radius.
A list of dicts will be returned.
Th... | [
"def",
"places_within_radius",
"(",
"self",
",",
"place",
"=",
"None",
",",
"latitude",
"=",
"None",
",",
"longitude",
"=",
"None",
",",
"radius",
"=",
"0",
",",
"*",
"*",
"kwargs",
")",
":",
"kwargs",
"[",
"'withdist'",
"]",
"=",
"True",
"kwargs",
"... | Return descriptions of the places stored in the collection that are
within the circle specified by the given location and radius.
A list of dicts will be returned.
The center of the circle can be specified by the identifier of another
place in the collection with the *place* keyword arg... | [
"Return",
"descriptions",
"of",
"the",
"places",
"stored",
"in",
"the",
"collection",
"that",
"are",
"within",
"the",
"circle",
"specified",
"by",
"the",
"given",
"location",
"and",
"radius",
".",
"A",
"list",
"of",
"dicts",
"will",
"be",
"returned",
"."
] | 07ca8efe88fb128f7dc7319dfa6a26cd39b3776b | https://github.com/honzajavorek/redis-collections/blob/07ca8efe88fb128f7dc7319dfa6a26cd39b3776b/redis_collections/sortedsets.py#L472-L526 | train |
honzajavorek/redis-collections | redis_collections/sortedsets.py | GeoDB.set_location | def set_location(self, place, latitude, longitude, pipe=None):
"""
Set the location of *place* to the location specified by
*latitude* and *longitude*.
*place* can be any pickle-able Python object.
"""
pipe = self.redis if pipe is None else pipe
pipe.geoadd(self.... | python | def set_location(self, place, latitude, longitude, pipe=None):
"""
Set the location of *place* to the location specified by
*latitude* and *longitude*.
*place* can be any pickle-able Python object.
"""
pipe = self.redis if pipe is None else pipe
pipe.geoadd(self.... | [
"def",
"set_location",
"(",
"self",
",",
"place",
",",
"latitude",
",",
"longitude",
",",
"pipe",
"=",
"None",
")",
":",
"pipe",
"=",
"self",
".",
"redis",
"if",
"pipe",
"is",
"None",
"else",
"pipe",
"pipe",
".",
"geoadd",
"(",
"self",
".",
"key",
... | Set the location of *place* to the location specified by
*latitude* and *longitude*.
*place* can be any pickle-able Python object. | [
"Set",
"the",
"location",
"of",
"*",
"place",
"*",
"to",
"the",
"location",
"specified",
"by",
"*",
"latitude",
"*",
"and",
"*",
"longitude",
"*",
"."
] | 07ca8efe88fb128f7dc7319dfa6a26cd39b3776b | https://github.com/honzajavorek/redis-collections/blob/07ca8efe88fb128f7dc7319dfa6a26cd39b3776b/redis_collections/sortedsets.py#L528-L536 | train |
honzajavorek/redis-collections | redis_collections/sortedsets.py | GeoDB.update | def update(self, other):
"""
Update the collection with items from *other*. Accepts other
:class:`GeoDB` instances, dictionaries mapping places to
``{'latitude': latitude, 'longitude': longitude}`` dicts,
or sequences of ``(place, latitude, longitude)`` tuples.
"""
... | python | def update(self, other):
"""
Update the collection with items from *other*. Accepts other
:class:`GeoDB` instances, dictionaries mapping places to
``{'latitude': latitude, 'longitude': longitude}`` dicts,
or sequences of ``(place, latitude, longitude)`` tuples.
"""
... | [
"def",
"update",
"(",
"self",
",",
"other",
")",
":",
"# other is another Sorted Set",
"def",
"update_sortedset_trans",
"(",
"pipe",
")",
":",
"items",
"=",
"other",
".",
"_data",
"(",
"pipe",
"=",
"pipe",
")",
"if",
"use_redis",
"else",
"other",
".",
"_da... | Update the collection with items from *other*. Accepts other
:class:`GeoDB` instances, dictionaries mapping places to
``{'latitude': latitude, 'longitude': longitude}`` dicts,
or sequences of ``(place, latitude, longitude)`` tuples. | [
"Update",
"the",
"collection",
"with",
"items",
"from",
"*",
"other",
"*",
".",
"Accepts",
"other",
":",
"class",
":",
"GeoDB",
"instances",
"dictionaries",
"mapping",
"places",
"to",
"{",
"latitude",
":",
"latitude",
"longitude",
":",
"longitude",
"}",
"dic... | 07ca8efe88fb128f7dc7319dfa6a26cd39b3776b | https://github.com/honzajavorek/redis-collections/blob/07ca8efe88fb128f7dc7319dfa6a26cd39b3776b/redis_collections/sortedsets.py#L538-L587 | train |
honzajavorek/redis-collections | redis_collections/syncable.py | LRUDict.copy | def copy(self, key=None):
"""
Creates another collection with the same items and maxsize with
the given *key*.
"""
other = self.__class__(
maxsize=self.maxsize, redis=self.persistence.redis, key=key
)
other.update(self)
return other | python | def copy(self, key=None):
"""
Creates another collection with the same items and maxsize with
the given *key*.
"""
other = self.__class__(
maxsize=self.maxsize, redis=self.persistence.redis, key=key
)
other.update(self)
return other | [
"def",
"copy",
"(",
"self",
",",
"key",
"=",
"None",
")",
":",
"other",
"=",
"self",
".",
"__class__",
"(",
"maxsize",
"=",
"self",
".",
"maxsize",
",",
"redis",
"=",
"self",
".",
"persistence",
".",
"redis",
",",
"key",
"=",
"key",
")",
"other",
... | Creates another collection with the same items and maxsize with
the given *key*. | [
"Creates",
"another",
"collection",
"with",
"the",
"same",
"items",
"and",
"maxsize",
"with",
"the",
"given",
"*",
"key",
"*",
"."
] | 07ca8efe88fb128f7dc7319dfa6a26cd39b3776b | https://github.com/honzajavorek/redis-collections/blob/07ca8efe88fb128f7dc7319dfa6a26cd39b3776b/redis_collections/syncable.py#L267-L277 | train |
honzajavorek/redis-collections | redis_collections/syncable.py | LRUDict.fromkeys | def fromkeys(cls, seq, value=None, **kwargs):
"""
Create a new collection with keys from *seq* and values set to
*value*. The keyword arguments are passed to the persistent ``Dict``.
"""
other = cls(**kwargs)
other.update(((key, value) for key in seq))
return oth... | python | def fromkeys(cls, seq, value=None, **kwargs):
"""
Create a new collection with keys from *seq* and values set to
*value*. The keyword arguments are passed to the persistent ``Dict``.
"""
other = cls(**kwargs)
other.update(((key, value) for key in seq))
return oth... | [
"def",
"fromkeys",
"(",
"cls",
",",
"seq",
",",
"value",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"other",
"=",
"cls",
"(",
"*",
"*",
"kwargs",
")",
"other",
".",
"update",
"(",
"(",
"(",
"key",
",",
"value",
")",
"for",
"key",
"in",
"... | Create a new collection with keys from *seq* and values set to
*value*. The keyword arguments are passed to the persistent ``Dict``. | [
"Create",
"a",
"new",
"collection",
"with",
"keys",
"from",
"*",
"seq",
"*",
"and",
"values",
"set",
"to",
"*",
"value",
"*",
".",
"The",
"keyword",
"arguments",
"are",
"passed",
"to",
"the",
"persistent",
"Dict",
"."
] | 07ca8efe88fb128f7dc7319dfa6a26cd39b3776b | https://github.com/honzajavorek/redis-collections/blob/07ca8efe88fb128f7dc7319dfa6a26cd39b3776b/redis_collections/syncable.py#L280-L288 | train |
honzajavorek/redis-collections | redis_collections/syncable.py | LRUDict.sync | def sync(self, clear_cache=False):
"""
Copy items from the local cache to the persistent Dict.
If *clear_cache* is ``True``, clear out the local cache after
pushing its items to Redis.
"""
self.persistence.update(self)
if clear_cache:
self.cache.clear... | python | def sync(self, clear_cache=False):
"""
Copy items from the local cache to the persistent Dict.
If *clear_cache* is ``True``, clear out the local cache after
pushing its items to Redis.
"""
self.persistence.update(self)
if clear_cache:
self.cache.clear... | [
"def",
"sync",
"(",
"self",
",",
"clear_cache",
"=",
"False",
")",
":",
"self",
".",
"persistence",
".",
"update",
"(",
"self",
")",
"if",
"clear_cache",
":",
"self",
".",
"cache",
".",
"clear",
"(",
")"
] | Copy items from the local cache to the persistent Dict.
If *clear_cache* is ``True``, clear out the local cache after
pushing its items to Redis. | [
"Copy",
"items",
"from",
"the",
"local",
"cache",
"to",
"the",
"persistent",
"Dict",
".",
"If",
"*",
"clear_cache",
"*",
"is",
"True",
"clear",
"out",
"the",
"local",
"cache",
"after",
"pushing",
"its",
"items",
"to",
"Redis",
"."
] | 07ca8efe88fb128f7dc7319dfa6a26cd39b3776b | https://github.com/honzajavorek/redis-collections/blob/07ca8efe88fb128f7dc7319dfa6a26cd39b3776b/redis_collections/syncable.py#L290-L299 | train |
honzajavorek/redis-collections | redis_collections/lists.py | List._data | def _data(self, pipe=None):
"""
Return a :obj:`list` of all values from Redis
(without checking the local cache).
"""
pipe = self.redis if pipe is None else pipe
return [self._unpickle(v) for v in pipe.lrange(self.key, 0, -1)] | python | def _data(self, pipe=None):
"""
Return a :obj:`list` of all values from Redis
(without checking the local cache).
"""
pipe = self.redis if pipe is None else pipe
return [self._unpickle(v) for v in pipe.lrange(self.key, 0, -1)] | [
"def",
"_data",
"(",
"self",
",",
"pipe",
"=",
"None",
")",
":",
"pipe",
"=",
"self",
".",
"redis",
"if",
"pipe",
"is",
"None",
"else",
"pipe",
"return",
"[",
"self",
".",
"_unpickle",
"(",
"v",
")",
"for",
"v",
"in",
"pipe",
".",
"lrange",
"(",
... | Return a :obj:`list` of all values from Redis
(without checking the local cache). | [
"Return",
"a",
":",
"obj",
":",
"list",
"of",
"all",
"values",
"from",
"Redis",
"(",
"without",
"checking",
"the",
"local",
"cache",
")",
"."
] | 07ca8efe88fb128f7dc7319dfa6a26cd39b3776b | https://github.com/honzajavorek/redis-collections/blob/07ca8efe88fb128f7dc7319dfa6a26cd39b3776b/redis_collections/lists.py#L245-L251 | train |
honzajavorek/redis-collections | redis_collections/lists.py | List.append | def append(self, value):
"""Insert *value* at the end of this collection."""
len_self = self.redis.rpush(self.key, self._pickle(value))
if self.writeback:
self.cache[len_self - 1] = value | python | def append(self, value):
"""Insert *value* at the end of this collection."""
len_self = self.redis.rpush(self.key, self._pickle(value))
if self.writeback:
self.cache[len_self - 1] = value | [
"def",
"append",
"(",
"self",
",",
"value",
")",
":",
"len_self",
"=",
"self",
".",
"redis",
".",
"rpush",
"(",
"self",
".",
"key",
",",
"self",
".",
"_pickle",
"(",
"value",
")",
")",
"if",
"self",
".",
"writeback",
":",
"self",
".",
"cache",
"[... | Insert *value* at the end of this collection. | [
"Insert",
"*",
"value",
"*",
"at",
"the",
"end",
"of",
"this",
"collection",
"."
] | 07ca8efe88fb128f7dc7319dfa6a26cd39b3776b | https://github.com/honzajavorek/redis-collections/blob/07ca8efe88fb128f7dc7319dfa6a26cd39b3776b/redis_collections/lists.py#L338-L343 | train |
honzajavorek/redis-collections | redis_collections/lists.py | List.copy | def copy(self, key=None):
"""
Return a new collection with the same items as this one.
If *key* is specified, create the new collection with the given
Redis key.
"""
other = self.__class__(
redis=self.redis, key=key, writeback=self.writeback
)
... | python | def copy(self, key=None):
"""
Return a new collection with the same items as this one.
If *key* is specified, create the new collection with the given
Redis key.
"""
other = self.__class__(
redis=self.redis, key=key, writeback=self.writeback
)
... | [
"def",
"copy",
"(",
"self",
",",
"key",
"=",
"None",
")",
":",
"other",
"=",
"self",
".",
"__class__",
"(",
"redis",
"=",
"self",
".",
"redis",
",",
"key",
"=",
"key",
",",
"writeback",
"=",
"self",
".",
"writeback",
")",
"other",
".",
"extend",
... | Return a new collection with the same items as this one.
If *key* is specified, create the new collection with the given
Redis key. | [
"Return",
"a",
"new",
"collection",
"with",
"the",
"same",
"items",
"as",
"this",
"one",
".",
"If",
"*",
"key",
"*",
"is",
"specified",
"create",
"the",
"new",
"collection",
"with",
"the",
"given",
"Redis",
"key",
"."
] | 07ca8efe88fb128f7dc7319dfa6a26cd39b3776b | https://github.com/honzajavorek/redis-collections/blob/07ca8efe88fb128f7dc7319dfa6a26cd39b3776b/redis_collections/lists.py#L352-L363 | train |
honzajavorek/redis-collections | redis_collections/lists.py | List.extend | def extend(self, other):
"""
Adds the values from the iterable *other* to the end of this
collection.
"""
def extend_trans(pipe):
values = list(other.__iter__(pipe)) if use_redis else other
len_self = pipe.rpush(self.key, *(self._pickle(v) for v in values)... | python | def extend(self, other):
"""
Adds the values from the iterable *other* to the end of this
collection.
"""
def extend_trans(pipe):
values = list(other.__iter__(pipe)) if use_redis else other
len_self = pipe.rpush(self.key, *(self._pickle(v) for v in values)... | [
"def",
"extend",
"(",
"self",
",",
"other",
")",
":",
"def",
"extend_trans",
"(",
"pipe",
")",
":",
"values",
"=",
"list",
"(",
"other",
".",
"__iter__",
"(",
"pipe",
")",
")",
"if",
"use_redis",
"else",
"other",
"len_self",
"=",
"pipe",
".",
"rpush"... | Adds the values from the iterable *other* to the end of this
collection. | [
"Adds",
"the",
"values",
"from",
"the",
"iterable",
"*",
"other",
"*",
"to",
"the",
"end",
"of",
"this",
"collection",
"."
] | 07ca8efe88fb128f7dc7319dfa6a26cd39b3776b | https://github.com/honzajavorek/redis-collections/blob/07ca8efe88fb128f7dc7319dfa6a26cd39b3776b/redis_collections/lists.py#L374-L391 | train |
honzajavorek/redis-collections | redis_collections/lists.py | List.index | def index(self, value, start=None, stop=None):
"""
Return the index of the first occurence of *value*.
If *start* or *stop* are provided, return the smallest
index such that ``s[index] == value`` and ``start <= index < stop``.
"""
def index_trans(pipe):
len_se... | python | def index(self, value, start=None, stop=None):
"""
Return the index of the first occurence of *value*.
If *start* or *stop* are provided, return the smallest
index such that ``s[index] == value`` and ``start <= index < stop``.
"""
def index_trans(pipe):
len_se... | [
"def",
"index",
"(",
"self",
",",
"value",
",",
"start",
"=",
"None",
",",
"stop",
"=",
"None",
")",
":",
"def",
"index_trans",
"(",
"pipe",
")",
":",
"len_self",
",",
"normal_start",
"=",
"self",
".",
"_normalize_index",
"(",
"start",
"or",
"0",
","... | Return the index of the first occurence of *value*.
If *start* or *stop* are provided, return the smallest
index such that ``s[index] == value`` and ``start <= index < stop``. | [
"Return",
"the",
"index",
"of",
"the",
"first",
"occurence",
"of",
"*",
"value",
"*",
".",
"If",
"*",
"start",
"*",
"or",
"*",
"stop",
"*",
"are",
"provided",
"return",
"the",
"smallest",
"index",
"such",
"that",
"s",
"[",
"index",
"]",
"==",
"value"... | 07ca8efe88fb128f7dc7319dfa6a26cd39b3776b | https://github.com/honzajavorek/redis-collections/blob/07ca8efe88fb128f7dc7319dfa6a26cd39b3776b/redis_collections/lists.py#L393-L411 | train |
honzajavorek/redis-collections | redis_collections/lists.py | List.insert | def insert(self, index, value):
"""
Insert *value* into the collection at *index*.
"""
if index == 0:
return self._insert_left(value)
def insert_middle_trans(pipe):
self._insert_middle(index, value, pipe=pipe)
return self._transaction(insert_midd... | python | def insert(self, index, value):
"""
Insert *value* into the collection at *index*.
"""
if index == 0:
return self._insert_left(value)
def insert_middle_trans(pipe):
self._insert_middle(index, value, pipe=pipe)
return self._transaction(insert_midd... | [
"def",
"insert",
"(",
"self",
",",
"index",
",",
"value",
")",
":",
"if",
"index",
"==",
"0",
":",
"return",
"self",
".",
"_insert_left",
"(",
"value",
")",
"def",
"insert_middle_trans",
"(",
"pipe",
")",
":",
"self",
".",
"_insert_middle",
"(",
"index... | Insert *value* into the collection at *index*. | [
"Insert",
"*",
"value",
"*",
"into",
"the",
"collection",
"at",
"*",
"index",
"*",
"."
] | 07ca8efe88fb128f7dc7319dfa6a26cd39b3776b | https://github.com/honzajavorek/redis-collections/blob/07ca8efe88fb128f7dc7319dfa6a26cd39b3776b/redis_collections/lists.py#L445-L455 | train |
honzajavorek/redis-collections | redis_collections/lists.py | List.pop | def pop(self, index=-1):
"""
Retrieve the value at *index*, remove it from the collection, and
return it.
"""
if index == 0:
return self._pop_left()
elif index == -1:
return self._pop_right()
else:
return self._pop_middle(index) | python | def pop(self, index=-1):
"""
Retrieve the value at *index*, remove it from the collection, and
return it.
"""
if index == 0:
return self._pop_left()
elif index == -1:
return self._pop_right()
else:
return self._pop_middle(index) | [
"def",
"pop",
"(",
"self",
",",
"index",
"=",
"-",
"1",
")",
":",
"if",
"index",
"==",
"0",
":",
"return",
"self",
".",
"_pop_left",
"(",
")",
"elif",
"index",
"==",
"-",
"1",
":",
"return",
"self",
".",
"_pop_right",
"(",
")",
"else",
":",
"re... | Retrieve the value at *index*, remove it from the collection, and
return it. | [
"Retrieve",
"the",
"value",
"at",
"*",
"index",
"*",
"remove",
"it",
"from",
"the",
"collection",
"and",
"return",
"it",
"."
] | 07ca8efe88fb128f7dc7319dfa6a26cd39b3776b | https://github.com/honzajavorek/redis-collections/blob/07ca8efe88fb128f7dc7319dfa6a26cd39b3776b/redis_collections/lists.py#L457-L467 | train |
honzajavorek/redis-collections | redis_collections/lists.py | List.remove | def remove(self, value):
"""Remove the first occurence of *value*."""
def remove_trans(pipe):
# If we're caching, we'll need to synchronize before removing.
if self.writeback:
self._sync_helper(pipe)
delete_count = pipe.lrem(self.key, 1, self._pickle(... | python | def remove(self, value):
"""Remove the first occurence of *value*."""
def remove_trans(pipe):
# If we're caching, we'll need to synchronize before removing.
if self.writeback:
self._sync_helper(pipe)
delete_count = pipe.lrem(self.key, 1, self._pickle(... | [
"def",
"remove",
"(",
"self",
",",
"value",
")",
":",
"def",
"remove_trans",
"(",
"pipe",
")",
":",
"# If we're caching, we'll need to synchronize before removing.",
"if",
"self",
".",
"writeback",
":",
"self",
".",
"_sync_helper",
"(",
"pipe",
")",
"delete_count"... | Remove the first occurence of *value*. | [
"Remove",
"the",
"first",
"occurence",
"of",
"*",
"value",
"*",
"."
] | 07ca8efe88fb128f7dc7319dfa6a26cd39b3776b | https://github.com/honzajavorek/redis-collections/blob/07ca8efe88fb128f7dc7319dfa6a26cd39b3776b/redis_collections/lists.py#L469-L480 | train |
honzajavorek/redis-collections | redis_collections/lists.py | List.reverse | def reverse(self):
"""
Reverses the items of this collection "in place" (only two values are
retrieved from Redis at a time).
"""
def reverse_trans(pipe):
if self.writeback:
self._sync_helper(pipe)
n = self.__len__(pipe)
for i ... | python | def reverse(self):
"""
Reverses the items of this collection "in place" (only two values are
retrieved from Redis at a time).
"""
def reverse_trans(pipe):
if self.writeback:
self._sync_helper(pipe)
n = self.__len__(pipe)
for i ... | [
"def",
"reverse",
"(",
"self",
")",
":",
"def",
"reverse_trans",
"(",
"pipe",
")",
":",
"if",
"self",
".",
"writeback",
":",
"self",
".",
"_sync_helper",
"(",
"pipe",
")",
"n",
"=",
"self",
".",
"__len__",
"(",
"pipe",
")",
"for",
"i",
"in",
"range... | Reverses the items of this collection "in place" (only two values are
retrieved from Redis at a time). | [
"Reverses",
"the",
"items",
"of",
"this",
"collection",
"in",
"place",
"(",
"only",
"two",
"values",
"are",
"retrieved",
"from",
"Redis",
"at",
"a",
"time",
")",
"."
] | 07ca8efe88fb128f7dc7319dfa6a26cd39b3776b | https://github.com/honzajavorek/redis-collections/blob/07ca8efe88fb128f7dc7319dfa6a26cd39b3776b/redis_collections/lists.py#L482-L498 | train |
honzajavorek/redis-collections | redis_collections/lists.py | List.sort | def sort(self, key=None, reverse=False):
"""
Sort the items of this collection according to the optional callable
*key*. If *reverse* is set then the sort order is reversed.
.. note::
This sort requires all items to be retrieved from Redis and stored
in memory.
... | python | def sort(self, key=None, reverse=False):
"""
Sort the items of this collection according to the optional callable
*key*. If *reverse* is set then the sort order is reversed.
.. note::
This sort requires all items to be retrieved from Redis and stored
in memory.
... | [
"def",
"sort",
"(",
"self",
",",
"key",
"=",
"None",
",",
"reverse",
"=",
"False",
")",
":",
"def",
"sort_trans",
"(",
"pipe",
")",
":",
"values",
"=",
"list",
"(",
"self",
".",
"__iter__",
"(",
"pipe",
")",
")",
"values",
".",
"sort",
"(",
"key"... | Sort the items of this collection according to the optional callable
*key*. If *reverse* is set then the sort order is reversed.
.. note::
This sort requires all items to be retrieved from Redis and stored
in memory. | [
"Sort",
"the",
"items",
"of",
"this",
"collection",
"according",
"to",
"the",
"optional",
"callable",
"*",
"key",
"*",
".",
"If",
"*",
"reverse",
"*",
"is",
"set",
"then",
"the",
"sort",
"order",
"is",
"reversed",
"."
] | 07ca8efe88fb128f7dc7319dfa6a26cd39b3776b | https://github.com/honzajavorek/redis-collections/blob/07ca8efe88fb128f7dc7319dfa6a26cd39b3776b/redis_collections/lists.py#L500-L520 | train |
honzajavorek/redis-collections | redis_collections/lists.py | Deque.append | def append(self, value):
"""Add *value* to the right side of the collection."""
def append_trans(pipe):
self._append_helper(value, pipe)
self._transaction(append_trans) | python | def append(self, value):
"""Add *value* to the right side of the collection."""
def append_trans(pipe):
self._append_helper(value, pipe)
self._transaction(append_trans) | [
"def",
"append",
"(",
"self",
",",
"value",
")",
":",
"def",
"append_trans",
"(",
"pipe",
")",
":",
"self",
".",
"_append_helper",
"(",
"value",
",",
"pipe",
")",
"self",
".",
"_transaction",
"(",
"append_trans",
")"
] | Add *value* to the right side of the collection. | [
"Add",
"*",
"value",
"*",
"to",
"the",
"right",
"side",
"of",
"the",
"collection",
"."
] | 07ca8efe88fb128f7dc7319dfa6a26cd39b3776b | https://github.com/honzajavorek/redis-collections/blob/07ca8efe88fb128f7dc7319dfa6a26cd39b3776b/redis_collections/lists.py#L739-L744 | train |
honzajavorek/redis-collections | redis_collections/lists.py | Deque.appendleft | def appendleft(self, value):
"""Add *value* to the left side of the collection."""
def appendleft_trans(pipe):
self._appendleft_helper(value, pipe)
self._transaction(appendleft_trans) | python | def appendleft(self, value):
"""Add *value* to the left side of the collection."""
def appendleft_trans(pipe):
self._appendleft_helper(value, pipe)
self._transaction(appendleft_trans) | [
"def",
"appendleft",
"(",
"self",
",",
"value",
")",
":",
"def",
"appendleft_trans",
"(",
"pipe",
")",
":",
"self",
".",
"_appendleft_helper",
"(",
"value",
",",
"pipe",
")",
"self",
".",
"_transaction",
"(",
"appendleft_trans",
")"
] | Add *value* to the left side of the collection. | [
"Add",
"*",
"value",
"*",
"to",
"the",
"left",
"side",
"of",
"the",
"collection",
"."
] | 07ca8efe88fb128f7dc7319dfa6a26cd39b3776b | https://github.com/honzajavorek/redis-collections/blob/07ca8efe88fb128f7dc7319dfa6a26cd39b3776b/redis_collections/lists.py#L764-L769 | train |
honzajavorek/redis-collections | redis_collections/lists.py | Deque.copy | def copy(self, key=None):
"""
Return a new collection with the same items as this one.
If *key* is specified, create the new collection with the given
Redis key.
"""
other = self.__class__(
self.__iter__(),
self.maxlen,
redis=self.redis... | python | def copy(self, key=None):
"""
Return a new collection with the same items as this one.
If *key* is specified, create the new collection with the given
Redis key.
"""
other = self.__class__(
self.__iter__(),
self.maxlen,
redis=self.redis... | [
"def",
"copy",
"(",
"self",
",",
"key",
"=",
"None",
")",
":",
"other",
"=",
"self",
".",
"__class__",
"(",
"self",
".",
"__iter__",
"(",
")",
",",
"self",
".",
"maxlen",
",",
"redis",
"=",
"self",
".",
"redis",
",",
"key",
"=",
"key",
",",
"wr... | Return a new collection with the same items as this one.
If *key* is specified, create the new collection with the given
Redis key. | [
"Return",
"a",
"new",
"collection",
"with",
"the",
"same",
"items",
"as",
"this",
"one",
".",
"If",
"*",
"key",
"*",
"is",
"specified",
"create",
"the",
"new",
"collection",
"with",
"the",
"given",
"Redis",
"key",
"."
] | 07ca8efe88fb128f7dc7319dfa6a26cd39b3776b | https://github.com/honzajavorek/redis-collections/blob/07ca8efe88fb128f7dc7319dfa6a26cd39b3776b/redis_collections/lists.py#L771-L785 | train |
honzajavorek/redis-collections | redis_collections/lists.py | Deque.extend | def extend(self, other):
"""
Extend the right side of the the collection by appending values from
the iterable *other*.
"""
def extend_trans(pipe):
values = list(other.__iter__(pipe)) if use_redis else other
for v in values:
self._append_he... | python | def extend(self, other):
"""
Extend the right side of the the collection by appending values from
the iterable *other*.
"""
def extend_trans(pipe):
values = list(other.__iter__(pipe)) if use_redis else other
for v in values:
self._append_he... | [
"def",
"extend",
"(",
"self",
",",
"other",
")",
":",
"def",
"extend_trans",
"(",
"pipe",
")",
":",
"values",
"=",
"list",
"(",
"other",
".",
"__iter__",
"(",
"pipe",
")",
")",
"if",
"use_redis",
"else",
"other",
"for",
"v",
"in",
"values",
":",
"s... | Extend the right side of the the collection by appending values from
the iterable *other*. | [
"Extend",
"the",
"right",
"side",
"of",
"the",
"the",
"collection",
"by",
"appending",
"values",
"from",
"the",
"iterable",
"*",
"other",
"*",
"."
] | 07ca8efe88fb128f7dc7319dfa6a26cd39b3776b | https://github.com/honzajavorek/redis-collections/blob/07ca8efe88fb128f7dc7319dfa6a26cd39b3776b/redis_collections/lists.py#L787-L802 | train |
honzajavorek/redis-collections | redis_collections/lists.py | Deque.extendleft | def extendleft(self, other):
"""
Extend the left side of the the collection by appending values from
the iterable *other*. Note that the appends will reverse the order
of the given values.
"""
def extendleft_trans(pipe):
values = list(other.__iter__(pipe)) if ... | python | def extendleft(self, other):
"""
Extend the left side of the the collection by appending values from
the iterable *other*. Note that the appends will reverse the order
of the given values.
"""
def extendleft_trans(pipe):
values = list(other.__iter__(pipe)) if ... | [
"def",
"extendleft",
"(",
"self",
",",
"other",
")",
":",
"def",
"extendleft_trans",
"(",
"pipe",
")",
":",
"values",
"=",
"list",
"(",
"other",
".",
"__iter__",
"(",
"pipe",
")",
")",
"if",
"use_redis",
"else",
"other",
"for",
"v",
"in",
"values",
"... | Extend the left side of the the collection by appending values from
the iterable *other*. Note that the appends will reverse the order
of the given values. | [
"Extend",
"the",
"left",
"side",
"of",
"the",
"the",
"collection",
"by",
"appending",
"values",
"from",
"the",
"iterable",
"*",
"other",
"*",
".",
"Note",
"that",
"the",
"appends",
"will",
"reverse",
"the",
"order",
"of",
"the",
"given",
"values",
"."
] | 07ca8efe88fb128f7dc7319dfa6a26cd39b3776b | https://github.com/honzajavorek/redis-collections/blob/07ca8efe88fb128f7dc7319dfa6a26cd39b3776b/redis_collections/lists.py#L804-L820 | train |
honzajavorek/redis-collections | redis_collections/lists.py | Deque.insert | def insert(self, index, value):
"""
Insert *value* into the collection at *index*.
If the insertion would the collection to grow beyond ``maxlen``,
raise ``IndexError``.
"""
def insert_trans(pipe):
len_self = self.__len__(pipe)
if (self.maxlen is n... | python | def insert(self, index, value):
"""
Insert *value* into the collection at *index*.
If the insertion would the collection to grow beyond ``maxlen``,
raise ``IndexError``.
"""
def insert_trans(pipe):
len_self = self.__len__(pipe)
if (self.maxlen is n... | [
"def",
"insert",
"(",
"self",
",",
"index",
",",
"value",
")",
":",
"def",
"insert_trans",
"(",
"pipe",
")",
":",
"len_self",
"=",
"self",
".",
"__len__",
"(",
"pipe",
")",
"if",
"(",
"self",
".",
"maxlen",
"is",
"not",
"None",
")",
"and",
"(",
"... | Insert *value* into the collection at *index*.
If the insertion would the collection to grow beyond ``maxlen``,
raise ``IndexError``. | [
"Insert",
"*",
"value",
"*",
"into",
"the",
"collection",
"at",
"*",
"index",
"*",
".",
"If",
"the",
"insertion",
"would",
"the",
"collection",
"to",
"grow",
"beyond",
"maxlen",
"raise",
"IndexError",
"."
] | 07ca8efe88fb128f7dc7319dfa6a26cd39b3776b | https://github.com/honzajavorek/redis-collections/blob/07ca8efe88fb128f7dc7319dfa6a26cd39b3776b/redis_collections/lists.py#L822-L838 | train |
honzajavorek/redis-collections | redis_collections/lists.py | Deque.rotate | def rotate(self, n=1):
"""
Rotate the deque n steps to the right.
If n is negative, rotate to the left.
"""
# No work to do for a 0-step rotate
if n == 0:
return
def rotate_trans(pipe):
# Synchronize the cache before rotating
i... | python | def rotate(self, n=1):
"""
Rotate the deque n steps to the right.
If n is negative, rotate to the left.
"""
# No work to do for a 0-step rotate
if n == 0:
return
def rotate_trans(pipe):
# Synchronize the cache before rotating
i... | [
"def",
"rotate",
"(",
"self",
",",
"n",
"=",
"1",
")",
":",
"# No work to do for a 0-step rotate",
"if",
"n",
"==",
"0",
":",
"return",
"def",
"rotate_trans",
"(",
"pipe",
")",
":",
"# Synchronize the cache before rotating",
"if",
"self",
".",
"writeback",
":"... | Rotate the deque n steps to the right.
If n is negative, rotate to the left. | [
"Rotate",
"the",
"deque",
"n",
"steps",
"to",
"the",
"right",
".",
"If",
"n",
"is",
"negative",
"rotate",
"to",
"the",
"left",
"."
] | 07ca8efe88fb128f7dc7319dfa6a26cd39b3776b | https://github.com/honzajavorek/redis-collections/blob/07ca8efe88fb128f7dc7319dfa6a26cd39b3776b/redis_collections/lists.py#L852-L883 | train |
ambitioninc/django-entity | entity/models.py | get_entities_by_kind | def get_entities_by_kind(membership_cache=None, is_active=True):
"""
Builds a dict with keys of entity kinds if and values are another dict. Each of these dicts are keyed
off of a super entity id and optional have an 'all' key for any group that has a null super entity.
Example structure:
{
... | python | def get_entities_by_kind(membership_cache=None, is_active=True):
"""
Builds a dict with keys of entity kinds if and values are another dict. Each of these dicts are keyed
off of a super entity id and optional have an 'all' key for any group that has a null super entity.
Example structure:
{
... | [
"def",
"get_entities_by_kind",
"(",
"membership_cache",
"=",
"None",
",",
"is_active",
"=",
"True",
")",
":",
"# Accept an existing cache or build a new one",
"if",
"membership_cache",
"is",
"None",
":",
"membership_cache",
"=",
"EntityGroup",
".",
"objects",
".",
"ge... | Builds a dict with keys of entity kinds if and values are another dict. Each of these dicts are keyed
off of a super entity id and optional have an 'all' key for any group that has a null super entity.
Example structure:
{
entity_kind_id: {
entity1_id: [1, 2, 3],
entity2_id: ... | [
"Builds",
"a",
"dict",
"with",
"keys",
"of",
"entity",
"kinds",
"if",
"and",
"values",
"are",
"another",
"dict",
".",
"Each",
"of",
"these",
"dicts",
"are",
"keyed",
"off",
"of",
"a",
"super",
"entity",
"id",
"and",
"optional",
"have",
"an",
"all",
"ke... | ebc61f34313c52f4ef5819eb1da25b2ad837e80c | https://github.com/ambitioninc/django-entity/blob/ebc61f34313c52f4ef5819eb1da25b2ad837e80c/entity/models.py#L543-L611 | train |
ambitioninc/django-entity | entity/models.py | EntityQuerySet.is_sub_to_all | def is_sub_to_all(self, *super_entities):
"""
Given a list of super entities, return the entities that have those as a subset of their super entities.
"""
if super_entities:
if len(super_entities) == 1:
# Optimize for the case of just one super entity since th... | python | def is_sub_to_all(self, *super_entities):
"""
Given a list of super entities, return the entities that have those as a subset of their super entities.
"""
if super_entities:
if len(super_entities) == 1:
# Optimize for the case of just one super entity since th... | [
"def",
"is_sub_to_all",
"(",
"self",
",",
"*",
"super_entities",
")",
":",
"if",
"super_entities",
":",
"if",
"len",
"(",
"super_entities",
")",
"==",
"1",
":",
"# Optimize for the case of just one super entity since this is a much less intensive query",
"has_subset",
"="... | Given a list of super entities, return the entities that have those as a subset of their super entities. | [
"Given",
"a",
"list",
"of",
"super",
"entities",
"return",
"the",
"entities",
"that",
"have",
"those",
"as",
"a",
"subset",
"of",
"their",
"super",
"entities",
"."
] | ebc61f34313c52f4ef5819eb1da25b2ad837e80c | https://github.com/ambitioninc/django-entity/blob/ebc61f34313c52f4ef5819eb1da25b2ad837e80c/entity/models.py#L79-L96 | train |
ambitioninc/django-entity | entity/models.py | EntityQuerySet.is_sub_to_any | def is_sub_to_any(self, *super_entities):
"""
Given a list of super entities, return the entities that have super entities that interset with those provided.
"""
if super_entities:
return self.filter(id__in=EntityRelationship.objects.filter(
super_entity__in=s... | python | def is_sub_to_any(self, *super_entities):
"""
Given a list of super entities, return the entities that have super entities that interset with those provided.
"""
if super_entities:
return self.filter(id__in=EntityRelationship.objects.filter(
super_entity__in=s... | [
"def",
"is_sub_to_any",
"(",
"self",
",",
"*",
"super_entities",
")",
":",
"if",
"super_entities",
":",
"return",
"self",
".",
"filter",
"(",
"id__in",
"=",
"EntityRelationship",
".",
"objects",
".",
"filter",
"(",
"super_entity__in",
"=",
"super_entities",
")... | Given a list of super entities, return the entities that have super entities that interset with those provided. | [
"Given",
"a",
"list",
"of",
"super",
"entities",
"return",
"the",
"entities",
"that",
"have",
"super",
"entities",
"that",
"interset",
"with",
"those",
"provided",
"."
] | ebc61f34313c52f4ef5819eb1da25b2ad837e80c | https://github.com/ambitioninc/django-entity/blob/ebc61f34313c52f4ef5819eb1da25b2ad837e80c/entity/models.py#L98-L106 | train |
ambitioninc/django-entity | entity/models.py | EntityQuerySet.is_sub_to_all_kinds | def is_sub_to_all_kinds(self, *super_entity_kinds):
"""
Each returned entity will have superentites whos combined entity_kinds included *super_entity_kinds
"""
if super_entity_kinds:
if len(super_entity_kinds) == 1:
# Optimize for the case of just one
... | python | def is_sub_to_all_kinds(self, *super_entity_kinds):
"""
Each returned entity will have superentites whos combined entity_kinds included *super_entity_kinds
"""
if super_entity_kinds:
if len(super_entity_kinds) == 1:
# Optimize for the case of just one
... | [
"def",
"is_sub_to_all_kinds",
"(",
"self",
",",
"*",
"super_entity_kinds",
")",
":",
"if",
"super_entity_kinds",
":",
"if",
"len",
"(",
"super_entity_kinds",
")",
"==",
"1",
":",
"# Optimize for the case of just one",
"has_subset",
"=",
"EntityRelationship",
".",
"o... | Each returned entity will have superentites whos combined entity_kinds included *super_entity_kinds | [
"Each",
"returned",
"entity",
"will",
"have",
"superentites",
"whos",
"combined",
"entity_kinds",
"included",
"*",
"super_entity_kinds"
] | ebc61f34313c52f4ef5819eb1da25b2ad837e80c | https://github.com/ambitioninc/django-entity/blob/ebc61f34313c52f4ef5819eb1da25b2ad837e80c/entity/models.py#L108-L126 | train |
ambitioninc/django-entity | entity/models.py | EntityQuerySet.is_sub_to_any_kind | def is_sub_to_any_kind(self, *super_entity_kinds):
"""
Find all entities that have super_entities of any of the specified kinds
"""
if super_entity_kinds:
# get the pks of the desired subs from the relationships table
if len(super_entity_kinds) == 1:
... | python | def is_sub_to_any_kind(self, *super_entity_kinds):
"""
Find all entities that have super_entities of any of the specified kinds
"""
if super_entity_kinds:
# get the pks of the desired subs from the relationships table
if len(super_entity_kinds) == 1:
... | [
"def",
"is_sub_to_any_kind",
"(",
"self",
",",
"*",
"super_entity_kinds",
")",
":",
"if",
"super_entity_kinds",
":",
"# get the pks of the desired subs from the relationships table",
"if",
"len",
"(",
"super_entity_kinds",
")",
"==",
"1",
":",
"entity_pks",
"=",
"Entity... | Find all entities that have super_entities of any of the specified kinds | [
"Find",
"all",
"entities",
"that",
"have",
"super_entities",
"of",
"any",
"of",
"the",
"specified",
"kinds"
] | ebc61f34313c52f4ef5819eb1da25b2ad837e80c | https://github.com/ambitioninc/django-entity/blob/ebc61f34313c52f4ef5819eb1da25b2ad837e80c/entity/models.py#L128-L145 | train |
ambitioninc/django-entity | entity/models.py | EntityQuerySet.cache_relationships | def cache_relationships(self, cache_super=True, cache_sub=True):
"""
Caches the super and sub relationships by doing a prefetch_related.
"""
relationships_to_cache = compress(
['super_relationships__super_entity', 'sub_relationships__sub_entity'], [cache_super, cache_sub])
... | python | def cache_relationships(self, cache_super=True, cache_sub=True):
"""
Caches the super and sub relationships by doing a prefetch_related.
"""
relationships_to_cache = compress(
['super_relationships__super_entity', 'sub_relationships__sub_entity'], [cache_super, cache_sub])
... | [
"def",
"cache_relationships",
"(",
"self",
",",
"cache_super",
"=",
"True",
",",
"cache_sub",
"=",
"True",
")",
":",
"relationships_to_cache",
"=",
"compress",
"(",
"[",
"'super_relationships__super_entity'",
",",
"'sub_relationships__sub_entity'",
"]",
",",
"[",
"c... | Caches the super and sub relationships by doing a prefetch_related. | [
"Caches",
"the",
"super",
"and",
"sub",
"relationships",
"by",
"doing",
"a",
"prefetch_related",
"."
] | ebc61f34313c52f4ef5819eb1da25b2ad837e80c | https://github.com/ambitioninc/django-entity/blob/ebc61f34313c52f4ef5819eb1da25b2ad837e80c/entity/models.py#L147-L153 | train |
ambitioninc/django-entity | entity/models.py | AllEntityManager.get_for_obj | def get_for_obj(self, entity_model_obj):
"""
Given a saved entity model object, return the associated entity.
"""
return self.get(entity_type=ContentType.objects.get_for_model(
entity_model_obj, for_concrete_model=False), entity_id=entity_model_obj.id) | python | def get_for_obj(self, entity_model_obj):
"""
Given a saved entity model object, return the associated entity.
"""
return self.get(entity_type=ContentType.objects.get_for_model(
entity_model_obj, for_concrete_model=False), entity_id=entity_model_obj.id) | [
"def",
"get_for_obj",
"(",
"self",
",",
"entity_model_obj",
")",
":",
"return",
"self",
".",
"get",
"(",
"entity_type",
"=",
"ContentType",
".",
"objects",
".",
"get_for_model",
"(",
"entity_model_obj",
",",
"for_concrete_model",
"=",
"False",
")",
",",
"entit... | Given a saved entity model object, return the associated entity. | [
"Given",
"a",
"saved",
"entity",
"model",
"object",
"return",
"the",
"associated",
"entity",
"."
] | ebc61f34313c52f4ef5819eb1da25b2ad837e80c | https://github.com/ambitioninc/django-entity/blob/ebc61f34313c52f4ef5819eb1da25b2ad837e80c/entity/models.py#L163-L168 | train |
ambitioninc/django-entity | entity/models.py | AllEntityManager.delete_for_obj | def delete_for_obj(self, entity_model_obj):
"""
Delete the entities associated with a model object.
"""
return self.filter(
entity_type=ContentType.objects.get_for_model(
entity_model_obj, for_concrete_model=False), entity_id=entity_model_obj.id).delete(
... | python | def delete_for_obj(self, entity_model_obj):
"""
Delete the entities associated with a model object.
"""
return self.filter(
entity_type=ContentType.objects.get_for_model(
entity_model_obj, for_concrete_model=False), entity_id=entity_model_obj.id).delete(
... | [
"def",
"delete_for_obj",
"(",
"self",
",",
"entity_model_obj",
")",
":",
"return",
"self",
".",
"filter",
"(",
"entity_type",
"=",
"ContentType",
".",
"objects",
".",
"get_for_model",
"(",
"entity_model_obj",
",",
"for_concrete_model",
"=",
"False",
")",
",",
... | Delete the entities associated with a model object. | [
"Delete",
"the",
"entities",
"associated",
"with",
"a",
"model",
"object",
"."
] | ebc61f34313c52f4ef5819eb1da25b2ad837e80c | https://github.com/ambitioninc/django-entity/blob/ebc61f34313c52f4ef5819eb1da25b2ad837e80c/entity/models.py#L170-L177 | train |
ambitioninc/django-entity | entity/models.py | AllEntityManager.cache_relationships | def cache_relationships(self, cache_super=True, cache_sub=True):
"""
Caches the super and sub relationships by doing a prefetch_related.
"""
return self.get_queryset().cache_relationships(cache_super=cache_super, cache_sub=cache_sub) | python | def cache_relationships(self, cache_super=True, cache_sub=True):
"""
Caches the super and sub relationships by doing a prefetch_related.
"""
return self.get_queryset().cache_relationships(cache_super=cache_super, cache_sub=cache_sub) | [
"def",
"cache_relationships",
"(",
"self",
",",
"cache_super",
"=",
"True",
",",
"cache_sub",
"=",
"True",
")",
":",
"return",
"self",
".",
"get_queryset",
"(",
")",
".",
"cache_relationships",
"(",
"cache_super",
"=",
"cache_super",
",",
"cache_sub",
"=",
"... | Caches the super and sub relationships by doing a prefetch_related. | [
"Caches",
"the",
"super",
"and",
"sub",
"relationships",
"by",
"doing",
"a",
"prefetch_related",
"."
] | ebc61f34313c52f4ef5819eb1da25b2ad837e80c | https://github.com/ambitioninc/django-entity/blob/ebc61f34313c52f4ef5819eb1da25b2ad837e80c/entity/models.py#L228-L232 | train |
ambitioninc/django-entity | entity/models.py | EntityGroupManager.get_membership_cache | def get_membership_cache(self, group_ids=None, is_active=True):
"""
Build a dict cache with the group membership info. Keyed off the group id and the values are
a 2 element list of entity id and entity kind id (same values as the membership model). If no group ids
are passed, then all gr... | python | def get_membership_cache(self, group_ids=None, is_active=True):
"""
Build a dict cache with the group membership info. Keyed off the group id and the values are
a 2 element list of entity id and entity kind id (same values as the membership model). If no group ids
are passed, then all gr... | [
"def",
"get_membership_cache",
"(",
"self",
",",
"group_ids",
"=",
"None",
",",
"is_active",
"=",
"True",
")",
":",
"membership_queryset",
"=",
"EntityGroupMembership",
".",
"objects",
".",
"filter",
"(",
"Q",
"(",
"entity__isnull",
"=",
"True",
")",
"|",
"(... | Build a dict cache with the group membership info. Keyed off the group id and the values are
a 2 element list of entity id and entity kind id (same values as the membership model). If no group ids
are passed, then all groups will be fetched
:param is_active: Flag indicating whether to filter on... | [
"Build",
"a",
"dict",
"cache",
"with",
"the",
"group",
"membership",
"info",
".",
"Keyed",
"off",
"the",
"group",
"id",
"and",
"the",
"values",
"are",
"a",
"2",
"element",
"list",
"of",
"entity",
"id",
"and",
"entity",
"kind",
"id",
"(",
"same",
"value... | ebc61f34313c52f4ef5819eb1da25b2ad837e80c | https://github.com/ambitioninc/django-entity/blob/ebc61f34313c52f4ef5819eb1da25b2ad837e80c/entity/models.py#L317-L343 | train |
ambitioninc/django-entity | entity/models.py | EntityGroup.all_entities | def all_entities(self, is_active=True):
"""
Return all the entities in the group.
Because groups can contain both individual entities, as well
as whole groups of entities, this method acts as a convenient
way to get a queryset of all the entities in the group.
"""
... | python | def all_entities(self, is_active=True):
"""
Return all the entities in the group.
Because groups can contain both individual entities, as well
as whole groups of entities, this method acts as a convenient
way to get a queryset of all the entities in the group.
"""
... | [
"def",
"all_entities",
"(",
"self",
",",
"is_active",
"=",
"True",
")",
":",
"return",
"self",
".",
"get_all_entities",
"(",
"return_models",
"=",
"True",
",",
"is_active",
"=",
"is_active",
")"
] | Return all the entities in the group.
Because groups can contain both individual entities, as well
as whole groups of entities, this method acts as a convenient
way to get a queryset of all the entities in the group. | [
"Return",
"all",
"the",
"entities",
"in",
"the",
"group",
"."
] | ebc61f34313c52f4ef5819eb1da25b2ad837e80c | https://github.com/ambitioninc/django-entity/blob/ebc61f34313c52f4ef5819eb1da25b2ad837e80c/entity/models.py#L364-L372 | train |
ambitioninc/django-entity | entity/models.py | EntityGroup.get_all_entities | def get_all_entities(self, membership_cache=None, entities_by_kind=None, return_models=False, is_active=True):
"""
Returns a list of all entity ids in this group or optionally returns a queryset for all entity models.
In order to reduce queries for multiple group lookups, it is expected that the... | python | def get_all_entities(self, membership_cache=None, entities_by_kind=None, return_models=False, is_active=True):
"""
Returns a list of all entity ids in this group or optionally returns a queryset for all entity models.
In order to reduce queries for multiple group lookups, it is expected that the... | [
"def",
"get_all_entities",
"(",
"self",
",",
"membership_cache",
"=",
"None",
",",
"entities_by_kind",
"=",
"None",
",",
"return_models",
"=",
"False",
",",
"is_active",
"=",
"True",
")",
":",
"# If cache args were not passed, generate the cache",
"if",
"membership_ca... | Returns a list of all entity ids in this group or optionally returns a queryset for all entity models.
In order to reduce queries for multiple group lookups, it is expected that the membership_cache and
entities_by_kind are built outside of this method and passed in as arguments.
:param membersh... | [
"Returns",
"a",
"list",
"of",
"all",
"entity",
"ids",
"in",
"this",
"group",
"or",
"optionally",
"returns",
"a",
"queryset",
"for",
"all",
"entity",
"models",
".",
"In",
"order",
"to",
"reduce",
"queries",
"for",
"multiple",
"group",
"lookups",
"it",
"is",... | ebc61f34313c52f4ef5819eb1da25b2ad837e80c | https://github.com/ambitioninc/django-entity/blob/ebc61f34313c52f4ef5819eb1da25b2ad837e80c/entity/models.py#L374-L418 | train |
ambitioninc/django-entity | entity/models.py | EntityGroup.add_entity | def add_entity(self, entity, sub_entity_kind=None):
"""
Add an entity, or sub-entity group to this EntityGroup.
:type entity: Entity
:param entity: The entity to add.
:type sub_entity_kind: Optional EntityKind
:param sub_entity_kind: If a sub_entity_kind is given, all
... | python | def add_entity(self, entity, sub_entity_kind=None):
"""
Add an entity, or sub-entity group to this EntityGroup.
:type entity: Entity
:param entity: The entity to add.
:type sub_entity_kind: Optional EntityKind
:param sub_entity_kind: If a sub_entity_kind is given, all
... | [
"def",
"add_entity",
"(",
"self",
",",
"entity",
",",
"sub_entity_kind",
"=",
"None",
")",
":",
"membership",
"=",
"EntityGroupMembership",
".",
"objects",
".",
"create",
"(",
"entity_group",
"=",
"self",
",",
"entity",
"=",
"entity",
",",
"sub_entity_kind",
... | Add an entity, or sub-entity group to this EntityGroup.
:type entity: Entity
:param entity: The entity to add.
:type sub_entity_kind: Optional EntityKind
:param sub_entity_kind: If a sub_entity_kind is given, all
sub_entities of the entity will be added to this
... | [
"Add",
"an",
"entity",
"or",
"sub",
"-",
"entity",
"group",
"to",
"this",
"EntityGroup",
"."
] | ebc61f34313c52f4ef5819eb1da25b2ad837e80c | https://github.com/ambitioninc/django-entity/blob/ebc61f34313c52f4ef5819eb1da25b2ad837e80c/entity/models.py#L420-L437 | train |
ambitioninc/django-entity | entity/models.py | EntityGroup.bulk_add_entities | def bulk_add_entities(self, entities_and_kinds):
"""
Add many entities and sub-entity groups to this EntityGroup.
:type entities_and_kinds: List of (Entity, EntityKind) pairs.
:param entities_and_kinds: A list of entity, entity-kind pairs
to add to the group. In the pairs th... | python | def bulk_add_entities(self, entities_and_kinds):
"""
Add many entities and sub-entity groups to this EntityGroup.
:type entities_and_kinds: List of (Entity, EntityKind) pairs.
:param entities_and_kinds: A list of entity, entity-kind pairs
to add to the group. In the pairs th... | [
"def",
"bulk_add_entities",
"(",
"self",
",",
"entities_and_kinds",
")",
":",
"memberships",
"=",
"[",
"EntityGroupMembership",
"(",
"entity_group",
"=",
"self",
",",
"entity",
"=",
"entity",
",",
"sub_entity_kind",
"=",
"sub_entity_kind",
",",
")",
"for",
"enti... | Add many entities and sub-entity groups to this EntityGroup.
:type entities_and_kinds: List of (Entity, EntityKind) pairs.
:param entities_and_kinds: A list of entity, entity-kind pairs
to add to the group. In the pairs the entity-kind can be
``None``, to add a single entity, or... | [
"Add",
"many",
"entities",
"and",
"sub",
"-",
"entity",
"groups",
"to",
"this",
"EntityGroup",
"."
] | ebc61f34313c52f4ef5819eb1da25b2ad837e80c | https://github.com/ambitioninc/django-entity/blob/ebc61f34313c52f4ef5819eb1da25b2ad837e80c/entity/models.py#L439-L455 | train |
ambitioninc/django-entity | entity/models.py | EntityGroup.remove_entity | def remove_entity(self, entity, sub_entity_kind=None):
"""
Remove an entity, or sub-entity group to this EntityGroup.
:type entity: Entity
:param entity: The entity to remove.
:type sub_entity_kind: Optional EntityKind
:param sub_entity_kind: If a sub_entity_kind is giv... | python | def remove_entity(self, entity, sub_entity_kind=None):
"""
Remove an entity, or sub-entity group to this EntityGroup.
:type entity: Entity
:param entity: The entity to remove.
:type sub_entity_kind: Optional EntityKind
:param sub_entity_kind: If a sub_entity_kind is giv... | [
"def",
"remove_entity",
"(",
"self",
",",
"entity",
",",
"sub_entity_kind",
"=",
"None",
")",
":",
"EntityGroupMembership",
".",
"objects",
".",
"get",
"(",
"entity_group",
"=",
"self",
",",
"entity",
"=",
"entity",
",",
"sub_entity_kind",
"=",
"sub_entity_kin... | Remove an entity, or sub-entity group to this EntityGroup.
:type entity: Entity
:param entity: The entity to remove.
:type sub_entity_kind: Optional EntityKind
:param sub_entity_kind: If a sub_entity_kind is given, all
sub_entities of the entity will be removed from this
... | [
"Remove",
"an",
"entity",
"or",
"sub",
"-",
"entity",
"group",
"to",
"this",
"EntityGroup",
"."
] | ebc61f34313c52f4ef5819eb1da25b2ad837e80c | https://github.com/ambitioninc/django-entity/blob/ebc61f34313c52f4ef5819eb1da25b2ad837e80c/entity/models.py#L457-L473 | train |
ambitioninc/django-entity | entity/models.py | EntityGroup.bulk_remove_entities | def bulk_remove_entities(self, entities_and_kinds):
"""
Remove many entities and sub-entity groups to this EntityGroup.
:type entities_and_kinds: List of (Entity, EntityKind) pairs.
:param entities_and_kinds: A list of entity, entity-kind pairs
to remove from the group. In t... | python | def bulk_remove_entities(self, entities_and_kinds):
"""
Remove many entities and sub-entity groups to this EntityGroup.
:type entities_and_kinds: List of (Entity, EntityKind) pairs.
:param entities_and_kinds: A list of entity, entity-kind pairs
to remove from the group. In t... | [
"def",
"bulk_remove_entities",
"(",
"self",
",",
"entities_and_kinds",
")",
":",
"criteria",
"=",
"[",
"Q",
"(",
"entity",
"=",
"entity",
",",
"sub_entity_kind",
"=",
"entity_kind",
")",
"for",
"entity",
",",
"entity_kind",
"in",
"entities_and_kinds",
"]",
"cr... | Remove many entities and sub-entity groups to this EntityGroup.
:type entities_and_kinds: List of (Entity, EntityKind) pairs.
:param entities_and_kinds: A list of entity, entity-kind pairs
to remove from the group. In the pairs, the entity-kind
can be ``None``, to add a single e... | [
"Remove",
"many",
"entities",
"and",
"sub",
"-",
"entity",
"groups",
"to",
"this",
"EntityGroup",
"."
] | ebc61f34313c52f4ef5819eb1da25b2ad837e80c | https://github.com/ambitioninc/django-entity/blob/ebc61f34313c52f4ef5819eb1da25b2ad837e80c/entity/models.py#L475-L491 | train |
ambitioninc/django-entity | entity/models.py | EntityGroup.bulk_overwrite | def bulk_overwrite(self, entities_and_kinds):
"""
Update the group to the given entities and sub-entity groups.
After this operation, the only members of this EntityGroup
will be the given entities, and sub-entity groups.
:type entities_and_kinds: List of (Entity, EntityKind) p... | python | def bulk_overwrite(self, entities_and_kinds):
"""
Update the group to the given entities and sub-entity groups.
After this operation, the only members of this EntityGroup
will be the given entities, and sub-entity groups.
:type entities_and_kinds: List of (Entity, EntityKind) p... | [
"def",
"bulk_overwrite",
"(",
"self",
",",
"entities_and_kinds",
")",
":",
"EntityGroupMembership",
".",
"objects",
".",
"filter",
"(",
"entity_group",
"=",
"self",
")",
".",
"delete",
"(",
")",
"return",
"self",
".",
"bulk_add_entities",
"(",
"entities_and_kind... | Update the group to the given entities and sub-entity groups.
After this operation, the only members of this EntityGroup
will be the given entities, and sub-entity groups.
:type entities_and_kinds: List of (Entity, EntityKind) pairs.
:param entities_and_kinds: A list of entity, entity-... | [
"Update",
"the",
"group",
"to",
"the",
"given",
"entities",
"and",
"sub",
"-",
"entity",
"groups",
"."
] | ebc61f34313c52f4ef5819eb1da25b2ad837e80c | https://github.com/ambitioninc/django-entity/blob/ebc61f34313c52f4ef5819eb1da25b2ad837e80c/entity/models.py#L493-L507 | train |
philgyford/django-spectator | spectator/events/migrations/0007_work_slug_20180102_1137.py | generate_slug | def generate_slug(value):
"A copy of spectator.core.models.SluggedModelMixin._generate_slug()"
alphabet = 'abcdefghijkmnopqrstuvwxyz23456789'
salt = 'Django Spectator'
if hasattr(settings, 'SPECTATOR_SLUG_ALPHABET'):
alphabet = settings.SPECTATOR_SLUG_ALPHABET
if hasattr(settings, 'SPECTAT... | python | def generate_slug(value):
"A copy of spectator.core.models.SluggedModelMixin._generate_slug()"
alphabet = 'abcdefghijkmnopqrstuvwxyz23456789'
salt = 'Django Spectator'
if hasattr(settings, 'SPECTATOR_SLUG_ALPHABET'):
alphabet = settings.SPECTATOR_SLUG_ALPHABET
if hasattr(settings, 'SPECTAT... | [
"def",
"generate_slug",
"(",
"value",
")",
":",
"alphabet",
"=",
"'abcdefghijkmnopqrstuvwxyz23456789'",
"salt",
"=",
"'Django Spectator'",
"if",
"hasattr",
"(",
"settings",
",",
"'SPECTATOR_SLUG_ALPHABET'",
")",
":",
"alphabet",
"=",
"settings",
".",
"SPECTATOR_SLUG_A... | A copy of spectator.core.models.SluggedModelMixin._generate_slug() | [
"A",
"copy",
"of",
"spectator",
".",
"core",
".",
"models",
".",
"SluggedModelMixin",
".",
"_generate_slug",
"()"
] | f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada | https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/events/migrations/0007_work_slug_20180102_1137.py#L8-L21 | train |
philgyford/django-spectator | spectator/events/migrations/0007_work_slug_20180102_1137.py | set_slug | def set_slug(apps, schema_editor, class_name):
"""
Create a slug for each Work already in the DB.
"""
Cls = apps.get_model('spectator_events', class_name)
for obj in Cls.objects.all():
obj.slug = generate_slug(obj.pk)
obj.save(update_fields=['slug']) | python | def set_slug(apps, schema_editor, class_name):
"""
Create a slug for each Work already in the DB.
"""
Cls = apps.get_model('spectator_events', class_name)
for obj in Cls.objects.all():
obj.slug = generate_slug(obj.pk)
obj.save(update_fields=['slug']) | [
"def",
"set_slug",
"(",
"apps",
",",
"schema_editor",
",",
"class_name",
")",
":",
"Cls",
"=",
"apps",
".",
"get_model",
"(",
"'spectator_events'",
",",
"class_name",
")",
"for",
"obj",
"in",
"Cls",
".",
"objects",
".",
"all",
"(",
")",
":",
"obj",
"."... | Create a slug for each Work already in the DB. | [
"Create",
"a",
"slug",
"for",
"each",
"Work",
"already",
"in",
"the",
"DB",
"."
] | f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada | https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/events/migrations/0007_work_slug_20180102_1137.py#L24-L32 | train |
philgyford/django-spectator | spectator/events/models.py | Event.kind_name | def kind_name(self):
"e.g. 'Gig' or 'Movie'."
return {k:v for (k,v) in self.KIND_CHOICES}[self.kind] | python | def kind_name(self):
"e.g. 'Gig' or 'Movie'."
return {k:v for (k,v) in self.KIND_CHOICES}[self.kind] | [
"def",
"kind_name",
"(",
"self",
")",
":",
"return",
"{",
"k",
":",
"v",
"for",
"(",
"k",
",",
"v",
")",
"in",
"self",
".",
"KIND_CHOICES",
"}",
"[",
"self",
".",
"kind",
"]"
] | e.g. 'Gig' or 'Movie'. | [
"e",
".",
"g",
".",
"Gig",
"or",
"Movie",
"."
] | f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada | https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/events/models.py#L231-L233 | train |
philgyford/django-spectator | spectator/events/models.py | Event.get_kind_name_plural | def get_kind_name_plural(kind):
"e.g. 'Gigs' or 'Movies'."
if kind in ['comedy', 'cinema', 'dance', 'theatre']:
return kind.title()
elif kind == 'museum':
return 'Galleries/Museums'
else:
return '{}s'.format(Event.get_kind_name(kind)) | python | def get_kind_name_plural(kind):
"e.g. 'Gigs' or 'Movies'."
if kind in ['comedy', 'cinema', 'dance', 'theatre']:
return kind.title()
elif kind == 'museum':
return 'Galleries/Museums'
else:
return '{}s'.format(Event.get_kind_name(kind)) | [
"def",
"get_kind_name_plural",
"(",
"kind",
")",
":",
"if",
"kind",
"in",
"[",
"'comedy'",
",",
"'cinema'",
",",
"'dance'",
",",
"'theatre'",
"]",
":",
"return",
"kind",
".",
"title",
"(",
")",
"elif",
"kind",
"==",
"'museum'",
":",
"return",
"'Galleries... | e.g. 'Gigs' or 'Movies'. | [
"e",
".",
"g",
".",
"Gigs",
"or",
"Movies",
"."
] | f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada | https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/events/models.py#L250-L257 | train |
philgyford/django-spectator | spectator/events/models.py | Event.get_kinds_data | def get_kinds_data():
"""
Returns a dict of all the data about the kinds, keyed to the kind
value. e.g:
{
'gig': {
'name': 'Gig',
'slug': 'gigs',
'name_plural': 'Gigs',
},
# et... | python | def get_kinds_data():
"""
Returns a dict of all the data about the kinds, keyed to the kind
value. e.g:
{
'gig': {
'name': 'Gig',
'slug': 'gigs',
'name_plural': 'Gigs',
},
# et... | [
"def",
"get_kinds_data",
"(",
")",
":",
"kinds",
"=",
"{",
"k",
":",
"{",
"'name'",
":",
"v",
"}",
"for",
"k",
",",
"v",
"in",
"Event",
".",
"KIND_CHOICES",
"}",
"for",
"k",
",",
"data",
"in",
"kinds",
".",
"items",
"(",
")",
":",
"kinds",
"[",... | Returns a dict of all the data about the kinds, keyed to the kind
value. e.g:
{
'gig': {
'name': 'Gig',
'slug': 'gigs',
'name_plural': 'Gigs',
},
# etc
} | [
"Returns",
"a",
"dict",
"of",
"all",
"the",
"data",
"about",
"the",
"kinds",
"keyed",
"to",
"the",
"kind",
"value",
".",
"e",
".",
"g",
":",
"{",
"gig",
":",
"{",
"name",
":",
"Gig",
"slug",
":",
"gigs",
"name_plural",
":",
"Gigs",
"}",
"#",
"etc... | f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada | https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/events/models.py#L277-L294 | train |
philgyford/django-spectator | spectator/events/models.py | Work.get_list_url | def get_list_url(self, kind_slug=None):
"""
Get the list URL for this Work.
You can also pass a kind_slug in (e.g. 'movies') and it will use that
instead of the Work's kind_slug. (Why? Useful in views. Or tests of
views, at least.)
"""
if kind_slug is None:
... | python | def get_list_url(self, kind_slug=None):
"""
Get the list URL for this Work.
You can also pass a kind_slug in (e.g. 'movies') and it will use that
instead of the Work's kind_slug. (Why? Useful in views. Or tests of
views, at least.)
"""
if kind_slug is None:
... | [
"def",
"get_list_url",
"(",
"self",
",",
"kind_slug",
"=",
"None",
")",
":",
"if",
"kind_slug",
"is",
"None",
":",
"kind_slug",
"=",
"self",
".",
"KIND_SLUGS",
"[",
"self",
".",
"kind",
"]",
"return",
"reverse",
"(",
"'spectator:events:work_list'",
",",
"k... | Get the list URL for this Work.
You can also pass a kind_slug in (e.g. 'movies') and it will use that
instead of the Work's kind_slug. (Why? Useful in views. Or tests of
views, at least.) | [
"Get",
"the",
"list",
"URL",
"for",
"this",
"Work",
".",
"You",
"can",
"also",
"pass",
"a",
"kind_slug",
"in",
"(",
"e",
".",
"g",
".",
"movies",
")",
"and",
"it",
"will",
"use",
"that",
"instead",
"of",
"the",
"Work",
"s",
"kind_slug",
".",
"(",
... | f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada | https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/events/models.py#L379-L389 | train |
frictionlessdata/tableschema-pandas-py | tableschema_pandas/mapper.py | Mapper.convert_descriptor_and_rows | def convert_descriptor_and_rows(self, descriptor, rows):
"""Convert descriptor and rows to Pandas
"""
# Prepare
primary_key = None
schema = tableschema.Schema(descriptor)
if len(schema.primary_key) == 1:
primary_key = schema.primary_key[0]
elif len(sc... | python | def convert_descriptor_and_rows(self, descriptor, rows):
"""Convert descriptor and rows to Pandas
"""
# Prepare
primary_key = None
schema = tableschema.Schema(descriptor)
if len(schema.primary_key) == 1:
primary_key = schema.primary_key[0]
elif len(sc... | [
"def",
"convert_descriptor_and_rows",
"(",
"self",
",",
"descriptor",
",",
"rows",
")",
":",
"# Prepare",
"primary_key",
"=",
"None",
"schema",
"=",
"tableschema",
".",
"Schema",
"(",
"descriptor",
")",
"if",
"len",
"(",
"schema",
".",
"primary_key",
")",
"=... | Convert descriptor and rows to Pandas | [
"Convert",
"descriptor",
"and",
"rows",
"to",
"Pandas"
] | ef941dbc12f5d346e9612f8fec1b4b356b8493ca | https://github.com/frictionlessdata/tableschema-pandas-py/blob/ef941dbc12f5d346e9612f8fec1b4b356b8493ca/tableschema_pandas/mapper.py#L23-L87 | train |
frictionlessdata/tableschema-pandas-py | tableschema_pandas/mapper.py | Mapper.convert_type | def convert_type(self, type):
"""Convert type to Pandas
"""
# Mapping
mapping = {
'any': np.dtype('O'),
'array': np.dtype(list),
'boolean': np.dtype(bool),
'date': np.dtype('O'),
'datetime': np.dtype('datetime64[ns]'),
... | python | def convert_type(self, type):
"""Convert type to Pandas
"""
# Mapping
mapping = {
'any': np.dtype('O'),
'array': np.dtype(list),
'boolean': np.dtype(bool),
'date': np.dtype('O'),
'datetime': np.dtype('datetime64[ns]'),
... | [
"def",
"convert_type",
"(",
"self",
",",
"type",
")",
":",
"# Mapping",
"mapping",
"=",
"{",
"'any'",
":",
"np",
".",
"dtype",
"(",
"'O'",
")",
",",
"'array'",
":",
"np",
".",
"dtype",
"(",
"list",
")",
",",
"'boolean'",
":",
"np",
".",
"dtype",
... | Convert type to Pandas | [
"Convert",
"type",
"to",
"Pandas"
] | ef941dbc12f5d346e9612f8fec1b4b356b8493ca | https://github.com/frictionlessdata/tableschema-pandas-py/blob/ef941dbc12f5d346e9612f8fec1b4b356b8493ca/tableschema_pandas/mapper.py#L89-L117 | train |
frictionlessdata/tableschema-pandas-py | tableschema_pandas/mapper.py | Mapper.restore_descriptor | def restore_descriptor(self, dataframe):
"""Restore descriptor from Pandas
"""
# Prepare
fields = []
primary_key = None
# Primary key
if dataframe.index.name:
field_type = self.restore_type(dataframe.index.dtype)
field = {
... | python | def restore_descriptor(self, dataframe):
"""Restore descriptor from Pandas
"""
# Prepare
fields = []
primary_key = None
# Primary key
if dataframe.index.name:
field_type = self.restore_type(dataframe.index.dtype)
field = {
... | [
"def",
"restore_descriptor",
"(",
"self",
",",
"dataframe",
")",
":",
"# Prepare",
"fields",
"=",
"[",
"]",
"primary_key",
"=",
"None",
"# Primary key",
"if",
"dataframe",
".",
"index",
".",
"name",
":",
"field_type",
"=",
"self",
".",
"restore_type",
"(",
... | Restore descriptor from Pandas | [
"Restore",
"descriptor",
"from",
"Pandas"
] | ef941dbc12f5d346e9612f8fec1b4b356b8493ca | https://github.com/frictionlessdata/tableschema-pandas-py/blob/ef941dbc12f5d346e9612f8fec1b4b356b8493ca/tableschema_pandas/mapper.py#L119-L154 | train |
frictionlessdata/tableschema-pandas-py | tableschema_pandas/mapper.py | Mapper.restore_row | def restore_row(self, row, schema, pk):
"""Restore row from Pandas
"""
result = []
for field in schema.fields:
if schema.primary_key and schema.primary_key[0] == field.name:
if field.type == 'number' and np.isnan(pk):
pk = None
... | python | def restore_row(self, row, schema, pk):
"""Restore row from Pandas
"""
result = []
for field in schema.fields:
if schema.primary_key and schema.primary_key[0] == field.name:
if field.type == 'number' and np.isnan(pk):
pk = None
... | [
"def",
"restore_row",
"(",
"self",
",",
"row",
",",
"schema",
",",
"pk",
")",
":",
"result",
"=",
"[",
"]",
"for",
"field",
"in",
"schema",
".",
"fields",
":",
"if",
"schema",
".",
"primary_key",
"and",
"schema",
".",
"primary_key",
"[",
"0",
"]",
... | Restore row from Pandas | [
"Restore",
"row",
"from",
"Pandas"
] | ef941dbc12f5d346e9612f8fec1b4b356b8493ca | https://github.com/frictionlessdata/tableschema-pandas-py/blob/ef941dbc12f5d346e9612f8fec1b4b356b8493ca/tableschema_pandas/mapper.py#L156-L176 | train |
frictionlessdata/tableschema-pandas-py | tableschema_pandas/mapper.py | Mapper.restore_type | def restore_type(self, dtype, sample=None):
"""Restore type from Pandas
"""
# Pandas types
if pdc.is_bool_dtype(dtype):
return 'boolean'
elif pdc.is_datetime64_any_dtype(dtype):
return 'datetime'
elif pdc.is_integer_dtype(dtype):
retur... | python | def restore_type(self, dtype, sample=None):
"""Restore type from Pandas
"""
# Pandas types
if pdc.is_bool_dtype(dtype):
return 'boolean'
elif pdc.is_datetime64_any_dtype(dtype):
return 'datetime'
elif pdc.is_integer_dtype(dtype):
retur... | [
"def",
"restore_type",
"(",
"self",
",",
"dtype",
",",
"sample",
"=",
"None",
")",
":",
"# Pandas types",
"if",
"pdc",
".",
"is_bool_dtype",
"(",
"dtype",
")",
":",
"return",
"'boolean'",
"elif",
"pdc",
".",
"is_datetime64_any_dtype",
"(",
"dtype",
")",
":... | Restore type from Pandas | [
"Restore",
"type",
"from",
"Pandas"
] | ef941dbc12f5d346e9612f8fec1b4b356b8493ca | https://github.com/frictionlessdata/tableschema-pandas-py/blob/ef941dbc12f5d346e9612f8fec1b4b356b8493ca/tableschema_pandas/mapper.py#L178-L207 | train |
philgyford/django-spectator | spectator/core/templatetags/spectator_core.py | change_object_link_card | def change_object_link_card(obj, perms):
"""
If the user has permission to change `obj`, show a link to its Admin page.
obj -- An object like Movie, Play, ClassicalWork, Publication, etc.
perms -- The `perms` object that it's the template.
"""
# eg: 'movie' or 'classicalwork':
name = obj.__c... | python | def change_object_link_card(obj, perms):
"""
If the user has permission to change `obj`, show a link to its Admin page.
obj -- An object like Movie, Play, ClassicalWork, Publication, etc.
perms -- The `perms` object that it's the template.
"""
# eg: 'movie' or 'classicalwork':
name = obj.__c... | [
"def",
"change_object_link_card",
"(",
"obj",
",",
"perms",
")",
":",
"# eg: 'movie' or 'classicalwork':",
"name",
"=",
"obj",
".",
"__class__",
".",
"__name__",
".",
"lower",
"(",
")",
"permission",
"=",
"'spectator.can_edit_{}'",
".",
"format",
"(",
"name",
")... | If the user has permission to change `obj`, show a link to its Admin page.
obj -- An object like Movie, Play, ClassicalWork, Publication, etc.
perms -- The `perms` object that it's the template. | [
"If",
"the",
"user",
"has",
"permission",
"to",
"change",
"obj",
"show",
"a",
"link",
"to",
"its",
"Admin",
"page",
".",
"obj",
"--",
"An",
"object",
"like",
"Movie",
"Play",
"ClassicalWork",
"Publication",
"etc",
".",
"perms",
"--",
"The",
"perms",
"obj... | f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada | https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/core/templatetags/spectator_core.py#L49-L64 | train |
philgyford/django-spectator | spectator/core/templatetags/spectator_core.py | domain_urlize | def domain_urlize(value):
"""
Returns an HTML link to the supplied URL, but only using the domain as the
text. Strips 'www.' from the start of the domain, if present.
e.g. if `my_url` is 'http://www.example.org/foo/' then:
{{ my_url|domain_urlize }}
returns:
<a href="http://www.ex... | python | def domain_urlize(value):
"""
Returns an HTML link to the supplied URL, but only using the domain as the
text. Strips 'www.' from the start of the domain, if present.
e.g. if `my_url` is 'http://www.example.org/foo/' then:
{{ my_url|domain_urlize }}
returns:
<a href="http://www.ex... | [
"def",
"domain_urlize",
"(",
"value",
")",
":",
"parsed_uri",
"=",
"urlparse",
"(",
"value",
")",
"domain",
"=",
"'{uri.netloc}'",
".",
"format",
"(",
"uri",
"=",
"parsed_uri",
")",
"if",
"domain",
".",
"startswith",
"(",
"'www.'",
")",
":",
"domain",
"=... | Returns an HTML link to the supplied URL, but only using the domain as the
text. Strips 'www.' from the start of the domain, if present.
e.g. if `my_url` is 'http://www.example.org/foo/' then:
{{ my_url|domain_urlize }}
returns:
<a href="http://www.example.org/foo/" rel="nofollow">example... | [
"Returns",
"an",
"HTML",
"link",
"to",
"the",
"supplied",
"URL",
"but",
"only",
"using",
"the",
"domain",
"as",
"the",
"text",
".",
"Strips",
"www",
".",
"from",
"the",
"start",
"of",
"the",
"domain",
"if",
"present",
"."
] | f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada | https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/core/templatetags/spectator_core.py#L68-L89 | train |
philgyford/django-spectator | spectator/core/templatetags/spectator_core.py | current_url_name | def current_url_name(context):
"""
Returns the name of the current URL, namespaced, or False.
Example usage:
{% current_url_name as url_name %}
<a href="#"{% if url_name == 'myapp:home' %} class="active"{% endif %}">Home</a>
"""
url_name = False
if context.request.resolver_ma... | python | def current_url_name(context):
"""
Returns the name of the current URL, namespaced, or False.
Example usage:
{% current_url_name as url_name %}
<a href="#"{% if url_name == 'myapp:home' %} class="active"{% endif %}">Home</a>
"""
url_name = False
if context.request.resolver_ma... | [
"def",
"current_url_name",
"(",
"context",
")",
":",
"url_name",
"=",
"False",
"if",
"context",
".",
"request",
".",
"resolver_match",
":",
"url_name",
"=",
"\"{}:{}\"",
".",
"format",
"(",
"context",
".",
"request",
".",
"resolver_match",
".",
"namespace",
... | Returns the name of the current URL, namespaced, or False.
Example usage:
{% current_url_name as url_name %}
<a href="#"{% if url_name == 'myapp:home' %} class="active"{% endif %}">Home</a> | [
"Returns",
"the",
"name",
"of",
"the",
"current",
"URL",
"namespaced",
"or",
"False",
"."
] | f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada | https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/core/templatetags/spectator_core.py#L93-L110 | train |
philgyford/django-spectator | spectator/core/templatetags/spectator_core.py | query_string | def query_string(context, key, value):
"""
For adding/replacing a key=value pair to the GET string for a URL.
eg, if we're viewing ?p=3 and we do {% query_string order 'taken' %}
then this returns "p=3&order=taken"
And, if we're viewing ?p=3&order=uploaded and we do the same thing, we get
the ... | python | def query_string(context, key, value):
"""
For adding/replacing a key=value pair to the GET string for a URL.
eg, if we're viewing ?p=3 and we do {% query_string order 'taken' %}
then this returns "p=3&order=taken"
And, if we're viewing ?p=3&order=uploaded and we do the same thing, we get
the ... | [
"def",
"query_string",
"(",
"context",
",",
"key",
",",
"value",
")",
":",
"try",
":",
"request",
"=",
"context",
"[",
"'request'",
"]",
"args",
"=",
"request",
".",
"GET",
".",
"copy",
"(",
")",
"except",
"KeyError",
":",
"args",
"=",
"QueryDict",
"... | For adding/replacing a key=value pair to the GET string for a URL.
eg, if we're viewing ?p=3 and we do {% query_string order 'taken' %}
then this returns "p=3&order=taken"
And, if we're viewing ?p=3&order=uploaded and we do the same thing, we get
the same result (ie, the existing "order=uploaded" is r... | [
"For",
"adding",
"/",
"replacing",
"a",
"key",
"=",
"value",
"pair",
"to",
"the",
"GET",
"string",
"for",
"a",
"URL",
"."
] | f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada | https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/core/templatetags/spectator_core.py#L114-L133 | train |
philgyford/django-spectator | spectator/core/templatetags/spectator_core.py | most_read_creators_card | def most_read_creators_card(num=10):
"""
Displays a card showing the Creators who have the most Readings
associated with their Publications.
In spectator_core tags, rather than spectator_reading so it can still be
used on core pages, even if spectator_reading isn't installed.
"""
if spectat... | python | def most_read_creators_card(num=10):
"""
Displays a card showing the Creators who have the most Readings
associated with their Publications.
In spectator_core tags, rather than spectator_reading so it can still be
used on core pages, even if spectator_reading isn't installed.
"""
if spectat... | [
"def",
"most_read_creators_card",
"(",
"num",
"=",
"10",
")",
":",
"if",
"spectator_apps",
".",
"is_enabled",
"(",
"'reading'",
")",
":",
"object_list",
"=",
"most_read_creators",
"(",
"num",
"=",
"num",
")",
"object_list",
"=",
"chartify",
"(",
"object_list",... | Displays a card showing the Creators who have the most Readings
associated with their Publications.
In spectator_core tags, rather than spectator_reading so it can still be
used on core pages, even if spectator_reading isn't installed. | [
"Displays",
"a",
"card",
"showing",
"the",
"Creators",
"who",
"have",
"the",
"most",
"Readings",
"associated",
"with",
"their",
"Publications",
"."
] | f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada | https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/core/templatetags/spectator_core.py#L149-L167 | train |
philgyford/django-spectator | spectator/core/templatetags/spectator_core.py | most_visited_venues_card | def most_visited_venues_card(num=10):
"""
Displays a card showing the Venues that have the most Events.
In spectator_core tags, rather than spectator_events so it can still be
used on core pages, even if spectator_events isn't installed.
"""
if spectator_apps.is_enabled('events'):
obje... | python | def most_visited_venues_card(num=10):
"""
Displays a card showing the Venues that have the most Events.
In spectator_core tags, rather than spectator_events so it can still be
used on core pages, even if spectator_events isn't installed.
"""
if spectator_apps.is_enabled('events'):
obje... | [
"def",
"most_visited_venues_card",
"(",
"num",
"=",
"10",
")",
":",
"if",
"spectator_apps",
".",
"is_enabled",
"(",
"'events'",
")",
":",
"object_list",
"=",
"most_visited_venues",
"(",
"num",
"=",
"num",
")",
"object_list",
"=",
"chartify",
"(",
"object_list"... | Displays a card showing the Venues that have the most Events.
In spectator_core tags, rather than spectator_events so it can still be
used on core pages, even if spectator_events isn't installed. | [
"Displays",
"a",
"card",
"showing",
"the",
"Venues",
"that",
"have",
"the",
"most",
"Events",
"."
] | f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada | https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/core/templatetags/spectator_core.py#L179-L196 | train |
philgyford/django-spectator | spectator/reading/models.py | Publication.has_urls | def has_urls(self):
"Handy for templates."
if self.isbn_uk or self.isbn_us or self.official_url or self.notes_url:
return True
else:
return False | python | def has_urls(self):
"Handy for templates."
if self.isbn_uk or self.isbn_us or self.official_url or self.notes_url:
return True
else:
return False | [
"def",
"has_urls",
"(",
"self",
")",
":",
"if",
"self",
".",
"isbn_uk",
"or",
"self",
".",
"isbn_us",
"or",
"self",
".",
"official_url",
"or",
"self",
".",
"notes_url",
":",
"return",
"True",
"else",
":",
"return",
"False"
] | Handy for templates. | [
"Handy",
"for",
"templates",
"."
] | f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada | https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/reading/models.py#L169-L174 | train |
philgyford/django-spectator | setup.py | get_entity | def get_entity(package, entity):
"""
eg, get_entity('spectator', 'version') returns `__version__` value in
`__init__.py`.
"""
init_py = open(os.path.join(package, '__init__.py')).read()
find = "__%s__ = ['\"]([^'\"]+)['\"]" % entity
return re.search(find, init_py).group(1) | python | def get_entity(package, entity):
"""
eg, get_entity('spectator', 'version') returns `__version__` value in
`__init__.py`.
"""
init_py = open(os.path.join(package, '__init__.py')).read()
find = "__%s__ = ['\"]([^'\"]+)['\"]" % entity
return re.search(find, init_py).group(1) | [
"def",
"get_entity",
"(",
"package",
",",
"entity",
")",
":",
"init_py",
"=",
"open",
"(",
"os",
".",
"path",
".",
"join",
"(",
"package",
",",
"'__init__.py'",
")",
")",
".",
"read",
"(",
")",
"find",
"=",
"\"__%s__ = ['\\\"]([^'\\\"]+)['\\\"]\"",
"%",
... | eg, get_entity('spectator', 'version') returns `__version__` value in
`__init__.py`. | [
"eg",
"get_entity",
"(",
"spectator",
"version",
")",
"returns",
"__version__",
"value",
"in",
"__init__",
".",
"py",
"."
] | f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada | https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/setup.py#L15-L22 | train |
philgyford/django-spectator | spectator/reading/views.py | ReadingYearArchiveView.get_queryset | def get_queryset(self):
"Reduce the number of queries and speed things up."
qs = super().get_queryset()
qs = qs.select_related('publication__series') \
.prefetch_related('publication__roles__creator')
return qs | python | def get_queryset(self):
"Reduce the number of queries and speed things up."
qs = super().get_queryset()
qs = qs.select_related('publication__series') \
.prefetch_related('publication__roles__creator')
return qs | [
"def",
"get_queryset",
"(",
"self",
")",
":",
"qs",
"=",
"super",
"(",
")",
".",
"get_queryset",
"(",
")",
"qs",
"=",
"qs",
".",
"select_related",
"(",
"'publication__series'",
")",
".",
"prefetch_related",
"(",
"'publication__roles__creator'",
")",
"return",
... | Reduce the number of queries and speed things up. | [
"Reduce",
"the",
"number",
"of",
"queries",
"and",
"speed",
"things",
"up",
"."
] | f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada | https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/reading/views.py#L122-L129 | train |
philgyford/django-spectator | spectator/core/migrations/0004_auto_20180102_0959.py | set_slug | def set_slug(apps, schema_editor):
"""
Create a slug for each Creator already in the DB.
"""
Creator = apps.get_model('spectator_core', 'Creator')
for c in Creator.objects.all():
c.slug = generate_slug(c.pk)
c.save(update_fields=['slug']) | python | def set_slug(apps, schema_editor):
"""
Create a slug for each Creator already in the DB.
"""
Creator = apps.get_model('spectator_core', 'Creator')
for c in Creator.objects.all():
c.slug = generate_slug(c.pk)
c.save(update_fields=['slug']) | [
"def",
"set_slug",
"(",
"apps",
",",
"schema_editor",
")",
":",
"Creator",
"=",
"apps",
".",
"get_model",
"(",
"'spectator_core'",
",",
"'Creator'",
")",
"for",
"c",
"in",
"Creator",
".",
"objects",
".",
"all",
"(",
")",
":",
"c",
".",
"slug",
"=",
"... | Create a slug for each Creator already in the DB. | [
"Create",
"a",
"slug",
"for",
"each",
"Creator",
"already",
"in",
"the",
"DB",
"."
] | f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada | https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/core/migrations/0004_auto_20180102_0959.py#L24-L32 | train |
philgyford/django-spectator | spectator/events/migrations/0013_copy_classical_and_dance_data.py | forwards | def forwards(apps, schema_editor):
"""
Copy the ClassicalWork and DancePiece data to use the new through models.
"""
Event = apps.get_model('spectator_events', 'Event')
ClassicalWorkSelection = apps.get_model(
'spectator_events', 'ClassicalWorkSelection')
DancePie... | python | def forwards(apps, schema_editor):
"""
Copy the ClassicalWork and DancePiece data to use the new through models.
"""
Event = apps.get_model('spectator_events', 'Event')
ClassicalWorkSelection = apps.get_model(
'spectator_events', 'ClassicalWorkSelection')
DancePie... | [
"def",
"forwards",
"(",
"apps",
",",
"schema_editor",
")",
":",
"Event",
"=",
"apps",
".",
"get_model",
"(",
"'spectator_events'",
",",
"'Event'",
")",
"ClassicalWorkSelection",
"=",
"apps",
".",
"get_model",
"(",
"'spectator_events'",
",",
"'ClassicalWorkSelectio... | Copy the ClassicalWork and DancePiece data to use the new through models. | [
"Copy",
"the",
"ClassicalWork",
"and",
"DancePiece",
"data",
"to",
"use",
"the",
"new",
"through",
"models",
"."
] | f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada | https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/events/migrations/0013_copy_classical_and_dance_data.py#L6-L28 | train |
philgyford/django-spectator | spectator/events/migrations/0024_event_venue_name.py | forwards | def forwards(apps, schema_editor):
"""
Set the venue_name field of all Events that have a Venue.
"""
Event = apps.get_model('spectator_events', 'Event')
for event in Event.objects.all():
if event.venue is not None:
event.venue_name = event.venue.name
event.save() | python | def forwards(apps, schema_editor):
"""
Set the venue_name field of all Events that have a Venue.
"""
Event = apps.get_model('spectator_events', 'Event')
for event in Event.objects.all():
if event.venue is not None:
event.venue_name = event.venue.name
event.save() | [
"def",
"forwards",
"(",
"apps",
",",
"schema_editor",
")",
":",
"Event",
"=",
"apps",
".",
"get_model",
"(",
"'spectator_events'",
",",
"'Event'",
")",
"for",
"event",
"in",
"Event",
".",
"objects",
".",
"all",
"(",
")",
":",
"if",
"event",
".",
"venue... | Set the venue_name field of all Events that have a Venue. | [
"Set",
"the",
"venue_name",
"field",
"of",
"all",
"Events",
"that",
"have",
"a",
"Venue",
"."
] | f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada | https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/events/migrations/0024_event_venue_name.py#L7-L16 | train |
philgyford/django-spectator | spectator/events/migrations/0037_exhibition_to_museum.py | forwards | def forwards(apps, schema_editor):
"""
Migrate all 'exhibition' Events to the new 'museum' Event kind.
"""
Event = apps.get_model('spectator_events', 'Event')
for ev in Event.objects.filter(kind='exhibition'):
ev.kind = 'museum'
ev.save() | python | def forwards(apps, schema_editor):
"""
Migrate all 'exhibition' Events to the new 'museum' Event kind.
"""
Event = apps.get_model('spectator_events', 'Event')
for ev in Event.objects.filter(kind='exhibition'):
ev.kind = 'museum'
ev.save() | [
"def",
"forwards",
"(",
"apps",
",",
"schema_editor",
")",
":",
"Event",
"=",
"apps",
".",
"get_model",
"(",
"'spectator_events'",
",",
"'Event'",
")",
"for",
"ev",
"in",
"Event",
".",
"objects",
".",
"filter",
"(",
"kind",
"=",
"'exhibition'",
")",
":",... | Migrate all 'exhibition' Events to the new 'museum' Event kind. | [
"Migrate",
"all",
"exhibition",
"Events",
"to",
"the",
"new",
"museum",
"Event",
"kind",
"."
] | f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada | https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/events/migrations/0037_exhibition_to_museum.py#L6-L14 | train |
philgyford/django-spectator | spectator/core/utils.py | truncate_string | def truncate_string(text, strip_html=True, chars=255, truncate='…', at_word_boundary=False):
"""Truncate a string to a certain length, removing line breaks and mutliple
spaces, optionally removing HTML, and appending a 'truncate' string.
Keyword arguments:
strip_html -- boolean.
chars -- Number of ... | python | def truncate_string(text, strip_html=True, chars=255, truncate='…', at_word_boundary=False):
"""Truncate a string to a certain length, removing line breaks and mutliple
spaces, optionally removing HTML, and appending a 'truncate' string.
Keyword arguments:
strip_html -- boolean.
chars -- Number of ... | [
"def",
"truncate_string",
"(",
"text",
",",
"strip_html",
"=",
"True",
",",
"chars",
"=",
"255",
",",
"truncate",
"=",
"'…', ",
"a",
"_word_boundary=F",
"a",
"lse):",
"",
"",
"if",
"strip_html",
":",
"text",
"=",
"strip_tags",
"(",
"text",
")",
"text",
... | Truncate a string to a certain length, removing line breaks and mutliple
spaces, optionally removing HTML, and appending a 'truncate' string.
Keyword arguments:
strip_html -- boolean.
chars -- Number of characters to return.
at_word_boundary -- Only truncate at a word boundary, which will probably
... | [
"Truncate",
"a",
"string",
"to",
"a",
"certain",
"length",
"removing",
"line",
"breaks",
"and",
"mutliple",
"spaces",
"optionally",
"removing",
"HTML",
"and",
"appending",
"a",
"truncate",
"string",
"."
] | f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada | https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/core/utils.py#L5-L25 | train |
philgyford/django-spectator | spectator/core/utils.py | chartify | def chartify(qs, score_field, cutoff=0, ensure_chartiness=True):
"""
Given a QuerySet it will go through and add a `chart_position` property to
each object returning a list of the objects.
If adjacent objects have the same 'score' (based on `score_field`) then
they will have the same `chart_positio... | python | def chartify(qs, score_field, cutoff=0, ensure_chartiness=True):
"""
Given a QuerySet it will go through and add a `chart_position` property to
each object returning a list of the objects.
If adjacent objects have the same 'score' (based on `score_field`) then
they will have the same `chart_positio... | [
"def",
"chartify",
"(",
"qs",
",",
"score_field",
",",
"cutoff",
"=",
"0",
",",
"ensure_chartiness",
"=",
"True",
")",
":",
"chart",
"=",
"[",
"]",
"position",
"=",
"0",
"prev_obj",
"=",
"None",
"for",
"counter",
",",
"obj",
"in",
"enumerate",
"(",
"... | Given a QuerySet it will go through and add a `chart_position` property to
each object returning a list of the objects.
If adjacent objects have the same 'score' (based on `score_field`) then
they will have the same `chart_position`. This can then be used in
templates for the `value` of <li> elements i... | [
"Given",
"a",
"QuerySet",
"it",
"will",
"go",
"through",
"and",
"add",
"a",
"chart_position",
"property",
"to",
"each",
"object",
"returning",
"a",
"list",
"of",
"the",
"objects",
"."
] | f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada | https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/core/utils.py#L28-L71 | train |
philgyford/django-spectator | spectator/events/managers.py | VenueManager.by_visits | def by_visits(self, event_kind=None):
"""
Gets Venues in order of how many Events have been held there.
Adds a `num_visits` field to each one.
event_kind filters by kind of Event, e.g. 'theatre', 'cinema', etc.
"""
qs = self.get_queryset()
if event_kind is not N... | python | def by_visits(self, event_kind=None):
"""
Gets Venues in order of how many Events have been held there.
Adds a `num_visits` field to each one.
event_kind filters by kind of Event, e.g. 'theatre', 'cinema', etc.
"""
qs = self.get_queryset()
if event_kind is not N... | [
"def",
"by_visits",
"(",
"self",
",",
"event_kind",
"=",
"None",
")",
":",
"qs",
"=",
"self",
".",
"get_queryset",
"(",
")",
"if",
"event_kind",
"is",
"not",
"None",
":",
"qs",
"=",
"qs",
".",
"filter",
"(",
"event__kind",
"=",
"event_kind",
")",
"qs... | Gets Venues in order of how many Events have been held there.
Adds a `num_visits` field to each one.
event_kind filters by kind of Event, e.g. 'theatre', 'cinema', etc. | [
"Gets",
"Venues",
"in",
"order",
"of",
"how",
"many",
"Events",
"have",
"been",
"held",
"there",
".",
"Adds",
"a",
"num_visits",
"field",
"to",
"each",
"one",
"."
] | f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada | https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/events/managers.py#L7-L22 | train |
philgyford/django-spectator | spectator/events/managers.py | WorkManager.by_views | def by_views(self, kind=None):
"""
Gets Works in order of how many times they've been attached to
Events.
kind is the kind of Work, e.g. 'play', 'movie', etc.
"""
qs = self.get_queryset()
if kind is not None:
qs = qs.filter(kind=kind)
qs = q... | python | def by_views(self, kind=None):
"""
Gets Works in order of how many times they've been attached to
Events.
kind is the kind of Work, e.g. 'play', 'movie', etc.
"""
qs = self.get_queryset()
if kind is not None:
qs = qs.filter(kind=kind)
qs = q... | [
"def",
"by_views",
"(",
"self",
",",
"kind",
"=",
"None",
")",
":",
"qs",
"=",
"self",
".",
"get_queryset",
"(",
")",
"if",
"kind",
"is",
"not",
"None",
":",
"qs",
"=",
"qs",
".",
"filter",
"(",
"kind",
"=",
"kind",
")",
"qs",
"=",
"qs",
".",
... | Gets Works in order of how many times they've been attached to
Events.
kind is the kind of Work, e.g. 'play', 'movie', etc. | [
"Gets",
"Works",
"in",
"order",
"of",
"how",
"many",
"times",
"they",
"ve",
"been",
"attached",
"to",
"Events",
"."
] | f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada | https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/events/managers.py#L27-L42 | train |
philgyford/django-spectator | spectator/core/fields.py | NaturalSortField.naturalize_thing | def naturalize_thing(self, string):
"""
Make a naturalized version of a general string, not a person's name.
e.g., title of a book, a band's name, etc.
string -- a lowercase string.
"""
# Things we want to move to the back of the string:
articles = [
... | python | def naturalize_thing(self, string):
"""
Make a naturalized version of a general string, not a person's name.
e.g., title of a book, a band's name, etc.
string -- a lowercase string.
"""
# Things we want to move to the back of the string:
articles = [
... | [
"def",
"naturalize_thing",
"(",
"self",
",",
"string",
")",
":",
"# Things we want to move to the back of the string:",
"articles",
"=",
"[",
"'a'",
",",
"'an'",
",",
"'the'",
",",
"'un'",
",",
"'une'",
",",
"'le'",
",",
"'la'",
",",
"'les'",
",",
"\"l'\"",
... | Make a naturalized version of a general string, not a person's name.
e.g., title of a book, a band's name, etc.
string -- a lowercase string. | [
"Make",
"a",
"naturalized",
"version",
"of",
"a",
"general",
"string",
"not",
"a",
"person",
"s",
"name",
".",
"e",
".",
"g",
".",
"title",
"of",
"a",
"book",
"a",
"band",
"s",
"name",
"etc",
"."
] | f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada | https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/core/fields.py#L147-L174 | train |
philgyford/django-spectator | spectator/core/fields.py | NaturalSortField.naturalize_person | def naturalize_person(self, string):
"""
Attempt to make a version of the string that has the surname, if any,
at the start.
'John, Brown' to 'Brown, John'
'Sir John Brown Jr' to 'Brown, Sir John Jr'
'Prince' to 'Prince'
string -- The string to change.
"... | python | def naturalize_person(self, string):
"""
Attempt to make a version of the string that has the surname, if any,
at the start.
'John, Brown' to 'Brown, John'
'Sir John Brown Jr' to 'Brown, Sir John Jr'
'Prince' to 'Prince'
string -- The string to change.
"... | [
"def",
"naturalize_person",
"(",
"self",
",",
"string",
")",
":",
"suffixes",
"=",
"[",
"'Jr'",
",",
"'Jr.'",
",",
"'Sr'",
",",
"'Sr.'",
",",
"'I'",
",",
"'II'",
",",
"'III'",
",",
"'IV'",
",",
"'V'",
",",
"]",
"# Add lowercase versions:",
"suffixes",
... | Attempt to make a version of the string that has the surname, if any,
at the start.
'John, Brown' to 'Brown, John'
'Sir John Brown Jr' to 'Brown, Sir John Jr'
'Prince' to 'Prince'
string -- The string to change. | [
"Attempt",
"to",
"make",
"a",
"version",
"of",
"the",
"string",
"that",
"has",
"the",
"surname",
"if",
"any",
"at",
"the",
"start",
"."
] | f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada | https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/core/fields.py#L176-L232 | train |
philgyford/django-spectator | spectator/core/fields.py | NaturalSortField._naturalize_numbers | def _naturalize_numbers(self, string):
"""
Makes any integers into very zero-padded numbers.
e.g. '1' becomes '00000001'.
"""
def naturalize_int_match(match):
return '%08d' % (int(match.group(0)),)
string = re.sub(r'\d+', naturalize_int_match, string)
... | python | def _naturalize_numbers(self, string):
"""
Makes any integers into very zero-padded numbers.
e.g. '1' becomes '00000001'.
"""
def naturalize_int_match(match):
return '%08d' % (int(match.group(0)),)
string = re.sub(r'\d+', naturalize_int_match, string)
... | [
"def",
"_naturalize_numbers",
"(",
"self",
",",
"string",
")",
":",
"def",
"naturalize_int_match",
"(",
"match",
")",
":",
"return",
"'%08d'",
"%",
"(",
"int",
"(",
"match",
".",
"group",
"(",
"0",
")",
")",
",",
")",
"string",
"=",
"re",
".",
"sub",... | Makes any integers into very zero-padded numbers.
e.g. '1' becomes '00000001'. | [
"Makes",
"any",
"integers",
"into",
"very",
"zero",
"-",
"padded",
"numbers",
".",
"e",
".",
"g",
".",
"1",
"becomes",
"00000001",
"."
] | f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada | https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/core/fields.py#L234-L245 | train |
philgyford/django-spectator | spectator/reading/utils.py | annual_reading_counts | def annual_reading_counts(kind='all'):
"""
Returns a list of dicts, one per year of reading. In year order.
Each dict is like this (if kind is 'all'):
{'year': datetime.date(2003, 1, 1),
'book': 12, # only included if kind is 'all' or 'book'
'periodical': 18, ... | python | def annual_reading_counts(kind='all'):
"""
Returns a list of dicts, one per year of reading. In year order.
Each dict is like this (if kind is 'all'):
{'year': datetime.date(2003, 1, 1),
'book': 12, # only included if kind is 'all' or 'book'
'periodical': 18, ... | [
"def",
"annual_reading_counts",
"(",
"kind",
"=",
"'all'",
")",
":",
"if",
"kind",
"==",
"'all'",
":",
"kinds",
"=",
"[",
"'book'",
",",
"'periodical'",
"]",
"else",
":",
"kinds",
"=",
"[",
"kind",
"]",
"# This will have keys of years (strings) and dicts of data... | Returns a list of dicts, one per year of reading. In year order.
Each dict is like this (if kind is 'all'):
{'year': datetime.date(2003, 1, 1),
'book': 12, # only included if kind is 'all' or 'book'
'periodical': 18, # only included if kind is 'all' or 'periodical'
... | [
"Returns",
"a",
"list",
"of",
"dicts",
"one",
"per",
"year",
"of",
"reading",
".",
"In",
"year",
"order",
".",
"Each",
"dict",
"is",
"like",
"this",
"(",
"if",
"kind",
"is",
"all",
")",
":"
] | f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada | https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/reading/utils.py#L9-L73 | train |
philgyford/django-spectator | spectator/events/admin.py | CountryListFilter.lookups | def lookups(self, request, model_admin):
"""
Returns a list of tuples like:
[
('AU', 'Australia'),
('GB', 'UK'),
('US', 'USA'),
]
One for each country that has at least one Venue.
Sorted by the label names.
... | python | def lookups(self, request, model_admin):
"""
Returns a list of tuples like:
[
('AU', 'Australia'),
('GB', 'UK'),
('US', 'USA'),
]
One for each country that has at least one Venue.
Sorted by the label names.
... | [
"def",
"lookups",
"(",
"self",
",",
"request",
",",
"model_admin",
")",
":",
"list_of_countries",
"=",
"[",
"]",
"# We don't need the country_count but we need to annotate them in order",
"# to group the results.",
"qs",
"=",
"Venue",
".",
"objects",
".",
"exclude",
"("... | Returns a list of tuples like:
[
('AU', 'Australia'),
('GB', 'UK'),
('US', 'USA'),
]
One for each country that has at least one Venue.
Sorted by the label names. | [
"Returns",
"a",
"list",
"of",
"tuples",
"like",
":"
] | f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada | https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/events/admin.py#L120-L147 | train |
philgyford/django-spectator | spectator/events/admin.py | CountryListFilter.queryset | def queryset(self, request, queryset):
"""
Returns the filtered queryset based on the value
provided in the query string and retrievable via
`self.value()`.
"""
if self.value():
return queryset.filter(country=self.value())
else:
return quer... | python | def queryset(self, request, queryset):
"""
Returns the filtered queryset based on the value
provided in the query string and retrievable via
`self.value()`.
"""
if self.value():
return queryset.filter(country=self.value())
else:
return quer... | [
"def",
"queryset",
"(",
"self",
",",
"request",
",",
"queryset",
")",
":",
"if",
"self",
".",
"value",
"(",
")",
":",
"return",
"queryset",
".",
"filter",
"(",
"country",
"=",
"self",
".",
"value",
"(",
")",
")",
"else",
":",
"return",
"queryset"
] | Returns the filtered queryset based on the value
provided in the query string and retrievable via
`self.value()`. | [
"Returns",
"the",
"filtered",
"queryset",
"based",
"on",
"the",
"value",
"provided",
"in",
"the",
"query",
"string",
"and",
"retrievable",
"via",
"self",
".",
"value",
"()",
"."
] | f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada | https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/events/admin.py#L149-L158 | train |
philgyford/django-spectator | spectator/events/migrations/0017_copy_movies_and_plays_data.py | forward | def forward(apps, schema_editor):
"""
Copying data from the old `Event.movie` and `Event.play` ForeignKey fields
into the new `Event.movies` and `Event.plays` ManyToManyFields.
"""
Event = apps.get_model('spectator_events', 'Event')
MovieSelection = apps.get_model('spectator_events', 'MovieSele... | python | def forward(apps, schema_editor):
"""
Copying data from the old `Event.movie` and `Event.play` ForeignKey fields
into the new `Event.movies` and `Event.plays` ManyToManyFields.
"""
Event = apps.get_model('spectator_events', 'Event')
MovieSelection = apps.get_model('spectator_events', 'MovieSele... | [
"def",
"forward",
"(",
"apps",
",",
"schema_editor",
")",
":",
"Event",
"=",
"apps",
".",
"get_model",
"(",
"'spectator_events'",
",",
"'Event'",
")",
"MovieSelection",
"=",
"apps",
".",
"get_model",
"(",
"'spectator_events'",
",",
"'MovieSelection'",
")",
"Pl... | Copying data from the old `Event.movie` and `Event.play` ForeignKey fields
into the new `Event.movies` and `Event.plays` ManyToManyFields. | [
"Copying",
"data",
"from",
"the",
"old",
"Event",
".",
"movie",
"and",
"Event",
".",
"play",
"ForeignKey",
"fields",
"into",
"the",
"new",
"Event",
".",
"movies",
"and",
"Event",
".",
"plays",
"ManyToManyFields",
"."
] | f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada | https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/events/migrations/0017_copy_movies_and_plays_data.py#L6-L23 | train |
philgyford/django-spectator | spectator/events/migrations/0006_event_slug_20180102_1127.py | set_slug | def set_slug(apps, schema_editor):
"""
Create a slug for each Event already in the DB.
"""
Event = apps.get_model('spectator_events', 'Event')
for e in Event.objects.all():
e.slug = generate_slug(e.pk)
e.save(update_fields=['slug']) | python | def set_slug(apps, schema_editor):
"""
Create a slug for each Event already in the DB.
"""
Event = apps.get_model('spectator_events', 'Event')
for e in Event.objects.all():
e.slug = generate_slug(e.pk)
e.save(update_fields=['slug']) | [
"def",
"set_slug",
"(",
"apps",
",",
"schema_editor",
")",
":",
"Event",
"=",
"apps",
".",
"get_model",
"(",
"'spectator_events'",
",",
"'Event'",
")",
"for",
"e",
"in",
"Event",
".",
"objects",
".",
"all",
"(",
")",
":",
"e",
".",
"slug",
"=",
"gene... | Create a slug for each Event already in the DB. | [
"Create",
"a",
"slug",
"for",
"each",
"Event",
"already",
"in",
"the",
"DB",
"."
] | f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada | https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/events/migrations/0006_event_slug_20180102_1127.py#L24-L32 | train |
philgyford/django-spectator | spectator/core/paginator.py | DiggPaginator.page | def page(self, number, *args, **kwargs):
"""Return a standard ``Page`` instance with custom, digg-specific
page ranges attached.
"""
page = super().page(number, *args, **kwargs)
number = int(number) # we know this will work
# easier access
num_pages, body, tail,... | python | def page(self, number, *args, **kwargs):
"""Return a standard ``Page`` instance with custom, digg-specific
page ranges attached.
"""
page = super().page(number, *args, **kwargs)
number = int(number) # we know this will work
# easier access
num_pages, body, tail,... | [
"def",
"page",
"(",
"self",
",",
"number",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"page",
"=",
"super",
"(",
")",
".",
"page",
"(",
"number",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
"number",
"=",
"int",
"(",
"number",
"... | Return a standard ``Page`` instance with custom, digg-specific
page ranges attached. | [
"Return",
"a",
"standard",
"Page",
"instance",
"with",
"custom",
"digg",
"-",
"specific",
"page",
"ranges",
"attached",
"."
] | f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada | https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/core/paginator.py#L195-L269 | train |
ccpem/mrcfile | setup.py | version | def version():
"""Get the version number without importing the mrcfile package."""
namespace = {}
with open(os.path.join('mrcfile', 'version.py')) as f:
exec(f.read(), namespace)
return namespace['__version__'] | python | def version():
"""Get the version number without importing the mrcfile package."""
namespace = {}
with open(os.path.join('mrcfile', 'version.py')) as f:
exec(f.read(), namespace)
return namespace['__version__'] | [
"def",
"version",
"(",
")",
":",
"namespace",
"=",
"{",
"}",
"with",
"open",
"(",
"os",
".",
"path",
".",
"join",
"(",
"'mrcfile'",
",",
"'version.py'",
")",
")",
"as",
"f",
":",
"exec",
"(",
"f",
".",
"read",
"(",
")",
",",
"namespace",
")",
"... | Get the version number without importing the mrcfile package. | [
"Get",
"the",
"version",
"number",
"without",
"importing",
"the",
"mrcfile",
"package",
"."
] | 96b862ad29884f5a5082a69e2aba8b0829090838 | https://github.com/ccpem/mrcfile/blob/96b862ad29884f5a5082a69e2aba8b0829090838/setup.py#L9-L14 | train |
philgyford/django-spectator | spectator/events/views.py | EventListView.get_event_counts | def get_event_counts(self):
"""
Returns a dict like:
{'counts': {
'all': 30,
'movie': 12,
'gig': 10,
}}
"""
counts = {'all': Event.objects.count(),}
for k,v in Event.KIND_CHOICES:
# e.g. 'movie_c... | python | def get_event_counts(self):
"""
Returns a dict like:
{'counts': {
'all': 30,
'movie': 12,
'gig': 10,
}}
"""
counts = {'all': Event.objects.count(),}
for k,v in Event.KIND_CHOICES:
# e.g. 'movie_c... | [
"def",
"get_event_counts",
"(",
"self",
")",
":",
"counts",
"=",
"{",
"'all'",
":",
"Event",
".",
"objects",
".",
"count",
"(",
")",
",",
"}",
"for",
"k",
",",
"v",
"in",
"Event",
".",
"KIND_CHOICES",
":",
"# e.g. 'movie_count':",
"counts",
"[",
"k",
... | Returns a dict like:
{'counts': {
'all': 30,
'movie': 12,
'gig': 10,
}} | [
"Returns",
"a",
"dict",
"like",
":",
"{",
"counts",
":",
"{",
"all",
":",
"30",
"movie",
":",
"12",
"gig",
":",
"10",
"}}"
] | f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada | https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/events/views.py#L52-L67 | train |
philgyford/django-spectator | spectator/events/views.py | EventListView.get_event_kind | def get_event_kind(self):
"""
Unless we're on the front page we'll have a kind_slug like 'movies'.
We need to translate that into an event `kind` like 'movie'.
"""
slug = self.kwargs.get('kind_slug', None)
if slug is None:
return None # Front page; showing al... | python | def get_event_kind(self):
"""
Unless we're on the front page we'll have a kind_slug like 'movies'.
We need to translate that into an event `kind` like 'movie'.
"""
slug = self.kwargs.get('kind_slug', None)
if slug is None:
return None # Front page; showing al... | [
"def",
"get_event_kind",
"(",
"self",
")",
":",
"slug",
"=",
"self",
".",
"kwargs",
".",
"get",
"(",
"'kind_slug'",
",",
"None",
")",
"if",
"slug",
"is",
"None",
":",
"return",
"None",
"# Front page; showing all Event kinds.",
"else",
":",
"slugs_to_kinds",
... | Unless we're on the front page we'll have a kind_slug like 'movies'.
We need to translate that into an event `kind` like 'movie'. | [
"Unless",
"we",
"re",
"on",
"the",
"front",
"page",
"we",
"ll",
"have",
"a",
"kind_slug",
"like",
"movies",
".",
"We",
"need",
"to",
"translate",
"that",
"into",
"an",
"event",
"kind",
"like",
"movie",
"."
] | f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada | https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/events/views.py#L69-L79 | train |
philgyford/django-spectator | spectator/events/views.py | EventListView.get_queryset | def get_queryset(self):
"Restrict to a single kind of event, if any, and include Venue data."
qs = super().get_queryset()
kind = self.get_event_kind()
if kind is not None:
qs = qs.filter(kind=kind)
qs = qs.select_related('venue')
return qs | python | def get_queryset(self):
"Restrict to a single kind of event, if any, and include Venue data."
qs = super().get_queryset()
kind = self.get_event_kind()
if kind is not None:
qs = qs.filter(kind=kind)
qs = qs.select_related('venue')
return qs | [
"def",
"get_queryset",
"(",
"self",
")",
":",
"qs",
"=",
"super",
"(",
")",
".",
"get_queryset",
"(",
")",
"kind",
"=",
"self",
".",
"get_event_kind",
"(",
")",
"if",
"kind",
"is",
"not",
"None",
":",
"qs",
"=",
"qs",
".",
"filter",
"(",
"kind",
... | Restrict to a single kind of event, if any, and include Venue data. | [
"Restrict",
"to",
"a",
"single",
"kind",
"of",
"event",
"if",
"any",
"and",
"include",
"Venue",
"data",
"."
] | f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada | https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/events/views.py#L81-L91 | train |
philgyford/django-spectator | spectator/events/views.py | WorkMixin.get_work_kind | def get_work_kind(self):
"""
We'll have a kind_slug like 'movies'.
We need to translate that into a work `kind` like 'movie'.
"""
slugs_to_kinds = {v:k for k,v in Work.KIND_SLUGS.items()}
return slugs_to_kinds.get(self.kind_slug, None) | python | def get_work_kind(self):
"""
We'll have a kind_slug like 'movies'.
We need to translate that into a work `kind` like 'movie'.
"""
slugs_to_kinds = {v:k for k,v in Work.KIND_SLUGS.items()}
return slugs_to_kinds.get(self.kind_slug, None) | [
"def",
"get_work_kind",
"(",
"self",
")",
":",
"slugs_to_kinds",
"=",
"{",
"v",
":",
"k",
"for",
"k",
",",
"v",
"in",
"Work",
".",
"KIND_SLUGS",
".",
"items",
"(",
")",
"}",
"return",
"slugs_to_kinds",
".",
"get",
"(",
"self",
".",
"kind_slug",
",",
... | We'll have a kind_slug like 'movies'.
We need to translate that into a work `kind` like 'movie'. | [
"We",
"ll",
"have",
"a",
"kind_slug",
"like",
"movies",
".",
"We",
"need",
"to",
"translate",
"that",
"into",
"a",
"work",
"kind",
"like",
"movie",
"."
] | f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada | https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/events/views.py#L147-L153 | train |
philgyford/django-spectator | spectator/events/views.py | VenueListView.get_countries | def get_countries(self):
"""
Returns a list of dicts, one per country that has at least one Venue
in it.
Each dict has 'code' and 'name' elements.
The list is sorted by the country 'name's.
"""
qs = Venue.objects.values('country') \
... | python | def get_countries(self):
"""
Returns a list of dicts, one per country that has at least one Venue
in it.
Each dict has 'code' and 'name' elements.
The list is sorted by the country 'name's.
"""
qs = Venue.objects.values('country') \
... | [
"def",
"get_countries",
"(",
"self",
")",
":",
"qs",
"=",
"Venue",
".",
"objects",
".",
"values",
"(",
"'country'",
")",
".",
"exclude",
"(",
"country",
"=",
"''",
")",
".",
"distinct",
"(",
")",
".",
"order_by",
"(",
"'country'",
")",
"countries",
"... | Returns a list of dicts, one per country that has at least one Venue
in it.
Each dict has 'code' and 'name' elements.
The list is sorted by the country 'name's. | [
"Returns",
"a",
"list",
"of",
"dicts",
"one",
"per",
"country",
"that",
"has",
"at",
"least",
"one",
"Venue",
"in",
"it",
"."
] | f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada | https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/events/views.py#L216-L237 | train |
philgyford/django-spectator | spectator/events/migrations/0032_recreate_work_slugs.py | forwards | def forwards(apps, schema_editor):
"""
Re-save all the Works because something earlier didn't create their slugs.
"""
Work = apps.get_model('spectator_events', 'Work')
for work in Work.objects.all():
if not work.slug:
work.slug = generate_slug(work.pk)
work.save() | python | def forwards(apps, schema_editor):
"""
Re-save all the Works because something earlier didn't create their slugs.
"""
Work = apps.get_model('spectator_events', 'Work')
for work in Work.objects.all():
if not work.slug:
work.slug = generate_slug(work.pk)
work.save() | [
"def",
"forwards",
"(",
"apps",
",",
"schema_editor",
")",
":",
"Work",
"=",
"apps",
".",
"get_model",
"(",
"'spectator_events'",
",",
"'Work'",
")",
"for",
"work",
"in",
"Work",
".",
"objects",
".",
"all",
"(",
")",
":",
"if",
"not",
"work",
".",
"s... | Re-save all the Works because something earlier didn't create their slugs. | [
"Re",
"-",
"save",
"all",
"the",
"Works",
"because",
"something",
"earlier",
"didn",
"t",
"create",
"their",
"slugs",
"."
] | f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada | https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/events/migrations/0032_recreate_work_slugs.py#L30-L39 | train |
philgyford/django-spectator | spectator/events/templatetags/spectator_events.py | annual_event_counts | def annual_event_counts(kind='all'):
"""
Returns a QuerySet of dicts, each one with these keys:
* year - a date object representing the year
* total - the number of events of `kind` that year
kind - The Event `kind`, or 'all' for all kinds (default).
"""
qs = Event.objects
if ... | python | def annual_event_counts(kind='all'):
"""
Returns a QuerySet of dicts, each one with these keys:
* year - a date object representing the year
* total - the number of events of `kind` that year
kind - The Event `kind`, or 'all' for all kinds (default).
"""
qs = Event.objects
if ... | [
"def",
"annual_event_counts",
"(",
"kind",
"=",
"'all'",
")",
":",
"qs",
"=",
"Event",
".",
"objects",
"if",
"kind",
"!=",
"'all'",
":",
"qs",
"=",
"qs",
".",
"filter",
"(",
"kind",
"=",
"kind",
")",
"qs",
"=",
"qs",
".",
"annotate",
"(",
"year",
... | Returns a QuerySet of dicts, each one with these keys:
* year - a date object representing the year
* total - the number of events of `kind` that year
kind - The Event `kind`, or 'all' for all kinds (default). | [
"Returns",
"a",
"QuerySet",
"of",
"dicts",
"each",
"one",
"with",
"these",
"keys",
":"
] | f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada | https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/events/templatetags/spectator_events.py#L17-L36 | train |
philgyford/django-spectator | spectator/events/templatetags/spectator_events.py | annual_event_counts_card | def annual_event_counts_card(kind='all', current_year=None):
"""
Displays years and the number of events per year.
kind is an Event kind (like 'cinema', 'gig', etc.) or 'all' (default).
current_year is an optional date object representing the year we're already
showing information about.
""... | python | def annual_event_counts_card(kind='all', current_year=None):
"""
Displays years and the number of events per year.
kind is an Event kind (like 'cinema', 'gig', etc.) or 'all' (default).
current_year is an optional date object representing the year we're already
showing information about.
""... | [
"def",
"annual_event_counts_card",
"(",
"kind",
"=",
"'all'",
",",
"current_year",
"=",
"None",
")",
":",
"if",
"kind",
"==",
"'all'",
":",
"card_title",
"=",
"'Events per year'",
"else",
":",
"card_title",
"=",
"'{} per year'",
".",
"format",
"(",
"Event",
... | Displays years and the number of events per year.
kind is an Event kind (like 'cinema', 'gig', etc.) or 'all' (default).
current_year is an optional date object representing the year we're already
showing information about. | [
"Displays",
"years",
"and",
"the",
"number",
"of",
"events",
"per",
"year",
"."
] | f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada | https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/events/templatetags/spectator_events.py#L40-L58 | train |
philgyford/django-spectator | spectator/events/templatetags/spectator_events.py | display_date | def display_date(d):
"""
Render a date/datetime (d) as a date, using the SPECTATOR_DATE_FORMAT
setting. Wrap the output in a <time> tag.
Time tags: http://www.brucelawson.co.uk/2012/best-of-time/
"""
stamp = d.strftime('%Y-%m-%d')
visible_date = d.strftime(app_settings.DATE_FORMAT)
ret... | python | def display_date(d):
"""
Render a date/datetime (d) as a date, using the SPECTATOR_DATE_FORMAT
setting. Wrap the output in a <time> tag.
Time tags: http://www.brucelawson.co.uk/2012/best-of-time/
"""
stamp = d.strftime('%Y-%m-%d')
visible_date = d.strftime(app_settings.DATE_FORMAT)
ret... | [
"def",
"display_date",
"(",
"d",
")",
":",
"stamp",
"=",
"d",
".",
"strftime",
"(",
"'%Y-%m-%d'",
")",
"visible_date",
"=",
"d",
".",
"strftime",
"(",
"app_settings",
".",
"DATE_FORMAT",
")",
"return",
"format_html",
"(",
"'<time datetime=\"%(stamp)s\">%(visible... | Render a date/datetime (d) as a date, using the SPECTATOR_DATE_FORMAT
setting. Wrap the output in a <time> tag.
Time tags: http://www.brucelawson.co.uk/2012/best-of-time/ | [
"Render",
"a",
"date",
"/",
"datetime",
"(",
"d",
")",
"as",
"a",
"date",
"using",
"the",
"SPECTATOR_DATE_FORMAT",
"setting",
".",
"Wrap",
"the",
"output",
"in",
"a",
"<time",
">",
"tag",
"."
] | f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada | https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/events/templatetags/spectator_events.py#L62-L75 | train |
philgyford/django-spectator | spectator/events/templatetags/spectator_events.py | event_list_tabs | def event_list_tabs(counts, current_kind, page_number=1):
"""
Displays the tabs to different event_list pages.
`counts` is a dict of number of events for each kind, like:
{'all': 30, 'gig': 12, 'movie': 18,}
`current_kind` is the event kind that's active, if any. e.g. 'gig',
'movie', e... | python | def event_list_tabs(counts, current_kind, page_number=1):
"""
Displays the tabs to different event_list pages.
`counts` is a dict of number of events for each kind, like:
{'all': 30, 'gig': 12, 'movie': 18,}
`current_kind` is the event kind that's active, if any. e.g. 'gig',
'movie', e... | [
"def",
"event_list_tabs",
"(",
"counts",
",",
"current_kind",
",",
"page_number",
"=",
"1",
")",
":",
"return",
"{",
"'counts'",
":",
"counts",
",",
"'current_kind'",
":",
"current_kind",
",",
"'page_number'",
":",
"page_number",
",",
"# A list of all the kinds we... | Displays the tabs to different event_list pages.
`counts` is a dict of number of events for each kind, like:
{'all': 30, 'gig': 12, 'movie': 18,}
`current_kind` is the event kind that's active, if any. e.g. 'gig',
'movie', etc.
`page_number` is the current page of this kind of events we'r... | [
"Displays",
"the",
"tabs",
"to",
"different",
"event_list",
"pages",
"."
] | f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada | https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/events/templatetags/spectator_events.py#L79-L101 | train |
philgyford/django-spectator | spectator/events/templatetags/spectator_events.py | day_events_card | def day_events_card(date):
"""
Displays Events that happened on the supplied date.
`date` is a date object.
"""
d = date.strftime(app_settings.DATE_FORMAT)
card_title = 'Events on {}'.format(d)
return {
'card_title': card_title,
'event_list': day_events(date=date),
... | python | def day_events_card(date):
"""
Displays Events that happened on the supplied date.
`date` is a date object.
"""
d = date.strftime(app_settings.DATE_FORMAT)
card_title = 'Events on {}'.format(d)
return {
'card_title': card_title,
'event_list': day_events(date=date),
... | [
"def",
"day_events_card",
"(",
"date",
")",
":",
"d",
"=",
"date",
".",
"strftime",
"(",
"app_settings",
".",
"DATE_FORMAT",
")",
"card_title",
"=",
"'Events on {}'",
".",
"format",
"(",
"d",
")",
"return",
"{",
"'card_title'",
":",
"card_title",
",",
"'ev... | Displays Events that happened on the supplied date.
`date` is a date object. | [
"Displays",
"Events",
"that",
"happened",
"on",
"the",
"supplied",
"date",
".",
"date",
"is",
"a",
"date",
"object",
"."
] | f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada | https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/events/templatetags/spectator_events.py#L134-L144 | train |
philgyford/django-spectator | spectator/events/templatetags/spectator_events.py | most_seen_creators_card | def most_seen_creators_card(event_kind=None, num=10):
"""
Displays a card showing the Creators that are associated with the most Events.
"""
object_list = most_seen_creators(event_kind=event_kind, num=num)
object_list = chartify(object_list, 'num_events', cutoff=1)
return {
'card_title... | python | def most_seen_creators_card(event_kind=None, num=10):
"""
Displays a card showing the Creators that are associated with the most Events.
"""
object_list = most_seen_creators(event_kind=event_kind, num=num)
object_list = chartify(object_list, 'num_events', cutoff=1)
return {
'card_title... | [
"def",
"most_seen_creators_card",
"(",
"event_kind",
"=",
"None",
",",
"num",
"=",
"10",
")",
":",
"object_list",
"=",
"most_seen_creators",
"(",
"event_kind",
"=",
"event_kind",
",",
"num",
"=",
"num",
")",
"object_list",
"=",
"chartify",
"(",
"object_list",
... | Displays a card showing the Creators that are associated with the most Events. | [
"Displays",
"a",
"card",
"showing",
"the",
"Creators",
"that",
"are",
"associated",
"with",
"the",
"most",
"Events",
"."
] | f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada | https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/events/templatetags/spectator_events.py#L179-L191 | train |
philgyford/django-spectator | spectator/events/templatetags/spectator_events.py | most_seen_creators_by_works | def most_seen_creators_by_works(work_kind=None, role_name=None, num=10):
"""
Returns a QuerySet of the Creators that are associated with the most Works.
"""
return Creator.objects.by_works(kind=work_kind, role_name=role_name)[:num] | python | def most_seen_creators_by_works(work_kind=None, role_name=None, num=10):
"""
Returns a QuerySet of the Creators that are associated with the most Works.
"""
return Creator.objects.by_works(kind=work_kind, role_name=role_name)[:num] | [
"def",
"most_seen_creators_by_works",
"(",
"work_kind",
"=",
"None",
",",
"role_name",
"=",
"None",
",",
"num",
"=",
"10",
")",
":",
"return",
"Creator",
".",
"objects",
".",
"by_works",
"(",
"kind",
"=",
"work_kind",
",",
"role_name",
"=",
"role_name",
")... | Returns a QuerySet of the Creators that are associated with the most Works. | [
"Returns",
"a",
"QuerySet",
"of",
"the",
"Creators",
"that",
"are",
"associated",
"with",
"the",
"most",
"Works",
"."
] | f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada | https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/events/templatetags/spectator_events.py#L195-L199 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.