partition
stringclasses
3 values
func_name
stringlengths
1
134
docstring
stringlengths
1
46.9k
path
stringlengths
4
223
original_string
stringlengths
75
104k
code
stringlengths
75
104k
docstring_tokens
listlengths
1
1.97k
repo
stringlengths
7
55
language
stringclasses
1 value
url
stringlengths
87
315
code_tokens
listlengths
19
28.4k
sha
stringlengths
40
40
train
List.sort
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.
redis_collections/lists.py
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): """ 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", "." ]
honzajavorek/redis-collections
python
https://github.com/honzajavorek/redis-collections/blob/07ca8efe88fb128f7dc7319dfa6a26cd39b3776b/redis_collections/lists.py#L500-L520
[ "def", "sort", "(", "self", ",", "key", "=", "None", ",", "reverse", "=", "False", ")", ":", "def", "sort_trans", "(", "pipe", ")", ":", "values", "=", "list", "(", "self", ".", "__iter__", "(", "pipe", ")", ")", "values", ".", "sort", "(", "key"...
07ca8efe88fb128f7dc7319dfa6a26cd39b3776b
train
Deque.append
Add *value* to the right side of the collection.
redis_collections/lists.py
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): """Add *value* to the right side of the collection.""" def append_trans(pipe): self._append_helper(value, pipe) self._transaction(append_trans)
[ "Add", "*", "value", "*", "to", "the", "right", "side", "of", "the", "collection", "." ]
honzajavorek/redis-collections
python
https://github.com/honzajavorek/redis-collections/blob/07ca8efe88fb128f7dc7319dfa6a26cd39b3776b/redis_collections/lists.py#L739-L744
[ "def", "append", "(", "self", ",", "value", ")", ":", "def", "append_trans", "(", "pipe", ")", ":", "self", ".", "_append_helper", "(", "value", ",", "pipe", ")", "self", ".", "_transaction", "(", "append_trans", ")" ]
07ca8efe88fb128f7dc7319dfa6a26cd39b3776b
train
Deque.appendleft
Add *value* to the left side of the collection.
redis_collections/lists.py
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): """Add *value* to the left side of the collection.""" def appendleft_trans(pipe): self._appendleft_helper(value, pipe) self._transaction(appendleft_trans)
[ "Add", "*", "value", "*", "to", "the", "left", "side", "of", "the", "collection", "." ]
honzajavorek/redis-collections
python
https://github.com/honzajavorek/redis-collections/blob/07ca8efe88fb128f7dc7319dfa6a26cd39b3776b/redis_collections/lists.py#L764-L769
[ "def", "appendleft", "(", "self", ",", "value", ")", ":", "def", "appendleft_trans", "(", "pipe", ")", ":", "self", ".", "_appendleft_helper", "(", "value", ",", "pipe", ")", "self", ".", "_transaction", "(", "appendleft_trans", ")" ]
07ca8efe88fb128f7dc7319dfa6a26cd39b3776b
train
Deque.copy
Return a new collection with the same items as this one. If *key* is specified, create the new collection with the given Redis key.
redis_collections/lists.py
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): """ 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...
[ "Return", "a", "new", "collection", "with", "the", "same", "items", "as", "this", "one", ".", "If", "*", "key", "*", "is", "specified", "create", "the", "new", "collection", "with", "the", "given", "Redis", "key", "." ]
honzajavorek/redis-collections
python
https://github.com/honzajavorek/redis-collections/blob/07ca8efe88fb128f7dc7319dfa6a26cd39b3776b/redis_collections/lists.py#L771-L785
[ "def", "copy", "(", "self", ",", "key", "=", "None", ")", ":", "other", "=", "self", ".", "__class__", "(", "self", ".", "__iter__", "(", ")", ",", "self", ".", "maxlen", ",", "redis", "=", "self", ".", "redis", ",", "key", "=", "key", ",", "wr...
07ca8efe88fb128f7dc7319dfa6a26cd39b3776b
train
Deque.extend
Extend the right side of the the collection by appending values from the iterable *other*.
redis_collections/lists.py
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): """ 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...
[ "Extend", "the", "right", "side", "of", "the", "the", "collection", "by", "appending", "values", "from", "the", "iterable", "*", "other", "*", "." ]
honzajavorek/redis-collections
python
https://github.com/honzajavorek/redis-collections/blob/07ca8efe88fb128f7dc7319dfa6a26cd39b3776b/redis_collections/lists.py#L787-L802
[ "def", "extend", "(", "self", ",", "other", ")", ":", "def", "extend_trans", "(", "pipe", ")", ":", "values", "=", "list", "(", "other", ".", "__iter__", "(", "pipe", ")", ")", "if", "use_redis", "else", "other", "for", "v", "in", "values", ":", "s...
07ca8efe88fb128f7dc7319dfa6a26cd39b3776b
train
Deque.extendleft
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.
redis_collections/lists.py
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): """ 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 ...
[ "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", "." ]
honzajavorek/redis-collections
python
https://github.com/honzajavorek/redis-collections/blob/07ca8efe88fb128f7dc7319dfa6a26cd39b3776b/redis_collections/lists.py#L804-L820
[ "def", "extendleft", "(", "self", ",", "other", ")", ":", "def", "extendleft_trans", "(", "pipe", ")", ":", "values", "=", "list", "(", "other", ".", "__iter__", "(", "pipe", ")", ")", "if", "use_redis", "else", "other", "for", "v", "in", "values", "...
07ca8efe88fb128f7dc7319dfa6a26cd39b3776b
train
Deque.insert
Insert *value* into the collection at *index*. If the insertion would the collection to grow beyond ``maxlen``, raise ``IndexError``.
redis_collections/lists.py
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): """ 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...
[ "Insert", "*", "value", "*", "into", "the", "collection", "at", "*", "index", "*", ".", "If", "the", "insertion", "would", "the", "collection", "to", "grow", "beyond", "maxlen", "raise", "IndexError", "." ]
honzajavorek/redis-collections
python
https://github.com/honzajavorek/redis-collections/blob/07ca8efe88fb128f7dc7319dfa6a26cd39b3776b/redis_collections/lists.py#L822-L838
[ "def", "insert", "(", "self", ",", "index", ",", "value", ")", ":", "def", "insert_trans", "(", "pipe", ")", ":", "len_self", "=", "self", ".", "__len__", "(", "pipe", ")", "if", "(", "self", ".", "maxlen", "is", "not", "None", ")", "and", "(", "...
07ca8efe88fb128f7dc7319dfa6a26cd39b3776b
train
Deque.rotate
Rotate the deque n steps to the right. If n is negative, rotate to the left.
redis_collections/lists.py
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): """ 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...
[ "Rotate", "the", "deque", "n", "steps", "to", "the", "right", ".", "If", "n", "is", "negative", "rotate", "to", "the", "left", "." ]
honzajavorek/redis-collections
python
https://github.com/honzajavorek/redis-collections/blob/07ca8efe88fb128f7dc7319dfa6a26cd39b3776b/redis_collections/lists.py#L852-L883
[ "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", ":"...
07ca8efe88fb128f7dc7319dfa6a26cd39b3776b
train
get_entities_by_kind
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: ...
entity/models.py
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): """ 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: { ...
[ "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...
ambitioninc/django-entity
python
https://github.com/ambitioninc/django-entity/blob/ebc61f34313c52f4ef5819eb1da25b2ad837e80c/entity/models.py#L543-L611
[ "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...
ebc61f34313c52f4ef5819eb1da25b2ad837e80c
train
EntityQuerySet.is_sub_to_all
Given a list of super entities, return the entities that have those as a subset of their super entities.
entity/models.py
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): """ 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...
[ "Given", "a", "list", "of", "super", "entities", "return", "the", "entities", "that", "have", "those", "as", "a", "subset", "of", "their", "super", "entities", "." ]
ambitioninc/django-entity
python
https://github.com/ambitioninc/django-entity/blob/ebc61f34313c52f4ef5819eb1da25b2ad837e80c/entity/models.py#L79-L96
[ "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", "="...
ebc61f34313c52f4ef5819eb1da25b2ad837e80c
train
EntityQuerySet.is_sub_to_any
Given a list of super entities, return the entities that have super entities that interset with those provided.
entity/models.py
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): """ 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...
[ "Given", "a", "list", "of", "super", "entities", "return", "the", "entities", "that", "have", "super", "entities", "that", "interset", "with", "those", "provided", "." ]
ambitioninc/django-entity
python
https://github.com/ambitioninc/django-entity/blob/ebc61f34313c52f4ef5819eb1da25b2ad837e80c/entity/models.py#L98-L106
[ "def", "is_sub_to_any", "(", "self", ",", "*", "super_entities", ")", ":", "if", "super_entities", ":", "return", "self", ".", "filter", "(", "id__in", "=", "EntityRelationship", ".", "objects", ".", "filter", "(", "super_entity__in", "=", "super_entities", ")...
ebc61f34313c52f4ef5819eb1da25b2ad837e80c
train
EntityQuerySet.is_sub_to_all_kinds
Each returned entity will have superentites whos combined entity_kinds included *super_entity_kinds
entity/models.py
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): """ 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 ...
[ "Each", "returned", "entity", "will", "have", "superentites", "whos", "combined", "entity_kinds", "included", "*", "super_entity_kinds" ]
ambitioninc/django-entity
python
https://github.com/ambitioninc/django-entity/blob/ebc61f34313c52f4ef5819eb1da25b2ad837e80c/entity/models.py#L108-L126
[ "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...
ebc61f34313c52f4ef5819eb1da25b2ad837e80c
train
EntityQuerySet.is_sub_to_any_kind
Find all entities that have super_entities of any of the specified kinds
entity/models.py
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): """ 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: ...
[ "Find", "all", "entities", "that", "have", "super_entities", "of", "any", "of", "the", "specified", "kinds" ]
ambitioninc/django-entity
python
https://github.com/ambitioninc/django-entity/blob/ebc61f34313c52f4ef5819eb1da25b2ad837e80c/entity/models.py#L128-L145
[ "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...
ebc61f34313c52f4ef5819eb1da25b2ad837e80c
train
EntityQuerySet.cache_relationships
Caches the super and sub relationships by doing a prefetch_related.
entity/models.py
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): """ 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]) ...
[ "Caches", "the", "super", "and", "sub", "relationships", "by", "doing", "a", "prefetch_related", "." ]
ambitioninc/django-entity
python
https://github.com/ambitioninc/django-entity/blob/ebc61f34313c52f4ef5819eb1da25b2ad837e80c/entity/models.py#L147-L153
[ "def", "cache_relationships", "(", "self", ",", "cache_super", "=", "True", ",", "cache_sub", "=", "True", ")", ":", "relationships_to_cache", "=", "compress", "(", "[", "'super_relationships__super_entity'", ",", "'sub_relationships__sub_entity'", "]", ",", "[", "c...
ebc61f34313c52f4ef5819eb1da25b2ad837e80c
train
AllEntityManager.get_for_obj
Given a saved entity model object, return the associated entity.
entity/models.py
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): """ 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)
[ "Given", "a", "saved", "entity", "model", "object", "return", "the", "associated", "entity", "." ]
ambitioninc/django-entity
python
https://github.com/ambitioninc/django-entity/blob/ebc61f34313c52f4ef5819eb1da25b2ad837e80c/entity/models.py#L163-L168
[ "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...
ebc61f34313c52f4ef5819eb1da25b2ad837e80c
train
AllEntityManager.delete_for_obj
Delete the entities associated with a model object.
entity/models.py
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): """ 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( ...
[ "Delete", "the", "entities", "associated", "with", "a", "model", "object", "." ]
ambitioninc/django-entity
python
https://github.com/ambitioninc/django-entity/blob/ebc61f34313c52f4ef5819eb1da25b2ad837e80c/entity/models.py#L170-L177
[ "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", ")", ",", ...
ebc61f34313c52f4ef5819eb1da25b2ad837e80c
train
AllEntityManager.cache_relationships
Caches the super and sub relationships by doing a prefetch_related.
entity/models.py
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): """ 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)
[ "Caches", "the", "super", "and", "sub", "relationships", "by", "doing", "a", "prefetch_related", "." ]
ambitioninc/django-entity
python
https://github.com/ambitioninc/django-entity/blob/ebc61f34313c52f4ef5819eb1da25b2ad837e80c/entity/models.py#L228-L232
[ "def", "cache_relationships", "(", "self", ",", "cache_super", "=", "True", ",", "cache_sub", "=", "True", ")", ":", "return", "self", ".", "get_queryset", "(", ")", ".", "cache_relationships", "(", "cache_super", "=", "cache_super", ",", "cache_sub", "=", "...
ebc61f34313c52f4ef5819eb1da25b2ad837e80c
train
EntityGroupManager.get_membership_cache
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...
entity/models.py
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): """ 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...
[ "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...
ambitioninc/django-entity
python
https://github.com/ambitioninc/django-entity/blob/ebc61f34313c52f4ef5819eb1da25b2ad837e80c/entity/models.py#L317-L343
[ "def", "get_membership_cache", "(", "self", ",", "group_ids", "=", "None", ",", "is_active", "=", "True", ")", ":", "membership_queryset", "=", "EntityGroupMembership", ".", "objects", ".", "filter", "(", "Q", "(", "entity__isnull", "=", "True", ")", "|", "(...
ebc61f34313c52f4ef5819eb1da25b2ad837e80c
train
EntityGroup.all_entities
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.
entity/models.py
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 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", "." ]
ambitioninc/django-entity
python
https://github.com/ambitioninc/django-entity/blob/ebc61f34313c52f4ef5819eb1da25b2ad837e80c/entity/models.py#L364-L372
[ "def", "all_entities", "(", "self", ",", "is_active", "=", "True", ")", ":", "return", "self", ".", "get_all_entities", "(", "return_models", "=", "True", ",", "is_active", "=", "is_active", ")" ]
ebc61f34313c52f4ef5819eb1da25b2ad837e80c
train
EntityGroup.get_all_entities
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...
entity/models.py
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): """ 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...
[ "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",...
ambitioninc/django-entity
python
https://github.com/ambitioninc/django-entity/blob/ebc61f34313c52f4ef5819eb1da25b2ad837e80c/entity/models.py#L374-L418
[ "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...
ebc61f34313c52f4ef5819eb1da25b2ad837e80c
train
EntityGroup.add_entity
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 ...
entity/models.py
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): """ 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 ...
[ "Add", "an", "entity", "or", "sub", "-", "entity", "group", "to", "this", "EntityGroup", "." ]
ambitioninc/django-entity
python
https://github.com/ambitioninc/django-entity/blob/ebc61f34313c52f4ef5819eb1da25b2ad837e80c/entity/models.py#L420-L437
[ "def", "add_entity", "(", "self", ",", "entity", ",", "sub_entity_kind", "=", "None", ")", ":", "membership", "=", "EntityGroupMembership", ".", "objects", ".", "create", "(", "entity_group", "=", "self", ",", "entity", "=", "entity", ",", "sub_entity_kind", ...
ebc61f34313c52f4ef5819eb1da25b2ad837e80c
train
EntityGroup.bulk_add_entities
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...
entity/models.py
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): """ 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...
[ "Add", "many", "entities", "and", "sub", "-", "entity", "groups", "to", "this", "EntityGroup", "." ]
ambitioninc/django-entity
python
https://github.com/ambitioninc/django-entity/blob/ebc61f34313c52f4ef5819eb1da25b2ad837e80c/entity/models.py#L439-L455
[ "def", "bulk_add_entities", "(", "self", ",", "entities_and_kinds", ")", ":", "memberships", "=", "[", "EntityGroupMembership", "(", "entity_group", "=", "self", ",", "entity", "=", "entity", ",", "sub_entity_kind", "=", "sub_entity_kind", ",", ")", "for", "enti...
ebc61f34313c52f4ef5819eb1da25b2ad837e80c
train
EntityGroup.remove_entity
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 ...
entity/models.py
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): """ 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...
[ "Remove", "an", "entity", "or", "sub", "-", "entity", "group", "to", "this", "EntityGroup", "." ]
ambitioninc/django-entity
python
https://github.com/ambitioninc/django-entity/blob/ebc61f34313c52f4ef5819eb1da25b2ad837e80c/entity/models.py#L457-L473
[ "def", "remove_entity", "(", "self", ",", "entity", ",", "sub_entity_kind", "=", "None", ")", ":", "EntityGroupMembership", ".", "objects", ".", "get", "(", "entity_group", "=", "self", ",", "entity", "=", "entity", ",", "sub_entity_kind", "=", "sub_entity_kin...
ebc61f34313c52f4ef5819eb1da25b2ad837e80c
train
EntityGroup.bulk_remove_entities
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...
entity/models.py
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): """ 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...
[ "Remove", "many", "entities", "and", "sub", "-", "entity", "groups", "to", "this", "EntityGroup", "." ]
ambitioninc/django-entity
python
https://github.com/ambitioninc/django-entity/blob/ebc61f34313c52f4ef5819eb1da25b2ad837e80c/entity/models.py#L475-L491
[ "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...
ebc61f34313c52f4ef5819eb1da25b2ad837e80c
train
EntityGroup.bulk_overwrite
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-...
entity/models.py
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): """ 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...
[ "Update", "the", "group", "to", "the", "given", "entities", "and", "sub", "-", "entity", "groups", "." ]
ambitioninc/django-entity
python
https://github.com/ambitioninc/django-entity/blob/ebc61f34313c52f4ef5819eb1da25b2ad837e80c/entity/models.py#L493-L507
[ "def", "bulk_overwrite", "(", "self", ",", "entities_and_kinds", ")", ":", "EntityGroupMembership", ".", "objects", ".", "filter", "(", "entity_group", "=", "self", ")", ".", "delete", "(", ")", "return", "self", ".", "bulk_add_entities", "(", "entities_and_kind...
ebc61f34313c52f4ef5819eb1da25b2ad837e80c
train
generate_slug
A copy of spectator.core.models.SluggedModelMixin._generate_slug()
spectator/events/migrations/0007_work_slug_20180102_1137.py
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): "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...
[ "A", "copy", "of", "spectator", ".", "core", ".", "models", ".", "SluggedModelMixin", ".", "_generate_slug", "()" ]
philgyford/django-spectator
python
https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/events/migrations/0007_work_slug_20180102_1137.py#L8-L21
[ "def", "generate_slug", "(", "value", ")", ":", "alphabet", "=", "'abcdefghijkmnopqrstuvwxyz23456789'", "salt", "=", "'Django Spectator'", "if", "hasattr", "(", "settings", ",", "'SPECTATOR_SLUG_ALPHABET'", ")", ":", "alphabet", "=", "settings", ".", "SPECTATOR_SLUG_A...
f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada
train
set_slug
Create a slug for each Work already in the DB.
spectator/events/migrations/0007_work_slug_20180102_1137.py
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): """ 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'])
[ "Create", "a", "slug", "for", "each", "Work", "already", "in", "the", "DB", "." ]
philgyford/django-spectator
python
https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/events/migrations/0007_work_slug_20180102_1137.py#L24-L32
[ "def", "set_slug", "(", "apps", ",", "schema_editor", ",", "class_name", ")", ":", "Cls", "=", "apps", ".", "get_model", "(", "'spectator_events'", ",", "class_name", ")", "for", "obj", "in", "Cls", ".", "objects", ".", "all", "(", ")", ":", "obj", "."...
f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada
train
Event.kind_name
e.g. 'Gig' or 'Movie'.
spectator/events/models.py
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): "e.g. 'Gig' or 'Movie'." return {k:v for (k,v) in self.KIND_CHOICES}[self.kind]
[ "e", ".", "g", ".", "Gig", "or", "Movie", "." ]
philgyford/django-spectator
python
https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/events/models.py#L231-L233
[ "def", "kind_name", "(", "self", ")", ":", "return", "{", "k", ":", "v", "for", "(", "k", ",", "v", ")", "in", "self", ".", "KIND_CHOICES", "}", "[", "self", ".", "kind", "]" ]
f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada
train
Event.get_kind_name_plural
e.g. 'Gigs' or 'Movies'.
spectator/events/models.py
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): "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))
[ "e", ".", "g", ".", "Gigs", "or", "Movies", "." ]
philgyford/django-spectator
python
https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/events/models.py#L250-L257
[ "def", "get_kind_name_plural", "(", "kind", ")", ":", "if", "kind", "in", "[", "'comedy'", ",", "'cinema'", ",", "'dance'", ",", "'theatre'", "]", ":", "return", "kind", ".", "title", "(", ")", "elif", "kind", "==", "'museum'", ":", "return", "'Galleries...
f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada
train
Event.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', }, # etc }
spectator/events/models.py
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(): """ 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...
[ "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...
philgyford/django-spectator
python
https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/events/models.py#L277-L294
[ "def", "get_kinds_data", "(", ")", ":", "kinds", "=", "{", "k", ":", "{", "'name'", ":", "v", "}", "for", "k", ",", "v", "in", "Event", ".", "KIND_CHOICES", "}", "for", "k", ",", "data", "in", "kinds", ".", "items", "(", ")", ":", "kinds", "[",...
f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada
train
Work.get_list_url
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.)
spectator/events/models.py
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): """ 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: ...
[ "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", ".", "(", ...
philgyford/django-spectator
python
https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/events/models.py#L379-L389
[ "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...
f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada
train
Mapper.convert_descriptor_and_rows
Convert descriptor and rows to Pandas
tableschema_pandas/mapper.py
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): """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...
[ "Convert", "descriptor", "and", "rows", "to", "Pandas" ]
frictionlessdata/tableschema-pandas-py
python
https://github.com/frictionlessdata/tableschema-pandas-py/blob/ef941dbc12f5d346e9612f8fec1b4b356b8493ca/tableschema_pandas/mapper.py#L23-L87
[ "def", "convert_descriptor_and_rows", "(", "self", ",", "descriptor", ",", "rows", ")", ":", "# Prepare", "primary_key", "=", "None", "schema", "=", "tableschema", ".", "Schema", "(", "descriptor", ")", "if", "len", "(", "schema", ".", "primary_key", ")", "=...
ef941dbc12f5d346e9612f8fec1b4b356b8493ca
train
Mapper.convert_type
Convert type to Pandas
tableschema_pandas/mapper.py
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): """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]'), ...
[ "Convert", "type", "to", "Pandas" ]
frictionlessdata/tableschema-pandas-py
python
https://github.com/frictionlessdata/tableschema-pandas-py/blob/ef941dbc12f5d346e9612f8fec1b4b356b8493ca/tableschema_pandas/mapper.py#L89-L117
[ "def", "convert_type", "(", "self", ",", "type", ")", ":", "# Mapping", "mapping", "=", "{", "'any'", ":", "np", ".", "dtype", "(", "'O'", ")", ",", "'array'", ":", "np", ".", "dtype", "(", "list", ")", ",", "'boolean'", ":", "np", ".", "dtype", ...
ef941dbc12f5d346e9612f8fec1b4b356b8493ca
train
Mapper.restore_descriptor
Restore descriptor from Pandas
tableschema_pandas/mapper.py
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): """Restore descriptor from Pandas """ # Prepare fields = [] primary_key = None # Primary key if dataframe.index.name: field_type = self.restore_type(dataframe.index.dtype) field = { ...
[ "Restore", "descriptor", "from", "Pandas" ]
frictionlessdata/tableschema-pandas-py
python
https://github.com/frictionlessdata/tableschema-pandas-py/blob/ef941dbc12f5d346e9612f8fec1b4b356b8493ca/tableschema_pandas/mapper.py#L119-L154
[ "def", "restore_descriptor", "(", "self", ",", "dataframe", ")", ":", "# Prepare", "fields", "=", "[", "]", "primary_key", "=", "None", "# Primary key", "if", "dataframe", ".", "index", ".", "name", ":", "field_type", "=", "self", ".", "restore_type", "(", ...
ef941dbc12f5d346e9612f8fec1b4b356b8493ca
train
Mapper.restore_row
Restore row from Pandas
tableschema_pandas/mapper.py
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): """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 ...
[ "Restore", "row", "from", "Pandas" ]
frictionlessdata/tableschema-pandas-py
python
https://github.com/frictionlessdata/tableschema-pandas-py/blob/ef941dbc12f5d346e9612f8fec1b4b356b8493ca/tableschema_pandas/mapper.py#L156-L176
[ "def", "restore_row", "(", "self", ",", "row", ",", "schema", ",", "pk", ")", ":", "result", "=", "[", "]", "for", "field", "in", "schema", ".", "fields", ":", "if", "schema", ".", "primary_key", "and", "schema", ".", "primary_key", "[", "0", "]", ...
ef941dbc12f5d346e9612f8fec1b4b356b8493ca
train
Mapper.restore_type
Restore type from Pandas
tableschema_pandas/mapper.py
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): """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...
[ "Restore", "type", "from", "Pandas" ]
frictionlessdata/tableschema-pandas-py
python
https://github.com/frictionlessdata/tableschema-pandas-py/blob/ef941dbc12f5d346e9612f8fec1b4b356b8493ca/tableschema_pandas/mapper.py#L178-L207
[ "def", "restore_type", "(", "self", ",", "dtype", ",", "sample", "=", "None", ")", ":", "# Pandas types", "if", "pdc", ".", "is_bool_dtype", "(", "dtype", ")", ":", "return", "'boolean'", "elif", "pdc", ".", "is_datetime64_any_dtype", "(", "dtype", ")", ":...
ef941dbc12f5d346e9612f8fec1b4b356b8493ca
train
change_object_link_card
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.
spectator/core/templatetags/spectator_core.py
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): """ 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...
[ "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...
philgyford/django-spectator
python
https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/core/templatetags/spectator_core.py#L49-L64
[ "def", "change_object_link_card", "(", "obj", ",", "perms", ")", ":", "# eg: 'movie' or 'classicalwork':", "name", "=", "obj", ".", "__class__", ".", "__name__", ".", "lower", "(", ")", "permission", "=", "'spectator.can_edit_{}'", ".", "format", "(", "name", ")...
f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada
train
domain_urlize
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...
spectator/core/templatetags/spectator_core.py
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): """ 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...
[ "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", "." ]
philgyford/django-spectator
python
https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/core/templatetags/spectator_core.py#L68-L89
[ "def", "domain_urlize", "(", "value", ")", ":", "parsed_uri", "=", "urlparse", "(", "value", ")", "domain", "=", "'{uri.netloc}'", ".", "format", "(", "uri", "=", "parsed_uri", ")", "if", "domain", ".", "startswith", "(", "'www.'", ")", ":", "domain", "=...
f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada
train
current_url_name
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>
spectator/core/templatetags/spectator_core.py
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): """ 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...
[ "Returns", "the", "name", "of", "the", "current", "URL", "namespaced", "or", "False", "." ]
philgyford/django-spectator
python
https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/core/templatetags/spectator_core.py#L93-L110
[ "def", "current_url_name", "(", "context", ")", ":", "url_name", "=", "False", "if", "context", ".", "request", ".", "resolver_match", ":", "url_name", "=", "\"{}:{}\"", ".", "format", "(", "context", ".", "request", ".", "resolver_match", ".", "namespace", ...
f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada
train
query_string
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...
spectator/core/templatetags/spectator_core.py
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): """ 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 ...
[ "For", "adding", "/", "replacing", "a", "key", "=", "value", "pair", "to", "the", "GET", "string", "for", "a", "URL", "." ]
philgyford/django-spectator
python
https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/core/templatetags/spectator_core.py#L114-L133
[ "def", "query_string", "(", "context", ",", "key", ",", "value", ")", ":", "try", ":", "request", "=", "context", "[", "'request'", "]", "args", "=", "request", ".", "GET", ".", "copy", "(", ")", "except", "KeyError", ":", "args", "=", "QueryDict", "...
f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada
train
most_read_creators_card
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.
spectator/core/templatetags/spectator_core.py
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): """ 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...
[ "Displays", "a", "card", "showing", "the", "Creators", "who", "have", "the", "most", "Readings", "associated", "with", "their", "Publications", "." ]
philgyford/django-spectator
python
https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/core/templatetags/spectator_core.py#L149-L167
[ "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",...
f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada
train
most_visited_venues_card
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.
spectator/core/templatetags/spectator_core.py
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): """ 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...
[ "Displays", "a", "card", "showing", "the", "Venues", "that", "have", "the", "most", "Events", "." ]
philgyford/django-spectator
python
https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/core/templatetags/spectator_core.py#L179-L196
[ "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"...
f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada
train
Publication.has_urls
Handy for templates.
spectator/reading/models.py
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): "Handy for templates." if self.isbn_uk or self.isbn_us or self.official_url or self.notes_url: return True else: return False
[ "Handy", "for", "templates", "." ]
philgyford/django-spectator
python
https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/reading/models.py#L169-L174
[ "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" ]
f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada
train
get_entity
eg, get_entity('spectator', 'version') returns `__version__` value in `__init__.py`.
setup.py
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): """ 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)
[ "eg", "get_entity", "(", "spectator", "version", ")", "returns", "__version__", "value", "in", "__init__", ".", "py", "." ]
philgyford/django-spectator
python
https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/setup.py#L15-L22
[ "def", "get_entity", "(", "package", ",", "entity", ")", ":", "init_py", "=", "open", "(", "os", ".", "path", ".", "join", "(", "package", ",", "'__init__.py'", ")", ")", ".", "read", "(", ")", "find", "=", "\"__%s__ = ['\\\"]([^'\\\"]+)['\\\"]\"", "%", ...
f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada
train
ReadingYearArchiveView.get_queryset
Reduce the number of queries and speed things up.
spectator/reading/views.py
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): "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
[ "Reduce", "the", "number", "of", "queries", "and", "speed", "things", "up", "." ]
philgyford/django-spectator
python
https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/reading/views.py#L122-L129
[ "def", "get_queryset", "(", "self", ")", ":", "qs", "=", "super", "(", ")", ".", "get_queryset", "(", ")", "qs", "=", "qs", ".", "select_related", "(", "'publication__series'", ")", ".", "prefetch_related", "(", "'publication__roles__creator'", ")", "return", ...
f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada
train
set_slug
Create a slug for each Creator already in the DB.
spectator/core/migrations/0004_auto_20180102_0959.py
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): """ 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'])
[ "Create", "a", "slug", "for", "each", "Creator", "already", "in", "the", "DB", "." ]
philgyford/django-spectator
python
https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/core/migrations/0004_auto_20180102_0959.py#L24-L32
[ "def", "set_slug", "(", "apps", ",", "schema_editor", ")", ":", "Creator", "=", "apps", ".", "get_model", "(", "'spectator_core'", ",", "'Creator'", ")", "for", "c", "in", "Creator", ".", "objects", ".", "all", "(", ")", ":", "c", ".", "slug", "=", "...
f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada
train
forwards
Copy the ClassicalWork and DancePiece data to use the new through models.
spectator/events/migrations/0013_copy_classical_and_dance_data.py
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): """ 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...
[ "Copy", "the", "ClassicalWork", "and", "DancePiece", "data", "to", "use", "the", "new", "through", "models", "." ]
philgyford/django-spectator
python
https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/events/migrations/0013_copy_classical_and_dance_data.py#L6-L28
[ "def", "forwards", "(", "apps", ",", "schema_editor", ")", ":", "Event", "=", "apps", ".", "get_model", "(", "'spectator_events'", ",", "'Event'", ")", "ClassicalWorkSelection", "=", "apps", ".", "get_model", "(", "'spectator_events'", ",", "'ClassicalWorkSelectio...
f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada
train
forwards
Set the venue_name field of all Events that have a Venue.
spectator/events/migrations/0024_event_venue_name.py
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): """ 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()
[ "Set", "the", "venue_name", "field", "of", "all", "Events", "that", "have", "a", "Venue", "." ]
philgyford/django-spectator
python
https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/events/migrations/0024_event_venue_name.py#L7-L16
[ "def", "forwards", "(", "apps", ",", "schema_editor", ")", ":", "Event", "=", "apps", ".", "get_model", "(", "'spectator_events'", ",", "'Event'", ")", "for", "event", "in", "Event", ".", "objects", ".", "all", "(", ")", ":", "if", "event", ".", "venue...
f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada
train
forwards
Migrate all 'exhibition' Events to the new 'museum' Event kind.
spectator/events/migrations/0037_exhibition_to_museum.py
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): """ 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()
[ "Migrate", "all", "exhibition", "Events", "to", "the", "new", "museum", "Event", "kind", "." ]
philgyford/django-spectator
python
https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/events/migrations/0037_exhibition_to_museum.py#L6-L14
[ "def", "forwards", "(", "apps", ",", "schema_editor", ")", ":", "Event", "=", "apps", ".", "get_model", "(", "'spectator_events'", ",", "'Event'", ")", "for", "ev", "in", "Event", ".", "objects", ".", "filter", "(", "kind", "=", "'exhibition'", ")", ":",...
f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada
train
truncate_string
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 ...
spectator/core/utils.py
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='…', 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 ...
[ "Truncate", "a", "string", "to", "a", "certain", "length", "removing", "line", "breaks", "and", "mutliple", "spaces", "optionally", "removing", "HTML", "and", "appending", "a", "truncate", "string", "." ]
philgyford/django-spectator
python
https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/core/utils.py#L5-L25
[ "def", "truncate_string", "(", "text", ",", "strip_html", "=", "True", ",", "chars", "=", "255", ",", "truncate", "=", "'…', ", "a", "_word_boundary=F", "a", "lse):", "", "", "if", "strip_html", ":", "text", "=", "strip_tags", "(", "text", ")", "text", ...
f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada
train
chartify
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...
spectator/core/utils.py
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): """ 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...
[ "Given", "a", "QuerySet", "it", "will", "go", "through", "and", "add", "a", "chart_position", "property", "to", "each", "object", "returning", "a", "list", "of", "the", "objects", "." ]
philgyford/django-spectator
python
https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/core/utils.py#L28-L71
[ "def", "chartify", "(", "qs", ",", "score_field", ",", "cutoff", "=", "0", ",", "ensure_chartiness", "=", "True", ")", ":", "chart", "=", "[", "]", "position", "=", "0", "prev_obj", "=", "None", "for", "counter", ",", "obj", "in", "enumerate", "(", "...
f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada
train
VenueManager.by_visits
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.
spectator/events/managers.py
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): """ 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...
[ "Gets", "Venues", "in", "order", "of", "how", "many", "Events", "have", "been", "held", "there", ".", "Adds", "a", "num_visits", "field", "to", "each", "one", "." ]
philgyford/django-spectator
python
https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/events/managers.py#L7-L22
[ "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...
f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada
train
WorkManager.by_views
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.
spectator/events/managers.py
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): """ 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...
[ "Gets", "Works", "in", "order", "of", "how", "many", "times", "they", "ve", "been", "attached", "to", "Events", "." ]
philgyford/django-spectator
python
https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/events/managers.py#L27-L42
[ "def", "by_views", "(", "self", ",", "kind", "=", "None", ")", ":", "qs", "=", "self", ".", "get_queryset", "(", ")", "if", "kind", "is", "not", "None", ":", "qs", "=", "qs", ".", "filter", "(", "kind", "=", "kind", ")", "qs", "=", "qs", ".", ...
f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada
train
NaturalSortField.naturalize_thing
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.
spectator/core/fields.py
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): """ 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 = [ ...
[ "Make", "a", "naturalized", "version", "of", "a", "general", "string", "not", "a", "person", "s", "name", ".", "e", ".", "g", ".", "title", "of", "a", "book", "a", "band", "s", "name", "etc", "." ]
philgyford/django-spectator
python
https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/core/fields.py#L147-L174
[ "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'\"", ...
f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada
train
NaturalSortField.naturalize_person
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.
spectator/core/fields.py
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): """ 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", "." ]
philgyford/django-spectator
python
https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/core/fields.py#L176-L232
[ "def", "naturalize_person", "(", "self", ",", "string", ")", ":", "suffixes", "=", "[", "'Jr'", ",", "'Jr.'", ",", "'Sr'", ",", "'Sr.'", ",", "'I'", ",", "'II'", ",", "'III'", ",", "'IV'", ",", "'V'", ",", "]", "# Add lowercase versions:", "suffixes", ...
f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada
train
NaturalSortField._naturalize_numbers
Makes any integers into very zero-padded numbers. e.g. '1' becomes '00000001'.
spectator/core/fields.py
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): """ 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) ...
[ "Makes", "any", "integers", "into", "very", "zero", "-", "padded", "numbers", ".", "e", ".", "g", ".", "1", "becomes", "00000001", "." ]
philgyford/django-spectator
python
https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/core/fields.py#L234-L245
[ "def", "_naturalize_numbers", "(", "self", ",", "string", ")", ":", "def", "naturalize_int_match", "(", "match", ")", ":", "return", "'%08d'", "%", "(", "int", "(", "match", ".", "group", "(", "0", ")", ")", ",", ")", "string", "=", "re", ".", "sub",...
f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada
train
annual_reading_counts
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' ...
spectator/reading/utils.py
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'): """ 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, ...
[ "Returns", "a", "list", "of", "dicts", "one", "per", "year", "of", "reading", ".", "In", "year", "order", ".", "Each", "dict", "is", "like", "this", "(", "if", "kind", "is", "all", ")", ":" ]
philgyford/django-spectator
python
https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/reading/utils.py#L9-L73
[ "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...
f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada
train
CountryListFilter.lookups
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.
spectator/events/admin.py
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): """ 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", ":" ]
philgyford/django-spectator
python
https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/events/admin.py#L120-L147
[ "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", "("...
f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada
train
CountryListFilter.queryset
Returns the filtered queryset based on the value provided in the query string and retrievable via `self.value()`.
spectator/events/admin.py
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): """ 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...
[ "Returns", "the", "filtered", "queryset", "based", "on", "the", "value", "provided", "in", "the", "query", "string", "and", "retrievable", "via", "self", ".", "value", "()", "." ]
philgyford/django-spectator
python
https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/events/admin.py#L149-L158
[ "def", "queryset", "(", "self", ",", "request", ",", "queryset", ")", ":", "if", "self", ".", "value", "(", ")", ":", "return", "queryset", ".", "filter", "(", "country", "=", "self", ".", "value", "(", ")", ")", "else", ":", "return", "queryset" ]
f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada
train
forward
Copying data from the old `Event.movie` and `Event.play` ForeignKey fields into the new `Event.movies` and `Event.plays` ManyToManyFields.
spectator/events/migrations/0017_copy_movies_and_plays_data.py
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): """ 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...
[ "Copying", "data", "from", "the", "old", "Event", ".", "movie", "and", "Event", ".", "play", "ForeignKey", "fields", "into", "the", "new", "Event", ".", "movies", "and", "Event", ".", "plays", "ManyToManyFields", "." ]
philgyford/django-spectator
python
https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/events/migrations/0017_copy_movies_and_plays_data.py#L6-L23
[ "def", "forward", "(", "apps", ",", "schema_editor", ")", ":", "Event", "=", "apps", ".", "get_model", "(", "'spectator_events'", ",", "'Event'", ")", "MovieSelection", "=", "apps", ".", "get_model", "(", "'spectator_events'", ",", "'MovieSelection'", ")", "Pl...
f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada
train
set_slug
Create a slug for each Event already in the DB.
spectator/events/migrations/0006_event_slug_20180102_1127.py
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): """ 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'])
[ "Create", "a", "slug", "for", "each", "Event", "already", "in", "the", "DB", "." ]
philgyford/django-spectator
python
https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/events/migrations/0006_event_slug_20180102_1127.py#L24-L32
[ "def", "set_slug", "(", "apps", ",", "schema_editor", ")", ":", "Event", "=", "apps", ".", "get_model", "(", "'spectator_events'", ",", "'Event'", ")", "for", "e", "in", "Event", ".", "objects", ".", "all", "(", ")", ":", "e", ".", "slug", "=", "gene...
f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada
train
DiggPaginator.page
Return a standard ``Page`` instance with custom, digg-specific page ranges attached.
spectator/core/paginator.py
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): """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,...
[ "Return", "a", "standard", "Page", "instance", "with", "custom", "digg", "-", "specific", "page", "ranges", "attached", "." ]
philgyford/django-spectator
python
https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/core/paginator.py#L195-L269
[ "def", "page", "(", "self", ",", "number", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "page", "=", "super", "(", ")", ".", "page", "(", "number", ",", "*", "args", ",", "*", "*", "kwargs", ")", "number", "=", "int", "(", "number", "...
f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada
train
version
Get the version number without importing the mrcfile package.
setup.py
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(): """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__']
[ "Get", "the", "version", "number", "without", "importing", "the", "mrcfile", "package", "." ]
ccpem/mrcfile
python
https://github.com/ccpem/mrcfile/blob/96b862ad29884f5a5082a69e2aba8b0829090838/setup.py#L9-L14
[ "def", "version", "(", ")", ":", "namespace", "=", "{", "}", "with", "open", "(", "os", ".", "path", ".", "join", "(", "'mrcfile'", ",", "'version.py'", ")", ")", "as", "f", ":", "exec", "(", "f", ".", "read", "(", ")", ",", "namespace", ")", "...
96b862ad29884f5a5082a69e2aba8b0829090838
train
EventListView.get_event_counts
Returns a dict like: {'counts': { 'all': 30, 'movie': 12, 'gig': 10, }}
spectator/events/views.py
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): """ 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...
[ "Returns", "a", "dict", "like", ":", "{", "counts", ":", "{", "all", ":", "30", "movie", ":", "12", "gig", ":", "10", "}}" ]
philgyford/django-spectator
python
https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/events/views.py#L52-L67
[ "def", "get_event_counts", "(", "self", ")", ":", "counts", "=", "{", "'all'", ":", "Event", ".", "objects", ".", "count", "(", ")", ",", "}", "for", "k", ",", "v", "in", "Event", ".", "KIND_CHOICES", ":", "# e.g. 'movie_count':", "counts", "[", "k", ...
f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada
train
EventListView.get_event_kind
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'.
spectator/events/views.py
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): """ 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...
[ "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", "." ]
philgyford/django-spectator
python
https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/events/views.py#L69-L79
[ "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", ...
f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada
train
EventListView.get_queryset
Restrict to a single kind of event, if any, and include Venue data.
spectator/events/views.py
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): "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
[ "Restrict", "to", "a", "single", "kind", "of", "event", "if", "any", "and", "include", "Venue", "data", "." ]
philgyford/django-spectator
python
https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/events/views.py#L81-L91
[ "def", "get_queryset", "(", "self", ")", ":", "qs", "=", "super", "(", ")", ".", "get_queryset", "(", ")", "kind", "=", "self", ".", "get_event_kind", "(", ")", "if", "kind", "is", "not", "None", ":", "qs", "=", "qs", ".", "filter", "(", "kind", ...
f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada
train
WorkMixin.get_work_kind
We'll have a kind_slug like 'movies'. We need to translate that into a work `kind` like 'movie'.
spectator/events/views.py
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): """ 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)
[ "We", "ll", "have", "a", "kind_slug", "like", "movies", ".", "We", "need", "to", "translate", "that", "into", "a", "work", "kind", "like", "movie", "." ]
philgyford/django-spectator
python
https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/events/views.py#L147-L153
[ "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", ",", ...
f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada
train
VenueListView.get_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.
spectator/events/views.py
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): """ 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') \ ...
[ "Returns", "a", "list", "of", "dicts", "one", "per", "country", "that", "has", "at", "least", "one", "Venue", "in", "it", "." ]
philgyford/django-spectator
python
https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/events/views.py#L216-L237
[ "def", "get_countries", "(", "self", ")", ":", "qs", "=", "Venue", ".", "objects", ".", "values", "(", "'country'", ")", ".", "exclude", "(", "country", "=", "''", ")", ".", "distinct", "(", ")", ".", "order_by", "(", "'country'", ")", "countries", "...
f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada
train
forwards
Re-save all the Works because something earlier didn't create their slugs.
spectator/events/migrations/0032_recreate_work_slugs.py
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): """ 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()
[ "Re", "-", "save", "all", "the", "Works", "because", "something", "earlier", "didn", "t", "create", "their", "slugs", "." ]
philgyford/django-spectator
python
https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/events/migrations/0032_recreate_work_slugs.py#L30-L39
[ "def", "forwards", "(", "apps", ",", "schema_editor", ")", ":", "Work", "=", "apps", ".", "get_model", "(", "'spectator_events'", ",", "'Work'", ")", "for", "work", "in", "Work", ".", "objects", ".", "all", "(", ")", ":", "if", "not", "work", ".", "s...
f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada
train
annual_event_counts
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).
spectator/events/templatetags/spectator_events.py
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'): """ 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 ...
[ "Returns", "a", "QuerySet", "of", "dicts", "each", "one", "with", "these", "keys", ":" ]
philgyford/django-spectator
python
https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/events/templatetags/spectator_events.py#L17-L36
[ "def", "annual_event_counts", "(", "kind", "=", "'all'", ")", ":", "qs", "=", "Event", ".", "objects", "if", "kind", "!=", "'all'", ":", "qs", "=", "qs", ".", "filter", "(", "kind", "=", "kind", ")", "qs", "=", "qs", ".", "annotate", "(", "year", ...
f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada
train
annual_event_counts_card
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.
spectator/events/templatetags/spectator_events.py
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): """ 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", "." ]
philgyford/django-spectator
python
https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/events/templatetags/spectator_events.py#L40-L58
[ "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", ...
f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada
train
display_date
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/
spectator/events/templatetags/spectator_events.py
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): """ 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...
[ "Render", "a", "date", "/", "datetime", "(", "d", ")", "as", "a", "date", "using", "the", "SPECTATOR_DATE_FORMAT", "setting", ".", "Wrap", "the", "output", "in", "a", "<time", ">", "tag", "." ]
philgyford/django-spectator
python
https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/events/templatetags/spectator_events.py#L62-L75
[ "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...
f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada
train
event_list_tabs
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...
spectator/events/templatetags/spectator_events.py
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): """ 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...
[ "Displays", "the", "tabs", "to", "different", "event_list", "pages", "." ]
philgyford/django-spectator
python
https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/events/templatetags/spectator_events.py#L79-L101
[ "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...
f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada
train
day_events_card
Displays Events that happened on the supplied date. `date` is a date object.
spectator/events/templatetags/spectator_events.py
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): """ 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), ...
[ "Displays", "Events", "that", "happened", "on", "the", "supplied", "date", ".", "date", "is", "a", "date", "object", "." ]
philgyford/django-spectator
python
https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/events/templatetags/spectator_events.py#L134-L144
[ "def", "day_events_card", "(", "date", ")", ":", "d", "=", "date", ".", "strftime", "(", "app_settings", ".", "DATE_FORMAT", ")", "card_title", "=", "'Events on {}'", ".", "format", "(", "d", ")", "return", "{", "'card_title'", ":", "card_title", ",", "'ev...
f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada
train
most_seen_creators_card
Displays a card showing the Creators that are associated with the most Events.
spectator/events/templatetags/spectator_events.py
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): """ 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...
[ "Displays", "a", "card", "showing", "the", "Creators", "that", "are", "associated", "with", "the", "most", "Events", "." ]
philgyford/django-spectator
python
https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/events/templatetags/spectator_events.py#L179-L191
[ "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", ...
f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada
train
most_seen_creators_by_works
Returns a QuerySet of the Creators that are associated with the most Works.
spectator/events/templatetags/spectator_events.py
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): """ 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]
[ "Returns", "a", "QuerySet", "of", "the", "Creators", "that", "are", "associated", "with", "the", "most", "Works", "." ]
philgyford/django-spectator
python
https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/events/templatetags/spectator_events.py#L195-L199
[ "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", ")...
f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada
train
most_seen_creators_by_works_card
Displays a card showing the Creators that are associated with the most Works. e.g.: {% most_seen_creators_by_works_card work_kind='movie' role_name='Director' num=5 %}
spectator/events/templatetags/spectator_events.py
def most_seen_creators_by_works_card(work_kind=None, role_name=None, num=10): """ Displays a card showing the Creators that are associated with the most Works. e.g.: {% most_seen_creators_by_works_card work_kind='movie' role_name='Director' num=5 %} """ object_list = most_seen_creators_by_wo...
def most_seen_creators_by_works_card(work_kind=None, role_name=None, num=10): """ Displays a card showing the Creators that are associated with the most Works. e.g.: {% most_seen_creators_by_works_card work_kind='movie' role_name='Director' num=5 %} """ object_list = most_seen_creators_by_wo...
[ "Displays", "a", "card", "showing", "the", "Creators", "that", "are", "associated", "with", "the", "most", "Works", "." ]
philgyford/django-spectator
python
https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/events/templatetags/spectator_events.py#L203-L235
[ "def", "most_seen_creators_by_works_card", "(", "work_kind", "=", "None", ",", "role_name", "=", "None", ",", "num", "=", "10", ")", ":", "object_list", "=", "most_seen_creators_by_works", "(", "work_kind", "=", "work_kind", ",", "role_name", "=", "role_name", "...
f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada
train
most_seen_works_card
Displays a card showing the Works that are associated with the most Events.
spectator/events/templatetags/spectator_events.py
def most_seen_works_card(kind=None, num=10): """ Displays a card showing the Works that are associated with the most Events. """ object_list = most_seen_works(kind=kind, num=num) object_list = chartify(object_list, 'num_views', cutoff=1) if kind: card_title = 'Most seen {}'.format( ...
def most_seen_works_card(kind=None, num=10): """ Displays a card showing the Works that are associated with the most Events. """ object_list = most_seen_works(kind=kind, num=num) object_list = chartify(object_list, 'num_views', cutoff=1) if kind: card_title = 'Most seen {}'.format( ...
[ "Displays", "a", "card", "showing", "the", "Works", "that", "are", "associated", "with", "the", "most", "Events", "." ]
philgyford/django-spectator
python
https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/events/templatetags/spectator_events.py#L247-L267
[ "def", "most_seen_works_card", "(", "kind", "=", "None", ",", "num", "=", "10", ")", ":", "object_list", "=", "most_seen_works", "(", "kind", "=", "kind", ",", "num", "=", "num", ")", "object_list", "=", "chartify", "(", "object_list", ",", "'num_views'", ...
f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada
train
SluggedModelMixin._generate_slug
Generates a slug using a Hashid of `value`.
spectator/core/models.py
def _generate_slug(self, value): """ Generates a slug using a Hashid of `value`. """ alphabet = app_settings.SLUG_ALPHABET salt = app_settings.SLUG_SALT hashids = Hashids(alphabet=alphabet, salt=salt, min_length=5) return hashids.encode(value)
def _generate_slug(self, value): """ Generates a slug using a Hashid of `value`. """ alphabet = app_settings.SLUG_ALPHABET salt = app_settings.SLUG_SALT hashids = Hashids(alphabet=alphabet, salt=salt, min_length=5) return hashids.encode(value)
[ "Generates", "a", "slug", "using", "a", "Hashid", "of", "value", "." ]
philgyford/django-spectator
python
https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/core/models.py#L46-L55
[ "def", "_generate_slug", "(", "self", ",", "value", ")", ":", "alphabet", "=", "app_settings", ".", "SLUG_ALPHABET", "salt", "=", "app_settings", ".", "SLUG_SALT", "hashids", "=", "Hashids", "(", "alphabet", "=", "alphabet", ",", "salt", "=", "salt", ",", ...
f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada
train
Storage.create
https://github.com/frictionlessdata/tableschema-pandas-py#storage
tableschema_pandas/storage.py
def create(self, bucket, descriptor, force=False): """https://github.com/frictionlessdata/tableschema-pandas-py#storage """ # Make lists buckets = bucket if isinstance(bucket, six.string_types): buckets = [bucket] descriptors = descriptor if isinstanc...
def create(self, bucket, descriptor, force=False): """https://github.com/frictionlessdata/tableschema-pandas-py#storage """ # Make lists buckets = bucket if isinstance(bucket, six.string_types): buckets = [bucket] descriptors = descriptor if isinstanc...
[ "https", ":", "//", "github", ".", "com", "/", "frictionlessdata", "/", "tableschema", "-", "pandas", "-", "py#storage" ]
frictionlessdata/tableschema-pandas-py
python
https://github.com/frictionlessdata/tableschema-pandas-py/blob/ef941dbc12f5d346e9612f8fec1b4b356b8493ca/tableschema_pandas/storage.py#L47-L71
[ "def", "create", "(", "self", ",", "bucket", ",", "descriptor", ",", "force", "=", "False", ")", ":", "# Make lists", "buckets", "=", "bucket", "if", "isinstance", "(", "bucket", ",", "six", ".", "string_types", ")", ":", "buckets", "=", "[", "bucket", ...
ef941dbc12f5d346e9612f8fec1b4b356b8493ca
train
Storage.delete
https://github.com/frictionlessdata/tableschema-pandas-py#storage
tableschema_pandas/storage.py
def delete(self, bucket=None, ignore=False): """https://github.com/frictionlessdata/tableschema-pandas-py#storage """ # Make lists buckets = bucket if isinstance(bucket, six.string_types): buckets = [bucket] elif bucket is None: buckets = reversed...
def delete(self, bucket=None, ignore=False): """https://github.com/frictionlessdata/tableschema-pandas-py#storage """ # Make lists buckets = bucket if isinstance(bucket, six.string_types): buckets = [bucket] elif bucket is None: buckets = reversed...
[ "https", ":", "//", "github", ".", "com", "/", "frictionlessdata", "/", "tableschema", "-", "pandas", "-", "py#storage" ]
frictionlessdata/tableschema-pandas-py
python
https://github.com/frictionlessdata/tableschema-pandas-py/blob/ef941dbc12f5d346e9612f8fec1b4b356b8493ca/tableschema_pandas/storage.py#L73-L100
[ "def", "delete", "(", "self", ",", "bucket", "=", "None", ",", "ignore", "=", "False", ")", ":", "# Make lists", "buckets", "=", "bucket", "if", "isinstance", "(", "bucket", ",", "six", ".", "string_types", ")", ":", "buckets", "=", "[", "bucket", "]",...
ef941dbc12f5d346e9612f8fec1b4b356b8493ca
train
Storage.describe
https://github.com/frictionlessdata/tableschema-pandas-py#storage
tableschema_pandas/storage.py
def describe(self, bucket, descriptor=None): """https://github.com/frictionlessdata/tableschema-pandas-py#storage """ # Set descriptor if descriptor is not None: self.__descriptors[bucket] = descriptor # Get descriptor else: descriptor = self.__d...
def describe(self, bucket, descriptor=None): """https://github.com/frictionlessdata/tableschema-pandas-py#storage """ # Set descriptor if descriptor is not None: self.__descriptors[bucket] = descriptor # Get descriptor else: descriptor = self.__d...
[ "https", ":", "//", "github", ".", "com", "/", "frictionlessdata", "/", "tableschema", "-", "pandas", "-", "py#storage" ]
frictionlessdata/tableschema-pandas-py
python
https://github.com/frictionlessdata/tableschema-pandas-py/blob/ef941dbc12f5d346e9612f8fec1b4b356b8493ca/tableschema_pandas/storage.py#L102-L117
[ "def", "describe", "(", "self", ",", "bucket", ",", "descriptor", "=", "None", ")", ":", "# Set descriptor", "if", "descriptor", "is", "not", "None", ":", "self", ".", "__descriptors", "[", "bucket", "]", "=", "descriptor", "# Get descriptor", "else", ":", ...
ef941dbc12f5d346e9612f8fec1b4b356b8493ca
train
Storage.iter
https://github.com/frictionlessdata/tableschema-pandas-py#storage
tableschema_pandas/storage.py
def iter(self, bucket): """https://github.com/frictionlessdata/tableschema-pandas-py#storage """ # Check existense if bucket not in self.buckets: message = 'Bucket "%s" doesn\'t exist.' % bucket raise tableschema.exceptions.StorageError(message) # Prepar...
def iter(self, bucket): """https://github.com/frictionlessdata/tableschema-pandas-py#storage """ # Check existense if bucket not in self.buckets: message = 'Bucket "%s" doesn\'t exist.' % bucket raise tableschema.exceptions.StorageError(message) # Prepar...
[ "https", ":", "//", "github", ".", "com", "/", "frictionlessdata", "/", "tableschema", "-", "pandas", "-", "py#storage" ]
frictionlessdata/tableschema-pandas-py
python
https://github.com/frictionlessdata/tableschema-pandas-py/blob/ef941dbc12f5d346e9612f8fec1b4b356b8493ca/tableschema_pandas/storage.py#L119-L135
[ "def", "iter", "(", "self", ",", "bucket", ")", ":", "# Check existense", "if", "bucket", "not", "in", "self", ".", "buckets", ":", "message", "=", "'Bucket \"%s\" doesn\\'t exist.'", "%", "bucket", "raise", "tableschema", ".", "exceptions", ".", "StorageError",...
ef941dbc12f5d346e9612f8fec1b4b356b8493ca
train
Storage.write
https://github.com/frictionlessdata/tableschema-pandas-py#storage
tableschema_pandas/storage.py
def write(self, bucket, rows): """https://github.com/frictionlessdata/tableschema-pandas-py#storage """ # Prepare descriptor = self.describe(bucket) new_data_frame = self.__mapper.convert_descriptor_and_rows(descriptor, rows) # Just set new DataFrame if current is empty...
def write(self, bucket, rows): """https://github.com/frictionlessdata/tableschema-pandas-py#storage """ # Prepare descriptor = self.describe(bucket) new_data_frame = self.__mapper.convert_descriptor_and_rows(descriptor, rows) # Just set new DataFrame if current is empty...
[ "https", ":", "//", "github", ".", "com", "/", "frictionlessdata", "/", "tableschema", "-", "pandas", "-", "py#storage" ]
frictionlessdata/tableschema-pandas-py
python
https://github.com/frictionlessdata/tableschema-pandas-py/blob/ef941dbc12f5d346e9612f8fec1b4b356b8493ca/tableschema_pandas/storage.py#L143-L161
[ "def", "write", "(", "self", ",", "bucket", ",", "rows", ")", ":", "# Prepare", "descriptor", "=", "self", ".", "describe", "(", "bucket", ")", "new_data_frame", "=", "self", ".", "__mapper", ".", "convert_descriptor_and_rows", "(", "descriptor", ",", "rows"...
ef941dbc12f5d346e9612f8fec1b4b356b8493ca
train
forwards
Change all Movie objects into Work objects, and their associated data into WorkRole and WorkSelection models, then delete the Movie.
spectator/events/migrations/0030_movies_to_works.py
def forwards(apps, schema_editor): """ Change all Movie objects into Work objects, and their associated data into WorkRole and WorkSelection models, then delete the Movie. """ Movie = apps.get_model('spectator_events', 'Movie') Work = apps.get_model('spectator_events', 'Work') WorkRole = app...
def forwards(apps, schema_editor): """ Change all Movie objects into Work objects, and their associated data into WorkRole and WorkSelection models, then delete the Movie. """ Movie = apps.get_model('spectator_events', 'Movie') Work = apps.get_model('spectator_events', 'Work') WorkRole = app...
[ "Change", "all", "Movie", "objects", "into", "Work", "objects", "and", "their", "associated", "data", "into", "WorkRole", "and", "WorkSelection", "models", "then", "delete", "the", "Movie", "." ]
philgyford/django-spectator
python
https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/events/migrations/0030_movies_to_works.py#L6-L41
[ "def", "forwards", "(", "apps", ",", "schema_editor", ")", ":", "Movie", "=", "apps", ".", "get_model", "(", "'spectator_events'", ",", "'Movie'", ")", "Work", "=", "apps", ".", "get_model", "(", "'spectator_events'", ",", "'Work'", ")", "WorkRole", "=", "...
f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada
train
PaginatedListView.paginate_queryset
Paginate the queryset, if needed. This is EXACTLY the same as the standard ListView.paginate_queryset() except for this line: page = paginator.page(page_number, softlimit=True) Because we want to use the DiggPaginator's softlimit option. So that if you're viewing a page of, ...
spectator/core/views.py
def paginate_queryset(self, queryset, page_size): """ Paginate the queryset, if needed. This is EXACTLY the same as the standard ListView.paginate_queryset() except for this line: page = paginator.page(page_number, softlimit=True) Because we want to use the DiggPagin...
def paginate_queryset(self, queryset, page_size): """ Paginate the queryset, if needed. This is EXACTLY the same as the standard ListView.paginate_queryset() except for this line: page = paginator.page(page_number, softlimit=True) Because we want to use the DiggPagin...
[ "Paginate", "the", "queryset", "if", "needed", "." ]
philgyford/django-spectator
python
https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/core/views.py#L33-L73
[ "def", "paginate_queryset", "(", "self", ",", "queryset", ",", "page_size", ")", ":", "paginator", "=", "self", ".", "get_paginator", "(", "queryset", ",", "page_size", ",", "orphans", "=", "self", ".", "get_paginate_orphans", "(", ")", ",", "allow_empty_first...
f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada
train
annual_reading_counts_card
Displays years and the number of books/periodicals read per year. kind is one of 'book', 'periodical', 'all' (default). current_year is an optional date object representing the year we're already showing information about.
spectator/reading/templatetags/spectator_reading.py
def annual_reading_counts_card(kind='all', current_year=None): """ Displays years and the number of books/periodicals read per year. kind is one of 'book', 'periodical', 'all' (default). current_year is an optional date object representing the year we're already showing information about. "...
def annual_reading_counts_card(kind='all', current_year=None): """ Displays years and the number of books/periodicals read per year. kind is one of 'book', 'periodical', 'all' (default). current_year is an optional date object representing the year we're already showing information about. "...
[ "Displays", "years", "and", "the", "number", "of", "books", "/", "periodicals", "read", "per", "year", "." ]
philgyford/django-spectator
python
https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/reading/templatetags/spectator_reading.py#L33-L53
[ "def", "annual_reading_counts_card", "(", "kind", "=", "'all'", ",", "current_year", "=", "None", ")", ":", "if", "kind", "==", "'book'", ":", "card_title", "=", "'Books per year'", "elif", "kind", "==", "'periodical'", ":", "card_title", "=", "'Periodicals per ...
f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada
train
day_publications
Returns a QuerySet of Publications that were being read on `date`. `date` is a date tobject.
spectator/reading/templatetags/spectator_reading.py
def day_publications(date): """ Returns a QuerySet of Publications that were being read on `date`. `date` is a date tobject. """ readings = Reading.objects \ .filter(start_date__lte=date) \ .filter( Q(end_date__gte=date) ...
def day_publications(date): """ Returns a QuerySet of Publications that were being read on `date`. `date` is a date tobject. """ readings = Reading.objects \ .filter(start_date__lte=date) \ .filter( Q(end_date__gte=date) ...
[ "Returns", "a", "QuerySet", "of", "Publications", "that", "were", "being", "read", "on", "date", ".", "date", "is", "a", "date", "tobject", "." ]
philgyford/django-spectator
python
https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/reading/templatetags/spectator_reading.py#L78-L96
[ "def", "day_publications", "(", "date", ")", ":", "readings", "=", "Reading", ".", "objects", ".", "filter", "(", "start_date__lte", "=", "date", ")", ".", "filter", "(", "Q", "(", "end_date__gte", "=", "date", ")", "|", "Q", "(", "end_date__isnull", "="...
f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada
train
day_publications_card
Displays Publications that were being read on `date`. `date` is a date tobject.
spectator/reading/templatetags/spectator_reading.py
def day_publications_card(date): """ Displays Publications that were being read on `date`. `date` is a date tobject. """ d = date.strftime(app_settings.DATE_FORMAT) card_title = 'Reading on {}'.format(d) return { 'card_title': card_title, 'publication_list': day_publi...
def day_publications_card(date): """ Displays Publications that were being read on `date`. `date` is a date tobject. """ d = date.strftime(app_settings.DATE_FORMAT) card_title = 'Reading on {}'.format(d) return { 'card_title': card_title, 'publication_list': day_publi...
[ "Displays", "Publications", "that", "were", "being", "read", "on", "date", ".", "date", "is", "a", "date", "tobject", "." ]
philgyford/django-spectator
python
https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/reading/templatetags/spectator_reading.py#L100-L110
[ "def", "day_publications_card", "(", "date", ")", ":", "d", "=", "date", ".", "strftime", "(", "app_settings", ".", "DATE_FORMAT", ")", "card_title", "=", "'Reading on {}'", ".", "format", "(", "d", ")", "return", "{", "'card_title'", ":", "card_title", ",",...
f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada
train
reading_dates
Given a Reading, with start and end dates and granularities[1] it returns an HTML string representing that period. eg: * '1–6 Feb 2017' * '1 Feb to 3 Mar 2017' * 'Feb 2017 to Mar 2018' * '2017–2018' etc. [1] https://www.flickr.com/services/api/misc.dates.html
spectator/reading/templatetags/spectator_reading.py
def reading_dates(reading): """ Given a Reading, with start and end dates and granularities[1] it returns an HTML string representing that period. eg: * '1–6 Feb 2017' * '1 Feb to 3 Mar 2017' * 'Feb 2017 to Mar 2018' * '2017–2018' etc. [1] https://www.flickr.com/ser...
def reading_dates(reading): """ Given a Reading, with start and end dates and granularities[1] it returns an HTML string representing that period. eg: * '1–6 Feb 2017' * '1 Feb to 3 Mar 2017' * 'Feb 2017 to Mar 2018' * '2017–2018' etc. [1] https://www.flickr.com/ser...
[ "Given", "a", "Reading", "with", "start", "and", "end", "dates", "and", "granularities", "[", "1", "]", "it", "returns", "an", "HTML", "string", "representing", "that", "period", ".", "eg", ":" ]
philgyford/django-spectator
python
https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/reading/templatetags/spectator_reading.py#L136-L288
[ "def", "reading_dates", "(", "reading", ")", ":", "# 3 September 2017", "full_format", "=", "'<time datetime=\"%Y-%m-%d\">{}</time>'", ".", "format", "(", "'%-d %B %Y'", ")", "# September 2017", "month_year_format", "=", "'<time datetime=\"%Y-%m\">{}</time>'", ".", "format", ...
f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada
train
forwards
Change Events with kind 'movie' to 'cinema' and Events with kind 'play' to 'theatre'. Purely for more consistency.
spectator/events/migrations/0035_change_event_kinds.py
def forwards(apps, schema_editor): """ Change Events with kind 'movie' to 'cinema' and Events with kind 'play' to 'theatre'. Purely for more consistency. """ Event = apps.get_model('spectator_events', 'Event') for ev in Event.objects.filter(kind='movie'): ev.kind = 'cinema' ...
def forwards(apps, schema_editor): """ Change Events with kind 'movie' to 'cinema' and Events with kind 'play' to 'theatre'. Purely for more consistency. """ Event = apps.get_model('spectator_events', 'Event') for ev in Event.objects.filter(kind='movie'): ev.kind = 'cinema' ...
[ "Change", "Events", "with", "kind", "movie", "to", "cinema", "and", "Events", "with", "kind", "play", "to", "theatre", "." ]
philgyford/django-spectator
python
https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/events/migrations/0035_change_event_kinds.py#L6-L21
[ "def", "forwards", "(", "apps", ",", "schema_editor", ")", ":", "Event", "=", "apps", ".", "get_model", "(", "'spectator_events'", ",", "'Event'", ")", "for", "ev", "in", "Event", ".", "objects", ".", "filter", "(", "kind", "=", "'movie'", ")", ":", "e...
f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada
train
get_env_variable
Get the environment variable or return exception.
devproject/devproject/settings.py
def get_env_variable(var_name, default=None): """Get the environment variable or return exception.""" try: return os.environ[var_name] except KeyError: if default is None: error_msg = "Set the %s environment variable" % var_name raise ImproperlyConfigured(error_msg) ...
def get_env_variable(var_name, default=None): """Get the environment variable or return exception.""" try: return os.environ[var_name] except KeyError: if default is None: error_msg = "Set the %s environment variable" % var_name raise ImproperlyConfigured(error_msg) ...
[ "Get", "the", "environment", "variable", "or", "return", "exception", "." ]
philgyford/django-spectator
python
https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/devproject/devproject/settings.py#L21-L30
[ "def", "get_env_variable", "(", "var_name", ",", "default", "=", "None", ")", ":", "try", ":", "return", "os", ".", "environ", "[", "var_name", "]", "except", "KeyError", ":", "if", "default", "is", "None", ":", "error_msg", "=", "\"Set the %s environment va...
f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada
train
generate_slug
Generates a slug using a Hashid of `value`. COPIED from spectator.core.models.SluggedModelMixin() because migrations don't make this happen automatically and perhaps the least bad thing is to copy the method here, ugh.
spectator/events/migrations/0039_populate_exhibitions.py
def generate_slug(value): """ Generates a slug using a Hashid of `value`. COPIED from spectator.core.models.SluggedModelMixin() because migrations don't make this happen automatically and perhaps the least bad thing is to copy the method here, ugh. """ alphabet = app_settings.SLUG_ALPHABET ...
def generate_slug(value): """ Generates a slug using a Hashid of `value`. COPIED from spectator.core.models.SluggedModelMixin() because migrations don't make this happen automatically and perhaps the least bad thing is to copy the method here, ugh. """ alphabet = app_settings.SLUG_ALPHABET ...
[ "Generates", "a", "slug", "using", "a", "Hashid", "of", "value", "." ]
philgyford/django-spectator
python
https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/events/migrations/0039_populate_exhibitions.py#L11-L24
[ "def", "generate_slug", "(", "value", ")", ":", "alphabet", "=", "app_settings", ".", "SLUG_ALPHABET", "salt", "=", "app_settings", ".", "SLUG_SALT", "hashids", "=", "Hashids", "(", "alphabet", "=", "alphabet", ",", "salt", "=", "salt", ",", "min_length", "=...
f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada
train
forwards
Having added the new 'exhibition' Work type, we're going to assume that every Event of type 'museum' should actually have one Exhibition attached. So, we'll add one, with the same title as the Event. And we'll move all Creators from the Event to the Exhibition.
spectator/events/migrations/0039_populate_exhibitions.py
def forwards(apps, schema_editor): """ Having added the new 'exhibition' Work type, we're going to assume that every Event of type 'museum' should actually have one Exhibition attached. So, we'll add one, with the same title as the Event. And we'll move all Creators from the Event to the Exhibition...
def forwards(apps, schema_editor): """ Having added the new 'exhibition' Work type, we're going to assume that every Event of type 'museum' should actually have one Exhibition attached. So, we'll add one, with the same title as the Event. And we'll move all Creators from the Event to the Exhibition...
[ "Having", "added", "the", "new", "exhibition", "Work", "type", "we", "re", "going", "to", "assume", "that", "every", "Event", "of", "type", "museum", "should", "actually", "have", "one", "Exhibition", "attached", "." ]
philgyford/django-spectator
python
https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/events/migrations/0039_populate_exhibitions.py#L27-L70
[ "def", "forwards", "(", "apps", ",", "schema_editor", ")", ":", "Event", "=", "apps", ".", "get_model", "(", "'spectator_events'", ",", "'Event'", ")", "Work", "=", "apps", ".", "get_model", "(", "'spectator_events'", ",", "'Work'", ")", "WorkRole", "=", "...
f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada
train
CreatorManager.by_publications
The Creators who have been most-read, ordered by number of read publications (ignoring if any of those publicatinos have been read multiple times.) Each Creator will have a `num_publications` attribute.
spectator/core/managers.py
def by_publications(self): """ The Creators who have been most-read, ordered by number of read publications (ignoring if any of those publicatinos have been read multiple times.) Each Creator will have a `num_publications` attribute. """ if not spectator_apps.is_...
def by_publications(self): """ The Creators who have been most-read, ordered by number of read publications (ignoring if any of those publicatinos have been read multiple times.) Each Creator will have a `num_publications` attribute. """ if not spectator_apps.is_...
[ "The", "Creators", "who", "have", "been", "most", "-", "read", "ordered", "by", "number", "of", "read", "publications", "(", "ignoring", "if", "any", "of", "those", "publicatinos", "have", "been", "read", "multiple", "times", ".", ")" ]
philgyford/django-spectator
python
https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/core/managers.py#L10-L27
[ "def", "by_publications", "(", "self", ")", ":", "if", "not", "spectator_apps", ".", "is_enabled", "(", "'reading'", ")", ":", "raise", "ImproperlyConfigured", "(", "\"To use the CreatorManager.by_publications() method, 'spectator.reading' must by in INSTALLED_APPS.\"", ")", ...
f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada
train
CreatorManager.by_readings
The Creators who have been most-read, ordered by number of readings. By default it will only include Creators whose role was left empty, or is 'Author'. Each Creator will have a `num_readings` attribute.
spectator/core/managers.py
def by_readings(self, role_names=['', 'Author']): """ The Creators who have been most-read, ordered by number of readings. By default it will only include Creators whose role was left empty, or is 'Author'. Each Creator will have a `num_readings` attribute. """ ...
def by_readings(self, role_names=['', 'Author']): """ The Creators who have been most-read, ordered by number of readings. By default it will only include Creators whose role was left empty, or is 'Author'. Each Creator will have a `num_readings` attribute. """ ...
[ "The", "Creators", "who", "have", "been", "most", "-", "read", "ordered", "by", "number", "of", "readings", "." ]
philgyford/django-spectator
python
https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/core/managers.py#L29-L48
[ "def", "by_readings", "(", "self", ",", "role_names", "=", "[", "''", ",", "'Author'", "]", ")", ":", "if", "not", "spectator_apps", ".", "is_enabled", "(", "'reading'", ")", ":", "raise", "ImproperlyConfigured", "(", "\"To use the CreatorManager.by_readings() met...
f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada
train
CreatorManager.by_events
Get the Creators involved in the most Events. This only counts Creators directly involved in an Event. i.e. if a Creator is the director of a movie Work, and an Event was a viewing of that movie, that Event wouldn't count. Unless they were also directly involved in the Event (e.g. speak...
spectator/core/managers.py
def by_events(self, kind=None): """ Get the Creators involved in the most Events. This only counts Creators directly involved in an Event. i.e. if a Creator is the director of a movie Work, and an Event was a viewing of that movie, that Event wouldn't count. Unless they were ...
def by_events(self, kind=None): """ Get the Creators involved in the most Events. This only counts Creators directly involved in an Event. i.e. if a Creator is the director of a movie Work, and an Event was a viewing of that movie, that Event wouldn't count. Unless they were ...
[ "Get", "the", "Creators", "involved", "in", "the", "most", "Events", "." ]
philgyford/django-spectator
python
https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/core/managers.py#L50-L72
[ "def", "by_events", "(", "self", ",", "kind", "=", "None", ")", ":", "if", "not", "spectator_apps", ".", "is_enabled", "(", "'events'", ")", ":", "raise", "ImproperlyConfigured", "(", "\"To use the CreatorManager.by_events() method, 'spectator.events' must by in INSTALLED...
f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada
train
CreatorManager.by_works
Get the Creators involved in the most Works. kind - If supplied, only Works with that `kind` value will be counted. role_name - If supplied, only Works on which the role is that will be counted. e.g. To get all 'movie' Works on which the Creators had the role 'Director': Creator.o...
spectator/core/managers.py
def by_works(self, kind=None, role_name=None): """ Get the Creators involved in the most Works. kind - If supplied, only Works with that `kind` value will be counted. role_name - If supplied, only Works on which the role is that will be counted. e.g. To get all 'movie' Works on...
def by_works(self, kind=None, role_name=None): """ Get the Creators involved in the most Works. kind - If supplied, only Works with that `kind` value will be counted. role_name - If supplied, only Works on which the role is that will be counted. e.g. To get all 'movie' Works on...
[ "Get", "the", "Creators", "involved", "in", "the", "most", "Works", "." ]
philgyford/django-spectator
python
https://github.com/philgyford/django-spectator/blob/f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada/spectator/core/managers.py#L74-L104
[ "def", "by_works", "(", "self", ",", "kind", "=", "None", ",", "role_name", "=", "None", ")", ":", "if", "not", "spectator_apps", ".", "is_enabled", "(", "'events'", ")", ":", "raise", "ImproperlyConfigured", "(", "\"To use the CreatorManager.by_works() method, 's...
f3c72004f9caa1fde0f5a3b2f0d2bf285fc01ada
train
index
Query Elasticsearch using Invenio query syntax.
examples/app.py
def index(): """Query Elasticsearch using Invenio query syntax.""" page = request.values.get('page', 1, type=int) size = request.values.get('size', 2, type=int) search = ExampleSearch()[(page - 1) * size:page * size] if 'q' in request.values: search = search.query(QueryString(query=request.v...
def index(): """Query Elasticsearch using Invenio query syntax.""" page = request.values.get('page', 1, type=int) size = request.values.get('size', 2, type=int) search = ExampleSearch()[(page - 1) * size:page * size] if 'q' in request.values: search = search.query(QueryString(query=request.v...
[ "Query", "Elasticsearch", "using", "Invenio", "query", "syntax", "." ]
inveniosoftware/invenio-search
python
https://github.com/inveniosoftware/invenio-search/blob/19c073d608d4c811f1c5aecb6622402d39715228/examples/app.py#L106-L119
[ "def", "index", "(", ")", ":", "page", "=", "request", ".", "values", ".", "get", "(", "'page'", ",", "1", ",", "type", "=", "int", ")", "size", "=", "request", ".", "values", ".", "get", "(", "'size'", ",", "2", ",", "type", "=", "int", ")", ...
19c073d608d4c811f1c5aecb6622402d39715228
train
krbContext.clean_options
Clean argument to related object :param bool using_keytab: refer to ``krbContext.__init__``. :param str principal: refer to ``krbContext.__init__``. :param str keytab_file: refer to ``krbContext.__init__``. :param str ccache_file: refer to ``krbContext.__init__``. :param str pas...
krbcontext/context.py
def clean_options(self, using_keytab=False, principal=None, keytab_file=None, ccache_file=None, password=None): """Clean argument to related object :param bool using_keytab: refer to ``krbContext.__init__``. :param str principal:...
def clean_options(self, using_keytab=False, principal=None, keytab_file=None, ccache_file=None, password=None): """Clean argument to related object :param bool using_keytab: refer to ``krbContext.__init__``. :param str principal:...
[ "Clean", "argument", "to", "related", "object" ]
krbcontext/python-krbcontext
python
https://github.com/krbcontext/python-krbcontext/blob/9dc93765a4723fa04c2ca57125294d422a6356cd/krbcontext/context.py#L104-L148
[ "def", "clean_options", "(", "self", ",", "using_keytab", "=", "False", ",", "principal", "=", "None", ",", "keytab_file", "=", "None", ",", "ccache_file", "=", "None", ",", "password", "=", "None", ")", ":", "cleaned", "=", "{", "}", "if", "using_keytab...
9dc93765a4723fa04c2ca57125294d422a6356cd