repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1
value | code stringlengths 75 19.8k | code_tokens list | docstring stringlengths 3 17.3k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 87 242 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
ellmetha/django-machina | machina/templatetags/forum_tracking_tags.py | get_unread_topics | def get_unread_topics(context, topics, user):
""" This will return a list of unread topics for the given user from a given set of topics.
Usage::
{% get_unread_topics topics request.user as unread_topics %}
"""
request = context.get('request', None)
return TrackingHandler(request=request)... | python | def get_unread_topics(context, topics, user):
""" This will return a list of unread topics for the given user from a given set of topics.
Usage::
{% get_unread_topics topics request.user as unread_topics %}
"""
request = context.get('request', None)
return TrackingHandler(request=request)... | [
"def",
"get_unread_topics",
"(",
"context",
",",
"topics",
",",
"user",
")",
":",
"request",
"=",
"context",
".",
"get",
"(",
"'request'",
",",
"None",
")",
"return",
"TrackingHandler",
"(",
"request",
"=",
"request",
")",
".",
"get_unread_topics",
"(",
"t... | This will return a list of unread topics for the given user from a given set of topics.
Usage::
{% get_unread_topics topics request.user as unread_topics %} | [
"This",
"will",
"return",
"a",
"list",
"of",
"unread",
"topics",
"for",
"the",
"given",
"user",
"from",
"a",
"given",
"set",
"of",
"topics",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/templatetags/forum_tracking_tags.py#L12-L21 | train |
ellmetha/django-machina | machina/models/fields.py | ExtendedImageField.resize_image | def resize_image(self, data, size):
""" Resizes the given image to fit inside a box of the given size. """
from machina.core.compat import PILImage as Image
image = Image.open(BytesIO(data))
# Resize!
image.thumbnail(size, Image.ANTIALIAS)
string = BytesIO()
ima... | python | def resize_image(self, data, size):
""" Resizes the given image to fit inside a box of the given size. """
from machina.core.compat import PILImage as Image
image = Image.open(BytesIO(data))
# Resize!
image.thumbnail(size, Image.ANTIALIAS)
string = BytesIO()
ima... | [
"def",
"resize_image",
"(",
"self",
",",
"data",
",",
"size",
")",
":",
"from",
"machina",
".",
"core",
".",
"compat",
"import",
"PILImage",
"as",
"Image",
"image",
"=",
"Image",
".",
"open",
"(",
"BytesIO",
"(",
"data",
")",
")",
"image",
".",
"thum... | Resizes the given image to fit inside a box of the given size. | [
"Resizes",
"the",
"given",
"image",
"to",
"fit",
"inside",
"a",
"box",
"of",
"the",
"given",
"size",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/models/fields.py#L260-L270 | train |
ellmetha/django-machina | machina/apps/forum_conversation/forum_attachments/cache.py | AttachmentCache.get_backend | def get_backend(self):
""" Returns the associated cache backend. """
try:
cache = caches[machina_settings.ATTACHMENT_CACHE_NAME]
except InvalidCacheBackendError:
raise ImproperlyConfigured(
'The attachment cache backend ({}) is not configured'.format(
... | python | def get_backend(self):
""" Returns the associated cache backend. """
try:
cache = caches[machina_settings.ATTACHMENT_CACHE_NAME]
except InvalidCacheBackendError:
raise ImproperlyConfigured(
'The attachment cache backend ({}) is not configured'.format(
... | [
"def",
"get_backend",
"(",
"self",
")",
":",
"try",
":",
"cache",
"=",
"caches",
"[",
"machina_settings",
".",
"ATTACHMENT_CACHE_NAME",
"]",
"except",
"InvalidCacheBackendError",
":",
"raise",
"ImproperlyConfigured",
"(",
"'The attachment cache backend ({}) is not configu... | Returns the associated cache backend. | [
"Returns",
"the",
"associated",
"cache",
"backend",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_conversation/forum_attachments/cache.py#L33-L43 | train |
ellmetha/django-machina | machina/apps/forum_conversation/forum_attachments/cache.py | AttachmentCache.set | def set(self, key, files):
""" Stores the state of each file embedded in the request.FILES MultiValueDict instance.
This instance is assumed to be passed as the 'files' argument. Each state stored in the
cache is a dictionary containing the following values:
name
Th... | python | def set(self, key, files):
""" Stores the state of each file embedded in the request.FILES MultiValueDict instance.
This instance is assumed to be passed as the 'files' argument. Each state stored in the
cache is a dictionary containing the following values:
name
Th... | [
"def",
"set",
"(",
"self",
",",
"key",
",",
"files",
")",
":",
"files_states",
"=",
"{",
"}",
"for",
"name",
",",
"upload",
"in",
"files",
".",
"items",
"(",
")",
":",
"state",
"=",
"{",
"'name'",
":",
"upload",
".",
"name",
",",
"'size'",
":",
... | Stores the state of each file embedded in the request.FILES MultiValueDict instance.
This instance is assumed to be passed as the 'files' argument. Each state stored in the
cache is a dictionary containing the following values:
name
The name of the uploaded file.
... | [
"Stores",
"the",
"state",
"of",
"each",
"file",
"embedded",
"in",
"the",
"request",
".",
"FILES",
"MultiValueDict",
"instance",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_conversation/forum_attachments/cache.py#L45-L80 | train |
ellmetha/django-machina | machina/apps/forum_conversation/forum_attachments/cache.py | AttachmentCache.get | def get(self, key):
""" Regenerates a MultiValueDict instance containing the files related to all file states
stored for the given key.
"""
upload = None
files_states = self.backend.get(key)
files = MultiValueDict()
if files_states:
for name, state... | python | def get(self, key):
""" Regenerates a MultiValueDict instance containing the files related to all file states
stored for the given key.
"""
upload = None
files_states = self.backend.get(key)
files = MultiValueDict()
if files_states:
for name, state... | [
"def",
"get",
"(",
"self",
",",
"key",
")",
":",
"upload",
"=",
"None",
"files_states",
"=",
"self",
".",
"backend",
".",
"get",
"(",
"key",
")",
"files",
"=",
"MultiValueDict",
"(",
")",
"if",
"files_states",
":",
"for",
"name",
",",
"state",
"in",
... | Regenerates a MultiValueDict instance containing the files related to all file states
stored for the given key. | [
"Regenerates",
"a",
"MultiValueDict",
"instance",
"containing",
"the",
"files",
"related",
"to",
"all",
"file",
"states",
"stored",
"for",
"the",
"given",
"key",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_conversation/forum_attachments/cache.py#L82-L120 | train |
ellmetha/django-machina | machina/apps/forum_permission/handler.py | PermissionHandler.get_readable_forums | def get_readable_forums(self, forums, user):
""" Returns a queryset of forums that can be read by the considered user. """
# Any superuser should be able to read all the forums.
if user.is_superuser:
return forums
# Fetches the forums that can be read by the given user.
... | python | def get_readable_forums(self, forums, user):
""" Returns a queryset of forums that can be read by the considered user. """
# Any superuser should be able to read all the forums.
if user.is_superuser:
return forums
# Fetches the forums that can be read by the given user.
... | [
"def",
"get_readable_forums",
"(",
"self",
",",
"forums",
",",
"user",
")",
":",
"if",
"user",
".",
"is_superuser",
":",
"return",
"forums",
"readable_forums",
"=",
"self",
".",
"_get_forums_for_user",
"(",
"user",
",",
"[",
"'can_read_forum'",
",",
"]",
","... | Returns a queryset of forums that can be read by the considered user. | [
"Returns",
"a",
"queryset",
"of",
"forums",
"that",
"can",
"be",
"read",
"by",
"the",
"considered",
"user",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_permission/handler.py#L74-L85 | train |
ellmetha/django-machina | machina/apps/forum_permission/handler.py | PermissionHandler.can_add_post | def can_add_post(self, topic, user):
""" Given a topic, checks whether the user can append posts to it. """
can_add_post = self._perform_basic_permission_check(
topic.forum, user, 'can_reply_to_topics',
)
can_add_post &= (
not topic.is_locked or
self._... | python | def can_add_post(self, topic, user):
""" Given a topic, checks whether the user can append posts to it. """
can_add_post = self._perform_basic_permission_check(
topic.forum, user, 'can_reply_to_topics',
)
can_add_post &= (
not topic.is_locked or
self._... | [
"def",
"can_add_post",
"(",
"self",
",",
"topic",
",",
"user",
")",
":",
"can_add_post",
"=",
"self",
".",
"_perform_basic_permission_check",
"(",
"topic",
".",
"forum",
",",
"user",
",",
"'can_reply_to_topics'",
",",
")",
"can_add_post",
"&=",
"(",
"not",
"... | Given a topic, checks whether the user can append posts to it. | [
"Given",
"a",
"topic",
"checks",
"whether",
"the",
"user",
"can",
"append",
"posts",
"to",
"it",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_permission/handler.py#L114-L123 | train |
ellmetha/django-machina | machina/apps/forum_permission/handler.py | PermissionHandler.can_edit_post | def can_edit_post(self, post, user):
""" Given a forum post, checks whether the user can edit the latter. """
checker = self._get_checker(user)
# A user can edit a post if...
# they are a superuser
# they are the original poster of the forum post
# they belon... | python | def can_edit_post(self, post, user):
""" Given a forum post, checks whether the user can edit the latter. """
checker = self._get_checker(user)
# A user can edit a post if...
# they are a superuser
# they are the original poster of the forum post
# they belon... | [
"def",
"can_edit_post",
"(",
"self",
",",
"post",
",",
"user",
")",
":",
"checker",
"=",
"self",
".",
"_get_checker",
"(",
"user",
")",
"is_author",
"=",
"self",
".",
"_is_post_author",
"(",
"post",
",",
"user",
")",
"can_edit",
"=",
"(",
"user",
".",
... | Given a forum post, checks whether the user can edit the latter. | [
"Given",
"a",
"forum",
"post",
"checks",
"whether",
"the",
"user",
"can",
"edit",
"the",
"latter",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_permission/handler.py#L125-L142 | train |
ellmetha/django-machina | machina/apps/forum_permission/handler.py | PermissionHandler.can_delete_post | def can_delete_post(self, post, user):
"""
Given a forum post, checks whether the user can delete the latter.
"""
checker = self._get_checker(user)
# A user can delete a post if...
# they are a superuser
# they are the original poster of the forum post
... | python | def can_delete_post(self, post, user):
"""
Given a forum post, checks whether the user can delete the latter.
"""
checker = self._get_checker(user)
# A user can delete a post if...
# they are a superuser
# they are the original poster of the forum post
... | [
"def",
"can_delete_post",
"(",
"self",
",",
"post",
",",
"user",
")",
":",
"checker",
"=",
"self",
".",
"_get_checker",
"(",
"user",
")",
"is_author",
"=",
"self",
".",
"_is_post_author",
"(",
"post",
",",
"user",
")",
"can_delete",
"=",
"(",
"user",
"... | Given a forum post, checks whether the user can delete the latter. | [
"Given",
"a",
"forum",
"post",
"checks",
"whether",
"the",
"user",
"can",
"delete",
"the",
"latter",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_permission/handler.py#L144-L160 | train |
ellmetha/django-machina | machina/apps/forum_permission/handler.py | PermissionHandler.can_vote_in_poll | def can_vote_in_poll(self, poll, user):
""" Given a poll, checks whether the user can answer to it. """
# First we have to check if the poll is curently open
if poll.duration:
poll_dtend = poll.created + dt.timedelta(days=poll.duration)
if poll_dtend < now():
... | python | def can_vote_in_poll(self, poll, user):
""" Given a poll, checks whether the user can answer to it. """
# First we have to check if the poll is curently open
if poll.duration:
poll_dtend = poll.created + dt.timedelta(days=poll.duration)
if poll_dtend < now():
... | [
"def",
"can_vote_in_poll",
"(",
"self",
",",
"poll",
",",
"user",
")",
":",
"if",
"poll",
".",
"duration",
":",
"poll_dtend",
"=",
"poll",
".",
"created",
"+",
"dt",
".",
"timedelta",
"(",
"days",
"=",
"poll",
".",
"duration",
")",
"if",
"poll_dtend",
... | Given a poll, checks whether the user can answer to it. | [
"Given",
"a",
"poll",
"checks",
"whether",
"the",
"user",
"can",
"answer",
"to",
"it",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_permission/handler.py#L168-L200 | train |
ellmetha/django-machina | machina/apps/forum_permission/handler.py | PermissionHandler.can_subscribe_to_topic | def can_subscribe_to_topic(self, topic, user):
""" Given a topic, checks whether the user can add it to their subscription list. """
# A user can subscribe to topics if they are authenticated and if they have the permission
# to read the related forum. Of course a user can subscribe only if they... | python | def can_subscribe_to_topic(self, topic, user):
""" Given a topic, checks whether the user can add it to their subscription list. """
# A user can subscribe to topics if they are authenticated and if they have the permission
# to read the related forum. Of course a user can subscribe only if they... | [
"def",
"can_subscribe_to_topic",
"(",
"self",
",",
"topic",
",",
"user",
")",
":",
"return",
"(",
"user",
".",
"is_authenticated",
"and",
"not",
"topic",
".",
"has_subscriber",
"(",
"user",
")",
"and",
"self",
".",
"_perform_basic_permission_check",
"(",
"topi... | Given a topic, checks whether the user can add it to their subscription list. | [
"Given",
"a",
"topic",
"checks",
"whether",
"the",
"user",
"can",
"add",
"it",
"to",
"their",
"subscription",
"list",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_permission/handler.py#L214-L223 | train |
ellmetha/django-machina | machina/apps/forum_permission/handler.py | PermissionHandler.can_unsubscribe_from_topic | def can_unsubscribe_from_topic(self, topic, user):
""" Given a topic, checks whether the user can remove it from their subscription list. """
# A user can unsubscribe from topics if they are authenticated and if they have the
# permission to read the related forum. Of course a user can unsubscri... | python | def can_unsubscribe_from_topic(self, topic, user):
""" Given a topic, checks whether the user can remove it from their subscription list. """
# A user can unsubscribe from topics if they are authenticated and if they have the
# permission to read the related forum. Of course a user can unsubscri... | [
"def",
"can_unsubscribe_from_topic",
"(",
"self",
",",
"topic",
",",
"user",
")",
":",
"return",
"(",
"user",
".",
"is_authenticated",
"and",
"topic",
".",
"has_subscriber",
"(",
"user",
")",
"and",
"self",
".",
"_perform_basic_permission_check",
"(",
"topic",
... | Given a topic, checks whether the user can remove it from their subscription list. | [
"Given",
"a",
"topic",
"checks",
"whether",
"the",
"user",
"can",
"remove",
"it",
"from",
"their",
"subscription",
"list",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_permission/handler.py#L225-L234 | train |
ellmetha/django-machina | machina/apps/forum_permission/handler.py | PermissionHandler.get_target_forums_for_moved_topics | def get_target_forums_for_moved_topics(self, user):
""" Returns a list of forums in which the considered user can add topics that have been
moved from another forum.
"""
return [f for f in self._get_forums_for_user(user, ['can_move_topics', ]) if f.is_forum] | python | def get_target_forums_for_moved_topics(self, user):
""" Returns a list of forums in which the considered user can add topics that have been
moved from another forum.
"""
return [f for f in self._get_forums_for_user(user, ['can_move_topics', ]) if f.is_forum] | [
"def",
"get_target_forums_for_moved_topics",
"(",
"self",
",",
"user",
")",
":",
"return",
"[",
"f",
"for",
"f",
"in",
"self",
".",
"_get_forums_for_user",
"(",
"user",
",",
"[",
"'can_move_topics'",
",",
"]",
")",
"if",
"f",
".",
"is_forum",
"]"
] | Returns a list of forums in which the considered user can add topics that have been
moved from another forum. | [
"Returns",
"a",
"list",
"of",
"forums",
"in",
"which",
"the",
"considered",
"user",
"can",
"add",
"topics",
"that",
"have",
"been",
"moved",
"from",
"another",
"forum",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_permission/handler.py#L254-L258 | train |
ellmetha/django-machina | machina/apps/forum_permission/handler.py | PermissionHandler.can_update_topics_to_sticky_topics | def can_update_topics_to_sticky_topics(self, forum, user):
""" Given a forum, checks whether the user can change its topic types to sticky topics. """
return (
self._perform_basic_permission_check(forum, user, 'can_edit_posts') and
self._perform_basic_permission_check(forum, user... | python | def can_update_topics_to_sticky_topics(self, forum, user):
""" Given a forum, checks whether the user can change its topic types to sticky topics. """
return (
self._perform_basic_permission_check(forum, user, 'can_edit_posts') and
self._perform_basic_permission_check(forum, user... | [
"def",
"can_update_topics_to_sticky_topics",
"(",
"self",
",",
"forum",
",",
"user",
")",
":",
"return",
"(",
"self",
".",
"_perform_basic_permission_check",
"(",
"forum",
",",
"user",
",",
"'can_edit_posts'",
")",
"and",
"self",
".",
"_perform_basic_permission_chec... | Given a forum, checks whether the user can change its topic types to sticky topics. | [
"Given",
"a",
"forum",
"checks",
"whether",
"the",
"user",
"can",
"change",
"its",
"topic",
"types",
"to",
"sticky",
"topics",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_permission/handler.py#L273-L278 | train |
ellmetha/django-machina | machina/apps/forum_permission/handler.py | PermissionHandler.can_update_topics_to_announces | def can_update_topics_to_announces(self, forum, user):
""" Given a forum, checks whether the user can change its topic types to announces. """
return (
self._perform_basic_permission_check(forum, user, 'can_edit_posts') and
self._perform_basic_permission_check(forum, user, 'can_p... | python | def can_update_topics_to_announces(self, forum, user):
""" Given a forum, checks whether the user can change its topic types to announces. """
return (
self._perform_basic_permission_check(forum, user, 'can_edit_posts') and
self._perform_basic_permission_check(forum, user, 'can_p... | [
"def",
"can_update_topics_to_announces",
"(",
"self",
",",
"forum",
",",
"user",
")",
":",
"return",
"(",
"self",
".",
"_perform_basic_permission_check",
"(",
"forum",
",",
"user",
",",
"'can_edit_posts'",
")",
"and",
"self",
".",
"_perform_basic_permission_check",
... | Given a forum, checks whether the user can change its topic types to announces. | [
"Given",
"a",
"forum",
"checks",
"whether",
"the",
"user",
"can",
"change",
"its",
"topic",
"types",
"to",
"announces",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_permission/handler.py#L280-L285 | train |
ellmetha/django-machina | machina/apps/forum_permission/handler.py | PermissionHandler._get_hidden_forum_ids | def _get_hidden_forum_ids(self, forums, user):
""" Given a set of forums and a user, returns the list of forums that are not visible by
this user.
"""
visible_forums = self._get_forums_for_user(
user, ['can_see_forum', 'can_read_forum', ], use_tree_hierarchy=True,
... | python | def _get_hidden_forum_ids(self, forums, user):
""" Given a set of forums and a user, returns the list of forums that are not visible by
this user.
"""
visible_forums = self._get_forums_for_user(
user, ['can_see_forum', 'can_read_forum', ], use_tree_hierarchy=True,
... | [
"def",
"_get_hidden_forum_ids",
"(",
"self",
",",
"forums",
",",
"user",
")",
":",
"visible_forums",
"=",
"self",
".",
"_get_forums_for_user",
"(",
"user",
",",
"[",
"'can_see_forum'",
",",
"'can_read_forum'",
",",
"]",
",",
"use_tree_hierarchy",
"=",
"True",
... | Given a set of forums and a user, returns the list of forums that are not visible by
this user. | [
"Given",
"a",
"set",
"of",
"forums",
"and",
"a",
"user",
"returns",
"the",
"list",
"of",
"forums",
"that",
"are",
"not",
"visible",
"by",
"this",
"user",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_permission/handler.py#L303-L310 | train |
ellmetha/django-machina | machina/apps/forum_permission/handler.py | PermissionHandler._perform_basic_permission_check | def _perform_basic_permission_check(self, forum, user, permission):
""" Given a forum and a user, checks whether the latter has the passed permission.
The workflow is:
1. The permission is granted if the user is a superuser
2. If not, a check is performed with the given permiss... | python | def _perform_basic_permission_check(self, forum, user, permission):
""" Given a forum and a user, checks whether the latter has the passed permission.
The workflow is:
1. The permission is granted if the user is a superuser
2. If not, a check is performed with the given permiss... | [
"def",
"_perform_basic_permission_check",
"(",
"self",
",",
"forum",
",",
"user",
",",
"permission",
")",
":",
"checker",
"=",
"self",
".",
"_get_checker",
"(",
"user",
")",
"check",
"=",
"(",
"user",
".",
"is_superuser",
"or",
"checker",
".",
"has_perm",
... | Given a forum and a user, checks whether the latter has the passed permission.
The workflow is:
1. The permission is granted if the user is a superuser
2. If not, a check is performed with the given permission | [
"Given",
"a",
"forum",
"and",
"a",
"user",
"checks",
"whether",
"the",
"latter",
"has",
"the",
"passed",
"permission",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_permission/handler.py#L480-L495 | train |
ellmetha/django-machina | machina/apps/forum_permission/handler.py | PermissionHandler._get_checker | def _get_checker(self, user):
""" Return a ForumPermissionChecker instance for the given user. """
user_perm_checkers_cache_key = user.id if not user.is_anonymous else 'anonymous'
if user_perm_checkers_cache_key in self._user_perm_checkers_cache:
return self._user_perm_checkers_cach... | python | def _get_checker(self, user):
""" Return a ForumPermissionChecker instance for the given user. """
user_perm_checkers_cache_key = user.id if not user.is_anonymous else 'anonymous'
if user_perm_checkers_cache_key in self._user_perm_checkers_cache:
return self._user_perm_checkers_cach... | [
"def",
"_get_checker",
"(",
"self",
",",
"user",
")",
":",
"user_perm_checkers_cache_key",
"=",
"user",
".",
"id",
"if",
"not",
"user",
".",
"is_anonymous",
"else",
"'anonymous'",
"if",
"user_perm_checkers_cache_key",
"in",
"self",
".",
"_user_perm_checkers_cache",
... | Return a ForumPermissionChecker instance for the given user. | [
"Return",
"a",
"ForumPermissionChecker",
"instance",
"for",
"the",
"given",
"user",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_permission/handler.py#L497-L506 | train |
ellmetha/django-machina | machina/apps/forum_permission/handler.py | PermissionHandler._get_all_forums | def _get_all_forums(self):
""" Returns all forums. """
if not hasattr(self, '_all_forums'):
self._all_forums = list(Forum.objects.all())
return self._all_forums | python | def _get_all_forums(self):
""" Returns all forums. """
if not hasattr(self, '_all_forums'):
self._all_forums = list(Forum.objects.all())
return self._all_forums | [
"def",
"_get_all_forums",
"(",
"self",
")",
":",
"if",
"not",
"hasattr",
"(",
"self",
",",
"'_all_forums'",
")",
":",
"self",
".",
"_all_forums",
"=",
"list",
"(",
"Forum",
".",
"objects",
".",
"all",
"(",
")",
")",
"return",
"self",
".",
"_all_forums"... | Returns all forums. | [
"Returns",
"all",
"forums",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_permission/handler.py#L508-L512 | train |
ellmetha/django-machina | machina/apps/forum/views.py | ForumView.get_forum | def get_forum(self):
""" Returns the forum to consider. """
if not hasattr(self, 'forum'):
self.forum = get_object_or_404(Forum, pk=self.kwargs['pk'])
return self.forum | python | def get_forum(self):
""" Returns the forum to consider. """
if not hasattr(self, 'forum'):
self.forum = get_object_or_404(Forum, pk=self.kwargs['pk'])
return self.forum | [
"def",
"get_forum",
"(",
"self",
")",
":",
"if",
"not",
"hasattr",
"(",
"self",
",",
"'forum'",
")",
":",
"self",
".",
"forum",
"=",
"get_object_or_404",
"(",
"Forum",
",",
"pk",
"=",
"self",
".",
"kwargs",
"[",
"'pk'",
"]",
")",
"return",
"self",
... | Returns the forum to consider. | [
"Returns",
"the",
"forum",
"to",
"consider",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum/views.py#L74-L78 | train |
ellmetha/django-machina | machina/apps/forum/views.py | ForumView.send_signal | def send_signal(self, request, response, forum):
""" Sends the signal associated with the view. """
self.view_signal.send(
sender=self, forum=forum, user=request.user, request=request, response=response,
) | python | def send_signal(self, request, response, forum):
""" Sends the signal associated with the view. """
self.view_signal.send(
sender=self, forum=forum, user=request.user, request=request, response=response,
) | [
"def",
"send_signal",
"(",
"self",
",",
"request",
",",
"response",
",",
"forum",
")",
":",
"self",
".",
"view_signal",
".",
"send",
"(",
"sender",
"=",
"self",
",",
"forum",
"=",
"forum",
",",
"user",
"=",
"request",
".",
"user",
",",
"request",
"="... | Sends the signal associated with the view. | [
"Sends",
"the",
"signal",
"associated",
"with",
"the",
"view",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum/views.py#L123-L127 | train |
ellmetha/django-machina | machina/apps/forum_conversation/abstract_models.py | AbstractTopic.has_subscriber | def has_subscriber(self, user):
""" Returns ``True`` if the given user is a subscriber of this topic. """
if not hasattr(self, '_subscribers'):
self._subscribers = list(self.subscribers.all())
return user in self._subscribers | python | def has_subscriber(self, user):
""" Returns ``True`` if the given user is a subscriber of this topic. """
if not hasattr(self, '_subscribers'):
self._subscribers = list(self.subscribers.all())
return user in self._subscribers | [
"def",
"has_subscriber",
"(",
"self",
",",
"user",
")",
":",
"if",
"not",
"hasattr",
"(",
"self",
",",
"'_subscribers'",
")",
":",
"self",
".",
"_subscribers",
"=",
"list",
"(",
"self",
".",
"subscribers",
".",
"all",
"(",
")",
")",
"return",
"user",
... | Returns ``True`` if the given user is a subscriber of this topic. | [
"Returns",
"True",
"if",
"the",
"given",
"user",
"is",
"a",
"subscriber",
"of",
"this",
"topic",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_conversation/abstract_models.py#L133-L137 | train |
ellmetha/django-machina | machina/apps/forum_conversation/abstract_models.py | AbstractTopic.clean | def clean(self):
""" Validates the topic instance. """
super().clean()
if self.forum.is_category or self.forum.is_link:
raise ValidationError(
_('A topic can not be associated with a category or a link forum')
) | python | def clean(self):
""" Validates the topic instance. """
super().clean()
if self.forum.is_category or self.forum.is_link:
raise ValidationError(
_('A topic can not be associated with a category or a link forum')
) | [
"def",
"clean",
"(",
"self",
")",
":",
"super",
"(",
")",
".",
"clean",
"(",
")",
"if",
"self",
".",
"forum",
".",
"is_category",
"or",
"self",
".",
"forum",
".",
"is_link",
":",
"raise",
"ValidationError",
"(",
"_",
"(",
"'A topic can not be associated ... | Validates the topic instance. | [
"Validates",
"the",
"topic",
"instance",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_conversation/abstract_models.py#L139-L145 | train |
ellmetha/django-machina | machina/apps/forum_conversation/abstract_models.py | AbstractTopic.save | def save(self, *args, **kwargs):
""" Saves the topic instance. """
# It is vital to track the changes of the forum associated with a topic in order to
# maintain counters up-to-date.
old_instance = None
if self.pk:
old_instance = self.__class__._default_manager.get(pk... | python | def save(self, *args, **kwargs):
""" Saves the topic instance. """
# It is vital to track the changes of the forum associated with a topic in order to
# maintain counters up-to-date.
old_instance = None
if self.pk:
old_instance = self.__class__._default_manager.get(pk... | [
"def",
"save",
"(",
"self",
",",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"old_instance",
"=",
"None",
"if",
"self",
".",
"pk",
":",
"old_instance",
"=",
"self",
".",
"__class__",
".",
"_default_manager",
".",
"get",
"(",
"pk",
"=",
"self",
".",
... | Saves the topic instance. | [
"Saves",
"the",
"topic",
"instance",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_conversation/abstract_models.py#L147-L168 | train |
ellmetha/django-machina | machina/apps/forum_conversation/abstract_models.py | AbstractTopic.update_trackers | def update_trackers(self):
""" Updates the denormalized trackers associated with the topic instance. """
self.posts_count = self.posts.filter(approved=True).count()
first_post = self.posts.all().order_by('created').first()
last_post = self.posts.filter(approved=True).order_by('-created')... | python | def update_trackers(self):
""" Updates the denormalized trackers associated with the topic instance. """
self.posts_count = self.posts.filter(approved=True).count()
first_post = self.posts.all().order_by('created').first()
last_post = self.posts.filter(approved=True).order_by('-created')... | [
"def",
"update_trackers",
"(",
"self",
")",
":",
"self",
".",
"posts_count",
"=",
"self",
".",
"posts",
".",
"filter",
"(",
"approved",
"=",
"True",
")",
".",
"count",
"(",
")",
"first_post",
"=",
"self",
".",
"posts",
".",
"all",
"(",
")",
".",
"o... | Updates the denormalized trackers associated with the topic instance. | [
"Updates",
"the",
"denormalized",
"trackers",
"associated",
"with",
"the",
"topic",
"instance",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_conversation/abstract_models.py#L188-L198 | train |
ellmetha/django-machina | machina/apps/forum_conversation/abstract_models.py | AbstractPost.is_topic_head | def is_topic_head(self):
""" Returns ``True`` if the post is the first post of the topic. """
return self.topic.first_post.id == self.id if self.topic.first_post else False | python | def is_topic_head(self):
""" Returns ``True`` if the post is the first post of the topic. """
return self.topic.first_post.id == self.id if self.topic.first_post else False | [
"def",
"is_topic_head",
"(",
"self",
")",
":",
"return",
"self",
".",
"topic",
".",
"first_post",
".",
"id",
"==",
"self",
".",
"id",
"if",
"self",
".",
"topic",
".",
"first_post",
"else",
"False"
] | Returns ``True`` if the post is the first post of the topic. | [
"Returns",
"True",
"if",
"the",
"post",
"is",
"the",
"first",
"post",
"of",
"the",
"topic",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_conversation/abstract_models.py#L269-L271 | train |
ellmetha/django-machina | machina/apps/forum_conversation/abstract_models.py | AbstractPost.is_topic_tail | def is_topic_tail(self):
""" Returns ``True`` if the post is the last post of the topic. """
return self.topic.last_post.id == self.id if self.topic.last_post else False | python | def is_topic_tail(self):
""" Returns ``True`` if the post is the last post of the topic. """
return self.topic.last_post.id == self.id if self.topic.last_post else False | [
"def",
"is_topic_tail",
"(",
"self",
")",
":",
"return",
"self",
".",
"topic",
".",
"last_post",
".",
"id",
"==",
"self",
".",
"id",
"if",
"self",
".",
"topic",
".",
"last_post",
"else",
"False"
] | Returns ``True`` if the post is the last post of the topic. | [
"Returns",
"True",
"if",
"the",
"post",
"is",
"the",
"last",
"post",
"of",
"the",
"topic",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_conversation/abstract_models.py#L274-L276 | train |
ellmetha/django-machina | machina/apps/forum_conversation/abstract_models.py | AbstractPost.position | def position(self):
""" Returns an integer corresponding to the position of the post in the topic. """
position = self.topic.posts.filter(Q(created__lt=self.created) | Q(id=self.id)).count()
return position | python | def position(self):
""" Returns an integer corresponding to the position of the post in the topic. """
position = self.topic.posts.filter(Q(created__lt=self.created) | Q(id=self.id)).count()
return position | [
"def",
"position",
"(",
"self",
")",
":",
"position",
"=",
"self",
".",
"topic",
".",
"posts",
".",
"filter",
"(",
"Q",
"(",
"created__lt",
"=",
"self",
".",
"created",
")",
"|",
"Q",
"(",
"id",
"=",
"self",
".",
"id",
")",
")",
".",
"count",
"... | Returns an integer corresponding to the position of the post in the topic. | [
"Returns",
"an",
"integer",
"corresponding",
"to",
"the",
"position",
"of",
"the",
"post",
"in",
"the",
"topic",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_conversation/abstract_models.py#L284-L287 | train |
ellmetha/django-machina | machina/apps/forum_conversation/abstract_models.py | AbstractPost.clean | def clean(self):
""" Validates the post instance. """
super().clean()
# At least a poster (user) or a session key must be associated with
# the post.
if self.poster is None and self.anonymous_key is None:
raise ValidationError(
_('A user id or an anon... | python | def clean(self):
""" Validates the post instance. """
super().clean()
# At least a poster (user) or a session key must be associated with
# the post.
if self.poster is None and self.anonymous_key is None:
raise ValidationError(
_('A user id or an anon... | [
"def",
"clean",
"(",
"self",
")",
":",
"super",
"(",
")",
".",
"clean",
"(",
")",
"if",
"self",
".",
"poster",
"is",
"None",
"and",
"self",
".",
"anonymous_key",
"is",
"None",
":",
"raise",
"ValidationError",
"(",
"_",
"(",
"'A user id or an anonymous ke... | Validates the post instance. | [
"Validates",
"the",
"post",
"instance",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_conversation/abstract_models.py#L289-L305 | train |
ellmetha/django-machina | machina/apps/forum_conversation/abstract_models.py | AbstractPost.save | def save(self, *args, **kwargs):
""" Saves the post instance. """
new_post = self.pk is None
super().save(*args, **kwargs)
# Ensures that the subject of the thread corresponds to the one associated
# with the first post. Do the same with the 'approved' flag.
if (new_post... | python | def save(self, *args, **kwargs):
""" Saves the post instance. """
new_post = self.pk is None
super().save(*args, **kwargs)
# Ensures that the subject of the thread corresponds to the one associated
# with the first post. Do the same with the 'approved' flag.
if (new_post... | [
"def",
"save",
"(",
"self",
",",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"new_post",
"=",
"self",
".",
"pk",
"is",
"None",
"super",
"(",
")",
".",
"save",
"(",
"*",
"args",
",",
"**",
"kwargs",
")",
"if",
"(",
"new_post",
"and",
"self",
"."... | Saves the post instance. | [
"Saves",
"the",
"post",
"instance",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_conversation/abstract_models.py#L307-L320 | train |
ellmetha/django-machina | machina/apps/forum_conversation/abstract_models.py | AbstractPost.delete | def delete(self, using=None):
""" Deletes the post instance. """
if self.is_alone:
# The default way of operating is to trigger the deletion of the associated topic
# only if the considered post is the only post embedded in the topic
self.topic.delete()
else:
... | python | def delete(self, using=None):
""" Deletes the post instance. """
if self.is_alone:
# The default way of operating is to trigger the deletion of the associated topic
# only if the considered post is the only post embedded in the topic
self.topic.delete()
else:
... | [
"def",
"delete",
"(",
"self",
",",
"using",
"=",
"None",
")",
":",
"if",
"self",
".",
"is_alone",
":",
"self",
".",
"topic",
".",
"delete",
"(",
")",
"else",
":",
"super",
"(",
"AbstractPost",
",",
"self",
")",
".",
"delete",
"(",
"using",
")",
"... | Deletes the post instance. | [
"Deletes",
"the",
"post",
"instance",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_conversation/abstract_models.py#L322-L330 | train |
ellmetha/django-machina | machina/apps/forum/visibility.py | ForumVisibilityContentTree.from_forums | def from_forums(cls, forums):
""" Initializes a ``ForumVisibilityContentTree`` instance from a list of forums. """
root_level = None
current_path = []
nodes = []
# Ensures forums last posts and related poster relations are "followed" for better
# performance (only if we'... | python | def from_forums(cls, forums):
""" Initializes a ``ForumVisibilityContentTree`` instance from a list of forums. """
root_level = None
current_path = []
nodes = []
# Ensures forums last posts and related poster relations are "followed" for better
# performance (only if we'... | [
"def",
"from_forums",
"(",
"cls",
",",
"forums",
")",
":",
"root_level",
"=",
"None",
"current_path",
"=",
"[",
"]",
"nodes",
"=",
"[",
"]",
"forums",
"=",
"(",
"forums",
".",
"select_related",
"(",
"'last_post'",
",",
"'last_post__poster'",
")",
"if",
"... | Initializes a ``ForumVisibilityContentTree`` instance from a list of forums. | [
"Initializes",
"a",
"ForumVisibilityContentTree",
"instance",
"from",
"a",
"list",
"of",
"forums",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum/visibility.py#L33-L108 | train |
ellmetha/django-machina | machina/apps/forum/visibility.py | ForumVisibilityContentNode.last_post | def last_post(self):
""" Returns the latest post associated with the node or one of its descendants. """
posts = [n.last_post for n in self.children if n.last_post is not None]
children_last_post = max(posts, key=lambda p: p.created) if posts else None
if children_last_post and self.obj.... | python | def last_post(self):
""" Returns the latest post associated with the node or one of its descendants. """
posts = [n.last_post for n in self.children if n.last_post is not None]
children_last_post = max(posts, key=lambda p: p.created) if posts else None
if children_last_post and self.obj.... | [
"def",
"last_post",
"(",
"self",
")",
":",
"posts",
"=",
"[",
"n",
".",
"last_post",
"for",
"n",
"in",
"self",
".",
"children",
"if",
"n",
".",
"last_post",
"is",
"not",
"None",
"]",
"children_last_post",
"=",
"max",
"(",
"posts",
",",
"key",
"=",
... | Returns the latest post associated with the node or one of its descendants. | [
"Returns",
"the",
"latest",
"post",
"associated",
"with",
"the",
"node",
"or",
"one",
"of",
"its",
"descendants",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum/visibility.py#L158-L164 | train |
ellmetha/django-machina | machina/apps/forum/visibility.py | ForumVisibilityContentNode.last_post_on | def last_post_on(self):
""" Returns the latest post date associated with the node or one of its descendants. """
dates = [n.last_post_on for n in self.children if n.last_post_on is not None]
children_last_post_on = max(dates) if dates else None
if children_last_post_on and self.obj.last_... | python | def last_post_on(self):
""" Returns the latest post date associated with the node or one of its descendants. """
dates = [n.last_post_on for n in self.children if n.last_post_on is not None]
children_last_post_on = max(dates) if dates else None
if children_last_post_on and self.obj.last_... | [
"def",
"last_post_on",
"(",
"self",
")",
":",
"dates",
"=",
"[",
"n",
".",
"last_post_on",
"for",
"n",
"in",
"self",
".",
"children",
"if",
"n",
".",
"last_post_on",
"is",
"not",
"None",
"]",
"children_last_post_on",
"=",
"max",
"(",
"dates",
")",
"if"... | Returns the latest post date associated with the node or one of its descendants. | [
"Returns",
"the",
"latest",
"post",
"date",
"associated",
"with",
"the",
"node",
"or",
"one",
"of",
"its",
"descendants",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum/visibility.py#L167-L173 | train |
ellmetha/django-machina | machina/apps/forum/visibility.py | ForumVisibilityContentNode.next_sibling | def next_sibling(self):
""" Returns the next sibling of the current node.
The next sibling is searched in the parent node if we are not considering a top-level node.
Otherwise it is searched inside the list of nodes (which should be sorted by tree ID) that
is associated with the conside... | python | def next_sibling(self):
""" Returns the next sibling of the current node.
The next sibling is searched in the parent node if we are not considering a top-level node.
Otherwise it is searched inside the list of nodes (which should be sorted by tree ID) that
is associated with the conside... | [
"def",
"next_sibling",
"(",
"self",
")",
":",
"if",
"self",
".",
"parent",
":",
"nodes",
"=",
"self",
".",
"parent",
".",
"children",
"index",
"=",
"nodes",
".",
"index",
"(",
"self",
")",
"sibling",
"=",
"nodes",
"[",
"index",
"+",
"1",
"]",
"if",... | Returns the next sibling of the current node.
The next sibling is searched in the parent node if we are not considering a top-level node.
Otherwise it is searched inside the list of nodes (which should be sorted by tree ID) that
is associated with the considered tree instance. | [
"Returns",
"the",
"next",
"sibling",
"of",
"the",
"current",
"node",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum/visibility.py#L176-L194 | train |
ellmetha/django-machina | machina/apps/forum/visibility.py | ForumVisibilityContentNode.posts_count | def posts_count(self):
""" Returns the number of posts associated with the current node and its descendants. """
return self.obj.direct_posts_count + sum(n.posts_count for n in self.children) | python | def posts_count(self):
""" Returns the number of posts associated with the current node and its descendants. """
return self.obj.direct_posts_count + sum(n.posts_count for n in self.children) | [
"def",
"posts_count",
"(",
"self",
")",
":",
"return",
"self",
".",
"obj",
".",
"direct_posts_count",
"+",
"sum",
"(",
"n",
".",
"posts_count",
"for",
"n",
"in",
"self",
".",
"children",
")"
] | Returns the number of posts associated with the current node and its descendants. | [
"Returns",
"the",
"number",
"of",
"posts",
"associated",
"with",
"the",
"current",
"node",
"and",
"its",
"descendants",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum/visibility.py#L197-L199 | train |
ellmetha/django-machina | machina/apps/forum/visibility.py | ForumVisibilityContentNode.previous_sibling | def previous_sibling(self):
""" Returns the previous sibling of the current node.
The previous sibling is searched in the parent node if we are not considering a top-level
node. Otherwise it is searched inside the list of nodes (which should be sorted by tree ID)
that is associated with... | python | def previous_sibling(self):
""" Returns the previous sibling of the current node.
The previous sibling is searched in the parent node if we are not considering a top-level
node. Otherwise it is searched inside the list of nodes (which should be sorted by tree ID)
that is associated with... | [
"def",
"previous_sibling",
"(",
"self",
")",
":",
"if",
"self",
".",
"parent",
":",
"nodes",
"=",
"self",
".",
"parent",
".",
"children",
"index",
"=",
"nodes",
".",
"index",
"(",
"self",
")",
"sibling",
"=",
"nodes",
"[",
"index",
"-",
"1",
"]",
"... | Returns the previous sibling of the current node.
The previous sibling is searched in the parent node if we are not considering a top-level
node. Otherwise it is searched inside the list of nodes (which should be sorted by tree ID)
that is associated with the considered tree instance. | [
"Returns",
"the",
"previous",
"sibling",
"of",
"the",
"current",
"node",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum/visibility.py#L202-L220 | train |
ellmetha/django-machina | machina/apps/forum/visibility.py | ForumVisibilityContentNode.topics_count | def topics_count(self):
""" Returns the number of topics associated with the current node and its descendants. """
return self.obj.direct_topics_count + sum(n.topics_count for n in self.children) | python | def topics_count(self):
""" Returns the number of topics associated with the current node and its descendants. """
return self.obj.direct_topics_count + sum(n.topics_count for n in self.children) | [
"def",
"topics_count",
"(",
"self",
")",
":",
"return",
"self",
".",
"obj",
".",
"direct_topics_count",
"+",
"sum",
"(",
"n",
".",
"topics_count",
"for",
"n",
"in",
"self",
".",
"children",
")"
] | Returns the number of topics associated with the current node and its descendants. | [
"Returns",
"the",
"number",
"of",
"topics",
"associated",
"with",
"the",
"current",
"node",
"and",
"its",
"descendants",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum/visibility.py#L223-L225 | train |
ellmetha/django-machina | machina/apps/forum_permission/checker.py | ForumPermissionChecker.has_perm | def has_perm(self, perm, forum):
""" Checks if the considered user has given permission for the passed forum. """
if not self.user.is_anonymous and not self.user.is_active:
# An inactive user cannot have permissions
return False
elif self.user and self.user.is_superuser:
... | python | def has_perm(self, perm, forum):
""" Checks if the considered user has given permission for the passed forum. """
if not self.user.is_anonymous and not self.user.is_active:
# An inactive user cannot have permissions
return False
elif self.user and self.user.is_superuser:
... | [
"def",
"has_perm",
"(",
"self",
",",
"perm",
",",
"forum",
")",
":",
"if",
"not",
"self",
".",
"user",
".",
"is_anonymous",
"and",
"not",
"self",
".",
"user",
".",
"is_active",
":",
"return",
"False",
"elif",
"self",
".",
"user",
"and",
"self",
".",
... | Checks if the considered user has given permission for the passed forum. | [
"Checks",
"if",
"the",
"considered",
"user",
"has",
"given",
"permission",
"for",
"the",
"passed",
"forum",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_permission/checker.py#L29-L37 | train |
ellmetha/django-machina | machina/apps/forum_conversation/forum_attachments/forms.py | BaseAttachmentFormset.save | def save(self, commit=True, **kwargs):
""" Saves the considered instances. """
if self.post:
for form in self.forms:
form.instance.post = self.post
super().save(commit) | python | def save(self, commit=True, **kwargs):
""" Saves the considered instances. """
if self.post:
for form in self.forms:
form.instance.post = self.post
super().save(commit) | [
"def",
"save",
"(",
"self",
",",
"commit",
"=",
"True",
",",
"**",
"kwargs",
")",
":",
"if",
"self",
".",
"post",
":",
"for",
"form",
"in",
"self",
".",
"forms",
":",
"form",
".",
"instance",
".",
"post",
"=",
"self",
".",
"post",
"super",
"(",
... | Saves the considered instances. | [
"Saves",
"the",
"considered",
"instances",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_conversation/forum_attachments/forms.py#L34-L39 | train |
ellmetha/django-machina | machina/apps/forum_permission/viewmixins.py | PermissionRequiredMixin.get_required_permissions | def get_required_permissions(self, request):
""" Returns the required permissions to access the considered object. """
perms = []
if not self.permission_required:
return perms
if isinstance(self.permission_required, string_types):
perms = [self.permission_requir... | python | def get_required_permissions(self, request):
""" Returns the required permissions to access the considered object. """
perms = []
if not self.permission_required:
return perms
if isinstance(self.permission_required, string_types):
perms = [self.permission_requir... | [
"def",
"get_required_permissions",
"(",
"self",
",",
"request",
")",
":",
"perms",
"=",
"[",
"]",
"if",
"not",
"self",
".",
"permission_required",
":",
"return",
"perms",
"if",
"isinstance",
"(",
"self",
".",
"permission_required",
",",
"string_types",
")",
... | Returns the required permissions to access the considered object. | [
"Returns",
"the",
"required",
"permissions",
"to",
"access",
"the",
"considered",
"object",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_permission/viewmixins.py#L51-L68 | train |
ellmetha/django-machina | machina/apps/forum_permission/viewmixins.py | PermissionRequiredMixin.check_permissions | def check_permissions(self, request):
""" Retrieves the controlled object and perform the permissions check. """
obj = (
hasattr(self, 'get_controlled_object') and self.get_controlled_object() or
hasattr(self, 'get_object') and self.get_object() or getattr(self, 'object', None)
... | python | def check_permissions(self, request):
""" Retrieves the controlled object and perform the permissions check. """
obj = (
hasattr(self, 'get_controlled_object') and self.get_controlled_object() or
hasattr(self, 'get_object') and self.get_object() or getattr(self, 'object', None)
... | [
"def",
"check_permissions",
"(",
"self",
",",
"request",
")",
":",
"obj",
"=",
"(",
"hasattr",
"(",
"self",
",",
"'get_controlled_object'",
")",
"and",
"self",
".",
"get_controlled_object",
"(",
")",
"or",
"hasattr",
"(",
"self",
",",
"'get_object'",
")",
... | Retrieves the controlled object and perform the permissions check. | [
"Retrieves",
"the",
"controlled",
"object",
"and",
"perform",
"the",
"permissions",
"check",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_permission/viewmixins.py#L84-L105 | train |
ellmetha/django-machina | machina/apps/forum_permission/viewmixins.py | PermissionRequiredMixin.dispatch | def dispatch(self, request, *args, **kwargs):
""" Dispatches an incoming request. """
self.request = request
self.args = args
self.kwargs = kwargs
response = self.check_permissions(request)
if response:
return response
return super().dispatch(request, ... | python | def dispatch(self, request, *args, **kwargs):
""" Dispatches an incoming request. """
self.request = request
self.args = args
self.kwargs = kwargs
response = self.check_permissions(request)
if response:
return response
return super().dispatch(request, ... | [
"def",
"dispatch",
"(",
"self",
",",
"request",
",",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"self",
".",
"request",
"=",
"request",
"self",
".",
"args",
"=",
"args",
"self",
".",
"kwargs",
"=",
"kwargs",
"response",
"=",
"self",
".",
"check_perm... | Dispatches an incoming request. | [
"Dispatches",
"an",
"incoming",
"request",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_permission/viewmixins.py#L107-L115 | train |
ellmetha/django-machina | machina/apps/forum_tracking/receivers.py | update_user_trackers | def update_user_trackers(sender, topic, user, request, response, **kwargs):
""" Receiver to mark a topic being viewed as read.
This can result in marking the related forum tracker as read.
"""
TrackingHandler = get_class('forum_tracking.handler', 'TrackingHandler') # noqa
track_handler = Tracking... | python | def update_user_trackers(sender, topic, user, request, response, **kwargs):
""" Receiver to mark a topic being viewed as read.
This can result in marking the related forum tracker as read.
"""
TrackingHandler = get_class('forum_tracking.handler', 'TrackingHandler') # noqa
track_handler = Tracking... | [
"def",
"update_user_trackers",
"(",
"sender",
",",
"topic",
",",
"user",
",",
"request",
",",
"response",
",",
"**",
"kwargs",
")",
":",
"TrackingHandler",
"=",
"get_class",
"(",
"'forum_tracking.handler'",
",",
"'TrackingHandler'",
")",
"track_handler",
"=",
"T... | Receiver to mark a topic being viewed as read.
This can result in marking the related forum tracker as read. | [
"Receiver",
"to",
"mark",
"a",
"topic",
"being",
"viewed",
"as",
"read",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_tracking/receivers.py#L18-L26 | train |
ellmetha/django-machina | machina/apps/forum/receivers.py | update_forum_redirects_counter | def update_forum_redirects_counter(sender, forum, user, request, response, **kwargs):
""" Handles the update of the link redirects counter associated with link forums. """
if forum.is_link and forum.link_redirects:
forum.link_redirects_count = F('link_redirects_count') + 1
forum.save() | python | def update_forum_redirects_counter(sender, forum, user, request, response, **kwargs):
""" Handles the update of the link redirects counter associated with link forums. """
if forum.is_link and forum.link_redirects:
forum.link_redirects_count = F('link_redirects_count') + 1
forum.save() | [
"def",
"update_forum_redirects_counter",
"(",
"sender",
",",
"forum",
",",
"user",
",",
"request",
",",
"response",
",",
"**",
"kwargs",
")",
":",
"if",
"forum",
".",
"is_link",
"and",
"forum",
".",
"link_redirects",
":",
"forum",
".",
"link_redirects_count",
... | Handles the update of the link redirects counter associated with link forums. | [
"Handles",
"the",
"update",
"of",
"the",
"link",
"redirects",
"counter",
"associated",
"with",
"link",
"forums",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum/receivers.py#L16-L20 | train |
ellmetha/django-machina | machina/apps/forum_member/abstract_models.py | AbstractForumProfile.get_avatar_upload_to | def get_avatar_upload_to(self, filename):
""" Returns the path to upload the associated avatar to. """
dummy, ext = os.path.splitext(filename)
return os.path.join(
machina_settings.PROFILE_AVATAR_UPLOAD_TO,
'{id}{ext}'.format(id=str(uuid.uuid4()).replace('-', ''), ext=ext... | python | def get_avatar_upload_to(self, filename):
""" Returns the path to upload the associated avatar to. """
dummy, ext = os.path.splitext(filename)
return os.path.join(
machina_settings.PROFILE_AVATAR_UPLOAD_TO,
'{id}{ext}'.format(id=str(uuid.uuid4()).replace('-', ''), ext=ext... | [
"def",
"get_avatar_upload_to",
"(",
"self",
",",
"filename",
")",
":",
"dummy",
",",
"ext",
"=",
"os",
".",
"path",
".",
"splitext",
"(",
"filename",
")",
"return",
"os",
".",
"path",
".",
"join",
"(",
"machina_settings",
".",
"PROFILE_AVATAR_UPLOAD_TO",
"... | Returns the path to upload the associated avatar to. | [
"Returns",
"the",
"path",
"to",
"upload",
"the",
"associated",
"avatar",
"to",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_member/abstract_models.py#L60-L66 | train |
ellmetha/django-machina | machina/apps/forum_conversation/managers.py | ApprovedManager.get_queryset | def get_queryset(self):
""" Returns all the approved topics or posts. """
qs = super().get_queryset()
qs = qs.filter(approved=True)
return qs | python | def get_queryset(self):
""" Returns all the approved topics or posts. """
qs = super().get_queryset()
qs = qs.filter(approved=True)
return qs | [
"def",
"get_queryset",
"(",
"self",
")",
":",
"qs",
"=",
"super",
"(",
")",
".",
"get_queryset",
"(",
")",
"qs",
"=",
"qs",
".",
"filter",
"(",
"approved",
"=",
"True",
")",
"return",
"qs"
] | Returns all the approved topics or posts. | [
"Returns",
"all",
"the",
"approved",
"topics",
"or",
"posts",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_conversation/managers.py#L13-L17 | train |
ellmetha/django-machina | machina/apps/forum_conversation/forum_polls/abstract_models.py | AbstractTopicPoll.votes | def votes(self):
""" Returns all the votes related to this topic poll. """
votes = []
for option in self.options.all():
votes += option.votes.all()
return votes | python | def votes(self):
""" Returns all the votes related to this topic poll. """
votes = []
for option in self.options.all():
votes += option.votes.all()
return votes | [
"def",
"votes",
"(",
"self",
")",
":",
"votes",
"=",
"[",
"]",
"for",
"option",
"in",
"self",
".",
"options",
".",
"all",
"(",
")",
":",
"votes",
"+=",
"option",
".",
"votes",
".",
"all",
"(",
")",
"return",
"votes"
] | Returns all the votes related to this topic poll. | [
"Returns",
"all",
"the",
"votes",
"related",
"to",
"this",
"topic",
"poll",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_conversation/forum_polls/abstract_models.py#L56-L61 | train |
ellmetha/django-machina | machina/apps/forum_conversation/forum_polls/abstract_models.py | AbstractTopicPollVote.clean | def clean(self):
""" Validates the considered instance. """
super().clean()
# At least a poster (user) or a session key must be associated with
# the vote instance.
if self.voter is None and self.anonymous_key is None:
raise ValidationError(_('A user id or an anonymo... | python | def clean(self):
""" Validates the considered instance. """
super().clean()
# At least a poster (user) or a session key must be associated with
# the vote instance.
if self.voter is None and self.anonymous_key is None:
raise ValidationError(_('A user id or an anonymo... | [
"def",
"clean",
"(",
"self",
")",
":",
"super",
"(",
")",
".",
"clean",
"(",
")",
"if",
"self",
".",
"voter",
"is",
"None",
"and",
"self",
".",
"anonymous_key",
"is",
"None",
":",
"raise",
"ValidationError",
"(",
"_",
"(",
"'A user id or an anonymous key... | Validates the considered instance. | [
"Validates",
"the",
"considered",
"instance",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_conversation/forum_polls/abstract_models.py#L114-L123 | train |
ellmetha/django-machina | machina/apps/forum_tracking/views.py | MarkForumsReadView.get_top_level_forum_url | def get_top_level_forum_url(self):
""" Returns the parent forum from which forums are marked as read. """
return (
reverse('forum:index') if self.top_level_forum is None else
reverse(
'forum:forum',
kwargs={'slug': self.top_level_forum.slug, 'pk': ... | python | def get_top_level_forum_url(self):
""" Returns the parent forum from which forums are marked as read. """
return (
reverse('forum:index') if self.top_level_forum is None else
reverse(
'forum:forum',
kwargs={'slug': self.top_level_forum.slug, 'pk': ... | [
"def",
"get_top_level_forum_url",
"(",
"self",
")",
":",
"return",
"(",
"reverse",
"(",
"'forum:index'",
")",
"if",
"self",
".",
"top_level_forum",
"is",
"None",
"else",
"reverse",
"(",
"'forum:forum'",
",",
"kwargs",
"=",
"{",
"'slug'",
":",
"self",
".",
... | Returns the parent forum from which forums are marked as read. | [
"Returns",
"the",
"parent",
"forum",
"from",
"which",
"forums",
"are",
"marked",
"as",
"read",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_tracking/views.py#L53-L61 | train |
ellmetha/django-machina | machina/apps/forum_tracking/views.py | MarkForumsReadView.mark_as_read | def mark_as_read(self, request, pk):
""" Marks the considered forums as read. """
if self.top_level_forum is not None:
forums = request.forum_permission_handler.get_readable_forums(
self.top_level_forum.get_descendants(include_self=True), request.user,
)
e... | python | def mark_as_read(self, request, pk):
""" Marks the considered forums as read. """
if self.top_level_forum is not None:
forums = request.forum_permission_handler.get_readable_forums(
self.top_level_forum.get_descendants(include_self=True), request.user,
)
e... | [
"def",
"mark_as_read",
"(",
"self",
",",
"request",
",",
"pk",
")",
":",
"if",
"self",
".",
"top_level_forum",
"is",
"not",
"None",
":",
"forums",
"=",
"request",
".",
"forum_permission_handler",
".",
"get_readable_forums",
"(",
"self",
".",
"top_level_forum",... | Marks the considered forums as read. | [
"Marks",
"the",
"considered",
"forums",
"as",
"read",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_tracking/views.py#L63-L80 | train |
ellmetha/django-machina | machina/apps/forum_tracking/views.py | MarkTopicsReadView.get_forum_url | def get_forum_url(self):
""" Returns the url of the forum whose topics will be marked read. """
return reverse('forum:forum', kwargs={'slug': self.forum.slug, 'pk': self.forum.pk}) | python | def get_forum_url(self):
""" Returns the url of the forum whose topics will be marked read. """
return reverse('forum:forum', kwargs={'slug': self.forum.slug, 'pk': self.forum.pk}) | [
"def",
"get_forum_url",
"(",
"self",
")",
":",
"return",
"reverse",
"(",
"'forum:forum'",
",",
"kwargs",
"=",
"{",
"'slug'",
":",
"self",
".",
"forum",
".",
"slug",
",",
"'pk'",
":",
"self",
".",
"forum",
".",
"pk",
"}",
")"
] | Returns the url of the forum whose topics will be marked read. | [
"Returns",
"the",
"url",
"of",
"the",
"forum",
"whose",
"topics",
"will",
"be",
"marked",
"read",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_tracking/views.py#L113-L115 | train |
ellmetha/django-machina | machina/apps/forum_tracking/views.py | MarkTopicsReadView.mark_topics_read | def mark_topics_read(self, request, pk):
""" Marks forum topics as read. """
track_handler.mark_forums_read([self.forum, ], request.user)
messages.success(request, self.success_message)
return HttpResponseRedirect(self.get_forum_url()) | python | def mark_topics_read(self, request, pk):
""" Marks forum topics as read. """
track_handler.mark_forums_read([self.forum, ], request.user)
messages.success(request, self.success_message)
return HttpResponseRedirect(self.get_forum_url()) | [
"def",
"mark_topics_read",
"(",
"self",
",",
"request",
",",
"pk",
")",
":",
"track_handler",
".",
"mark_forums_read",
"(",
"[",
"self",
".",
"forum",
",",
"]",
",",
"request",
".",
"user",
")",
"messages",
".",
"success",
"(",
"request",
",",
"self",
... | Marks forum topics as read. | [
"Marks",
"forum",
"topics",
"as",
"read",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_tracking/views.py#L117-L121 | train |
ellmetha/django-machina | machina/core/db/models.py | get_model | def get_model(app_label, model_name):
""" Given an app label and a model name, returns the corresponding model class. """
try:
return apps.get_model(app_label, model_name)
except AppRegistryNotReady:
if apps.apps_ready and not apps.models_ready:
# If the models module of the cons... | python | def get_model(app_label, model_name):
""" Given an app label and a model name, returns the corresponding model class. """
try:
return apps.get_model(app_label, model_name)
except AppRegistryNotReady:
if apps.apps_ready and not apps.models_ready:
# If the models module of the cons... | [
"def",
"get_model",
"(",
"app_label",
",",
"model_name",
")",
":",
"try",
":",
"return",
"apps",
".",
"get_model",
"(",
"app_label",
",",
"model_name",
")",
"except",
"AppRegistryNotReady",
":",
"if",
"apps",
".",
"apps_ready",
"and",
"not",
"apps",
".",
"... | Given an app label and a model name, returns the corresponding model class. | [
"Given",
"an",
"app",
"label",
"and",
"a",
"model",
"name",
"returns",
"the",
"corresponding",
"model",
"class",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/core/db/models.py#L12-L31 | train |
ellmetha/django-machina | machina/core/db/models.py | is_model_registered | def is_model_registered(app_label, model_name):
""" Checks whether the given model is registered or not.
It is usefull to prevent Machina models for being registered if they are overridden by local
apps.
"""
try:
apps.get_registered_model(app_label, model_name)
except LookupError:
... | python | def is_model_registered(app_label, model_name):
""" Checks whether the given model is registered or not.
It is usefull to prevent Machina models for being registered if they are overridden by local
apps.
"""
try:
apps.get_registered_model(app_label, model_name)
except LookupError:
... | [
"def",
"is_model_registered",
"(",
"app_label",
",",
"model_name",
")",
":",
"try",
":",
"apps",
".",
"get_registered_model",
"(",
"app_label",
",",
"model_name",
")",
"except",
"LookupError",
":",
"return",
"False",
"else",
":",
"return",
"True"
] | Checks whether the given model is registered or not.
It is usefull to prevent Machina models for being registered if they are overridden by local
apps. | [
"Checks",
"whether",
"the",
"given",
"model",
"is",
"registered",
"or",
"not",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/core/db/models.py#L34-L46 | train |
ellmetha/django-machina | machina/apps/forum_permission/abstract_models.py | AbstractUserForumPermission.clean | def clean(self):
""" Validates the current instance. """
super().clean()
if (
(self.user is None and not self.anonymous_user) or
(self.user and self.anonymous_user)
):
raise ValidationError(
_('A permission should target either a user o... | python | def clean(self):
""" Validates the current instance. """
super().clean()
if (
(self.user is None and not self.anonymous_user) or
(self.user and self.anonymous_user)
):
raise ValidationError(
_('A permission should target either a user o... | [
"def",
"clean",
"(",
"self",
")",
":",
"super",
"(",
")",
".",
"clean",
"(",
")",
"if",
"(",
"(",
"self",
".",
"user",
"is",
"None",
"and",
"not",
"self",
".",
"anonymous_user",
")",
"or",
"(",
"self",
".",
"user",
"and",
"self",
".",
"anonymous_... | Validates the current instance. | [
"Validates",
"the",
"current",
"instance",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_permission/abstract_models.py#L94-L103 | train |
ellmetha/django-machina | machina/apps/forum_conversation/forum_attachments/views.py | AttachmentView.render_to_response | def render_to_response(self, context, **response_kwargs):
""" Generates the appropriate response. """
filename = os.path.basename(self.object.file.name)
# Try to guess the content type of the given file
content_type, _ = mimetypes.guess_type(self.object.file.name)
if not content... | python | def render_to_response(self, context, **response_kwargs):
""" Generates the appropriate response. """
filename = os.path.basename(self.object.file.name)
# Try to guess the content type of the given file
content_type, _ = mimetypes.guess_type(self.object.file.name)
if not content... | [
"def",
"render_to_response",
"(",
"self",
",",
"context",
",",
"**",
"response_kwargs",
")",
":",
"filename",
"=",
"os",
".",
"path",
".",
"basename",
"(",
"self",
".",
"object",
".",
"file",
".",
"name",
")",
"content_type",
",",
"_",
"=",
"mimetypes",
... | Generates the appropriate response. | [
"Generates",
"the",
"appropriate",
"response",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_conversation/forum_attachments/views.py#L29-L41 | train |
ellmetha/django-machina | machina/apps/forum_conversation/forum_polls/views.py | TopicPollVoteView.get_form_kwargs | def get_form_kwargs(self):
""" Returns the keyword arguments to provide tp the associated form. """
kwargs = super(ModelFormMixin, self).get_form_kwargs()
kwargs['poll'] = self.object
return kwargs | python | def get_form_kwargs(self):
""" Returns the keyword arguments to provide tp the associated form. """
kwargs = super(ModelFormMixin, self).get_form_kwargs()
kwargs['poll'] = self.object
return kwargs | [
"def",
"get_form_kwargs",
"(",
"self",
")",
":",
"kwargs",
"=",
"super",
"(",
"ModelFormMixin",
",",
"self",
")",
".",
"get_form_kwargs",
"(",
")",
"kwargs",
"[",
"'poll'",
"]",
"=",
"self",
".",
"object",
"return",
"kwargs"
] | Returns the keyword arguments to provide tp the associated form. | [
"Returns",
"the",
"keyword",
"arguments",
"to",
"provide",
"tp",
"the",
"associated",
"form",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_conversation/forum_polls/views.py#L37-L41 | train |
ellmetha/django-machina | machina/apps/forum_conversation/forum_polls/views.py | TopicPollVoteView.form_invalid | def form_invalid(self, form):
""" Handles an invalid form. """
messages.error(self.request, form.errors[NON_FIELD_ERRORS])
return redirect(
reverse(
'forum_conversation:topic',
kwargs={
'forum_slug': self.object.topic.forum.slug,
... | python | def form_invalid(self, form):
""" Handles an invalid form. """
messages.error(self.request, form.errors[NON_FIELD_ERRORS])
return redirect(
reverse(
'forum_conversation:topic',
kwargs={
'forum_slug': self.object.topic.forum.slug,
... | [
"def",
"form_invalid",
"(",
"self",
",",
"form",
")",
":",
"messages",
".",
"error",
"(",
"self",
".",
"request",
",",
"form",
".",
"errors",
"[",
"NON_FIELD_ERRORS",
"]",
")",
"return",
"redirect",
"(",
"reverse",
"(",
"'forum_conversation:topic'",
",",
"... | Handles an invalid form. | [
"Handles",
"an",
"invalid",
"form",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_conversation/forum_polls/views.py#L62-L75 | train |
ellmetha/django-machina | machina/templatetags/forum_polls_tags.py | has_been_completed_by | def has_been_completed_by(poll, user):
""" This will return a boolean indicating if the passed user has already voted in the given
poll.
Usage::
{% if poll|has_been_completed_by:user %}...{% endif %}
"""
user_votes = TopicPollVote.objects.filter(
poll_option__poll=poll)
if ... | python | def has_been_completed_by(poll, user):
""" This will return a boolean indicating if the passed user has already voted in the given
poll.
Usage::
{% if poll|has_been_completed_by:user %}...{% endif %}
"""
user_votes = TopicPollVote.objects.filter(
poll_option__poll=poll)
if ... | [
"def",
"has_been_completed_by",
"(",
"poll",
",",
"user",
")",
":",
"user_votes",
"=",
"TopicPollVote",
".",
"objects",
".",
"filter",
"(",
"poll_option__poll",
"=",
"poll",
")",
"if",
"user",
".",
"is_anonymous",
":",
"forum_key",
"=",
"get_anonymous_user_forum... | This will return a boolean indicating if the passed user has already voted in the given
poll.
Usage::
{% if poll|has_been_completed_by:user %}...{% endif %} | [
"This",
"will",
"return",
"a",
"boolean",
"indicating",
"if",
"the",
"passed",
"user",
"has",
"already",
"voted",
"in",
"the",
"given",
"poll",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/templatetags/forum_polls_tags.py#L17-L33 | train |
ellmetha/django-machina | machina/apps/forum_tracking/managers.py | ForumReadTrackManager.get_unread_forums_from_list | def get_unread_forums_from_list(self, forums, user):
""" Filter a list of forums and return only those which are unread.
Given a list of forums find and returns the list of forums that are unread for the passed
user. If a forum is unread all of its ancestors are also unread and will be included... | python | def get_unread_forums_from_list(self, forums, user):
""" Filter a list of forums and return only those which are unread.
Given a list of forums find and returns the list of forums that are unread for the passed
user. If a forum is unread all of its ancestors are also unread and will be included... | [
"def",
"get_unread_forums_from_list",
"(",
"self",
",",
"forums",
",",
"user",
")",
":",
"unread_forums",
"=",
"[",
"]",
"visibility_contents",
"=",
"ForumVisibilityContentTree",
".",
"from_forums",
"(",
"forums",
")",
"forum_ids_to_visibility_nodes",
"=",
"visibility... | Filter a list of forums and return only those which are unread.
Given a list of forums find and returns the list of forums that are unread for the passed
user. If a forum is unread all of its ancestors are also unread and will be included in the
final list. | [
"Filter",
"a",
"list",
"of",
"forums",
"and",
"return",
"only",
"those",
"which",
"are",
"unread",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_tracking/managers.py#L20-L48 | train |
ellmetha/django-machina | machina/apps/forum_member/receivers.py | increase_posts_count | def increase_posts_count(sender, instance, **kwargs):
""" Increases the member's post count after a post save.
This receiver handles the update of the profile related to the user who is the poster of the
forum post being created or updated.
"""
if instance.poster is None:
# An anonymous po... | python | def increase_posts_count(sender, instance, **kwargs):
""" Increases the member's post count after a post save.
This receiver handles the update of the profile related to the user who is the poster of the
forum post being created or updated.
"""
if instance.poster is None:
# An anonymous po... | [
"def",
"increase_posts_count",
"(",
"sender",
",",
"instance",
",",
"**",
"kwargs",
")",
":",
"if",
"instance",
".",
"poster",
"is",
"None",
":",
"return",
"profile",
",",
"dummy",
"=",
"ForumProfile",
".",
"objects",
".",
"get_or_create",
"(",
"user",
"="... | Increases the member's post count after a post save.
This receiver handles the update of the profile related to the user who is the poster of the
forum post being created or updated. | [
"Increases",
"the",
"member",
"s",
"post",
"count",
"after",
"a",
"post",
"save",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_member/receivers.py#L25-L54 | train |
ellmetha/django-machina | machina/apps/forum_member/receivers.py | decrease_posts_count_after_post_unaproval | def decrease_posts_count_after_post_unaproval(sender, instance, **kwargs):
""" Decreases the member's post count after a post unaproval.
This receiver handles the unaproval of a forum post: the posts count associated with the post's
author is decreased.
"""
if not instance.pk:
# Do not cons... | python | def decrease_posts_count_after_post_unaproval(sender, instance, **kwargs):
""" Decreases the member's post count after a post unaproval.
This receiver handles the unaproval of a forum post: the posts count associated with the post's
author is decreased.
"""
if not instance.pk:
# Do not cons... | [
"def",
"decrease_posts_count_after_post_unaproval",
"(",
"sender",
",",
"instance",
",",
"**",
"kwargs",
")",
":",
"if",
"not",
"instance",
".",
"pk",
":",
"return",
"profile",
",",
"dummy",
"=",
"ForumProfile",
".",
"objects",
".",
"get_or_create",
"(",
"user... | Decreases the member's post count after a post unaproval.
This receiver handles the unaproval of a forum post: the posts count associated with the post's
author is decreased. | [
"Decreases",
"the",
"member",
"s",
"post",
"count",
"after",
"a",
"post",
"unaproval",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_member/receivers.py#L58-L78 | train |
ellmetha/django-machina | machina/apps/forum_member/receivers.py | decrease_posts_count_after_post_deletion | def decrease_posts_count_after_post_deletion(sender, instance, **kwargs):
""" Decreases the member's post count after a post deletion.
This receiver handles the deletion of a forum post: the posts count related to the post's
author is decreased.
"""
if not instance.approved:
# If a post has... | python | def decrease_posts_count_after_post_deletion(sender, instance, **kwargs):
""" Decreases the member's post count after a post deletion.
This receiver handles the deletion of a forum post: the posts count related to the post's
author is decreased.
"""
if not instance.approved:
# If a post has... | [
"def",
"decrease_posts_count_after_post_deletion",
"(",
"sender",
",",
"instance",
",",
"**",
"kwargs",
")",
":",
"if",
"not",
"instance",
".",
"approved",
":",
"return",
"try",
":",
"assert",
"instance",
".",
"poster_id",
"is",
"not",
"None",
"poster",
"=",
... | Decreases the member's post count after a post deletion.
This receiver handles the deletion of a forum post: the posts count related to the post's
author is decreased. | [
"Decreases",
"the",
"member",
"s",
"post",
"count",
"after",
"a",
"post",
"deletion",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_member/receivers.py#L82-L108 | train |
ellmetha/django-machina | machina/apps/forum_moderation/views.py | TopicLockView.lock | def lock(self, request, *args, **kwargs):
""" Locks the considered topic and retirects the user to the success URL. """
self.object = self.get_object()
success_url = self.get_success_url()
self.object.status = Topic.TOPIC_LOCKED
self.object.save()
messages.success(self.re... | python | def lock(self, request, *args, **kwargs):
""" Locks the considered topic and retirects the user to the success URL. """
self.object = self.get_object()
success_url = self.get_success_url()
self.object.status = Topic.TOPIC_LOCKED
self.object.save()
messages.success(self.re... | [
"def",
"lock",
"(",
"self",
",",
"request",
",",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"self",
".",
"object",
"=",
"self",
".",
"get_object",
"(",
")",
"success_url",
"=",
"self",
".",
"get_success_url",
"(",
")",
"self",
".",
"object",
".",
... | Locks the considered topic and retirects the user to the success URL. | [
"Locks",
"the",
"considered",
"topic",
"and",
"retirects",
"the",
"user",
"to",
"the",
"success",
"URL",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_moderation/views.py#L42-L49 | train |
ellmetha/django-machina | machina/apps/forum_moderation/views.py | TopicUnlockView.unlock | def unlock(self, request, *args, **kwargs):
""" Unlocks the considered topic and retirects the user to the success URL. """
self.object = self.get_object()
success_url = self.get_success_url()
self.object.status = Topic.TOPIC_UNLOCKED
self.object.save()
messages.success(s... | python | def unlock(self, request, *args, **kwargs):
""" Unlocks the considered topic and retirects the user to the success URL. """
self.object = self.get_object()
success_url = self.get_success_url()
self.object.status = Topic.TOPIC_UNLOCKED
self.object.save()
messages.success(s... | [
"def",
"unlock",
"(",
"self",
",",
"request",
",",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"self",
".",
"object",
"=",
"self",
".",
"get_object",
"(",
")",
"success_url",
"=",
"self",
".",
"get_success_url",
"(",
")",
"self",
".",
"object",
".",
... | Unlocks the considered topic and retirects the user to the success URL. | [
"Unlocks",
"the",
"considered",
"topic",
"and",
"retirects",
"the",
"user",
"to",
"the",
"success",
"URL",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_moderation/views.py#L91-L98 | train |
ellmetha/django-machina | machina/apps/forum_moderation/views.py | TopicUpdateTypeBaseView.update_type | def update_type(self, request, *args, **kwargs):
""" Updates the type of the considered topic and retirects the user to the success URL.
"""
self.object = self.get_object()
success_url = self.get_success_url()
self.object.type = self.target_type
self.object.save()
... | python | def update_type(self, request, *args, **kwargs):
""" Updates the type of the considered topic and retirects the user to the success URL.
"""
self.object = self.get_object()
success_url = self.get_success_url()
self.object.type = self.target_type
self.object.save()
... | [
"def",
"update_type",
"(",
"self",
",",
"request",
",",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"self",
".",
"object",
"=",
"self",
".",
"get_object",
"(",
")",
"success_url",
"=",
"self",
".",
"get_success_url",
"(",
")",
"self",
".",
"object",
... | Updates the type of the considered topic and retirects the user to the success URL. | [
"Updates",
"the",
"type",
"of",
"the",
"considered",
"topic",
"and",
"retirects",
"the",
"user",
"to",
"the",
"success",
"URL",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_moderation/views.py#L257-L265 | train |
ellmetha/django-machina | machina/apps/forum_moderation/views.py | PostApproveView.approve | def approve(self, request, *args, **kwargs):
""" Approves the considered post and retirects the user to the success URL. """
self.object = self.get_object()
success_url = self.get_success_url()
self.object.approved = True
self.object.save()
messages.success(self.request, ... | python | def approve(self, request, *args, **kwargs):
""" Approves the considered post and retirects the user to the success URL. """
self.object = self.get_object()
success_url = self.get_success_url()
self.object.approved = True
self.object.save()
messages.success(self.request, ... | [
"def",
"approve",
"(",
"self",
",",
"request",
",",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"self",
".",
"object",
"=",
"self",
".",
"get_object",
"(",
")",
"success_url",
"=",
"self",
".",
"get_success_url",
"(",
")",
"self",
".",
"object",
".",... | Approves the considered post and retirects the user to the success URL. | [
"Approves",
"the",
"considered",
"post",
"and",
"retirects",
"the",
"user",
"to",
"the",
"success",
"URL",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_moderation/views.py#L404-L411 | train |
ellmetha/django-machina | machina/apps/forum_moderation/views.py | PostDisapproveView.disapprove | def disapprove(self, request, *args, **kwargs):
""" Disapproves the considered post and retirects the user to the success URL. """
self.object = self.get_object()
success_url = self.get_success_url()
self.object.delete()
messages.success(self.request, self.success_message)
... | python | def disapprove(self, request, *args, **kwargs):
""" Disapproves the considered post and retirects the user to the success URL. """
self.object = self.get_object()
success_url = self.get_success_url()
self.object.delete()
messages.success(self.request, self.success_message)
... | [
"def",
"disapprove",
"(",
"self",
",",
"request",
",",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"self",
".",
"object",
"=",
"self",
".",
"get_object",
"(",
")",
"success_url",
"=",
"self",
".",
"get_success_url",
"(",
")",
"self",
".",
"object",
"... | Disapproves the considered post and retirects the user to the success URL. | [
"Disapproves",
"the",
"considered",
"post",
"and",
"retirects",
"the",
"user",
"to",
"the",
"success",
"URL",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_moderation/views.py#L446-L452 | train |
ellmetha/django-machina | machina/apps/forum_member/views.py | UserPostsView.poster | def poster(self):
""" Returns the considered user. """
user_model = get_user_model()
return get_object_or_404(user_model, pk=self.kwargs[self.user_pk_url_kwarg]) | python | def poster(self):
""" Returns the considered user. """
user_model = get_user_model()
return get_object_or_404(user_model, pk=self.kwargs[self.user_pk_url_kwarg]) | [
"def",
"poster",
"(",
"self",
")",
":",
"user_model",
"=",
"get_user_model",
"(",
")",
"return",
"get_object_or_404",
"(",
"user_model",
",",
"pk",
"=",
"self",
".",
"kwargs",
"[",
"self",
".",
"user_pk_url_kwarg",
"]",
")"
] | Returns the considered user. | [
"Returns",
"the",
"considered",
"user",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_member/views.py#L66-L69 | train |
ellmetha/django-machina | machina/apps/forum_member/views.py | TopicSubscribeView.subscribe | def subscribe(self, request, *args, **kwargs):
""" Performs the subscribe action. """
self.object = self.get_object()
self.object.subscribers.add(request.user)
messages.success(self.request, self.success_message)
return HttpResponseRedirect(self.get_success_url()) | python | def subscribe(self, request, *args, **kwargs):
""" Performs the subscribe action. """
self.object = self.get_object()
self.object.subscribers.add(request.user)
messages.success(self.request, self.success_message)
return HttpResponseRedirect(self.get_success_url()) | [
"def",
"subscribe",
"(",
"self",
",",
"request",
",",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"self",
".",
"object",
"=",
"self",
".",
"get_object",
"(",
")",
"self",
".",
"object",
".",
"subscribers",
".",
"add",
"(",
"request",
".",
"user",
"... | Performs the subscribe action. | [
"Performs",
"the",
"subscribe",
"action",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_member/views.py#L145-L150 | train |
ellmetha/django-machina | machina/apps/forum_member/views.py | TopicUnsubscribeView.unsubscribe | def unsubscribe(self, request, *args, **kwargs):
""" Performs the unsubscribe action. """
self.object = self.get_object()
self.object.subscribers.remove(request.user)
messages.success(self.request, self.success_message)
return HttpResponseRedirect(self.get_success_url()) | python | def unsubscribe(self, request, *args, **kwargs):
""" Performs the unsubscribe action. """
self.object = self.get_object()
self.object.subscribers.remove(request.user)
messages.success(self.request, self.success_message)
return HttpResponseRedirect(self.get_success_url()) | [
"def",
"unsubscribe",
"(",
"self",
",",
"request",
",",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"self",
".",
"object",
"=",
"self",
".",
"get_object",
"(",
")",
"self",
".",
"object",
".",
"subscribers",
".",
"remove",
"(",
"request",
".",
"user"... | Performs the unsubscribe action. | [
"Performs",
"the",
"unsubscribe",
"action",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_member/views.py#L191-L196 | train |
ellmetha/django-machina | machina/apps/forum_conversation/receivers.py | update_topic_counter | def update_topic_counter(sender, topic, user, request, response, **kwargs):
""" Handles the update of the views counter associated with topics. """
topic.__class__._default_manager.filter(id=topic.id).update(views_count=F('views_count') + 1) | python | def update_topic_counter(sender, topic, user, request, response, **kwargs):
""" Handles the update of the views counter associated with topics. """
topic.__class__._default_manager.filter(id=topic.id).update(views_count=F('views_count') + 1) | [
"def",
"update_topic_counter",
"(",
"sender",
",",
"topic",
",",
"user",
",",
"request",
",",
"response",
",",
"**",
"kwargs",
")",
":",
"topic",
".",
"__class__",
".",
"_default_manager",
".",
"filter",
"(",
"id",
"=",
"topic",
".",
"id",
")",
".",
"u... | Handles the update of the views counter associated with topics. | [
"Handles",
"the",
"update",
"of",
"the",
"views",
"counter",
"associated",
"with",
"topics",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_conversation/receivers.py#L16-L18 | train |
ellmetha/django-machina | machina/apps/forum_conversation/views.py | TopicView.get_topic | def get_topic(self):
""" Returns the topic to consider. """
if not hasattr(self, 'topic'):
self.topic = get_object_or_404(
Topic.objects.select_related('forum').all(), pk=self.kwargs['pk'],
)
return self.topic | python | def get_topic(self):
""" Returns the topic to consider. """
if not hasattr(self, 'topic'):
self.topic = get_object_or_404(
Topic.objects.select_related('forum').all(), pk=self.kwargs['pk'],
)
return self.topic | [
"def",
"get_topic",
"(",
"self",
")",
":",
"if",
"not",
"hasattr",
"(",
"self",
",",
"'topic'",
")",
":",
"self",
".",
"topic",
"=",
"get_object_or_404",
"(",
"Topic",
".",
"objects",
".",
"select_related",
"(",
"'forum'",
")",
".",
"all",
"(",
")",
... | Returns the topic to consider. | [
"Returns",
"the",
"topic",
"to",
"consider",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_conversation/views.py#L73-L79 | train |
ellmetha/django-machina | machina/apps/forum_conversation/views.py | BasePostFormView.init_attachment_cache | def init_attachment_cache(self):
""" Initializes the attachment cache for the current view. """
if self.request.method == 'GET':
# Invalidates previous attachments
attachments_cache.delete(self.get_attachments_cache_key(self.request))
return
# Try to restore ... | python | def init_attachment_cache(self):
""" Initializes the attachment cache for the current view. """
if self.request.method == 'GET':
# Invalidates previous attachments
attachments_cache.delete(self.get_attachments_cache_key(self.request))
return
# Try to restore ... | [
"def",
"init_attachment_cache",
"(",
"self",
")",
":",
"if",
"self",
".",
"request",
".",
"method",
"==",
"'GET'",
":",
"attachments_cache",
".",
"delete",
"(",
"self",
".",
"get_attachments_cache_key",
"(",
"self",
".",
"request",
")",
")",
"return",
"attac... | Initializes the attachment cache for the current view. | [
"Initializes",
"the",
"attachment",
"cache",
"for",
"the",
"current",
"view",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_conversation/views.py#L179-L195 | train |
ellmetha/django-machina | machina/apps/forum_conversation/views.py | BasePostFormView.get_post_form_kwargs | def get_post_form_kwargs(self):
""" Returns the keyword arguments for instantiating the post form. """
kwargs = {
'user': self.request.user,
'forum': self.get_forum(),
'topic': self.get_topic(),
}
post = self.get_post()
if post:
kw... | python | def get_post_form_kwargs(self):
""" Returns the keyword arguments for instantiating the post form. """
kwargs = {
'user': self.request.user,
'forum': self.get_forum(),
'topic': self.get_topic(),
}
post = self.get_post()
if post:
kw... | [
"def",
"get_post_form_kwargs",
"(",
"self",
")",
":",
"kwargs",
"=",
"{",
"'user'",
":",
"self",
".",
"request",
".",
"user",
",",
"'forum'",
":",
"self",
".",
"get_forum",
"(",
")",
",",
"'topic'",
":",
"self",
".",
"get_topic",
"(",
")",
",",
"}",
... | Returns the keyword arguments for instantiating the post form. | [
"Returns",
"the",
"keyword",
"arguments",
"for",
"instantiating",
"the",
"post",
"form",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_conversation/views.py#L209-L226 | train |
ellmetha/django-machina | machina/apps/forum_conversation/views.py | BasePostFormView.get_attachment_formset | def get_attachment_formset(self, formset_class):
""" Returns an instance of the attachment formset to be used in the view. """
if (
self.request.forum_permission_handler.can_attach_files(
self.get_forum(), self.request.user,
)
):
return formset... | python | def get_attachment_formset(self, formset_class):
""" Returns an instance of the attachment formset to be used in the view. """
if (
self.request.forum_permission_handler.can_attach_files(
self.get_forum(), self.request.user,
)
):
return formset... | [
"def",
"get_attachment_formset",
"(",
"self",
",",
"formset_class",
")",
":",
"if",
"(",
"self",
".",
"request",
".",
"forum_permission_handler",
".",
"can_attach_files",
"(",
"self",
".",
"get_forum",
"(",
")",
",",
"self",
".",
"request",
".",
"user",
",",... | Returns an instance of the attachment formset to be used in the view. | [
"Returns",
"an",
"instance",
"of",
"the",
"attachment",
"formset",
"to",
"be",
"used",
"in",
"the",
"view",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_conversation/views.py#L228-L235 | train |
ellmetha/django-machina | machina/apps/forum_conversation/views.py | BasePostFormView.get_attachment_formset_kwargs | def get_attachment_formset_kwargs(self):
""" Returns the keyword arguments for instantiating the attachment formset. """
kwargs = {
'prefix': 'attachment',
}
if self.request.method in ('POST', 'PUT'):
kwargs.update({
'data': self.request.POST,
... | python | def get_attachment_formset_kwargs(self):
""" Returns the keyword arguments for instantiating the attachment formset. """
kwargs = {
'prefix': 'attachment',
}
if self.request.method in ('POST', 'PUT'):
kwargs.update({
'data': self.request.POST,
... | [
"def",
"get_attachment_formset_kwargs",
"(",
"self",
")",
":",
"kwargs",
"=",
"{",
"'prefix'",
":",
"'attachment'",
",",
"}",
"if",
"self",
".",
"request",
".",
"method",
"in",
"(",
"'POST'",
",",
"'PUT'",
")",
":",
"kwargs",
".",
"update",
"(",
"{",
"... | Returns the keyword arguments for instantiating the attachment formset. | [
"Returns",
"the",
"keyword",
"arguments",
"for",
"instantiating",
"the",
"attachment",
"formset",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_conversation/views.py#L241-L258 | train |
ellmetha/django-machina | machina/apps/forum_conversation/views.py | BasePostFormView.get_forum | def get_forum(self):
""" Returns the considered forum. """
pk = self.kwargs.get(self.forum_pk_url_kwarg, None)
if not pk: # pragma: no cover
# This should never happen
return
if not hasattr(self, '_forum'):
self._forum = get_object_or_404(Forum, pk=pk... | python | def get_forum(self):
""" Returns the considered forum. """
pk = self.kwargs.get(self.forum_pk_url_kwarg, None)
if not pk: # pragma: no cover
# This should never happen
return
if not hasattr(self, '_forum'):
self._forum = get_object_or_404(Forum, pk=pk... | [
"def",
"get_forum",
"(",
"self",
")",
":",
"pk",
"=",
"self",
".",
"kwargs",
".",
"get",
"(",
"self",
".",
"forum_pk_url_kwarg",
",",
"None",
")",
"if",
"not",
"pk",
":",
"return",
"if",
"not",
"hasattr",
"(",
"self",
",",
"'_forum'",
")",
":",
"se... | Returns the considered forum. | [
"Returns",
"the",
"considered",
"forum",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_conversation/views.py#L295-L303 | train |
ellmetha/django-machina | machina/apps/forum_conversation/views.py | BasePostFormView.get_topic | def get_topic(self):
""" Returns the considered topic if applicable. """
pk = self.kwargs.get(self.topic_pk_url_kwarg, None)
if not pk:
return
if not hasattr(self, '_topic'):
self._topic = get_object_or_404(Topic, pk=pk)
return self._topic | python | def get_topic(self):
""" Returns the considered topic if applicable. """
pk = self.kwargs.get(self.topic_pk_url_kwarg, None)
if not pk:
return
if not hasattr(self, '_topic'):
self._topic = get_object_or_404(Topic, pk=pk)
return self._topic | [
"def",
"get_topic",
"(",
"self",
")",
":",
"pk",
"=",
"self",
".",
"kwargs",
".",
"get",
"(",
"self",
".",
"topic_pk_url_kwarg",
",",
"None",
")",
"if",
"not",
"pk",
":",
"return",
"if",
"not",
"hasattr",
"(",
"self",
",",
"'_topic'",
")",
":",
"se... | Returns the considered topic if applicable. | [
"Returns",
"the",
"considered",
"topic",
"if",
"applicable",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_conversation/views.py#L305-L312 | train |
ellmetha/django-machina | machina/apps/forum_conversation/views.py | BasePostFormView.get_post | def get_post(self):
""" Returns the considered post if applicable. """
pk = self.kwargs.get(self.post_pk_url_kwarg, None)
if not pk:
return
if not hasattr(self, '_forum_post'):
self._forum_post = get_object_or_404(Post, pk=pk)
return self._forum_post | python | def get_post(self):
""" Returns the considered post if applicable. """
pk = self.kwargs.get(self.post_pk_url_kwarg, None)
if not pk:
return
if not hasattr(self, '_forum_post'):
self._forum_post = get_object_or_404(Post, pk=pk)
return self._forum_post | [
"def",
"get_post",
"(",
"self",
")",
":",
"pk",
"=",
"self",
".",
"kwargs",
".",
"get",
"(",
"self",
".",
"post_pk_url_kwarg",
",",
"None",
")",
"if",
"not",
"pk",
":",
"return",
"if",
"not",
"hasattr",
"(",
"self",
",",
"'_forum_post'",
")",
":",
... | Returns the considered post if applicable. | [
"Returns",
"the",
"considered",
"post",
"if",
"applicable",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_conversation/views.py#L314-L321 | train |
ellmetha/django-machina | machina/apps/forum_conversation/views.py | BaseTopicFormView.get_poll_option_formset | def get_poll_option_formset(self, formset_class):
""" Returns an instance of the poll option formset to be used in the view. """
if self.request.forum_permission_handler.can_create_polls(
self.get_forum(), self.request.user,
):
return formset_class(**self.get_poll_option_... | python | def get_poll_option_formset(self, formset_class):
""" Returns an instance of the poll option formset to be used in the view. """
if self.request.forum_permission_handler.can_create_polls(
self.get_forum(), self.request.user,
):
return formset_class(**self.get_poll_option_... | [
"def",
"get_poll_option_formset",
"(",
"self",
",",
"formset_class",
")",
":",
"if",
"self",
".",
"request",
".",
"forum_permission_handler",
".",
"can_create_polls",
"(",
"self",
".",
"get_forum",
"(",
")",
",",
"self",
".",
"request",
".",
"user",
",",
")"... | Returns an instance of the poll option formset to be used in the view. | [
"Returns",
"an",
"instance",
"of",
"the",
"poll",
"option",
"formset",
"to",
"be",
"used",
"in",
"the",
"view",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_conversation/views.py#L448-L453 | train |
ellmetha/django-machina | machina/apps/forum_conversation/views.py | BaseTopicFormView.get_poll_option_formset_kwargs | def get_poll_option_formset_kwargs(self):
""" Returns the keyword arguments for instantiating the poll option formset. """
kwargs = {
'prefix': 'poll',
}
if self.request.method in ('POST', 'PUT'):
kwargs.update({
'data': self.request.POST,
... | python | def get_poll_option_formset_kwargs(self):
""" Returns the keyword arguments for instantiating the poll option formset. """
kwargs = {
'prefix': 'poll',
}
if self.request.method in ('POST', 'PUT'):
kwargs.update({
'data': self.request.POST,
... | [
"def",
"get_poll_option_formset_kwargs",
"(",
"self",
")",
":",
"kwargs",
"=",
"{",
"'prefix'",
":",
"'poll'",
",",
"}",
"if",
"self",
".",
"request",
".",
"method",
"in",
"(",
"'POST'",
",",
"'PUT'",
")",
":",
"kwargs",
".",
"update",
"(",
"{",
"'data... | Returns the keyword arguments for instantiating the poll option formset. | [
"Returns",
"the",
"keyword",
"arguments",
"for",
"instantiating",
"the",
"poll",
"option",
"formset",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_conversation/views.py#L459-L476 | train |
e1ven/Robohash | robohash/robohash.py | Robohash._remove_exts | def _remove_exts(self,string):
"""
Sets the string, to create the Robohash
"""
# If the user hasn't disabled it, we will detect image extensions, such as .png, .jpg, etc.
# We'll remove them from the string before hashing.
# This ensures that /Bear.png and /Bear.bmp will... | python | def _remove_exts(self,string):
"""
Sets the string, to create the Robohash
"""
# If the user hasn't disabled it, we will detect image extensions, such as .png, .jpg, etc.
# We'll remove them from the string before hashing.
# This ensures that /Bear.png and /Bear.bmp will... | [
"def",
"_remove_exts",
"(",
"self",
",",
"string",
")",
":",
"if",
"string",
".",
"lower",
"(",
")",
".",
"endswith",
"(",
"(",
"'.png'",
",",
"'.gif'",
",",
"'.jpg'",
",",
"'.bmp'",
",",
"'.jpeg'",
",",
"'.ppm'",
",",
"'.datauri'",
")",
")",
":",
... | Sets the string, to create the Robohash | [
"Sets",
"the",
"string",
"to",
"create",
"the",
"Robohash"
] | 8dbbf9e69948ae2abc93c27511ef04f90b56c4d3 | https://github.com/e1ven/Robohash/blob/8dbbf9e69948ae2abc93c27511ef04f90b56c4d3/robohash/robohash.py#L46-L61 | train |
e1ven/Robohash | robohash/robohash.py | Robohash._get_list_of_files | def _get_list_of_files(self,path):
"""
Go through each subdirectory of `path`, and choose one file from each to use in our hash.
Continue to increase self.iter, so we use a different 'slot' of randomness each time.
"""
chosen_files = []
# Get a list of all subdirectories... | python | def _get_list_of_files(self,path):
"""
Go through each subdirectory of `path`, and choose one file from each to use in our hash.
Continue to increase self.iter, so we use a different 'slot' of randomness each time.
"""
chosen_files = []
# Get a list of all subdirectories... | [
"def",
"_get_list_of_files",
"(",
"self",
",",
"path",
")",
":",
"chosen_files",
"=",
"[",
"]",
"directories",
"=",
"[",
"]",
"for",
"root",
",",
"dirs",
",",
"files",
"in",
"natsort",
".",
"natsorted",
"(",
"os",
".",
"walk",
"(",
"path",
",",
"topd... | Go through each subdirectory of `path`, and choose one file from each to use in our hash.
Continue to increase self.iter, so we use a different 'slot' of randomness each time. | [
"Go",
"through",
"each",
"subdirectory",
"of",
"path",
"and",
"choose",
"one",
"file",
"from",
"each",
"to",
"use",
"in",
"our",
"hash",
".",
"Continue",
"to",
"increase",
"self",
".",
"iter",
"so",
"we",
"use",
"a",
"different",
"slot",
"of",
"randomnes... | 8dbbf9e69948ae2abc93c27511ef04f90b56c4d3 | https://github.com/e1ven/Robohash/blob/8dbbf9e69948ae2abc93c27511ef04f90b56c4d3/robohash/robohash.py#L85-L113 | train |
e1ven/Robohash | robohash/robohash.py | Robohash.assemble | def assemble(self,roboset=None,color=None,format=None,bgset=None,sizex=300,sizey=300):
"""
Build our Robot!
Returns the robot image itself.
"""
# Allow users to manually specify a robot 'set' that they like.
# Ensure that this is one of the allowed choices, or allow all
... | python | def assemble(self,roboset=None,color=None,format=None,bgset=None,sizex=300,sizey=300):
"""
Build our Robot!
Returns the robot image itself.
"""
# Allow users to manually specify a robot 'set' that they like.
# Ensure that this is one of the allowed choices, or allow all
... | [
"def",
"assemble",
"(",
"self",
",",
"roboset",
"=",
"None",
",",
"color",
"=",
"None",
",",
"format",
"=",
"None",
",",
"bgset",
"=",
"None",
",",
"sizex",
"=",
"300",
",",
"sizey",
"=",
"300",
")",
":",
"if",
"roboset",
"==",
"'any'",
":",
"rob... | Build our Robot!
Returns the robot image itself. | [
"Build",
"our",
"Robot!",
"Returns",
"the",
"robot",
"image",
"itself",
"."
] | 8dbbf9e69948ae2abc93c27511ef04f90b56c4d3 | https://github.com/e1ven/Robohash/blob/8dbbf9e69948ae2abc93c27511ef04f90b56c4d3/robohash/robohash.py#L115-L198 | train |
tensorflow/skflow | scripts/docs/docs.py | collect_members | def collect_members(module_to_name):
"""Collect all symbols from a list of modules.
Args:
module_to_name: Dictionary mapping modules to short names.
Returns:
Dictionary mapping name to (fullname, member) pairs.
"""
members = {}
for module, module_name in module_to_name.items():
all_names = get... | python | def collect_members(module_to_name):
"""Collect all symbols from a list of modules.
Args:
module_to_name: Dictionary mapping modules to short names.
Returns:
Dictionary mapping name to (fullname, member) pairs.
"""
members = {}
for module, module_name in module_to_name.items():
all_names = get... | [
"def",
"collect_members",
"(",
"module_to_name",
")",
":",
"members",
"=",
"{",
"}",
"for",
"module",
",",
"module_name",
"in",
"module_to_name",
".",
"items",
"(",
")",
":",
"all_names",
"=",
"getattr",
"(",
"module",
",",
"\"__all__\"",
",",
"None",
")",... | Collect all symbols from a list of modules.
Args:
module_to_name: Dictionary mapping modules to short names.
Returns:
Dictionary mapping name to (fullname, member) pairs. | [
"Collect",
"all",
"symbols",
"from",
"a",
"list",
"of",
"modules",
"."
] | f8da498a1abb7562f57dfc7010941578103061b6 | https://github.com/tensorflow/skflow/blob/f8da498a1abb7562f57dfc7010941578103061b6/scripts/docs/docs.py#L103-L132 | train |
tensorflow/skflow | scripts/docs/docs.py | _get_anchor | def _get_anchor(module_to_name, fullname):
"""Turn a full member name into an anchor.
Args:
module_to_name: Dictionary mapping modules to short names.
fullname: Fully qualified name of symbol.
Returns:
HTML anchor string. The longest module name prefix of fullname is
removed to make the anchor.... | python | def _get_anchor(module_to_name, fullname):
"""Turn a full member name into an anchor.
Args:
module_to_name: Dictionary mapping modules to short names.
fullname: Fully qualified name of symbol.
Returns:
HTML anchor string. The longest module name prefix of fullname is
removed to make the anchor.... | [
"def",
"_get_anchor",
"(",
"module_to_name",
",",
"fullname",
")",
":",
"if",
"not",
"_anchor_re",
".",
"match",
"(",
"fullname",
")",
":",
"raise",
"ValueError",
"(",
"\"'%s' is not a valid anchor\"",
"%",
"fullname",
")",
"anchor",
"=",
"fullname",
"for",
"m... | Turn a full member name into an anchor.
Args:
module_to_name: Dictionary mapping modules to short names.
fullname: Fully qualified name of symbol.
Returns:
HTML anchor string. The longest module name prefix of fullname is
removed to make the anchor.
Raises:
ValueError: If fullname uses cha... | [
"Turn",
"a",
"full",
"member",
"name",
"into",
"an",
"anchor",
"."
] | f8da498a1abb7562f57dfc7010941578103061b6 | https://github.com/tensorflow/skflow/blob/f8da498a1abb7562f57dfc7010941578103061b6/scripts/docs/docs.py#L135-L158 | train |
tensorflow/skflow | scripts/docs/docs.py | write_libraries | def write_libraries(dir, libraries):
"""Write a list of libraries to disk.
Args:
dir: Output directory.
libraries: List of (filename, library) pairs.
"""
files = [open(os.path.join(dir, k), "w") for k, _ in libraries]
# Document mentioned symbols for all libraries
for f, (_, v) in zip(files, librar... | python | def write_libraries(dir, libraries):
"""Write a list of libraries to disk.
Args:
dir: Output directory.
libraries: List of (filename, library) pairs.
"""
files = [open(os.path.join(dir, k), "w") for k, _ in libraries]
# Document mentioned symbols for all libraries
for f, (_, v) in zip(files, librar... | [
"def",
"write_libraries",
"(",
"dir",
",",
"libraries",
")",
":",
"files",
"=",
"[",
"open",
"(",
"os",
".",
"path",
".",
"join",
"(",
"dir",
",",
"k",
")",
",",
"\"w\"",
")",
"for",
"k",
",",
"_",
"in",
"libraries",
"]",
"for",
"f",
",",
"(",
... | Write a list of libraries to disk.
Args:
dir: Output directory.
libraries: List of (filename, library) pairs. | [
"Write",
"a",
"list",
"of",
"libraries",
"to",
"disk",
"."
] | f8da498a1abb7562f57dfc7010941578103061b6 | https://github.com/tensorflow/skflow/blob/f8da498a1abb7562f57dfc7010941578103061b6/scripts/docs/docs.py#L514-L530 | train |
tensorflow/skflow | scripts/docs/docs.py | Index.write_markdown_to_file | def write_markdown_to_file(self, f):
"""Writes this index to file `f`.
The output is formatted as an unordered list. Each list element
contains the title of the library, followed by a list of symbols
in that library hyperlinked to the corresponding anchor in that
library.
Args:
f: The ou... | python | def write_markdown_to_file(self, f):
"""Writes this index to file `f`.
The output is formatted as an unordered list. Each list element
contains the title of the library, followed by a list of symbols
in that library hyperlinked to the corresponding anchor in that
library.
Args:
f: The ou... | [
"def",
"write_markdown_to_file",
"(",
"self",
",",
"f",
")",
":",
"print",
"(",
"\"---\"",
",",
"file",
"=",
"f",
")",
"print",
"(",
"\"---\"",
",",
"file",
"=",
"f",
")",
"print",
"(",
"\"<!-- This file is machine generated: DO NOT EDIT! ",
",",
"file",
"="... | Writes this index to file `f`.
The output is formatted as an unordered list. Each list element
contains the title of the library, followed by a list of symbols
in that library hyperlinked to the corresponding anchor in that
library.
Args:
f: The output file. | [
"Writes",
"this",
"index",
"to",
"file",
"f",
"."
] | f8da498a1abb7562f57dfc7010941578103061b6 | https://github.com/tensorflow/skflow/blob/f8da498a1abb7562f57dfc7010941578103061b6/scripts/docs/docs.py#L68-L100 | train |
tensorflow/skflow | scripts/docs/docs.py | Library._should_include_member | def _should_include_member(self, name, member):
"""Returns True if this member should be included in the document."""
# Always exclude symbols matching _always_drop_symbol_re.
if _always_drop_symbol_re.match(name):
return False
# Finally, exclude any specifically-excluded symbols.
if name in s... | python | def _should_include_member(self, name, member):
"""Returns True if this member should be included in the document."""
# Always exclude symbols matching _always_drop_symbol_re.
if _always_drop_symbol_re.match(name):
return False
# Finally, exclude any specifically-excluded symbols.
if name in s... | [
"def",
"_should_include_member",
"(",
"self",
",",
"name",
",",
"member",
")",
":",
"if",
"_always_drop_symbol_re",
".",
"match",
"(",
"name",
")",
":",
"return",
"False",
"if",
"name",
"in",
"self",
".",
"_exclude_symbols",
":",
"return",
"False",
"return",... | Returns True if this member should be included in the document. | [
"Returns",
"True",
"if",
"this",
"member",
"should",
"be",
"included",
"in",
"the",
"document",
"."
] | f8da498a1abb7562f57dfc7010941578103061b6 | https://github.com/tensorflow/skflow/blob/f8da498a1abb7562f57dfc7010941578103061b6/scripts/docs/docs.py#L209-L217 | train |
tensorflow/skflow | scripts/docs/docs.py | Library.get_imported_modules | def get_imported_modules(self, module):
"""Returns the list of modules imported from `module`."""
for name, member in inspect.getmembers(module):
if inspect.ismodule(member):
yield name, member | python | def get_imported_modules(self, module):
"""Returns the list of modules imported from `module`."""
for name, member in inspect.getmembers(module):
if inspect.ismodule(member):
yield name, member | [
"def",
"get_imported_modules",
"(",
"self",
",",
"module",
")",
":",
"for",
"name",
",",
"member",
"in",
"inspect",
".",
"getmembers",
"(",
"module",
")",
":",
"if",
"inspect",
".",
"ismodule",
"(",
"member",
")",
":",
"yield",
"name",
",",
"member"
] | Returns the list of modules imported from `module`. | [
"Returns",
"the",
"list",
"of",
"modules",
"imported",
"from",
"module",
"."
] | f8da498a1abb7562f57dfc7010941578103061b6 | https://github.com/tensorflow/skflow/blob/f8da498a1abb7562f57dfc7010941578103061b6/scripts/docs/docs.py#L219-L223 | train |
tensorflow/skflow | scripts/docs/docs.py | Library.get_class_members | def get_class_members(self, cls_name, cls):
"""Returns the list of class members to document in `cls`.
This function filters the class member to ONLY return those
defined by the class. It drops the inherited ones.
Args:
cls_name: Qualified name of `cls`.
cls: An inspect object of type 'cl... | python | def get_class_members(self, cls_name, cls):
"""Returns the list of class members to document in `cls`.
This function filters the class member to ONLY return those
defined by the class. It drops the inherited ones.
Args:
cls_name: Qualified name of `cls`.
cls: An inspect object of type 'cl... | [
"def",
"get_class_members",
"(",
"self",
",",
"cls_name",
",",
"cls",
")",
":",
"for",
"name",
",",
"member",
"in",
"inspect",
".",
"getmembers",
"(",
"cls",
")",
":",
"is_method",
"=",
"inspect",
".",
"ismethod",
"(",
"member",
")",
"or",
"inspect",
"... | Returns the list of class members to document in `cls`.
This function filters the class member to ONLY return those
defined by the class. It drops the inherited ones.
Args:
cls_name: Qualified name of `cls`.
cls: An inspect object of type 'class'.
Yields:
name, member tuples. | [
"Returns",
"the",
"list",
"of",
"class",
"members",
"to",
"document",
"in",
"cls",
"."
] | f8da498a1abb7562f57dfc7010941578103061b6 | https://github.com/tensorflow/skflow/blob/f8da498a1abb7562f57dfc7010941578103061b6/scripts/docs/docs.py#L225-L246 | train |
tensorflow/skflow | scripts/docs/docs.py | Library._generate_signature_for_function | def _generate_signature_for_function(self, func):
"""Given a function, returns a string representing its args."""
args_list = []
argspec = inspect.getargspec(func)
first_arg_with_default = (
len(argspec.args or []) - len(argspec.defaults or []))
for arg in argspec.args[:first_arg_with_defaul... | python | def _generate_signature_for_function(self, func):
"""Given a function, returns a string representing its args."""
args_list = []
argspec = inspect.getargspec(func)
first_arg_with_default = (
len(argspec.args or []) - len(argspec.defaults or []))
for arg in argspec.args[:first_arg_with_defaul... | [
"def",
"_generate_signature_for_function",
"(",
"self",
",",
"func",
")",
":",
"args_list",
"=",
"[",
"]",
"argspec",
"=",
"inspect",
".",
"getargspec",
"(",
"func",
")",
"first_arg_with_default",
"=",
"(",
"len",
"(",
"argspec",
".",
"args",
"or",
"[",
"]... | Given a function, returns a string representing its args. | [
"Given",
"a",
"function",
"returns",
"a",
"string",
"representing",
"its",
"args",
"."
] | f8da498a1abb7562f57dfc7010941578103061b6 | https://github.com/tensorflow/skflow/blob/f8da498a1abb7562f57dfc7010941578103061b6/scripts/docs/docs.py#L248-L279 | train |
tensorflow/skflow | scripts/docs/docs.py | Library._remove_docstring_indent | def _remove_docstring_indent(self, docstring):
"""Remove indenting.
We follow Python's convention and remove the minimum indent of the lines
after the first, see:
https://www.python.org/dev/peps/pep-0257/#handling-docstring-indentation
preserving relative indentation.
Args:
docstring: A ... | python | def _remove_docstring_indent(self, docstring):
"""Remove indenting.
We follow Python's convention and remove the minimum indent of the lines
after the first, see:
https://www.python.org/dev/peps/pep-0257/#handling-docstring-indentation
preserving relative indentation.
Args:
docstring: A ... | [
"def",
"_remove_docstring_indent",
"(",
"self",
",",
"docstring",
")",
":",
"docstring",
"=",
"docstring",
"or",
"\"\"",
"lines",
"=",
"docstring",
".",
"strip",
"(",
")",
".",
"split",
"(",
"\"\\n\"",
")",
"min_indent",
"=",
"len",
"(",
"docstring",
")",
... | Remove indenting.
We follow Python's convention and remove the minimum indent of the lines
after the first, see:
https://www.python.org/dev/peps/pep-0257/#handling-docstring-indentation
preserving relative indentation.
Args:
docstring: A docstring.
Returns:
A list of strings, one ... | [
"Remove",
"indenting",
"."
] | f8da498a1abb7562f57dfc7010941578103061b6 | https://github.com/tensorflow/skflow/blob/f8da498a1abb7562f57dfc7010941578103061b6/scripts/docs/docs.py#L281-L311 | train |
tensorflow/skflow | scripts/docs/docs.py | Library._print_formatted_docstring | def _print_formatted_docstring(self, docstring, f):
"""Formats the given `docstring` as Markdown and prints it to `f`."""
lines = self._remove_docstring_indent(docstring)
# Output the lines, identifying "Args" and other section blocks.
i = 0
def _at_start_of_section():
"""Returns the header ... | python | def _print_formatted_docstring(self, docstring, f):
"""Formats the given `docstring` as Markdown and prints it to `f`."""
lines = self._remove_docstring_indent(docstring)
# Output the lines, identifying "Args" and other section blocks.
i = 0
def _at_start_of_section():
"""Returns the header ... | [
"def",
"_print_formatted_docstring",
"(",
"self",
",",
"docstring",
",",
"f",
")",
":",
"lines",
"=",
"self",
".",
"_remove_docstring_indent",
"(",
"docstring",
")",
"i",
"=",
"0",
"def",
"_at_start_of_section",
"(",
")",
":",
"l",
"=",
"lines",
"[",
"i",
... | Formats the given `docstring` as Markdown and prints it to `f`. | [
"Formats",
"the",
"given",
"docstring",
"as",
"Markdown",
"and",
"prints",
"it",
"to",
"f",
"."
] | f8da498a1abb7562f57dfc7010941578103061b6 | https://github.com/tensorflow/skflow/blob/f8da498a1abb7562f57dfc7010941578103061b6/scripts/docs/docs.py#L313-L364 | train |
tensorflow/skflow | scripts/docs/docs.py | Library._print_function | def _print_function(self, f, prefix, fullname, func):
"""Prints the given function to `f`."""
heading = prefix + " `" + fullname
if not isinstance(func, property):
heading += self._generate_signature_for_function(func)
heading += "` {#%s}" % _get_anchor(self._module_to_name, fullname)
print(he... | python | def _print_function(self, f, prefix, fullname, func):
"""Prints the given function to `f`."""
heading = prefix + " `" + fullname
if not isinstance(func, property):
heading += self._generate_signature_for_function(func)
heading += "` {#%s}" % _get_anchor(self._module_to_name, fullname)
print(he... | [
"def",
"_print_function",
"(",
"self",
",",
"f",
",",
"prefix",
",",
"fullname",
",",
"func",
")",
":",
"heading",
"=",
"prefix",
"+",
"\" `\"",
"+",
"fullname",
"if",
"not",
"isinstance",
"(",
"func",
",",
"property",
")",
":",
"heading",
"+=",
"self"... | Prints the given function to `f`. | [
"Prints",
"the",
"given",
"function",
"to",
"f",
"."
] | f8da498a1abb7562f57dfc7010941578103061b6 | https://github.com/tensorflow/skflow/blob/f8da498a1abb7562f57dfc7010941578103061b6/scripts/docs/docs.py#L366-L375 | train |
tensorflow/skflow | scripts/docs/docs.py | Library._write_member_markdown_to_file | def _write_member_markdown_to_file(self, f, prefix, name, member):
"""Print `member` to `f`."""
if (inspect.isfunction(member) or inspect.ismethod(member) or
isinstance(member, property)):
print("- - -", file=f)
print("", file=f)
self._print_function(f, prefix, name, member)
prin... | python | def _write_member_markdown_to_file(self, f, prefix, name, member):
"""Print `member` to `f`."""
if (inspect.isfunction(member) or inspect.ismethod(member) or
isinstance(member, property)):
print("- - -", file=f)
print("", file=f)
self._print_function(f, prefix, name, member)
prin... | [
"def",
"_write_member_markdown_to_file",
"(",
"self",
",",
"f",
",",
"prefix",
",",
"name",
",",
"member",
")",
":",
"if",
"(",
"inspect",
".",
"isfunction",
"(",
"member",
")",
"or",
"inspect",
".",
"ismethod",
"(",
"member",
")",
"or",
"isinstance",
"(... | Print `member` to `f`. | [
"Print",
"member",
"to",
"f",
"."
] | f8da498a1abb7562f57dfc7010941578103061b6 | https://github.com/tensorflow/skflow/blob/f8da498a1abb7562f57dfc7010941578103061b6/scripts/docs/docs.py#L377-L395 | train |
tensorflow/skflow | scripts/docs/docs.py | Library._write_class_markdown_to_file | def _write_class_markdown_to_file(self, f, name, cls):
"""Write the class doc to `f`.
Args:
f: File to write to.
prefix: Prefix for names.
cls: class object.
name: name to use.
"""
# Build the list of class methods to document.
methods = dict(self.get_class_members(name, cls... | python | def _write_class_markdown_to_file(self, f, name, cls):
"""Write the class doc to `f`.
Args:
f: File to write to.
prefix: Prefix for names.
cls: class object.
name: name to use.
"""
# Build the list of class methods to document.
methods = dict(self.get_class_members(name, cls... | [
"def",
"_write_class_markdown_to_file",
"(",
"self",
",",
"f",
",",
"name",
",",
"cls",
")",
":",
"methods",
"=",
"dict",
"(",
"self",
".",
"get_class_members",
"(",
"name",
",",
"cls",
")",
")",
"num_methods",
"=",
"len",
"(",
"methods",
")",
"try",
"... | Write the class doc to `f`.
Args:
f: File to write to.
prefix: Prefix for names.
cls: class object.
name: name to use. | [
"Write",
"the",
"class",
"doc",
"to",
"f",
"."
] | f8da498a1abb7562f57dfc7010941578103061b6 | https://github.com/tensorflow/skflow/blob/f8da498a1abb7562f57dfc7010941578103061b6/scripts/docs/docs.py#L414-L448 | train |
tensorflow/skflow | scripts/docs/docs.py | Library.write_markdown_to_file | def write_markdown_to_file(self, f):
"""Prints this library to file `f`.
Args:
f: File to write to.
Returns:
Dictionary of documented members.
"""
print("---", file=f)
print("---", file=f)
print("<!-- This file is machine generated: DO NOT EDIT! -->", file=f)
print("", file... | python | def write_markdown_to_file(self, f):
"""Prints this library to file `f`.
Args:
f: File to write to.
Returns:
Dictionary of documented members.
"""
print("---", file=f)
print("---", file=f)
print("<!-- This file is machine generated: DO NOT EDIT! -->", file=f)
print("", file... | [
"def",
"write_markdown_to_file",
"(",
"self",
",",
"f",
")",
":",
"print",
"(",
"\"---\"",
",",
"file",
"=",
"f",
")",
"print",
"(",
"\"---\"",
",",
"file",
"=",
"f",
")",
"print",
"(",
"\"<!-- This file is machine generated: DO NOT EDIT! ",
",",
"file",
"="... | Prints this library to file `f`.
Args:
f: File to write to.
Returns:
Dictionary of documented members. | [
"Prints",
"this",
"library",
"to",
"file",
"f",
"."
] | f8da498a1abb7562f57dfc7010941578103061b6 | https://github.com/tensorflow/skflow/blob/f8da498a1abb7562f57dfc7010941578103061b6/scripts/docs/docs.py#L455-L476 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.