id int32 0 252k | 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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
9,300 | libtcod/python-tcod | tcod/console.py | Console._init_setup_console_data | def _init_setup_console_data(self, order: str = "C") -> None:
"""Setup numpy arrays over libtcod data buffers."""
global _root_console
self._key_color = None
if self.console_c == ffi.NULL:
_root_console = self
self._console_data = lib.TCOD_ctx.root
else:
... | python | def _init_setup_console_data(self, order: str = "C") -> None:
"""Setup numpy arrays over libtcod data buffers."""
global _root_console
self._key_color = None
if self.console_c == ffi.NULL:
_root_console = self
self._console_data = lib.TCOD_ctx.root
else:
... | [
"def",
"_init_setup_console_data",
"(",
"self",
",",
"order",
":",
"str",
"=",
"\"C\"",
")",
"->",
"None",
":",
"global",
"_root_console",
"self",
".",
"_key_color",
"=",
"None",
"if",
"self",
".",
"console_c",
"==",
"ffi",
".",
"NULL",
":",
"_root_console... | Setup numpy arrays over libtcod data buffers. | [
"Setup",
"numpy",
"arrays",
"over",
"libtcod",
"data",
"buffers",
"."
] | 8ba10c5cfb813eaf3e834de971ba2d6acb7838e4 | https://github.com/libtcod/python-tcod/blob/8ba10c5cfb813eaf3e834de971ba2d6acb7838e4/tcod/console.py#L179-L196 |
9,301 | libtcod/python-tcod | tcod/console.py | Console.tiles | def tiles(self) -> np.array:
"""An array of this consoles tile data.
This acts as a combination of the `ch`, `fg`, and `bg` attributes.
Colors include an alpha channel but how alpha works is currently
undefined.
Example::
>>> con = tcod.console.Console(10, 2, order=... | python | def tiles(self) -> np.array:
"""An array of this consoles tile data.
This acts as a combination of the `ch`, `fg`, and `bg` attributes.
Colors include an alpha channel but how alpha works is currently
undefined.
Example::
>>> con = tcod.console.Console(10, 2, order=... | [
"def",
"tiles",
"(",
"self",
")",
"->",
"np",
".",
"array",
":",
"return",
"self",
".",
"_tiles",
".",
"T",
"if",
"self",
".",
"_order",
"==",
"\"F\"",
"else",
"self",
".",
"_tiles"
] | An array of this consoles tile data.
This acts as a combination of the `ch`, `fg`, and `bg` attributes.
Colors include an alpha channel but how alpha works is currently
undefined.
Example::
>>> con = tcod.console.Console(10, 2, order="F")
>>> con.tiles[0, 0] = (... | [
"An",
"array",
"of",
"this",
"consoles",
"tile",
"data",
"."
] | 8ba10c5cfb813eaf3e834de971ba2d6acb7838e4 | https://github.com/libtcod/python-tcod/blob/8ba10c5cfb813eaf3e834de971ba2d6acb7838e4/tcod/console.py#L249-L268 |
9,302 | libtcod/python-tcod | tcod/console.py | Console.__clear_warning | def __clear_warning(self, name: str, value: Tuple[int, int, int]) -> None:
"""Raise a warning for bad default values during calls to clear."""
warnings.warn(
"Clearing with the console default values is deprecated.\n"
"Add %s=%r to this call." % (name, value),
Depreca... | python | def __clear_warning(self, name: str, value: Tuple[int, int, int]) -> None:
"""Raise a warning for bad default values during calls to clear."""
warnings.warn(
"Clearing with the console default values is deprecated.\n"
"Add %s=%r to this call." % (name, value),
Depreca... | [
"def",
"__clear_warning",
"(",
"self",
",",
"name",
":",
"str",
",",
"value",
":",
"Tuple",
"[",
"int",
",",
"int",
",",
"int",
"]",
")",
"->",
"None",
":",
"warnings",
".",
"warn",
"(",
"\"Clearing with the console default values is deprecated.\\n\"",
"\"Add ... | Raise a warning for bad default values during calls to clear. | [
"Raise",
"a",
"warning",
"for",
"bad",
"default",
"values",
"during",
"calls",
"to",
"clear",
"."
] | 8ba10c5cfb813eaf3e834de971ba2d6acb7838e4 | https://github.com/libtcod/python-tcod/blob/8ba10c5cfb813eaf3e834de971ba2d6acb7838e4/tcod/console.py#L312-L319 |
9,303 | libtcod/python-tcod | tcod/console.py | Console.__deprecate_defaults | def __deprecate_defaults(
self,
new_func: str,
bg_blend: Any,
alignment: Any = ...,
clear: Any = ...,
) -> None:
"""Return the parameters needed to recreate the current default state.
"""
if not __debug__:
return
fg = self.default_... | python | def __deprecate_defaults(
self,
new_func: str,
bg_blend: Any,
alignment: Any = ...,
clear: Any = ...,
) -> None:
"""Return the parameters needed to recreate the current default state.
"""
if not __debug__:
return
fg = self.default_... | [
"def",
"__deprecate_defaults",
"(",
"self",
",",
"new_func",
":",
"str",
",",
"bg_blend",
":",
"Any",
",",
"alignment",
":",
"Any",
"=",
"...",
",",
"clear",
":",
"Any",
"=",
"...",
",",
")",
"->",
"None",
":",
"if",
"not",
"__debug__",
":",
"return"... | Return the parameters needed to recreate the current default state. | [
"Return",
"the",
"parameters",
"needed",
"to",
"recreate",
"the",
"current",
"default",
"state",
"."
] | 8ba10c5cfb813eaf3e834de971ba2d6acb7838e4 | https://github.com/libtcod/python-tcod/blob/8ba10c5cfb813eaf3e834de971ba2d6acb7838e4/tcod/console.py#L390-L448 |
9,304 | libtcod/python-tcod | tcod/console.py | Console.get_height_rect | def get_height_rect(
self, x: int, y: int, width: int, height: int, string: str
) -> int:
"""Return the height of this text word-wrapped into this rectangle.
Args:
x (int): The x coordinate from the left.
y (int): The y coordinate from the top.
width (int... | python | def get_height_rect(
self, x: int, y: int, width: int, height: int, string: str
) -> int:
"""Return the height of this text word-wrapped into this rectangle.
Args:
x (int): The x coordinate from the left.
y (int): The y coordinate from the top.
width (int... | [
"def",
"get_height_rect",
"(",
"self",
",",
"x",
":",
"int",
",",
"y",
":",
"int",
",",
"width",
":",
"int",
",",
"height",
":",
"int",
",",
"string",
":",
"str",
")",
"->",
"int",
":",
"string_",
"=",
"string",
".",
"encode",
"(",
"\"utf-8\"",
"... | Return the height of this text word-wrapped into this rectangle.
Args:
x (int): The x coordinate from the left.
y (int): The y coordinate from the top.
width (int): Maximum width to render the text.
height (int): Maximum lines to render the text.
stri... | [
"Return",
"the",
"height",
"of",
"this",
"text",
"word",
"-",
"wrapped",
"into",
"this",
"rectangle",
"."
] | 8ba10c5cfb813eaf3e834de971ba2d6acb7838e4 | https://github.com/libtcod/python-tcod/blob/8ba10c5cfb813eaf3e834de971ba2d6acb7838e4/tcod/console.py#L529-L549 |
9,305 | libtcod/python-tcod | tcod/console.py | Console.print_frame | def print_frame(
self,
x: int,
y: int,
width: int,
height: int,
string: str = "",
clear: bool = True,
bg_blend: int = tcod.constants.BKGND_DEFAULT,
) -> None:
"""Draw a framed rectangle with optional text.
This uses the default backgro... | python | def print_frame(
self,
x: int,
y: int,
width: int,
height: int,
string: str = "",
clear: bool = True,
bg_blend: int = tcod.constants.BKGND_DEFAULT,
) -> None:
"""Draw a framed rectangle with optional text.
This uses the default backgro... | [
"def",
"print_frame",
"(",
"self",
",",
"x",
":",
"int",
",",
"y",
":",
"int",
",",
"width",
":",
"int",
",",
"height",
":",
"int",
",",
"string",
":",
"str",
"=",
"\"\"",
",",
"clear",
":",
"bool",
"=",
"True",
",",
"bg_blend",
":",
"int",
"="... | Draw a framed rectangle with optional text.
This uses the default background color and blend mode to fill the
rectangle and the default foreground to draw the outline.
`string` will be printed on the inside of the rectangle, word-wrapped.
If `string` is empty then no title will be draw... | [
"Draw",
"a",
"framed",
"rectangle",
"with",
"optional",
"text",
"."
] | 8ba10c5cfb813eaf3e834de971ba2d6acb7838e4 | https://github.com/libtcod/python-tcod/blob/8ba10c5cfb813eaf3e834de971ba2d6acb7838e4/tcod/console.py#L639-L681 |
9,306 | libtcod/python-tcod | tcod/console.py | Console.blit | def blit(
self,
dest: "Console",
dest_x: int = 0,
dest_y: int = 0,
src_x: int = 0,
src_y: int = 0,
width: int = 0,
height: int = 0,
fg_alpha: float = 1.0,
bg_alpha: float = 1.0,
key_color: Optional[Tuple[int, int, int]] = None,
... | python | def blit(
self,
dest: "Console",
dest_x: int = 0,
dest_y: int = 0,
src_x: int = 0,
src_y: int = 0,
width: int = 0,
height: int = 0,
fg_alpha: float = 1.0,
bg_alpha: float = 1.0,
key_color: Optional[Tuple[int, int, int]] = None,
... | [
"def",
"blit",
"(",
"self",
",",
"dest",
":",
"\"Console\"",
",",
"dest_x",
":",
"int",
"=",
"0",
",",
"dest_y",
":",
"int",
"=",
"0",
",",
"src_x",
":",
"int",
"=",
"0",
",",
"src_y",
":",
"int",
"=",
"0",
",",
"width",
":",
"int",
"=",
"0",... | Blit from this console onto the ``dest`` console.
Args:
dest (Console): The destintaion console to blit onto.
dest_x (int): Leftmost coordinate of the destintaion console.
dest_y (int): Topmost coordinate of the destintaion console.
src_x (int): X coordinate from... | [
"Blit",
"from",
"this",
"console",
"onto",
"the",
"dest",
"console",
"."
] | 8ba10c5cfb813eaf3e834de971ba2d6acb7838e4 | https://github.com/libtcod/python-tcod/blob/8ba10c5cfb813eaf3e834de971ba2d6acb7838e4/tcod/console.py#L683-L766 |
9,307 | libtcod/python-tcod | tcod/console.py | Console.print | def print(
self,
x: int,
y: int,
string: str,
fg: Optional[Tuple[int, int, int]] = None,
bg: Optional[Tuple[int, int, int]] = None,
bg_blend: int = tcod.constants.BKGND_SET,
alignment: int = tcod.constants.LEFT,
) -> None:
"""Print a string on ... | python | def print(
self,
x: int,
y: int,
string: str,
fg: Optional[Tuple[int, int, int]] = None,
bg: Optional[Tuple[int, int, int]] = None,
bg_blend: int = tcod.constants.BKGND_SET,
alignment: int = tcod.constants.LEFT,
) -> None:
"""Print a string on ... | [
"def",
"print",
"(",
"self",
",",
"x",
":",
"int",
",",
"y",
":",
"int",
",",
"string",
":",
"str",
",",
"fg",
":",
"Optional",
"[",
"Tuple",
"[",
"int",
",",
"int",
",",
"int",
"]",
"]",
"=",
"None",
",",
"bg",
":",
"Optional",
"[",
"Tuple",... | Print a string on a console with manual line breaks.
`x` and `y` are the starting tile, with ``0,0`` as the upper-left
corner of the console. You can use negative numbers if you want to
start printing relative to the bottom-right corner, but this behavior
may change in future versions.... | [
"Print",
"a",
"string",
"on",
"a",
"console",
"with",
"manual",
"line",
"breaks",
"."
] | 8ba10c5cfb813eaf3e834de971ba2d6acb7838e4 | https://github.com/libtcod/python-tcod/blob/8ba10c5cfb813eaf3e834de971ba2d6acb7838e4/tcod/console.py#L874-L921 |
9,308 | libtcod/python-tcod | tcod/console.py | Console.draw_frame | def draw_frame(
self,
x: int,
y: int,
width: int,
height: int,
title: str = "",
clear: bool = True,
fg: Optional[Tuple[int, int, int]] = None,
bg: Optional[Tuple[int, int, int]] = None,
bg_blend: int = tcod.constants.BKGND_SET,
) -> Non... | python | def draw_frame(
self,
x: int,
y: int,
width: int,
height: int,
title: str = "",
clear: bool = True,
fg: Optional[Tuple[int, int, int]] = None,
bg: Optional[Tuple[int, int, int]] = None,
bg_blend: int = tcod.constants.BKGND_SET,
) -> Non... | [
"def",
"draw_frame",
"(",
"self",
",",
"x",
":",
"int",
",",
"y",
":",
"int",
",",
"width",
":",
"int",
",",
"height",
":",
"int",
",",
"title",
":",
"str",
"=",
"\"\"",
",",
"clear",
":",
"bool",
"=",
"True",
",",
"fg",
":",
"Optional",
"[",
... | Draw a framed rectangle with an optional title.
`x` and `y` are the starting tile, with ``0,0`` as the upper-left
corner of the console. You can use negative numbers if you want to
start printing relative to the bottom-right corner, but this behavior
may change in future versions.
... | [
"Draw",
"a",
"framed",
"rectangle",
"with",
"an",
"optional",
"title",
"."
] | 8ba10c5cfb813eaf3e834de971ba2d6acb7838e4 | https://github.com/libtcod/python-tcod/blob/8ba10c5cfb813eaf3e834de971ba2d6acb7838e4/tcod/console.py#L982-L1033 |
9,309 | libtcod/python-tcod | tcod/console.py | Console.draw_rect | def draw_rect(
self,
x: int,
y: int,
width: int,
height: int,
ch: int,
fg: Optional[Tuple[int, int, int]] = None,
bg: Optional[Tuple[int, int, int]] = None,
bg_blend: int = tcod.constants.BKGND_SET,
) -> None:
"""Draw characters and col... | python | def draw_rect(
self,
x: int,
y: int,
width: int,
height: int,
ch: int,
fg: Optional[Tuple[int, int, int]] = None,
bg: Optional[Tuple[int, int, int]] = None,
bg_blend: int = tcod.constants.BKGND_SET,
) -> None:
"""Draw characters and col... | [
"def",
"draw_rect",
"(",
"self",
",",
"x",
":",
"int",
",",
"y",
":",
"int",
",",
"width",
":",
"int",
",",
"height",
":",
"int",
",",
"ch",
":",
"int",
",",
"fg",
":",
"Optional",
"[",
"Tuple",
"[",
"int",
",",
"int",
",",
"int",
"]",
"]",
... | Draw characters and colors over a rectangular region.
`x` and `y` are the starting tile, with ``0,0`` as the upper-left
corner of the console. You can use negative numbers if you want to
start printing relative to the bottom-right corner, but this behavior
may change in future versions... | [
"Draw",
"characters",
"and",
"colors",
"over",
"a",
"rectangular",
"region",
"."
] | 8ba10c5cfb813eaf3e834de971ba2d6acb7838e4 | https://github.com/libtcod/python-tcod/blob/8ba10c5cfb813eaf3e834de971ba2d6acb7838e4/tcod/console.py#L1035-L1081 |
9,310 | libtcod/python-tcod | fonts/X11/bdf/bdf2png.py | Glyph.blit | def blit(self, image, x, y):
"""blit to the image array"""
# adjust the position with the local bbox
x += self.font_bbox[2] - self.bbox[2]
y += self.font_bbox[3] - self.bbox[3]
x += self.font_bbox[0] - self.bbox[0]
y += self.font_bbox[1] - self.bbox[1]
image[y:y+s... | python | def blit(self, image, x, y):
"""blit to the image array"""
# adjust the position with the local bbox
x += self.font_bbox[2] - self.bbox[2]
y += self.font_bbox[3] - self.bbox[3]
x += self.font_bbox[0] - self.bbox[0]
y += self.font_bbox[1] - self.bbox[1]
image[y:y+s... | [
"def",
"blit",
"(",
"self",
",",
"image",
",",
"x",
",",
"y",
")",
":",
"# adjust the position with the local bbox",
"x",
"+=",
"self",
".",
"font_bbox",
"[",
"2",
"]",
"-",
"self",
".",
"bbox",
"[",
"2",
"]",
"y",
"+=",
"self",
".",
"font_bbox",
"["... | blit to the image array | [
"blit",
"to",
"the",
"image",
"array"
] | 8ba10c5cfb813eaf3e834de971ba2d6acb7838e4 | https://github.com/libtcod/python-tcod/blob/8ba10c5cfb813eaf3e834de971ba2d6acb7838e4/fonts/X11/bdf/bdf2png.py#L80-L87 |
9,311 | libtcod/python-tcod | fonts/X11/bdf/bdf2png.py | Glyph.parseBits | def parseBits(self, hexcode, width):
"""enumerate over bits in a line of data"""
bitarray = []
for byte in hexcode[::-1]:
bits = int(byte, 16)
for x in range(4):
bitarray.append(bool((2 ** x) & bits))
bitarray = bitarray[::-1]
return enumer... | python | def parseBits(self, hexcode, width):
"""enumerate over bits in a line of data"""
bitarray = []
for byte in hexcode[::-1]:
bits = int(byte, 16)
for x in range(4):
bitarray.append(bool((2 ** x) & bits))
bitarray = bitarray[::-1]
return enumer... | [
"def",
"parseBits",
"(",
"self",
",",
"hexcode",
",",
"width",
")",
":",
"bitarray",
"=",
"[",
"]",
"for",
"byte",
"in",
"hexcode",
"[",
":",
":",
"-",
"1",
"]",
":",
"bits",
"=",
"int",
"(",
"byte",
",",
"16",
")",
"for",
"x",
"in",
"range",
... | enumerate over bits in a line of data | [
"enumerate",
"over",
"bits",
"in",
"a",
"line",
"of",
"data"
] | 8ba10c5cfb813eaf3e834de971ba2d6acb7838e4 | https://github.com/libtcod/python-tcod/blob/8ba10c5cfb813eaf3e834de971ba2d6acb7838e4/fonts/X11/bdf/bdf2png.py#L89-L97 |
9,312 | Netflix-Skunkworks/raven-python-lambda | raven_python_lambda/__init__.py | memory_warning | def memory_warning(config, context):
"""Determines when memory usage is nearing it's max."""
used = psutil.Process(os.getpid()).memory_info().rss / 1048576
limit = float(context.memory_limit_in_mb)
p = used / limit
memory_threshold = config.get('memory_warning_threshold')
if p >= memory_thresh... | python | def memory_warning(config, context):
"""Determines when memory usage is nearing it's max."""
used = psutil.Process(os.getpid()).memory_info().rss / 1048576
limit = float(context.memory_limit_in_mb)
p = used / limit
memory_threshold = config.get('memory_warning_threshold')
if p >= memory_thresh... | [
"def",
"memory_warning",
"(",
"config",
",",
"context",
")",
":",
"used",
"=",
"psutil",
".",
"Process",
"(",
"os",
".",
"getpid",
"(",
")",
")",
".",
"memory_info",
"(",
")",
".",
"rss",
"/",
"1048576",
"limit",
"=",
"float",
"(",
"context",
".",
... | Determines when memory usage is nearing it's max. | [
"Determines",
"when",
"memory",
"usage",
"is",
"nearing",
"it",
"s",
"max",
"."
] | 640d5cfcef6e69ea685ca13469cfca71adf0e78c | https://github.com/Netflix-Skunkworks/raven-python-lambda/blob/640d5cfcef6e69ea685ca13469cfca71adf0e78c/raven_python_lambda/__init__.py#L233-L252 |
9,313 | Netflix-Skunkworks/raven-python-lambda | raven_python_lambda/__init__.py | install_timers | def install_timers(config, context):
"""Create the timers as specified by the plugin configuration."""
timers = []
if config.get('capture_timeout_warnings'):
timeout_threshold = config.get('timeout_warning_threshold')
# Schedule the warning at the user specified threshold given in percent.
... | python | def install_timers(config, context):
"""Create the timers as specified by the plugin configuration."""
timers = []
if config.get('capture_timeout_warnings'):
timeout_threshold = config.get('timeout_warning_threshold')
# Schedule the warning at the user specified threshold given in percent.
... | [
"def",
"install_timers",
"(",
"config",
",",
"context",
")",
":",
"timers",
"=",
"[",
"]",
"if",
"config",
".",
"get",
"(",
"'capture_timeout_warnings'",
")",
":",
"timeout_threshold",
"=",
"config",
".",
"get",
"(",
"'timeout_warning_threshold'",
")",
"# Sche... | Create the timers as specified by the plugin configuration. | [
"Create",
"the",
"timers",
"as",
"specified",
"by",
"the",
"plugin",
"configuration",
"."
] | 640d5cfcef6e69ea685ca13469cfca71adf0e78c | https://github.com/Netflix-Skunkworks/raven-python-lambda/blob/640d5cfcef6e69ea685ca13469cfca71adf0e78c/raven_python_lambda/__init__.py#L255-L274 |
9,314 | ellmetha/django-machina | machina/templatetags/forum_tags.py | recurseforumcontents | def recurseforumcontents(parser, token):
""" Iterates over the content nodes and renders the contained forum block for each node. """
bits = token.contents.split()
forums_contents_var = template.Variable(bits[1])
template_nodes = parser.parse(('endrecurseforumcontents',))
parser.delete_first_token(... | python | def recurseforumcontents(parser, token):
""" Iterates over the content nodes and renders the contained forum block for each node. """
bits = token.contents.split()
forums_contents_var = template.Variable(bits[1])
template_nodes = parser.parse(('endrecurseforumcontents',))
parser.delete_first_token(... | [
"def",
"recurseforumcontents",
"(",
"parser",
",",
"token",
")",
":",
"bits",
"=",
"token",
".",
"contents",
".",
"split",
"(",
")",
"forums_contents_var",
"=",
"template",
".",
"Variable",
"(",
"bits",
"[",
"1",
"]",
")",
"template_nodes",
"=",
"parser",
... | Iterates over the content nodes and renders the contained forum block for each node. | [
"Iterates",
"over",
"the",
"content",
"nodes",
"and",
"renders",
"the",
"contained",
"forum",
"block",
"for",
"each",
"node",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/templatetags/forum_tags.py#L40-L48 |
9,315 | ellmetha/django-machina | machina/templatetags/forum_tags.py | forum_list | def forum_list(context, forum_visibility_contents):
""" Renders the considered forum list.
This will render the given list of forums by respecting the order and the depth of each
forum in the forums tree.
Usage::
{% forum_list my_forums %}
"""
request = context.get('request')
tra... | python | def forum_list(context, forum_visibility_contents):
""" Renders the considered forum list.
This will render the given list of forums by respecting the order and the depth of each
forum in the forums tree.
Usage::
{% forum_list my_forums %}
"""
request = context.get('request')
tra... | [
"def",
"forum_list",
"(",
"context",
",",
"forum_visibility_contents",
")",
":",
"request",
"=",
"context",
".",
"get",
"(",
"'request'",
")",
"tracking_handler",
"=",
"TrackingHandler",
"(",
"request",
"=",
"request",
")",
"data_dict",
"=",
"{",
"'forum_content... | Renders the considered forum list.
This will render the given list of forums by respecting the order and the depth of each
forum in the forums tree.
Usage::
{% forum_list my_forums %} | [
"Renders",
"the",
"considered",
"forum",
"list",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/templatetags/forum_tags.py#L52-L80 |
9,316 | ellmetha/django-machina | machina/apps/forum_feeds/feeds.py | LastTopicsFeed.get_object | def get_object(self, request, *args, **kwargs):
""" Handles the considered object. """
forum_pk = kwargs.get('forum_pk', None)
descendants = kwargs.get('descendants', None)
self.user = request.user
if forum_pk:
forum = get_object_or_404(Forum, pk=forum_pk)
... | python | def get_object(self, request, *args, **kwargs):
""" Handles the considered object. """
forum_pk = kwargs.get('forum_pk', None)
descendants = kwargs.get('descendants', None)
self.user = request.user
if forum_pk:
forum = get_object_or_404(Forum, pk=forum_pk)
... | [
"def",
"get_object",
"(",
"self",
",",
"request",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"forum_pk",
"=",
"kwargs",
".",
"get",
"(",
"'forum_pk'",
",",
"None",
")",
"descendants",
"=",
"kwargs",
".",
"get",
"(",
"'descendants'",
",",
"N... | Handles the considered object. | [
"Handles",
"the",
"considered",
"object",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_feeds/feeds.py#L34-L52 |
9,317 | ellmetha/django-machina | machina/apps/forum_feeds/feeds.py | LastTopicsFeed.items | def items(self):
""" Returns the items to include into the feed. """
return Topic.objects.filter(forum__in=self.forums, approved=True).order_by('-last_post_on') | python | def items(self):
""" Returns the items to include into the feed. """
return Topic.objects.filter(forum__in=self.forums, approved=True).order_by('-last_post_on') | [
"def",
"items",
"(",
"self",
")",
":",
"return",
"Topic",
".",
"objects",
".",
"filter",
"(",
"forum__in",
"=",
"self",
".",
"forums",
",",
"approved",
"=",
"True",
")",
".",
"order_by",
"(",
"'-last_post_on'",
")"
] | Returns the items to include into the feed. | [
"Returns",
"the",
"items",
"to",
"include",
"into",
"the",
"feed",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_feeds/feeds.py#L54-L56 |
9,318 | ellmetha/django-machina | machina/apps/forum_feeds/feeds.py | LastTopicsFeed.item_link | def item_link(self, item):
""" Generates a link for a specific item of the feed. """
return reverse_lazy(
'forum_conversation:topic',
kwargs={
'forum_slug': item.forum.slug,
'forum_pk': item.forum.pk,
'slug': item.slug,
... | python | def item_link(self, item):
""" Generates a link for a specific item of the feed. """
return reverse_lazy(
'forum_conversation:topic',
kwargs={
'forum_slug': item.forum.slug,
'forum_pk': item.forum.pk,
'slug': item.slug,
... | [
"def",
"item_link",
"(",
"self",
",",
"item",
")",
":",
"return",
"reverse_lazy",
"(",
"'forum_conversation:topic'",
",",
"kwargs",
"=",
"{",
"'forum_slug'",
":",
"item",
".",
"forum",
".",
"slug",
",",
"'forum_pk'",
":",
"item",
".",
"forum",
".",
"pk",
... | Generates a link for a specific item of the feed. | [
"Generates",
"a",
"link",
"for",
"a",
"specific",
"item",
"of",
"the",
"feed",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_feeds/feeds.py#L58-L68 |
9,319 | ellmetha/django-machina | machina/templatetags/forum_conversation_tags.py | topic_pages_inline_list | def topic_pages_inline_list(topic):
""" This will render an inline pagination for the posts related to the given topic.
Usage::
{% topic_pages_inline_list my_topic %}
"""
data_dict = {
'topic': topic,
}
pages_number = ((topic.posts_count - 1) // machina_settings.TOPIC_POSTS_N... | python | def topic_pages_inline_list(topic):
""" This will render an inline pagination for the posts related to the given topic.
Usage::
{% topic_pages_inline_list my_topic %}
"""
data_dict = {
'topic': topic,
}
pages_number = ((topic.posts_count - 1) // machina_settings.TOPIC_POSTS_N... | [
"def",
"topic_pages_inline_list",
"(",
"topic",
")",
":",
"data_dict",
"=",
"{",
"'topic'",
":",
"topic",
",",
"}",
"pages_number",
"=",
"(",
"(",
"topic",
".",
"posts_count",
"-",
"1",
")",
"//",
"machina_settings",
".",
"TOPIC_POSTS_NUMBER_PER_PAGE",
")",
... | This will render an inline pagination for the posts related to the given topic.
Usage::
{% topic_pages_inline_list my_topic %} | [
"This",
"will",
"render",
"an",
"inline",
"pagination",
"for",
"the",
"posts",
"related",
"to",
"the",
"given",
"topic",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/templatetags/forum_conversation_tags.py#L22-L41 |
9,320 | ellmetha/django-machina | machina/apps/forum/admin.py | ForumAdmin.get_urls | def get_urls(self):
""" Returns the URLs associated with the admin abstraction. """
urls = super().get_urls()
forum_admin_urls = [
url(
r'^(?P<forum_id>[0-9]+)/move-forum/(?P<direction>up|down)/$',
self.admin_site.admin_view(self.moveforum_view),
... | python | def get_urls(self):
""" Returns the URLs associated with the admin abstraction. """
urls = super().get_urls()
forum_admin_urls = [
url(
r'^(?P<forum_id>[0-9]+)/move-forum/(?P<direction>up|down)/$',
self.admin_site.admin_view(self.moveforum_view),
... | [
"def",
"get_urls",
"(",
"self",
")",
":",
"urls",
"=",
"super",
"(",
")",
".",
"get_urls",
"(",
")",
"forum_admin_urls",
"=",
"[",
"url",
"(",
"r'^(?P<forum_id>[0-9]+)/move-forum/(?P<direction>up|down)/$'",
",",
"self",
".",
"admin_site",
".",
"admin_view",
"(",... | Returns the URLs associated with the admin abstraction. | [
"Returns",
"the",
"URLs",
"associated",
"with",
"the",
"admin",
"abstraction",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum/admin.py#L66-L116 |
9,321 | ellmetha/django-machina | machina/apps/forum/admin.py | ForumAdmin.get_forum_perms_base_context | def get_forum_perms_base_context(self, request, obj=None):
""" Returns the context to provide to the template for permissions contents. """
context = {
'adminform': {'model_admin': self},
'media': self.media,
'object': obj,
'app_label': self.model._meta.ap... | python | def get_forum_perms_base_context(self, request, obj=None):
""" Returns the context to provide to the template for permissions contents. """
context = {
'adminform': {'model_admin': self},
'media': self.media,
'object': obj,
'app_label': self.model._meta.ap... | [
"def",
"get_forum_perms_base_context",
"(",
"self",
",",
"request",
",",
"obj",
"=",
"None",
")",
":",
"context",
"=",
"{",
"'adminform'",
":",
"{",
"'model_admin'",
":",
"self",
"}",
",",
"'media'",
":",
"self",
".",
"media",
",",
"'object'",
":",
"obj"... | Returns the context to provide to the template for permissions contents. | [
"Returns",
"the",
"context",
"to",
"provide",
"to",
"the",
"template",
"for",
"permissions",
"contents",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum/admin.py#L118-L135 |
9,322 | ellmetha/django-machina | machina/apps/forum/admin.py | ForumAdmin.moveforum_view | def moveforum_view(self, request, forum_id, direction):
""" Moves the given forum toward the requested direction. """
forum = get_object_or_404(Forum, pk=forum_id)
# Fetch the target
target, position = None, None
if direction == 'up':
target, position = forum.get_pre... | python | def moveforum_view(self, request, forum_id, direction):
""" Moves the given forum toward the requested direction. """
forum = get_object_or_404(Forum, pk=forum_id)
# Fetch the target
target, position = None, None
if direction == 'up':
target, position = forum.get_pre... | [
"def",
"moveforum_view",
"(",
"self",
",",
"request",
",",
"forum_id",
",",
"direction",
")",
":",
"forum",
"=",
"get_object_or_404",
"(",
"Forum",
",",
"pk",
"=",
"forum_id",
")",
"# Fetch the target",
"target",
",",
"position",
"=",
"None",
",",
"None",
... | Moves the given forum toward the requested direction. | [
"Moves",
"the",
"given",
"forum",
"toward",
"the",
"requested",
"direction",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum/admin.py#L137-L155 |
9,323 | ellmetha/django-machina | machina/apps/forum/admin.py | ForumAdmin.editpermissions_index_view | def editpermissions_index_view(self, request, forum_id=None):
""" Allows to select how to edit forum permissions.
The view displays a form to select a user or a group in order to edit its permissions for
the considered forum.
"""
forum = get_object_or_404(Forum, pk=forum_id) if... | python | def editpermissions_index_view(self, request, forum_id=None):
""" Allows to select how to edit forum permissions.
The view displays a form to select a user or a group in order to edit its permissions for
the considered forum.
"""
forum = get_object_or_404(Forum, pk=forum_id) if... | [
"def",
"editpermissions_index_view",
"(",
"self",
",",
"request",
",",
"forum_id",
"=",
"None",
")",
":",
"forum",
"=",
"get_object_or_404",
"(",
"Forum",
",",
"pk",
"=",
"forum_id",
")",
"if",
"forum_id",
"else",
"None",
"# Set up the context",
"context",
"="... | Allows to select how to edit forum permissions.
The view displays a form to select a user or a group in order to edit its permissions for
the considered forum. | [
"Allows",
"to",
"select",
"how",
"to",
"edit",
"forum",
"permissions",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum/admin.py#L157-L240 |
9,324 | ellmetha/django-machina | machina/apps/forum/admin.py | ForumAdmin.editpermissions_user_view | def editpermissions_user_view(self, request, user_id, forum_id=None):
""" Allows to edit user permissions for the considered forum.
The view displays a form to define which permissions are granted for the given user for the
considered forum.
"""
user_model = get_user_model()
... | python | def editpermissions_user_view(self, request, user_id, forum_id=None):
""" Allows to edit user permissions for the considered forum.
The view displays a form to define which permissions are granted for the given user for the
considered forum.
"""
user_model = get_user_model()
... | [
"def",
"editpermissions_user_view",
"(",
"self",
",",
"request",
",",
"user_id",
",",
"forum_id",
"=",
"None",
")",
":",
"user_model",
"=",
"get_user_model",
"(",
")",
"user",
"=",
"get_object_or_404",
"(",
"user_model",
",",
"pk",
"=",
"user_id",
")",
"foru... | Allows to edit user permissions for the considered forum.
The view displays a form to define which permissions are granted for the given user for the
considered forum. | [
"Allows",
"to",
"edit",
"user",
"permissions",
"for",
"the",
"considered",
"forum",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum/admin.py#L242-L261 |
9,325 | ellmetha/django-machina | machina/apps/forum/admin.py | ForumAdmin.editpermissions_anonymous_user_view | def editpermissions_anonymous_user_view(self, request, forum_id=None):
""" Allows to edit anonymous user permissions for the considered forum.
The view displays a form to define which permissions are granted for the anonymous user for
the considered forum.
"""
forum = get_objec... | python | def editpermissions_anonymous_user_view(self, request, forum_id=None):
""" Allows to edit anonymous user permissions for the considered forum.
The view displays a form to define which permissions are granted for the anonymous user for
the considered forum.
"""
forum = get_objec... | [
"def",
"editpermissions_anonymous_user_view",
"(",
"self",
",",
"request",
",",
"forum_id",
"=",
"None",
")",
":",
"forum",
"=",
"get_object_or_404",
"(",
"Forum",
",",
"pk",
"=",
"forum_id",
")",
"if",
"forum_id",
"else",
"None",
"# Set up the context",
"contex... | Allows to edit anonymous user permissions for the considered forum.
The view displays a form to define which permissions are granted for the anonymous user for
the considered forum. | [
"Allows",
"to",
"edit",
"anonymous",
"user",
"permissions",
"for",
"the",
"considered",
"forum",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum/admin.py#L263-L280 |
9,326 | ellmetha/django-machina | machina/apps/forum/admin.py | ForumAdmin.editpermissions_group_view | def editpermissions_group_view(self, request, group_id, forum_id=None):
""" Allows to edit group permissions for the considered forum.
The view displays a form to define which permissions are granted for the given group for the
considered forum.
"""
group = get_object_or_404(Gr... | python | def editpermissions_group_view(self, request, group_id, forum_id=None):
""" Allows to edit group permissions for the considered forum.
The view displays a form to define which permissions are granted for the given group for the
considered forum.
"""
group = get_object_or_404(Gr... | [
"def",
"editpermissions_group_view",
"(",
"self",
",",
"request",
",",
"group_id",
",",
"forum_id",
"=",
"None",
")",
":",
"group",
"=",
"get_object_or_404",
"(",
"Group",
",",
"pk",
"=",
"group_id",
")",
"forum",
"=",
"get_object_or_404",
"(",
"Forum",
",",... | Allows to edit group permissions for the considered forum.
The view displays a form to define which permissions are granted for the given group for the
considered forum. | [
"Allows",
"to",
"edit",
"group",
"permissions",
"for",
"the",
"considered",
"forum",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum/admin.py#L282-L300 |
9,327 | ellmetha/django-machina | machina/templatetags/forum_permission_tags.py | get_permission | def get_permission(context, method, *args, **kwargs):
""" This will return a boolean indicating if the considered permission is granted for the passed
user.
Usage::
{% get_permission 'can_access_moderation_panel' request.user as var %}
"""
request = context.get('request', None)
pe... | python | def get_permission(context, method, *args, **kwargs):
""" This will return a boolean indicating if the considered permission is granted for the passed
user.
Usage::
{% get_permission 'can_access_moderation_panel' request.user as var %}
"""
request = context.get('request', None)
pe... | [
"def",
"get_permission",
"(",
"context",
",",
"method",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"request",
"=",
"context",
".",
"get",
"(",
"'request'",
",",
"None",
")",
"perm_handler",
"=",
"request",
".",
"forum_permission_handler",
"if",
... | This will return a boolean indicating if the considered permission is granted for the passed
user.
Usage::
{% get_permission 'can_access_moderation_panel' request.user as var %} | [
"This",
"will",
"return",
"a",
"boolean",
"indicating",
"if",
"the",
"considered",
"permission",
"is",
"granted",
"for",
"the",
"passed",
"user",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/templatetags/forum_permission_tags.py#L14-L35 |
9,328 | ellmetha/django-machina | machina/apps/forum_conversation/forum_polls/forms.py | BaseTopicPollOptionFormset.total_form_count | def total_form_count(self):
"""
This rewrite of total_form_count allows to add an empty form to the formset only when
no initial data is provided.
"""
total_forms = super().total_form_count()
if not self.data and not self.files and self.initial_form_count() > 0:
... | python | def total_form_count(self):
"""
This rewrite of total_form_count allows to add an empty form to the formset only when
no initial data is provided.
"""
total_forms = super().total_form_count()
if not self.data and not self.files and self.initial_form_count() > 0:
... | [
"def",
"total_form_count",
"(",
"self",
")",
":",
"total_forms",
"=",
"super",
"(",
")",
".",
"total_form_count",
"(",
")",
"if",
"not",
"self",
".",
"data",
"and",
"not",
"self",
".",
"files",
"and",
"self",
".",
"initial_form_count",
"(",
")",
">",
"... | This rewrite of total_form_count allows to add an empty form to the formset only when
no initial data is provided. | [
"This",
"rewrite",
"of",
"total_form_count",
"allows",
"to",
"add",
"an",
"empty",
"form",
"to",
"the",
"formset",
"only",
"when",
"no",
"initial",
"data",
"is",
"provided",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_conversation/forum_polls/forms.py#L52-L60 |
9,329 | ellmetha/django-machina | machina/core/loading.py | get_classes | def get_classes(module_label, classnames):
""" Imports a set of classes from a given module.
Usage::
get_classes('forum.models', ['Forum', 'ForumReadTrack', ])
"""
app_label = module_label.split('.')[0]
app_module_path = _get_app_module_path(module_label)
if not app_module_path:
... | python | def get_classes(module_label, classnames):
""" Imports a set of classes from a given module.
Usage::
get_classes('forum.models', ['Forum', 'ForumReadTrack', ])
"""
app_label = module_label.split('.')[0]
app_module_path = _get_app_module_path(module_label)
if not app_module_path:
... | [
"def",
"get_classes",
"(",
"module_label",
",",
"classnames",
")",
":",
"app_label",
"=",
"module_label",
".",
"split",
"(",
"'.'",
")",
"[",
"0",
"]",
"app_module_path",
"=",
"_get_app_module_path",
"(",
"module_label",
")",
"if",
"not",
"app_module_path",
":... | Imports a set of classes from a given module.
Usage::
get_classes('forum.models', ['Forum', 'ForumReadTrack', ]) | [
"Imports",
"a",
"set",
"of",
"classes",
"from",
"a",
"given",
"module",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/core/loading.py#L19-L59 |
9,330 | ellmetha/django-machina | machina/core/loading.py | _import_module | def _import_module(module_path, classnames):
""" Tries to import the given Python module path. """
try:
imported_module = __import__(module_path, fromlist=classnames)
return imported_module
except ImportError:
# In case of an ImportError, the module being loaded generally does not ex... | python | def _import_module(module_path, classnames):
""" Tries to import the given Python module path. """
try:
imported_module = __import__(module_path, fromlist=classnames)
return imported_module
except ImportError:
# In case of an ImportError, the module being loaded generally does not ex... | [
"def",
"_import_module",
"(",
"module_path",
",",
"classnames",
")",
":",
"try",
":",
"imported_module",
"=",
"__import__",
"(",
"module_path",
",",
"fromlist",
"=",
"classnames",
")",
"return",
"imported_module",
"except",
"ImportError",
":",
"# In case of an Impor... | Tries to import the given Python module path. | [
"Tries",
"to",
"import",
"the",
"given",
"Python",
"module",
"path",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/core/loading.py#L62-L79 |
9,331 | ellmetha/django-machina | machina/core/loading.py | _pick_up_classes | def _pick_up_classes(modules, classnames):
""" Given a list of class names to retrieve, try to fetch them from the specified list of
modules and returns the list of the fetched classes.
"""
klasses = []
for classname in classnames:
klass = None
for module in modules:
... | python | def _pick_up_classes(modules, classnames):
""" Given a list of class names to retrieve, try to fetch them from the specified list of
modules and returns the list of the fetched classes.
"""
klasses = []
for classname in classnames:
klass = None
for module in modules:
... | [
"def",
"_pick_up_classes",
"(",
"modules",
",",
"classnames",
")",
":",
"klasses",
"=",
"[",
"]",
"for",
"classname",
"in",
"classnames",
":",
"klass",
"=",
"None",
"for",
"module",
"in",
"modules",
":",
"if",
"hasattr",
"(",
"module",
",",
"classname",
... | Given a list of class names to retrieve, try to fetch them from the specified list of
modules and returns the list of the fetched classes. | [
"Given",
"a",
"list",
"of",
"class",
"names",
"to",
"retrieve",
"try",
"to",
"fetch",
"them",
"from",
"the",
"specified",
"list",
"of",
"modules",
"and",
"returns",
"the",
"list",
"of",
"the",
"fetched",
"classes",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/core/loading.py#L82-L98 |
9,332 | ellmetha/django-machina | machina/core/loading.py | _get_app_module_path | def _get_app_module_path(module_label):
""" Given a module label, loop over the apps specified in the INSTALLED_APPS to find the
corresponding application module path.
"""
app_name = module_label.rsplit('.', 1)[0]
for app in settings.INSTALLED_APPS:
if app.endswith('.' + app_name) or app... | python | def _get_app_module_path(module_label):
""" Given a module label, loop over the apps specified in the INSTALLED_APPS to find the
corresponding application module path.
"""
app_name = module_label.rsplit('.', 1)[0]
for app in settings.INSTALLED_APPS:
if app.endswith('.' + app_name) or app... | [
"def",
"_get_app_module_path",
"(",
"module_label",
")",
":",
"app_name",
"=",
"module_label",
".",
"rsplit",
"(",
"'.'",
",",
"1",
")",
"[",
"0",
"]",
"for",
"app",
"in",
"settings",
".",
"INSTALLED_APPS",
":",
"if",
"app",
".",
"endswith",
"(",
"'.'",
... | Given a module label, loop over the apps specified in the INSTALLED_APPS to find the
corresponding application module path. | [
"Given",
"a",
"module",
"label",
"loop",
"over",
"the",
"apps",
"specified",
"in",
"the",
"INSTALLED_APPS",
"to",
"find",
"the",
"corresponding",
"application",
"module",
"path",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/core/loading.py#L101-L109 |
9,333 | ellmetha/django-machina | machina/apps/forum_tracking/handler.py | TrackingHandler.get_unread_forums | def get_unread_forums(self, user):
""" Returns the list of unread forums for the given user. """
return self.get_unread_forums_from_list(
user, self.perm_handler.get_readable_forums(Forum.objects.all(), user)) | python | def get_unread_forums(self, user):
""" Returns the list of unread forums for the given user. """
return self.get_unread_forums_from_list(
user, self.perm_handler.get_readable_forums(Forum.objects.all(), user)) | [
"def",
"get_unread_forums",
"(",
"self",
",",
"user",
")",
":",
"return",
"self",
".",
"get_unread_forums_from_list",
"(",
"user",
",",
"self",
".",
"perm_handler",
".",
"get_readable_forums",
"(",
"Forum",
".",
"objects",
".",
"all",
"(",
")",
",",
"user",
... | Returns the list of unread forums for the given user. | [
"Returns",
"the",
"list",
"of",
"unread",
"forums",
"for",
"the",
"given",
"user",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_tracking/handler.py#L36-L39 |
9,334 | ellmetha/django-machina | machina/apps/forum_tracking/handler.py | TrackingHandler.get_unread_forums_from_list | def get_unread_forums_from_list(self, user, forums):
""" Returns the list of unread forums for the given user from a given list of forums. """
unread_forums = []
# A user which is not authenticated will never see a forum as unread
if not user.is_authenticated:
return unread_... | python | def get_unread_forums_from_list(self, user, forums):
""" Returns the list of unread forums for the given user from a given list of forums. """
unread_forums = []
# A user which is not authenticated will never see a forum as unread
if not user.is_authenticated:
return unread_... | [
"def",
"get_unread_forums_from_list",
"(",
"self",
",",
"user",
",",
"forums",
")",
":",
"unread_forums",
"=",
"[",
"]",
"# A user which is not authenticated will never see a forum as unread",
"if",
"not",
"user",
".",
"is_authenticated",
":",
"return",
"unread_forums",
... | Returns the list of unread forums for the given user from a given list of forums. | [
"Returns",
"the",
"list",
"of",
"unread",
"forums",
"for",
"the",
"given",
"user",
"from",
"a",
"given",
"list",
"of",
"forums",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_tracking/handler.py#L41-L52 |
9,335 | ellmetha/django-machina | machina/apps/forum_tracking/handler.py | TrackingHandler.get_unread_topics | def get_unread_topics(self, topics, user):
""" Returns a list of unread topics for the given user from a given set of topics. """
unread_topics = []
# A user which is not authenticated will never see a topic as unread.
# If there are no topics to consider, we stop here.
if not u... | python | def get_unread_topics(self, topics, user):
""" Returns a list of unread topics for the given user from a given set of topics. """
unread_topics = []
# A user which is not authenticated will never see a topic as unread.
# If there are no topics to consider, we stop here.
if not u... | [
"def",
"get_unread_topics",
"(",
"self",
",",
"topics",
",",
"user",
")",
":",
"unread_topics",
"=",
"[",
"]",
"# A user which is not authenticated will never see a topic as unread.",
"# If there are no topics to consider, we stop here.",
"if",
"not",
"user",
".",
"is_authent... | Returns a list of unread topics for the given user from a given set of topics. | [
"Returns",
"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/apps/forum_tracking/handler.py#L54-L98 |
9,336 | ellmetha/django-machina | machina/apps/forum_tracking/handler.py | TrackingHandler.mark_forums_read | def mark_forums_read(self, forums, user):
""" Marks a list of forums as read. """
if not forums or not user.is_authenticated:
return
forums = sorted(forums, key=lambda f: f.level)
# Update all forum tracks to the current date for the considered forums
for forum in f... | python | def mark_forums_read(self, forums, user):
""" Marks a list of forums as read. """
if not forums or not user.is_authenticated:
return
forums = sorted(forums, key=lambda f: f.level)
# Update all forum tracks to the current date for the considered forums
for forum in f... | [
"def",
"mark_forums_read",
"(",
"self",
",",
"forums",
",",
"user",
")",
":",
"if",
"not",
"forums",
"or",
"not",
"user",
".",
"is_authenticated",
":",
"return",
"forums",
"=",
"sorted",
"(",
"forums",
",",
"key",
"=",
"lambda",
"f",
":",
"f",
".",
"... | Marks a list of forums as read. | [
"Marks",
"a",
"list",
"of",
"forums",
"as",
"read",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_tracking/handler.py#L100-L114 |
9,337 | ellmetha/django-machina | machina/apps/forum_tracking/handler.py | TrackingHandler.mark_topic_read | def mark_topic_read(self, topic, user):
""" Marks a topic as read. """
if not user.is_authenticated:
return
forum = topic.forum
try:
forum_track = ForumReadTrack.objects.get(forum=forum, user=user)
except ForumReadTrack.DoesNotExist:
forum_tra... | python | def mark_topic_read(self, topic, user):
""" Marks a topic as read. """
if not user.is_authenticated:
return
forum = topic.forum
try:
forum_track = ForumReadTrack.objects.get(forum=forum, user=user)
except ForumReadTrack.DoesNotExist:
forum_tra... | [
"def",
"mark_topic_read",
"(",
"self",
",",
"topic",
",",
"user",
")",
":",
"if",
"not",
"user",
".",
"is_authenticated",
":",
"return",
"forum",
"=",
"topic",
".",
"forum",
"try",
":",
"forum_track",
"=",
"ForumReadTrack",
".",
"objects",
".",
"get",
"(... | Marks a topic as read. | [
"Marks",
"a",
"topic",
"as",
"read",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_tracking/handler.py#L116-L166 |
9,338 | ellmetha/django-machina | machina/apps/forum/abstract_models.py | AbstractForum.clean | def clean(self):
""" Validates the forum instance. """
super().clean()
if self.parent and self.parent.is_link:
raise ValidationError(_('A forum can not have a link forum as parent'))
if self.is_category and self.parent and self.parent.is_category:
raise Validati... | python | def clean(self):
""" Validates the forum instance. """
super().clean()
if self.parent and self.parent.is_link:
raise ValidationError(_('A forum can not have a link forum as parent'))
if self.is_category and self.parent and self.parent.is_category:
raise Validati... | [
"def",
"clean",
"(",
"self",
")",
":",
"super",
"(",
")",
".",
"clean",
"(",
")",
"if",
"self",
".",
"parent",
"and",
"self",
".",
"parent",
".",
"is_link",
":",
"raise",
"ValidationError",
"(",
"_",
"(",
"'A forum can not have a link forum as parent'",
")... | Validates the forum instance. | [
"Validates",
"the",
"forum",
"instance",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum/abstract_models.py#L134-L145 |
9,339 | ellmetha/django-machina | machina/apps/forum/abstract_models.py | AbstractForum.get_image_upload_to | def get_image_upload_to(self, filename):
""" Returns the path to upload a new associated image to. """
dummy, ext = os.path.splitext(filename)
return os.path.join(
machina_settings.FORUM_IMAGE_UPLOAD_TO,
'{id}{ext}'.format(id=str(uuid.uuid4()).replace('-', ''), ext=ext),
... | python | def get_image_upload_to(self, filename):
""" Returns the path to upload a new associated image to. """
dummy, ext = os.path.splitext(filename)
return os.path.join(
machina_settings.FORUM_IMAGE_UPLOAD_TO,
'{id}{ext}'.format(id=str(uuid.uuid4()).replace('-', ''), ext=ext),
... | [
"def",
"get_image_upload_to",
"(",
"self",
",",
"filename",
")",
":",
"dummy",
",",
"ext",
"=",
"os",
".",
"path",
".",
"splitext",
"(",
"filename",
")",
"return",
"os",
".",
"path",
".",
"join",
"(",
"machina_settings",
".",
"FORUM_IMAGE_UPLOAD_TO",
",",
... | Returns the path to upload a new associated image to. | [
"Returns",
"the",
"path",
"to",
"upload",
"a",
"new",
"associated",
"image",
"to",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum/abstract_models.py#L147-L153 |
9,340 | ellmetha/django-machina | machina/apps/forum/abstract_models.py | AbstractForum.save | def save(self, *args, **kwargs):
""" Saves the forum instance. """
# It is vital to track the changes of the parent associated with a forum in order to
# maintain counters up-to-date and to trigger other operations such as permissions updates.
old_instance = None
if self.pk:
... | python | def save(self, *args, **kwargs):
""" Saves the forum instance. """
# It is vital to track the changes of the parent associated with a forum in order to
# maintain counters up-to-date and to trigger other operations such as permissions updates.
old_instance = None
if self.pk:
... | [
"def",
"save",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"# It is vital to track the changes of the parent associated with a forum in order to",
"# maintain counters up-to-date and to trigger other operations such as permissions updates.",
"old_instance",
"=",... | Saves the forum instance. | [
"Saves",
"the",
"forum",
"instance",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum/abstract_models.py#L155-L173 |
9,341 | ellmetha/django-machina | machina/apps/forum/abstract_models.py | AbstractForum.update_trackers | def update_trackers(self):
""" Updates the denormalized trackers associated with the forum instance. """
direct_approved_topics = self.topics.filter(approved=True).order_by('-last_post_on')
# Compute the direct topics count and the direct posts count.
self.direct_topics_count = direct_a... | python | def update_trackers(self):
""" Updates the denormalized trackers associated with the forum instance. """
direct_approved_topics = self.topics.filter(approved=True).order_by('-last_post_on')
# Compute the direct topics count and the direct posts count.
self.direct_topics_count = direct_a... | [
"def",
"update_trackers",
"(",
"self",
")",
":",
"direct_approved_topics",
"=",
"self",
".",
"topics",
".",
"filter",
"(",
"approved",
"=",
"True",
")",
".",
"order_by",
"(",
"'-last_post_on'",
")",
"# Compute the direct topics count and the direct posts count.",
"sel... | Updates the denormalized trackers associated with the forum instance. | [
"Updates",
"the",
"denormalized",
"trackers",
"associated",
"with",
"the",
"forum",
"instance",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum/abstract_models.py#L175-L195 |
9,342 | 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 |
9,343 | 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",
")",
")",
"# Resize!",
"image",... | 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 |
9,344 | 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 |
9,345 | 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",
"(",
")",
":",
"# Generates the state of the file",
"state",
"=",
"{",
"'name'",
":",
"upload",
"."... | 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 |
9,346 | 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 |
9,347 | 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",
")",
":",
"# 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.",
"readable_forums",
... | 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 |
9,348 | 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 |
9,349 | 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",
")",
"# A user can edit a post if...",
"# they are a superuser",
"# they are the original poster of the forum post",
"# they belong... | 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 |
9,350 | 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",
")",
"# A user can delete a post if...",
"# they are a superuser",
"# they are the original poster of the forum post",
"# they be... | 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 |
9,351 | 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",
")",
":",
"# First we have to check if the poll is curently open",
"if",
"poll",
".",
"duration",
":",
"poll_dtend",
"=",
"poll",
".",
"created",
"+",
"dt",
".",
"timedelta",
"(",
"days",
"=",
"... | 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 |
9,352 | 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",
")",
":",
"# 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 have not already",
"# subscribed to the c... | 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 |
9,353 | 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",
")",
":",
"# 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 unsubscribe only if they are",
"# already a subscriber ... | 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 |
9,354 | 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 |
9,355 | 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 |
9,356 | 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 |
9,357 | 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 |
9,358 | 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",
")",
"# The action is granted if...",
"# the user is the superuser",
"# the user has the permis... | 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 |
9,359 | 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 |
9,360 | 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 |
9,361 | 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 |
9,362 | 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 |
9,363 | 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 |
9,364 | 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 |
9,365 | 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",
")",
":",
"# 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_ins... | 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 |
9,366 | 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 |
9,367 | 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 |
9,368 | 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 |
9,369 | 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 |
9,370 | 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",
"(",
")",
"# 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",
... | 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 |
9,371 | 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",
")",
"# Ensures that the subject of the thre... | 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 |
9,372 | 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",
":",
"# 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",
".",
"topi... | 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 |
9,373 | 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",
"=",
"[",
"]",
"# Ensures forums last posts and related poster relations are \"followed\" for better",
"# performance (only if we're considering a que... | 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 |
9,374 | 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 |
9,375 | 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 |
9,376 | 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 |
9,377 | 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 |
9,378 | 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 |
9,379 | 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 |
9,380 | 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",
":",
"# An inactive user cannot have permissions",
"return",
"False",
"elif",
"se... | 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 |
9,381 | 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 |
9,382 | 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 |
9,383 | 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 |
9,384 | 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",
".",
"chec... | 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 |
9,385 | 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'",
")",
"# noqa",
"track_han... | 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 |
9,386 | 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_co... | 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 |
9,387 | 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 |
9,388 | 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 |
9,389 | 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 |
9,390 | 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",
"(",
")",
"# 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",
"N... | 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 |
9,391 | 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 |
9,392 | 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 |
9,393 | 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 |
9,394 | 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 |
9,395 | 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 |
9,396 | 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 |
9,397 | 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 |
9,398 | 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",
")",
"# Try to guess the content type of the given ... | 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 |
9,399 | 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 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.