repository_name stringlengths 5 67 | func_path_in_repository stringlengths 4 234 | func_name stringlengths 0 314 | whole_func_string stringlengths 52 3.87M | language stringclasses 6
values | func_code_string stringlengths 52 3.87M | func_code_tokens listlengths 15 672k | func_documentation_string stringlengths 1 47.2k | func_documentation_tokens listlengths 1 3.92k | split_name stringclasses 1
value | func_code_url stringlengths 85 339 |
|---|---|---|---|---|---|---|---|---|---|---|
gregmuellegger/django-autofixture | autofixture/__init__.py | get | def get(model, *args, **kwargs):
'''
Get an autofixture instance for the passed in *model* sing the either an
appropiate autofixture that was :ref:`registry <registry>` or fall back
to the default:class:`AutoFixture` class. *model* can be a model class or
its string representation (e.g. ``"app.Mod... | python | def get(model, *args, **kwargs):
'''
Get an autofixture instance for the passed in *model* sing the either an
appropiate autofixture that was :ref:`registry <registry>` or fall back
to the default:class:`AutoFixture` class. *model* can be a model class or
its string representation (e.g. ``"app.Mod... | [
"def",
"get",
"(",
"model",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"from",
".",
"compat",
"import",
"get_model",
"if",
"isinstance",
"(",
"model",
",",
"string_types",
")",
":",
"model",
"=",
"get_model",
"(",
"*",
"model",
".",
"split"... | Get an autofixture instance for the passed in *model* sing the either an
appropiate autofixture that was :ref:`registry <registry>` or fall back
to the default:class:`AutoFixture` class. *model* can be a model class or
its string representation (e.g. ``"app.ModelClass"``).
All positional and keyword ... | [
"Get",
"an",
"autofixture",
"instance",
"for",
"the",
"passed",
"in",
"*",
"model",
"*",
"sing",
"the",
"either",
"an",
"appropiate",
"autofixture",
"that",
"was",
":",
"ref",
":",
"registry",
"<registry",
">",
"or",
"fall",
"back",
"to",
"the",
"default",... | train | https://github.com/gregmuellegger/django-autofixture/blob/0b696fd3a06747459981e4269aff427676f84ae0/autofixture/__init__.py#L81-L98 |
gregmuellegger/django-autofixture | autofixture/__init__.py | create | def create(model, count, *args, **kwargs):
'''
Create *count* instances of *model* using the either an appropiate
autofixture that was :ref:`registry <registry>` or fall back to the
default:class:`AutoFixture` class. *model* can be a model class or its
string representation (e.g. ``"app.ModelClass"`... | python | def create(model, count, *args, **kwargs):
'''
Create *count* instances of *model* using the either an appropiate
autofixture that was :ref:`registry <registry>` or fall back to the
default:class:`AutoFixture` class. *model* can be a model class or its
string representation (e.g. ``"app.ModelClass"`... | [
"def",
"create",
"(",
"model",
",",
"count",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"from",
".",
"compat",
"import",
"get_model",
"if",
"isinstance",
"(",
"model",
",",
"string_types",
")",
":",
"model",
"=",
"get_model",
"(",
"*",
"mod... | Create *count* instances of *model* using the either an appropiate
autofixture that was :ref:`registry <registry>` or fall back to the
default:class:`AutoFixture` class. *model* can be a model class or its
string representation (e.g. ``"app.ModelClass"``).
All positional and keyword arguments are passe... | [
"Create",
"*",
"count",
"*",
"instances",
"of",
"*",
"model",
"*",
"using",
"the",
"either",
"an",
"appropiate",
"autofixture",
"that",
"was",
":",
"ref",
":",
"registry",
"<registry",
">",
"or",
"fall",
"back",
"to",
"the",
"default",
":",
"class",
":",... | train | https://github.com/gregmuellegger/django-autofixture/blob/0b696fd3a06747459981e4269aff427676f84ae0/autofixture/__init__.py#L101-L136 |
gregmuellegger/django-autofixture | autofixture/__init__.py | autodiscover | def autodiscover():
'''
Auto-discover INSTALLED_APPS autofixtures.py and tests.py modules and fail
silently when not present. This forces an import on them to register any
autofixture bits they may want.
'''
from .compat import importlib
# Bail out if autodiscover didn't finish loading from... | python | def autodiscover():
'''
Auto-discover INSTALLED_APPS autofixtures.py and tests.py modules and fail
silently when not present. This forces an import on them to register any
autofixture bits they may want.
'''
from .compat import importlib
# Bail out if autodiscover didn't finish loading from... | [
"def",
"autodiscover",
"(",
")",
":",
"from",
".",
"compat",
"import",
"importlib",
"# Bail out if autodiscover didn't finish loading from a previous call so",
"# that we avoid running autodiscover again when the URLconf is loaded by",
"# the exception handler to resolve the handler500 view.... | Auto-discover INSTALLED_APPS autofixtures.py and tests.py modules and fail
silently when not present. This forces an import on them to register any
autofixture bits they may want. | [
"Auto",
"-",
"discover",
"INSTALLED_APPS",
"autofixtures",
".",
"py",
"and",
"tests",
".",
"py",
"modules",
"and",
"fail",
"silently",
"when",
"not",
"present",
".",
"This",
"forces",
"an",
"import",
"on",
"them",
"to",
"register",
"any",
"autofixture",
"bit... | train | https://github.com/gregmuellegger/django-autofixture/blob/0b696fd3a06747459981e4269aff427676f84ae0/autofixture/__init__.py#L151-L235 |
gregmuellegger/django-autofixture | autofixture/placeholder.py | get_placeholder_image | def get_placeholder_image(width, height, name=None, fg_color=get_color('black'),
bg_color=get_color('grey'), text=None, font=u'Verdana.ttf',
fontsize=42, encoding=u'unic', mode='RGBA', fmt=u'PNG'):
"""Little spin-off from https://github.com/Visgean/python-placeholder
that not saves an image and ... | python | def get_placeholder_image(width, height, name=None, fg_color=get_color('black'),
bg_color=get_color('grey'), text=None, font=u'Verdana.ttf',
fontsize=42, encoding=u'unic', mode='RGBA', fmt=u'PNG'):
"""Little spin-off from https://github.com/Visgean/python-placeholder
that not saves an image and ... | [
"def",
"get_placeholder_image",
"(",
"width",
",",
"height",
",",
"name",
"=",
"None",
",",
"fg_color",
"=",
"get_color",
"(",
"'black'",
")",
",",
"bg_color",
"=",
"get_color",
"(",
"'grey'",
")",
",",
"text",
"=",
"None",
",",
"font",
"=",
"u'Verdana.t... | Little spin-off from https://github.com/Visgean/python-placeholder
that not saves an image and instead returns it. | [
"Little",
"spin",
"-",
"off",
"from",
"https",
":",
"//",
"github",
".",
"com",
"/",
"Visgean",
"/",
"python",
"-",
"placeholder",
"that",
"not",
"saves",
"an",
"image",
"and",
"instead",
"returns",
"it",
"."
] | train | https://github.com/gregmuellegger/django-autofixture/blob/0b696fd3a06747459981e4269aff427676f84ae0/autofixture/placeholder.py#L13-L47 |
gregmuellegger/django-autofixture | autofixture/base.py | AutoFixtureBase.is_inheritance_parent | def is_inheritance_parent(self, field):
'''
Checks if the field is the automatically created OneToOneField used by
django mulit-table inheritance
'''
return (
isinstance(field, related.OneToOneField) and
field.primary_key and
issubclass(field.m... | python | def is_inheritance_parent(self, field):
'''
Checks if the field is the automatically created OneToOneField used by
django mulit-table inheritance
'''
return (
isinstance(field, related.OneToOneField) and
field.primary_key and
issubclass(field.m... | [
"def",
"is_inheritance_parent",
"(",
"self",
",",
"field",
")",
":",
"return",
"(",
"isinstance",
"(",
"field",
",",
"related",
".",
"OneToOneField",
")",
"and",
"field",
".",
"primary_key",
"and",
"issubclass",
"(",
"field",
".",
"model",
",",
"get_remote_f... | Checks if the field is the automatically created OneToOneField used by
django mulit-table inheritance | [
"Checks",
"if",
"the",
"field",
"is",
"the",
"automatically",
"created",
"OneToOneField",
"used",
"by",
"django",
"mulit",
"-",
"table",
"inheritance"
] | train | https://github.com/gregmuellegger/django-autofixture/blob/0b696fd3a06747459981e4269aff427676f84ae0/autofixture/base.py#L249-L258 |
gregmuellegger/django-autofixture | autofixture/base.py | AutoFixtureBase.get_generator | def get_generator(self, field):
'''
Return a value generator based on the field instance that is passed to
this method. This function may return ``None`` which means that the
specified field will be ignored (e.g. if no matching generator was
found).
'''
if isinsta... | python | def get_generator(self, field):
'''
Return a value generator based on the field instance that is passed to
this method. This function may return ``None`` which means that the
specified field will be ignored (e.g. if no matching generator was
found).
'''
if isinsta... | [
"def",
"get_generator",
"(",
"self",
",",
"field",
")",
":",
"if",
"isinstance",
"(",
"field",
",",
"fields",
".",
"AutoField",
")",
":",
"return",
"None",
"if",
"self",
".",
"is_inheritance_parent",
"(",
"field",
")",
":",
"return",
"None",
"if",
"(",
... | Return a value generator based on the field instance that is passed to
this method. This function may return ``None`` which means that the
specified field will be ignored (e.g. if no matching generator was
found). | [
"Return",
"a",
"value",
"generator",
"based",
"on",
"the",
"field",
"instance",
"that",
"is",
"passed",
"to",
"this",
"method",
".",
"This",
"function",
"may",
"return",
"None",
"which",
"means",
"that",
"the",
"specified",
"field",
"will",
"be",
"ignored",
... | train | https://github.com/gregmuellegger/django-autofixture/blob/0b696fd3a06747459981e4269aff427676f84ae0/autofixture/base.py#L260-L391 |
gregmuellegger/django-autofixture | autofixture/base.py | AutoFixtureBase.get_value | def get_value(self, field):
'''
Return a random value that can be assigned to the passed *field*
instance.
'''
if field not in self._field_generators:
self._field_generators[field] = self.get_generator(field)
generator = self._field_generators[field]
i... | python | def get_value(self, field):
'''
Return a random value that can be assigned to the passed *field*
instance.
'''
if field not in self._field_generators:
self._field_generators[field] = self.get_generator(field)
generator = self._field_generators[field]
i... | [
"def",
"get_value",
"(",
"self",
",",
"field",
")",
":",
"if",
"field",
"not",
"in",
"self",
".",
"_field_generators",
":",
"self",
".",
"_field_generators",
"[",
"field",
"]",
"=",
"self",
".",
"get_generator",
"(",
"field",
")",
"generator",
"=",
"self... | Return a random value that can be assigned to the passed *field*
instance. | [
"Return",
"a",
"random",
"value",
"that",
"can",
"be",
"assigned",
"to",
"the",
"passed",
"*",
"field",
"*",
"instance",
"."
] | train | https://github.com/gregmuellegger/django-autofixture/blob/0b696fd3a06747459981e4269aff427676f84ae0/autofixture/base.py#L393-L404 |
gregmuellegger/django-autofixture | autofixture/base.py | AutoFixtureBase.check_constraints | def check_constraints(self, instance):
'''
Return fieldnames which need recalculation.
'''
recalc_fields = []
for constraint in self.constraints:
try:
constraint(self.model, instance)
except constraints.InvalidConstraint as e:
... | python | def check_constraints(self, instance):
'''
Return fieldnames which need recalculation.
'''
recalc_fields = []
for constraint in self.constraints:
try:
constraint(self.model, instance)
except constraints.InvalidConstraint as e:
... | [
"def",
"check_constraints",
"(",
"self",
",",
"instance",
")",
":",
"recalc_fields",
"=",
"[",
"]",
"for",
"constraint",
"in",
"self",
".",
"constraints",
":",
"try",
":",
"constraint",
"(",
"self",
".",
"model",
",",
"instance",
")",
"except",
"constraint... | Return fieldnames which need recalculation. | [
"Return",
"fieldnames",
"which",
"need",
"recalculation",
"."
] | train | https://github.com/gregmuellegger/django-autofixture/blob/0b696fd3a06747459981e4269aff427676f84ae0/autofixture/base.py#L458-L468 |
gregmuellegger/django-autofixture | autofixture/base.py | AutoFixtureBase.create_one | def create_one(self, commit=True):
'''
Create and return one model instance. If *commit* is ``False`` the
instance will not be saved and many to many relations will not be
processed.
Subclasses that override ``create_one`` can specify arbitrary keyword
arguments. They wi... | python | def create_one(self, commit=True):
'''
Create and return one model instance. If *commit* is ``False`` the
instance will not be saved and many to many relations will not be
processed.
Subclasses that override ``create_one`` can specify arbitrary keyword
arguments. They wi... | [
"def",
"create_one",
"(",
"self",
",",
"commit",
"=",
"True",
")",
":",
"tries",
"=",
"self",
".",
"tries",
"instance",
"=",
"self",
".",
"model",
"(",
")",
"process",
"=",
"instance",
".",
"_meta",
".",
"fields",
"while",
"process",
"and",
"tries",
... | Create and return one model instance. If *commit* is ``False`` the
instance will not be saved and many to many relations will not be
processed.
Subclasses that override ``create_one`` can specify arbitrary keyword
arguments. They will be passed through by the
:meth:`autofixture.... | [
"Create",
"and",
"return",
"one",
"model",
"instance",
".",
"If",
"*",
"commit",
"*",
"is",
"False",
"the",
"instance",
"will",
"not",
"be",
"saved",
"and",
"many",
"to",
"many",
"relations",
"will",
"not",
"be",
"processed",
"."
] | train | https://github.com/gregmuellegger/django-autofixture/blob/0b696fd3a06747459981e4269aff427676f84ae0/autofixture/base.py#L489-L547 |
gregmuellegger/django-autofixture | autofixture/base.py | AutoFixtureBase.create | def create(self, count=1, commit=True, **kwargs):
'''
Create and return ``count`` model instances. If *commit* is ``False``
the instances will not be saved and many to many relations will not be
processed.
May raise ``CreateInstanceError`` if constraints are not satisfied.
... | python | def create(self, count=1, commit=True, **kwargs):
'''
Create and return ``count`` model instances. If *commit* is ``False``
the instances will not be saved and many to many relations will not be
processed.
May raise ``CreateInstanceError`` if constraints are not satisfied.
... | [
"def",
"create",
"(",
"self",
",",
"count",
"=",
"1",
",",
"commit",
"=",
"True",
",",
"*",
"*",
"kwargs",
")",
":",
"object_list",
"=",
"[",
"]",
"for",
"i",
"in",
"range",
"(",
"count",
")",
":",
"instance",
"=",
"self",
".",
"create_one",
"(",... | Create and return ``count`` model instances. If *commit* is ``False``
the instances will not be saved and many to many relations will not be
processed.
May raise ``CreateInstanceError`` if constraints are not satisfied.
The method internally calls :meth:`create_one` to generate instanc... | [
"Create",
"and",
"return",
"count",
"model",
"instances",
".",
"If",
"*",
"commit",
"*",
"is",
"False",
"the",
"instances",
"will",
"not",
"be",
"saved",
"and",
"many",
"to",
"many",
"relations",
"will",
"not",
"be",
"processed",
"."
] | train | https://github.com/gregmuellegger/django-autofixture/blob/0b696fd3a06747459981e4269aff427676f84ae0/autofixture/base.py#L549-L563 |
gregmuellegger/django-autofixture | docs/conf.py | get_release | def get_release(package):
"""
Return package version as listed in `__version__` in `init.py`.
"""
init_path = os.path.join(PROJECT_PATH, package, '__init__.py')
init_py = open(init_path).read()
return re.search("__version__ = ['\"]([^'\"]+)['\"]", init_py).group(1) | python | def get_release(package):
"""
Return package version as listed in `__version__` in `init.py`.
"""
init_path = os.path.join(PROJECT_PATH, package, '__init__.py')
init_py = open(init_path).read()
return re.search("__version__ = ['\"]([^'\"]+)['\"]", init_py).group(1) | [
"def",
"get_release",
"(",
"package",
")",
":",
"init_path",
"=",
"os",
".",
"path",
".",
"join",
"(",
"PROJECT_PATH",
",",
"package",
",",
"'__init__.py'",
")",
"init_py",
"=",
"open",
"(",
"init_path",
")",
".",
"read",
"(",
")",
"return",
"re",
".",... | Return package version as listed in `__version__` in `init.py`. | [
"Return",
"package",
"version",
"as",
"listed",
"in",
"__version__",
"in",
"init",
".",
"py",
"."
] | train | https://github.com/gregmuellegger/django-autofixture/blob/0b696fd3a06747459981e4269aff427676f84ae0/docs/conf.py#L59-L65 |
gregmuellegger/django-autofixture | fabfile.py | opendocs | def opendocs(where='index', how='default'):
'''
Rebuild documentation and opens it in your browser.
Use the first argument to specify how it should be opened:
`d` or `default`: Open in new tab or new window, using the default
method of your browser.
`t` or `tab`: Open documentatio... | python | def opendocs(where='index', how='default'):
'''
Rebuild documentation and opens it in your browser.
Use the first argument to specify how it should be opened:
`d` or `default`: Open in new tab or new window, using the default
method of your browser.
`t` or `tab`: Open documentatio... | [
"def",
"opendocs",
"(",
"where",
"=",
"'index'",
",",
"how",
"=",
"'default'",
")",
":",
"import",
"webbrowser",
"docs_dir",
"=",
"os",
".",
"path",
".",
"join",
"(",
"os",
".",
"path",
".",
"dirname",
"(",
"os",
".",
"path",
".",
"abspath",
"(",
"... | Rebuild documentation and opens it in your browser.
Use the first argument to specify how it should be opened:
`d` or `default`: Open in new tab or new window, using the default
method of your browser.
`t` or `tab`: Open documentation in new tab.
`n`, `w` or `window`: Open docume... | [
"Rebuild",
"documentation",
"and",
"opens",
"it",
"in",
"your",
"browser",
"."
] | train | https://github.com/gregmuellegger/django-autofixture/blob/0b696fd3a06747459981e4269aff427676f84ae0/fabfile.py#L24-L49 |
plumdog/flask_table | examples/column_html_attrs.py | main | def main():
items = [Item('Name1', 'Description1'),
Item('Name2', 'Description2'),
Item('Name3', 'Description3')]
table = ItemTable(items)
# or {{ table }} in jinja
print(table.__html__())
"""Outputs:
<table>
<thead>
<tr>
<th class="my-name-c... | python | def main():
items = [Item('Name1', 'Description1'),
Item('Name2', 'Description2'),
Item('Name3', 'Description3')]
table = ItemTable(items)
# or {{ table }} in jinja
print(table.__html__())
"""Outputs:
<table>
<thead>
<tr>
<th class="my-name-c... | [
"def",
"main",
"(",
")",
":",
"items",
"=",
"[",
"Item",
"(",
"'Name1'",
",",
"'Description1'",
")",
",",
"Item",
"(",
"'Name2'",
",",
"'Description2'",
")",
",",
"Item",
"(",
"'Name3'",
",",
"'Description3'",
")",
"]",
"table",
"=",
"ItemTable",
"(",
... | Outputs:
<table>
<thead>
<tr>
<th class="my-name-class">Name</th>
<th class="my-description-class"
data-something="my-data"
data-something-else="my-description-th-class">
Description
</th>
</tr>
</thead>
<tbody>... | [
"Outputs",
":"
] | train | https://github.com/plumdog/flask_table/blob/1eae252c6b26037a6aa19fcd787a981ddb3a9191/examples/column_html_attrs.py#L44-L93 |
plumdog/flask_table | examples/simple_nested.py | main | def main():
items = [Item('Name1', 'Description1', [SubItem('r1sr1c1', 'r1sr1c2'),
SubItem('r1sr2c1', 'r1sr2c2')]),
Item('Name2', 'Description2', [SubItem('r2sr1c1', 'r2sr1c2'),
SubItem('r2sr2c1', 'r2sr2c2')]),
... | python | def main():
items = [Item('Name1', 'Description1', [SubItem('r1sr1c1', 'r1sr1c2'),
SubItem('r1sr2c1', 'r1sr2c2')]),
Item('Name2', 'Description2', [SubItem('r2sr1c1', 'r2sr1c2'),
SubItem('r2sr2c1', 'r2sr2c2')]),
... | [
"def",
"main",
"(",
")",
":",
"items",
"=",
"[",
"Item",
"(",
"'Name1'",
",",
"'Description1'",
",",
"[",
"SubItem",
"(",
"'r1sr1c1'",
",",
"'r1sr1c2'",
")",
",",
"SubItem",
"(",
"'r1sr2c1'",
",",
"'r1sr2c2'",
")",
"]",
")",
",",
"Item",
"(",
"'Name2... | Outputs:
<table>
<thead>
<tr><th>Name</th><th>Description</th><th>Subtable</th></tr>
</thead>
<tbody>
<tr><td>Name1</td><td>Description1</td><td><table>
<thead>
<tr><th>Sub-column 1</th><th>Sub-column 2</th></tr>
</thead>
<... | [
"Outputs",
":"
] | train | https://github.com/plumdog/flask_table/blob/1eae252c6b26037a6aa19fcd787a981ddb3a9191/examples/simple_nested.py#L37-L78 |
plumdog/flask_table | examples/dynamic.py | main | def main():
TableCls = create_table()\
.add_column('name', Col('Name'))\
.add_column('description', Col('Description'))
items = [dict(name='Name1', description='Description1'),
dict(name='Name2', description='Description2'),
dict(name='Name3', description='Description3... | python | def main():
TableCls = create_table()\
.add_column('name', Col('Name'))\
.add_column('description', Col('Description'))
items = [dict(name='Name1', description='Description1'),
dict(name='Name2', description='Description2'),
dict(name='Name3', description='Description3... | [
"def",
"main",
"(",
")",
":",
"TableCls",
"=",
"create_table",
"(",
")",
".",
"add_column",
"(",
"'name'",
",",
"Col",
"(",
"'Name'",
")",
")",
".",
"add_column",
"(",
"'description'",
",",
"Col",
"(",
"'Description'",
")",
")",
"items",
"=",
"[",
"d... | Outputs:
<table>
<thead>
<tr>
<th>Name</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>Name1</td>
<td>Description1</td>
</tr>
<tr>
<td>Name2</td>
<td>Description2</td>
</tr>
... | [
"Outputs",
":"
] | train | https://github.com/plumdog/flask_table/blob/1eae252c6b26037a6aa19fcd787a981ddb3a9191/examples/dynamic.py#L4-L41 |
plumdog/flask_table | flask_table/table.py | create_table | def create_table(name=str('_Table'), base=Table, options=None):
"""Creates and returns a new table class. You can specify a name for
you class if you wish. You can also set the base class (or
classes) that should be used when creating the class.
"""
try:
base = tuple(base)
except TypeEr... | python | def create_table(name=str('_Table'), base=Table, options=None):
"""Creates and returns a new table class. You can specify a name for
you class if you wish. You can also set the base class (or
classes) that should be used when creating the class.
"""
try:
base = tuple(base)
except TypeEr... | [
"def",
"create_table",
"(",
"name",
"=",
"str",
"(",
"'_Table'",
")",
",",
"base",
"=",
"Table",
",",
"options",
"=",
"None",
")",
":",
"try",
":",
"base",
"=",
"tuple",
"(",
"base",
")",
"except",
"TypeError",
":",
"# Then assume that what we have is a si... | Creates and returns a new table class. You can specify a name for
you class if you wish. You can also set the base class (or
classes) that should be used when creating the class. | [
"Creates",
"and",
"returns",
"a",
"new",
"table",
"class",
".",
"You",
"can",
"specify",
"a",
"name",
"for",
"you",
"class",
"if",
"you",
"wish",
".",
"You",
"can",
"also",
"set",
"the",
"base",
"class",
"(",
"or",
"classes",
")",
"that",
"should",
"... | train | https://github.com/plumdog/flask_table/blob/1eae252c6b26037a6aa19fcd787a981ddb3a9191/flask_table/table.py#L182-L195 |
plumdog/flask_table | flask_table/columns.py | Col.td_contents | def td_contents(self, item, attr_list):
"""Given an item and an attr, return the contents of the td.
This method is a likely candidate to override when extending
the Col class, which is done in LinkCol and
ButtonCol. Override this method if you need to get some extra
data from t... | python | def td_contents(self, item, attr_list):
"""Given an item and an attr, return the contents of the td.
This method is a likely candidate to override when extending
the Col class, which is done in LinkCol and
ButtonCol. Override this method if you need to get some extra
data from t... | [
"def",
"td_contents",
"(",
"self",
",",
"item",
",",
"attr_list",
")",
":",
"return",
"self",
".",
"td_format",
"(",
"self",
".",
"from_attr_list",
"(",
"item",
",",
"attr_list",
")",
")"
] | Given an item and an attr, return the contents of the td.
This method is a likely candidate to override when extending
the Col class, which is done in LinkCol and
ButtonCol. Override this method if you need to get some extra
data from the item.
Note that the output of this func... | [
"Given",
"an",
"item",
"and",
"an",
"attr",
"return",
"the",
"contents",
"of",
"the",
"td",
"."
] | train | https://github.com/plumdog/flask_table/blob/1eae252c6b26037a6aa19fcd787a981ddb3a9191/flask_table/columns.py#L102-L113 |
peterjc/backports.lzma | backports/lzma/__init__.py | open | def open(filename, mode="rb",
format=None, check=-1, preset=None, filters=None,
encoding=None, errors=None, newline=None):
"""Open an LZMA-compressed file in binary or text mode.
filename can be either an actual file name (given as a str or bytes object),
in which case the named file is o... | python | def open(filename, mode="rb",
format=None, check=-1, preset=None, filters=None,
encoding=None, errors=None, newline=None):
"""Open an LZMA-compressed file in binary or text mode.
filename can be either an actual file name (given as a str or bytes object),
in which case the named file is o... | [
"def",
"open",
"(",
"filename",
",",
"mode",
"=",
"\"rb\"",
",",
"format",
"=",
"None",
",",
"check",
"=",
"-",
"1",
",",
"preset",
"=",
"None",
",",
"filters",
"=",
"None",
",",
"encoding",
"=",
"None",
",",
"errors",
"=",
"None",
",",
"newline",
... | Open an LZMA-compressed file in binary or text mode.
filename can be either an actual file name (given as a str or bytes object),
in which case the named file is opened, or it can be an existing file object
to read from or write to.
The mode argument can be "r", "rb" (default), "w", "wb", "a", or "ab"... | [
"Open",
"an",
"LZMA",
"-",
"compressed",
"file",
"in",
"binary",
"or",
"text",
"mode",
"."
] | train | https://github.com/peterjc/backports.lzma/blob/6555d8b8e493a35159025b4cfc204dfb54c33d3e/backports/lzma/__init__.py#L396-L438 |
peterjc/backports.lzma | backports/lzma/__init__.py | compress | def compress(data, format=FORMAT_XZ, check=-1, preset=None, filters=None):
"""Compress a block of data.
Refer to LZMACompressor's docstring for a description of the
optional arguments *format*, *check*, *preset* and *filters*.
For incremental compression, use an LZMACompressor object instead.
"""
... | python | def compress(data, format=FORMAT_XZ, check=-1, preset=None, filters=None):
"""Compress a block of data.
Refer to LZMACompressor's docstring for a description of the
optional arguments *format*, *check*, *preset* and *filters*.
For incremental compression, use an LZMACompressor object instead.
"""
... | [
"def",
"compress",
"(",
"data",
",",
"format",
"=",
"FORMAT_XZ",
",",
"check",
"=",
"-",
"1",
",",
"preset",
"=",
"None",
",",
"filters",
"=",
"None",
")",
":",
"comp",
"=",
"LZMACompressor",
"(",
"format",
",",
"check",
",",
"preset",
",",
"filters"... | Compress a block of data.
Refer to LZMACompressor's docstring for a description of the
optional arguments *format*, *check*, *preset* and *filters*.
For incremental compression, use an LZMACompressor object instead. | [
"Compress",
"a",
"block",
"of",
"data",
"."
] | train | https://github.com/peterjc/backports.lzma/blob/6555d8b8e493a35159025b4cfc204dfb54c33d3e/backports/lzma/__init__.py#L441-L450 |
peterjc/backports.lzma | backports/lzma/__init__.py | decompress | def decompress(data, format=FORMAT_AUTO, memlimit=None, filters=None):
"""Decompress a block of data.
Refer to LZMADecompressor's docstring for a description of the
optional arguments *format*, *check* and *filters*.
For incremental decompression, use a LZMADecompressor object instead.
"""
res... | python | def decompress(data, format=FORMAT_AUTO, memlimit=None, filters=None):
"""Decompress a block of data.
Refer to LZMADecompressor's docstring for a description of the
optional arguments *format*, *check* and *filters*.
For incremental decompression, use a LZMADecompressor object instead.
"""
res... | [
"def",
"decompress",
"(",
"data",
",",
"format",
"=",
"FORMAT_AUTO",
",",
"memlimit",
"=",
"None",
",",
"filters",
"=",
"None",
")",
":",
"results",
"=",
"[",
"]",
"while",
"True",
":",
"decomp",
"=",
"LZMADecompressor",
"(",
"format",
",",
"memlimit",
... | Decompress a block of data.
Refer to LZMADecompressor's docstring for a description of the
optional arguments *format*, *check* and *filters*.
For incremental decompression, use a LZMADecompressor object instead. | [
"Decompress",
"a",
"block",
"of",
"data",
"."
] | train | https://github.com/peterjc/backports.lzma/blob/6555d8b8e493a35159025b4cfc204dfb54c33d3e/backports/lzma/__init__.py#L453-L478 |
peterjc/backports.lzma | backports/lzma/__init__.py | LZMAFile.close | def close(self):
"""Flush and close the file.
May be called more than once without error. Once the file is
closed, any other operation on it will raise a ValueError.
"""
if self._mode == _MODE_CLOSED:
return
try:
if self._mode in (_MODE_READ, _MOD... | python | def close(self):
"""Flush and close the file.
May be called more than once without error. Once the file is
closed, any other operation on it will raise a ValueError.
"""
if self._mode == _MODE_CLOSED:
return
try:
if self._mode in (_MODE_READ, _MOD... | [
"def",
"close",
"(",
"self",
")",
":",
"if",
"self",
".",
"_mode",
"==",
"_MODE_CLOSED",
":",
"return",
"try",
":",
"if",
"self",
".",
"_mode",
"in",
"(",
"_MODE_READ",
",",
"_MODE_READ_EOF",
")",
":",
"self",
".",
"_decompressor",
"=",
"None",
"self",... | Flush and close the file.
May be called more than once without error. Once the file is
closed, any other operation on it will raise a ValueError. | [
"Flush",
"and",
"close",
"the",
"file",
"."
] | train | https://github.com/peterjc/backports.lzma/blob/6555d8b8e493a35159025b4cfc204dfb54c33d3e/backports/lzma/__init__.py#L134-L156 |
peterjc/backports.lzma | backports/lzma/__init__.py | LZMAFile.peek | def peek(self, size=-1):
"""Return buffered data without advancing the file position.
Always returns at least one byte of data, unless at EOF.
The exact number of bytes returned is unspecified.
"""
self._check_can_read()
if self._mode == _MODE_READ_EOF or not self._fill_... | python | def peek(self, size=-1):
"""Return buffered data without advancing the file position.
Always returns at least one byte of data, unless at EOF.
The exact number of bytes returned is unspecified.
"""
self._check_can_read()
if self._mode == _MODE_READ_EOF or not self._fill_... | [
"def",
"peek",
"(",
"self",
",",
"size",
"=",
"-",
"1",
")",
":",
"self",
".",
"_check_can_read",
"(",
")",
"if",
"self",
".",
"_mode",
"==",
"_MODE_READ_EOF",
"or",
"not",
"self",
".",
"_fill_buffer",
"(",
")",
":",
"return",
"b\"\"",
"return",
"sel... | Return buffered data without advancing the file position.
Always returns at least one byte of data, unless at EOF.
The exact number of bytes returned is unspecified. | [
"Return",
"buffered",
"data",
"without",
"advancing",
"the",
"file",
"position",
"."
] | train | https://github.com/peterjc/backports.lzma/blob/6555d8b8e493a35159025b4cfc204dfb54c33d3e/backports/lzma/__init__.py#L268-L277 |
peterjc/backports.lzma | backports/lzma/__init__.py | LZMAFile.read | def read(self, size=-1):
"""Read up to size uncompressed bytes from the file.
If size is negative or omitted, read until EOF is reached.
Returns b"" if the file is already at EOF.
"""
self._check_can_read()
if size is None:
#This is not needed on Python 3 whe... | python | def read(self, size=-1):
"""Read up to size uncompressed bytes from the file.
If size is negative or omitted, read until EOF is reached.
Returns b"" if the file is already at EOF.
"""
self._check_can_read()
if size is None:
#This is not needed on Python 3 whe... | [
"def",
"read",
"(",
"self",
",",
"size",
"=",
"-",
"1",
")",
":",
"self",
".",
"_check_can_read",
"(",
")",
"if",
"size",
"is",
"None",
":",
"#This is not needed on Python 3 where the comparison to zeo",
"#will fail with a TypeError.",
"raise",
"TypeError",
"(",
"... | Read up to size uncompressed bytes from the file.
If size is negative or omitted, read until EOF is reached.
Returns b"" if the file is already at EOF. | [
"Read",
"up",
"to",
"size",
"uncompressed",
"bytes",
"from",
"the",
"file",
"."
] | train | https://github.com/peterjc/backports.lzma/blob/6555d8b8e493a35159025b4cfc204dfb54c33d3e/backports/lzma/__init__.py#L279-L295 |
peterjc/backports.lzma | backports/lzma/__init__.py | LZMAFile.read1 | def read1(self, size=-1):
"""Read up to size uncompressed bytes, while trying to avoid
making multiple reads from the underlying stream.
Returns b"" if the file is at EOF.
"""
# Usually, read1() calls _fp.read() at most once. However, sometimes
# this does not give enoug... | python | def read1(self, size=-1):
"""Read up to size uncompressed bytes, while trying to avoid
making multiple reads from the underlying stream.
Returns b"" if the file is at EOF.
"""
# Usually, read1() calls _fp.read() at most once. However, sometimes
# this does not give enoug... | [
"def",
"read1",
"(",
"self",
",",
"size",
"=",
"-",
"1",
")",
":",
"# Usually, read1() calls _fp.read() at most once. However, sometimes",
"# this does not give enough data for the decompressor to make progress.",
"# In this case we make multiple reads, to avoid returning b\"\".",
"self"... | Read up to size uncompressed bytes, while trying to avoid
making multiple reads from the underlying stream.
Returns b"" if the file is at EOF. | [
"Read",
"up",
"to",
"size",
"uncompressed",
"bytes",
"while",
"trying",
"to",
"avoid",
"making",
"multiple",
"reads",
"from",
"the",
"underlying",
"stream",
"."
] | train | https://github.com/peterjc/backports.lzma/blob/6555d8b8e493a35159025b4cfc204dfb54c33d3e/backports/lzma/__init__.py#L297-L321 |
peterjc/backports.lzma | backports/lzma/__init__.py | LZMAFile.write | def write(self, data):
"""Write a bytes object to the file.
Returns the number of uncompressed bytes written, which is
always len(data). Note that due to buffering, the file on disk
may not reflect the data written until close() is called.
"""
self._check_can_write()
... | python | def write(self, data):
"""Write a bytes object to the file.
Returns the number of uncompressed bytes written, which is
always len(data). Note that due to buffering, the file on disk
may not reflect the data written until close() is called.
"""
self._check_can_write()
... | [
"def",
"write",
"(",
"self",
",",
"data",
")",
":",
"self",
".",
"_check_can_write",
"(",
")",
"compressed",
"=",
"self",
".",
"_compressor",
".",
"compress",
"(",
"data",
")",
"self",
".",
"_fp",
".",
"write",
"(",
"compressed",
")",
"self",
".",
"_... | Write a bytes object to the file.
Returns the number of uncompressed bytes written, which is
always len(data). Note that due to buffering, the file on disk
may not reflect the data written until close() is called. | [
"Write",
"a",
"bytes",
"object",
"to",
"the",
"file",
"."
] | train | https://github.com/peterjc/backports.lzma/blob/6555d8b8e493a35159025b4cfc204dfb54c33d3e/backports/lzma/__init__.py#L323-L334 |
peterjc/backports.lzma | backports/lzma/__init__.py | LZMAFile.seek | def seek(self, offset, whence=0):
"""Change the file position.
The new position is specified by offset, relative to the
position indicated by whence. Possible values for whence are:
0: start of stream (default): offset must not be negative
1: current stream position
... | python | def seek(self, offset, whence=0):
"""Change the file position.
The new position is specified by offset, relative to the
position indicated by whence. Possible values for whence are:
0: start of stream (default): offset must not be negative
1: current stream position
... | [
"def",
"seek",
"(",
"self",
",",
"offset",
",",
"whence",
"=",
"0",
")",
":",
"self",
".",
"_check_can_seek",
"(",
")",
"# Recalculate offset as an absolute file position.",
"if",
"whence",
"==",
"0",
":",
"pass",
"elif",
"whence",
"==",
"1",
":",
"offset",
... | Change the file position.
The new position is specified by offset, relative to the
position indicated by whence. Possible values for whence are:
0: start of stream (default): offset must not be negative
1: current stream position
2: end of stream; offset must not be... | [
"Change",
"the",
"file",
"position",
"."
] | train | https://github.com/peterjc/backports.lzma/blob/6555d8b8e493a35159025b4cfc204dfb54c33d3e/backports/lzma/__init__.py#L344-L388 |
inveniosoftware/invenio-github | invenio_github/models.py | Repository.create | def create(cls, user_id, github_id=None, name=None, **kwargs):
"""Create the repository."""
with db.session.begin_nested():
obj = cls(user_id=user_id, github_id=github_id, name=name,
**kwargs)
db.session.add(obj)
return obj | python | def create(cls, user_id, github_id=None, name=None, **kwargs):
"""Create the repository."""
with db.session.begin_nested():
obj = cls(user_id=user_id, github_id=github_id, name=name,
**kwargs)
db.session.add(obj)
return obj | [
"def",
"create",
"(",
"cls",
",",
"user_id",
",",
"github_id",
"=",
"None",
",",
"name",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"with",
"db",
".",
"session",
".",
"begin_nested",
"(",
")",
":",
"obj",
"=",
"cls",
"(",
"user_id",
"=",
"us... | Create the repository. | [
"Create",
"the",
"repository",
"."
] | train | https://github.com/inveniosoftware/invenio-github/blob/ec42fd6a06079310dcbe2c46d9fd79d5197bbe26/invenio_github/models.py#L172-L178 |
inveniosoftware/invenio-github | invenio_github/models.py | Repository.get | def get(cls, user_id, github_id=None, name=None, check_owner=True):
"""Return a repository.
:param integer user_id: User identifier.
:param integer github_id: GitHub repository identifier.
:param str name: GitHub repository full name.
:returns: The repository object.
:ra... | python | def get(cls, user_id, github_id=None, name=None, check_owner=True):
"""Return a repository.
:param integer user_id: User identifier.
:param integer github_id: GitHub repository identifier.
:param str name: GitHub repository full name.
:returns: The repository object.
:ra... | [
"def",
"get",
"(",
"cls",
",",
"user_id",
",",
"github_id",
"=",
"None",
",",
"name",
"=",
"None",
",",
"check_owner",
"=",
"True",
")",
":",
"repo",
"=",
"cls",
".",
"query",
".",
"filter",
"(",
"(",
"Repository",
".",
"github_id",
"==",
"github_id"... | Return a repository.
:param integer user_id: User identifier.
:param integer github_id: GitHub repository identifier.
:param str name: GitHub repository full name.
:returns: The repository object.
:raises: :py:exc:`~sqlalchemy.orm.exc.NoResultFound`: if the repository
... | [
"Return",
"a",
"repository",
"."
] | train | https://github.com/inveniosoftware/invenio-github/blob/ec42fd6a06079310dcbe2c46d9fd79d5197bbe26/invenio_github/models.py#L181-L204 |
inveniosoftware/invenio-github | invenio_github/models.py | Repository.enable | def enable(cls, user_id, github_id, name, hook):
"""Enable webhooks for a repository.
If the repository does not exist it will create one.
:param user_id: User identifier.
:param repo_id: GitHub repository identifier.
:param name: Fully qualified name of the repository.
... | python | def enable(cls, user_id, github_id, name, hook):
"""Enable webhooks for a repository.
If the repository does not exist it will create one.
:param user_id: User identifier.
:param repo_id: GitHub repository identifier.
:param name: Fully qualified name of the repository.
... | [
"def",
"enable",
"(",
"cls",
",",
"user_id",
",",
"github_id",
",",
"name",
",",
"hook",
")",
":",
"try",
":",
"repo",
"=",
"cls",
".",
"get",
"(",
"user_id",
",",
"github_id",
"=",
"github_id",
",",
"name",
"=",
"name",
")",
"except",
"NoResultFound... | Enable webhooks for a repository.
If the repository does not exist it will create one.
:param user_id: User identifier.
:param repo_id: GitHub repository identifier.
:param name: Fully qualified name of the repository.
:param hook: GitHub hook identifier. | [
"Enable",
"webhooks",
"for",
"a",
"repository",
"."
] | train | https://github.com/inveniosoftware/invenio-github/blob/ec42fd6a06079310dcbe2c46d9fd79d5197bbe26/invenio_github/models.py#L207-L223 |
inveniosoftware/invenio-github | invenio_github/models.py | Repository.disable | def disable(cls, user_id, github_id, name):
"""Disable webhooks for a repository.
Disables the webhook from a repository if it exists in the DB.
:param user_id: User identifier.
:param repo_id: GitHub id of the repository.
:param name: Fully qualified name of the repository.
... | python | def disable(cls, user_id, github_id, name):
"""Disable webhooks for a repository.
Disables the webhook from a repository if it exists in the DB.
:param user_id: User identifier.
:param repo_id: GitHub id of the repository.
:param name: Fully qualified name of the repository.
... | [
"def",
"disable",
"(",
"cls",
",",
"user_id",
",",
"github_id",
",",
"name",
")",
":",
"repo",
"=",
"cls",
".",
"get",
"(",
"user_id",
",",
"github_id",
"=",
"github_id",
",",
"name",
"=",
"name",
")",
"repo",
".",
"hook",
"=",
"None",
"repo",
".",... | Disable webhooks for a repository.
Disables the webhook from a repository if it exists in the DB.
:param user_id: User identifier.
:param repo_id: GitHub id of the repository.
:param name: Fully qualified name of the repository. | [
"Disable",
"webhooks",
"for",
"a",
"repository",
"."
] | train | https://github.com/inveniosoftware/invenio-github/blob/ec42fd6a06079310dcbe2c46d9fd79d5197bbe26/invenio_github/models.py#L226-L238 |
inveniosoftware/invenio-github | invenio_github/models.py | Release.create | def create(cls, event):
"""Create a new Release model."""
# Check if the release has already been received
release_id = event.payload['release']['id']
existing_release = Release.query.filter_by(
release_id=release_id,
).first()
if existing_release:
... | python | def create(cls, event):
"""Create a new Release model."""
# Check if the release has already been received
release_id = event.payload['release']['id']
existing_release = Release.query.filter_by(
release_id=release_id,
).first()
if existing_release:
... | [
"def",
"create",
"(",
"cls",
",",
"event",
")",
":",
"# Check if the release has already been received",
"release_id",
"=",
"event",
".",
"payload",
"[",
"'release'",
"]",
"[",
"'id'",
"]",
"existing_release",
"=",
"Release",
".",
"query",
".",
"filter_by",
"(",... | Create a new Release model. | [
"Create",
"a",
"new",
"Release",
"model",
"."
] | train | https://github.com/inveniosoftware/invenio-github/blob/ec42fd6a06079310dcbe2c46d9fd79d5197bbe26/invenio_github/models.py#L314-L348 |
inveniosoftware/invenio-github | invenio_github/models.py | Release.record | def record(self):
"""Get Record object."""
if self.recordmetadata:
return Record(self.recordmetadata.json, model=self.recordmetadata)
else:
return None | python | def record(self):
"""Get Record object."""
if self.recordmetadata:
return Record(self.recordmetadata.json, model=self.recordmetadata)
else:
return None | [
"def",
"record",
"(",
"self",
")",
":",
"if",
"self",
".",
"recordmetadata",
":",
"return",
"Record",
"(",
"self",
".",
"recordmetadata",
".",
"json",
",",
"model",
"=",
"self",
".",
"recordmetadata",
")",
"else",
":",
"return",
"None"
] | Get Record object. | [
"Get",
"Record",
"object",
"."
] | train | https://github.com/inveniosoftware/invenio-github/blob/ec42fd6a06079310dcbe2c46d9fd79d5197bbe26/invenio_github/models.py#L351-L356 |
inveniosoftware/invenio-github | invenio_github/views/badge.py | get_badge_image_url | def get_badge_image_url(pid, ext='svg'):
"""Return the badge for a DOI."""
return url_for('invenio_formatter_badges.badge',
title=pid.pid_type, value=pid.pid_value, ext=ext) | python | def get_badge_image_url(pid, ext='svg'):
"""Return the badge for a DOI."""
return url_for('invenio_formatter_badges.badge',
title=pid.pid_type, value=pid.pid_value, ext=ext) | [
"def",
"get_badge_image_url",
"(",
"pid",
",",
"ext",
"=",
"'svg'",
")",
":",
"return",
"url_for",
"(",
"'invenio_formatter_badges.badge'",
",",
"title",
"=",
"pid",
".",
"pid_type",
",",
"value",
"=",
"pid",
".",
"pid_value",
",",
"ext",
"=",
"ext",
")"
] | Return the badge for a DOI. | [
"Return",
"the",
"badge",
"for",
"a",
"DOI",
"."
] | train | https://github.com/inveniosoftware/invenio-github/blob/ec42fd6a06079310dcbe2c46d9fd79d5197bbe26/invenio_github/views/badge.py#L51-L54 |
inveniosoftware/invenio-github | invenio_github/views/badge.py | index_old | def index_old(user_id, repo_name):
"""Generate a badge for a specific GitHub repository."""
pid = get_pid_of_latest_release_or_404(name=repo_name)
return redirect(get_badge_image_url(pid)) | python | def index_old(user_id, repo_name):
"""Generate a badge for a specific GitHub repository."""
pid = get_pid_of_latest_release_or_404(name=repo_name)
return redirect(get_badge_image_url(pid)) | [
"def",
"index_old",
"(",
"user_id",
",",
"repo_name",
")",
":",
"pid",
"=",
"get_pid_of_latest_release_or_404",
"(",
"name",
"=",
"repo_name",
")",
"return",
"redirect",
"(",
"get_badge_image_url",
"(",
"pid",
")",
")"
] | Generate a badge for a specific GitHub repository. | [
"Generate",
"a",
"badge",
"for",
"a",
"specific",
"GitHub",
"repository",
"."
] | train | https://github.com/inveniosoftware/invenio-github/blob/ec42fd6a06079310dcbe2c46d9fd79d5197bbe26/invenio_github/views/badge.py#L73-L76 |
inveniosoftware/invenio-github | invenio_github/tasks.py | disconnect_github | def disconnect_github(access_token, repo_hooks):
"""Uninstall webhooks."""
# Note at this point the remote account and all associated data have
# already been deleted. The celery task is passed the access_token to make
# some last cleanup and afterwards delete itself remotely.
import github3
fro... | python | def disconnect_github(access_token, repo_hooks):
"""Uninstall webhooks."""
# Note at this point the remote account and all associated data have
# already been deleted. The celery task is passed the access_token to make
# some last cleanup and afterwards delete itself remotely.
import github3
fro... | [
"def",
"disconnect_github",
"(",
"access_token",
",",
"repo_hooks",
")",
":",
"# Note at this point the remote account and all associated data have",
"# already been deleted. The celery task is passed the access_token to make",
"# some last cleanup and afterwards delete itself remotely.",
"imp... | Uninstall webhooks. | [
"Uninstall",
"webhooks",
"."
] | train | https://github.com/inveniosoftware/invenio-github/blob/ec42fd6a06079310dcbe2c46d9fd79d5197bbe26/invenio_github/tasks.py#L38-L60 |
inveniosoftware/invenio-github | invenio_github/tasks.py | sync_hooks | def sync_hooks(user_id, repositories):
"""Sync repository hooks for a user."""
from .api import GitHubAPI
try:
# Sync hooks
gh = GitHubAPI(user_id=user_id)
for repo_id in repositories:
try:
with db.session.begin_nested():
gh.sync_repo_... | python | def sync_hooks(user_id, repositories):
"""Sync repository hooks for a user."""
from .api import GitHubAPI
try:
# Sync hooks
gh = GitHubAPI(user_id=user_id)
for repo_id in repositories:
try:
with db.session.begin_nested():
gh.sync_repo_... | [
"def",
"sync_hooks",
"(",
"user_id",
",",
"repositories",
")",
":",
"from",
".",
"api",
"import",
"GitHubAPI",
"try",
":",
"# Sync hooks",
"gh",
"=",
"GitHubAPI",
"(",
"user_id",
"=",
"user_id",
")",
"for",
"repo_id",
"in",
"repositories",
":",
"try",
":",... | Sync repository hooks for a user. | [
"Sync",
"repository",
"hooks",
"for",
"a",
"user",
"."
] | train | https://github.com/inveniosoftware/invenio-github/blob/ec42fd6a06079310dcbe2c46d9fd79d5197bbe26/invenio_github/tasks.py#L64-L83 |
inveniosoftware/invenio-github | invenio_github/tasks.py | process_release | def process_release(release_id, verify_sender=False):
"""Process a received Release."""
from invenio_db import db
from invenio_rest.errors import RESTException
from .errors import InvalidSenderError
from .models import Release, ReleaseStatus
from .proxies import current_github
release_mode... | python | def process_release(release_id, verify_sender=False):
"""Process a received Release."""
from invenio_db import db
from invenio_rest.errors import RESTException
from .errors import InvalidSenderError
from .models import Release, ReleaseStatus
from .proxies import current_github
release_mode... | [
"def",
"process_release",
"(",
"release_id",
",",
"verify_sender",
"=",
"False",
")",
":",
"from",
"invenio_db",
"import",
"db",
"from",
"invenio_rest",
".",
"errors",
"import",
"RESTException",
"from",
".",
"errors",
"import",
"InvalidSenderError",
"from",
".",
... | Process a received Release. | [
"Process",
"a",
"received",
"Release",
"."
] | train | https://github.com/inveniosoftware/invenio-github/blob/ec42fd6a06079310dcbe2c46d9fd79d5197bbe26/invenio_github/tasks.py#L87-L143 |
inveniosoftware/invenio-github | invenio_github/views/github.py | naturaltime | def naturaltime(val):
"""Get humanized version of time."""
val = val.replace(tzinfo=pytz.utc) \
if isinstance(val, datetime) else parse(val)
now = datetime.utcnow().replace(tzinfo=pytz.utc)
return humanize.naturaltime(now - val) | python | def naturaltime(val):
"""Get humanized version of time."""
val = val.replace(tzinfo=pytz.utc) \
if isinstance(val, datetime) else parse(val)
now = datetime.utcnow().replace(tzinfo=pytz.utc)
return humanize.naturaltime(now - val) | [
"def",
"naturaltime",
"(",
"val",
")",
":",
"val",
"=",
"val",
".",
"replace",
"(",
"tzinfo",
"=",
"pytz",
".",
"utc",
")",
"if",
"isinstance",
"(",
"val",
",",
"datetime",
")",
"else",
"parse",
"(",
"val",
")",
"now",
"=",
"datetime",
".",
"utcnow... | Get humanized version of time. | [
"Get",
"humanized",
"version",
"of",
"time",
"."
] | train | https://github.com/inveniosoftware/invenio-github/blob/ec42fd6a06079310dcbe2c46d9fd79d5197bbe26/invenio_github/views/github.py#L61-L67 |
inveniosoftware/invenio-github | invenio_github/views/github.py | index | def index():
"""Display list of the user's repositories."""
github = GitHubAPI(user_id=current_user.id)
token = github.session_token
ctx = dict(connected=False)
if token:
# The user is authenticated and the token we have is still valid.
if github.account.extra_data.get('login') is N... | python | def index():
"""Display list of the user's repositories."""
github = GitHubAPI(user_id=current_user.id)
token = github.session_token
ctx = dict(connected=False)
if token:
# The user is authenticated and the token we have is still valid.
if github.account.extra_data.get('login') is N... | [
"def",
"index",
"(",
")",
":",
"github",
"=",
"GitHubAPI",
"(",
"user_id",
"=",
"current_user",
".",
"id",
")",
"token",
"=",
"github",
".",
"session_token",
"ctx",
"=",
"dict",
"(",
"connected",
"=",
"False",
")",
"if",
"token",
":",
"# The user is auth... | Display list of the user's repositories. | [
"Display",
"list",
"of",
"the",
"user",
"s",
"repositories",
"."
] | train | https://github.com/inveniosoftware/invenio-github/blob/ec42fd6a06079310dcbe2c46d9fd79d5197bbe26/invenio_github/views/github.py#L94-L134 |
inveniosoftware/invenio-github | invenio_github/views/github.py | repository | def repository(name):
"""Display selected repository."""
user_id = current_user.id
github = GitHubAPI(user_id=user_id)
token = github.session_token
if token:
repos = github.account.extra_data.get('repos', [])
repo = next((repo for repo_id, repo in repos.items()
... | python | def repository(name):
"""Display selected repository."""
user_id = current_user.id
github = GitHubAPI(user_id=user_id)
token = github.session_token
if token:
repos = github.account.extra_data.get('repos', [])
repo = next((repo for repo_id, repo in repos.items()
... | [
"def",
"repository",
"(",
"name",
")",
":",
"user_id",
"=",
"current_user",
".",
"id",
"github",
"=",
"GitHubAPI",
"(",
"user_id",
"=",
"user_id",
")",
"token",
"=",
"github",
".",
"session_token",
"if",
"token",
":",
"repos",
"=",
"github",
".",
"accoun... | Display selected repository. | [
"Display",
"selected",
"repository",
"."
] | train | https://github.com/inveniosoftware/invenio-github/blob/ec42fd6a06079310dcbe2c46d9fd79d5197bbe26/invenio_github/views/github.py#L141-L180 |
inveniosoftware/invenio-github | invenio_github/views/github.py | hook | def hook():
"""Install or remove GitHub webhook."""
repo_id = request.json['id']
github = GitHubAPI(user_id=current_user.id)
repos = github.account.extra_data['repos']
if repo_id not in repos:
abort(404)
if request.method == 'DELETE':
try:
if github.remove_hook(rep... | python | def hook():
"""Install or remove GitHub webhook."""
repo_id = request.json['id']
github = GitHubAPI(user_id=current_user.id)
repos = github.account.extra_data['repos']
if repo_id not in repos:
abort(404)
if request.method == 'DELETE':
try:
if github.remove_hook(rep... | [
"def",
"hook",
"(",
")",
":",
"repo_id",
"=",
"request",
".",
"json",
"[",
"'id'",
"]",
"github",
"=",
"GitHubAPI",
"(",
"user_id",
"=",
"current_user",
".",
"id",
")",
"repos",
"=",
"github",
".",
"account",
".",
"extra_data",
"[",
"'repos'",
"]",
"... | Install or remove GitHub webhook. | [
"Install",
"or",
"remove",
"GitHub",
"webhook",
"."
] | train | https://github.com/inveniosoftware/invenio-github/blob/ec42fd6a06079310dcbe2c46d9fd79d5197bbe26/invenio_github/views/github.py#L192-L221 |
inveniosoftware/invenio-github | invenio_github/views/github.py | hook_action | def hook_action(action, repo_id):
"""Display selected repository."""
github = GitHubAPI(user_id=current_user.id)
repos = github.account.extra_data['repos']
if repo_id not in repos:
abort(404)
if action == 'disable':
if github.remove_hook(repo_id, repos[repo_id]['full_name']):
... | python | def hook_action(action, repo_id):
"""Display selected repository."""
github = GitHubAPI(user_id=current_user.id)
repos = github.account.extra_data['repos']
if repo_id not in repos:
abort(404)
if action == 'disable':
if github.remove_hook(repo_id, repos[repo_id]['full_name']):
... | [
"def",
"hook_action",
"(",
"action",
",",
"repo_id",
")",
":",
"github",
"=",
"GitHubAPI",
"(",
"user_id",
"=",
"current_user",
".",
"id",
")",
"repos",
"=",
"github",
".",
"account",
".",
"extra_data",
"[",
"'repos'",
"]",
"if",
"repo_id",
"not",
"in",
... | Display selected repository. | [
"Display",
"selected",
"repository",
"."
] | train | https://github.com/inveniosoftware/invenio-github/blob/ec42fd6a06079310dcbe2c46d9fd79d5197bbe26/invenio_github/views/github.py#L226-L247 |
inveniosoftware/invenio-github | invenio_github/ext.py | InvenioGitHub.release_api_class | def release_api_class(self):
"""Github Release API class."""
cls = current_app.config['GITHUB_RELEASE_CLASS']
if isinstance(cls, string_types):
cls = import_string(cls)
assert issubclass(cls, GitHubRelease)
return cls | python | def release_api_class(self):
"""Github Release API class."""
cls = current_app.config['GITHUB_RELEASE_CLASS']
if isinstance(cls, string_types):
cls = import_string(cls)
assert issubclass(cls, GitHubRelease)
return cls | [
"def",
"release_api_class",
"(",
"self",
")",
":",
"cls",
"=",
"current_app",
".",
"config",
"[",
"'GITHUB_RELEASE_CLASS'",
"]",
"if",
"isinstance",
"(",
"cls",
",",
"string_types",
")",
":",
"cls",
"=",
"import_string",
"(",
"cls",
")",
"assert",
"issubclas... | Github Release API class. | [
"Github",
"Release",
"API",
"class",
"."
] | train | https://github.com/inveniosoftware/invenio-github/blob/ec42fd6a06079310dcbe2c46d9fd79d5197bbe26/invenio_github/ext.py#L47-L53 |
inveniosoftware/invenio-github | invenio_github/ext.py | InvenioGitHub.record_serializer | def record_serializer(self):
"""Github Release API class."""
imp = current_app.config['GITHUB_RECORD_SERIALIZER']
if isinstance(imp, string_types):
return import_string(imp)
return imp | python | def record_serializer(self):
"""Github Release API class."""
imp = current_app.config['GITHUB_RECORD_SERIALIZER']
if isinstance(imp, string_types):
return import_string(imp)
return imp | [
"def",
"record_serializer",
"(",
"self",
")",
":",
"imp",
"=",
"current_app",
".",
"config",
"[",
"'GITHUB_RECORD_SERIALIZER'",
"]",
"if",
"isinstance",
"(",
"imp",
",",
"string_types",
")",
":",
"return",
"import_string",
"(",
"imp",
")",
"return",
"imp"
] | Github Release API class. | [
"Github",
"Release",
"API",
"class",
"."
] | train | https://github.com/inveniosoftware/invenio-github/blob/ec42fd6a06079310dcbe2c46d9fd79d5197bbe26/invenio_github/ext.py#L56-L61 |
inveniosoftware/invenio-github | invenio_github/ext.py | InvenioGitHub.init_app | def init_app(self, app):
"""Flask application initialization."""
self.init_config(app)
app.extensions['invenio-github'] = self
@app.before_first_request
def connect_signals():
"""Connect OAuthClient signals."""
from invenio_oauthclient.models import Remot... | python | def init_app(self, app):
"""Flask application initialization."""
self.init_config(app)
app.extensions['invenio-github'] = self
@app.before_first_request
def connect_signals():
"""Connect OAuthClient signals."""
from invenio_oauthclient.models import Remot... | [
"def",
"init_app",
"(",
"self",
",",
"app",
")",
":",
"self",
".",
"init_config",
"(",
"app",
")",
"app",
".",
"extensions",
"[",
"'invenio-github'",
"]",
"=",
"self",
"@",
"app",
".",
"before_first_request",
"def",
"connect_signals",
"(",
")",
":",
"\"\... | Flask application initialization. | [
"Flask",
"application",
"initialization",
"."
] | train | https://github.com/inveniosoftware/invenio-github/blob/ec42fd6a06079310dcbe2c46d9fd79d5197bbe26/invenio_github/ext.py#L63-L84 |
inveniosoftware/invenio-github | invenio_github/api.py | GitHubAPI.access_token | def access_token(self):
"""Return OAuth access token."""
if self.user_id:
return RemoteToken.get(
self.user_id, self.remote.consumer_key
).access_token
return self.remote.get_request_token()[0] | python | def access_token(self):
"""Return OAuth access token."""
if self.user_id:
return RemoteToken.get(
self.user_id, self.remote.consumer_key
).access_token
return self.remote.get_request_token()[0] | [
"def",
"access_token",
"(",
"self",
")",
":",
"if",
"self",
".",
"user_id",
":",
"return",
"RemoteToken",
".",
"get",
"(",
"self",
".",
"user_id",
",",
"self",
".",
"remote",
".",
"consumer_key",
")",
".",
"access_token",
"return",
"self",
".",
"remote",... | Return OAuth access token. | [
"Return",
"OAuth",
"access",
"token",
"."
] | train | https://github.com/inveniosoftware/invenio-github/blob/ec42fd6a06079310dcbe2c46d9fd79d5197bbe26/invenio_github/api.py#L60-L66 |
inveniosoftware/invenio-github | invenio_github/api.py | GitHubAPI.session_token | def session_token(self):
"""Return OAuth session token."""
session_token = None
if self.user_id is not None:
session_token = token_getter(self.remote)
if session_token:
token = RemoteToken.get(
self.user_id, self.remote.consumer_key,
... | python | def session_token(self):
"""Return OAuth session token."""
session_token = None
if self.user_id is not None:
session_token = token_getter(self.remote)
if session_token:
token = RemoteToken.get(
self.user_id, self.remote.consumer_key,
... | [
"def",
"session_token",
"(",
"self",
")",
":",
"session_token",
"=",
"None",
"if",
"self",
".",
"user_id",
"is",
"not",
"None",
":",
"session_token",
"=",
"token_getter",
"(",
"self",
".",
"remote",
")",
"if",
"session_token",
":",
"token",
"=",
"RemoteTok... | Return OAuth session token. | [
"Return",
"OAuth",
"session",
"token",
"."
] | train | https://github.com/inveniosoftware/invenio-github/blob/ec42fd6a06079310dcbe2c46d9fd79d5197bbe26/invenio_github/api.py#L69-L80 |
inveniosoftware/invenio-github | invenio_github/api.py | GitHubAPI.webhook_url | def webhook_url(self):
"""Return the url to be used by a GitHub webhook."""
webhook_token = ProviderToken.query.filter_by(
id=self.account.extra_data['tokens']['webhook']
).first()
if webhook_token:
wh_url = current_app.config.get('GITHUB_WEBHOOK_RECEIVER_URL')
... | python | def webhook_url(self):
"""Return the url to be used by a GitHub webhook."""
webhook_token = ProviderToken.query.filter_by(
id=self.account.extra_data['tokens']['webhook']
).first()
if webhook_token:
wh_url = current_app.config.get('GITHUB_WEBHOOK_RECEIVER_URL')
... | [
"def",
"webhook_url",
"(",
"self",
")",
":",
"webhook_token",
"=",
"ProviderToken",
".",
"query",
".",
"filter_by",
"(",
"id",
"=",
"self",
".",
"account",
".",
"extra_data",
"[",
"'tokens'",
"]",
"[",
"'webhook'",
"]",
")",
".",
"first",
"(",
")",
"if... | Return the url to be used by a GitHub webhook. | [
"Return",
"the",
"url",
"to",
"be",
"used",
"by",
"a",
"GitHub",
"webhook",
"."
] | train | https://github.com/inveniosoftware/invenio-github/blob/ec42fd6a06079310dcbe2c46d9fd79d5197bbe26/invenio_github/api.py#L95-L105 |
inveniosoftware/invenio-github | invenio_github/api.py | GitHubAPI.init_account | def init_account(self):
"""Setup a new GitHub account."""
ghuser = self.api.me()
# Setup local access tokens to be used by the webhooks
hook_token = ProviderToken.create_personal(
'github-webhook',
self.user_id,
scopes=['webhooks:event'],
i... | python | def init_account(self):
"""Setup a new GitHub account."""
ghuser = self.api.me()
# Setup local access tokens to be used by the webhooks
hook_token = ProviderToken.create_personal(
'github-webhook',
self.user_id,
scopes=['webhooks:event'],
i... | [
"def",
"init_account",
"(",
"self",
")",
":",
"ghuser",
"=",
"self",
".",
"api",
".",
"me",
"(",
")",
"# Setup local access tokens to be used by the webhooks",
"hook_token",
"=",
"ProviderToken",
".",
"create_personal",
"(",
"'github-webhook'",
",",
"self",
".",
"... | Setup a new GitHub account. | [
"Setup",
"a",
"new",
"GitHub",
"account",
"."
] | train | https://github.com/inveniosoftware/invenio-github/blob/ec42fd6a06079310dcbe2c46d9fd79d5197bbe26/invenio_github/api.py#L107-L131 |
inveniosoftware/invenio-github | invenio_github/api.py | GitHubAPI.sync | def sync(self, hooks=True, async_hooks=True):
"""Synchronize user repositories.
:param bool hooks: True for syncing hooks.
:param bool async_hooks: True for sending of an asynchronous task to
sync hooks.
.. note::
Syncing happens from GitHu... | python | def sync(self, hooks=True, async_hooks=True):
"""Synchronize user repositories.
:param bool hooks: True for syncing hooks.
:param bool async_hooks: True for sending of an asynchronous task to
sync hooks.
.. note::
Syncing happens from GitHu... | [
"def",
"sync",
"(",
"self",
",",
"hooks",
"=",
"True",
",",
"async_hooks",
"=",
"True",
")",
":",
"active_repos",
"=",
"{",
"}",
"github_repos",
"=",
"{",
"repo",
".",
"id",
":",
"repo",
"for",
"repo",
"in",
"self",
".",
"api",
".",
"repositories",
... | Synchronize user repositories.
:param bool hooks: True for syncing hooks.
:param bool async_hooks: True for sending of an asynchronous task to
sync hooks.
.. note::
Syncing happens from GitHub's direction only. This means that we
consid... | [
"Synchronize",
"user",
"repositories",
"."
] | train | https://github.com/inveniosoftware/invenio-github/blob/ec42fd6a06079310dcbe2c46d9fd79d5197bbe26/invenio_github/api.py#L133-L185 |
inveniosoftware/invenio-github | invenio_github/api.py | GitHubAPI._sync_hooks | def _sync_hooks(self, repos, asynchronous=True):
"""Check if a hooks sync task needs to be started."""
if not asynchronous:
for repo_id in repos:
try:
with db.session.begin_nested():
self.sync_repo_hook(repo_id)
... | python | def _sync_hooks(self, repos, asynchronous=True):
"""Check if a hooks sync task needs to be started."""
if not asynchronous:
for repo_id in repos:
try:
with db.session.begin_nested():
self.sync_repo_hook(repo_id)
... | [
"def",
"_sync_hooks",
"(",
"self",
",",
"repos",
",",
"asynchronous",
"=",
"True",
")",
":",
"if",
"not",
"asynchronous",
":",
"for",
"repo_id",
"in",
"repos",
":",
"try",
":",
"with",
"db",
".",
"session",
".",
"begin_nested",
"(",
")",
":",
"self",
... | Check if a hooks sync task needs to be started. | [
"Check",
"if",
"a",
"hooks",
"sync",
"task",
"needs",
"to",
"be",
"started",
"."
] | train | https://github.com/inveniosoftware/invenio-github/blob/ec42fd6a06079310dcbe2c46d9fd79d5197bbe26/invenio_github/api.py#L187-L202 |
inveniosoftware/invenio-github | invenio_github/api.py | GitHubAPI.sync_repo_hook | def sync_repo_hook(self, repo_id):
"""Sync a GitHub repo's hook with the locally stored repo."""
# Get the hook that we may have set in the past
gh_repo = self.api.repository_with_id(repo_id)
hooks = (hook.id for hook in gh_repo.hooks()
if hook.config.get('url', '') == s... | python | def sync_repo_hook(self, repo_id):
"""Sync a GitHub repo's hook with the locally stored repo."""
# Get the hook that we may have set in the past
gh_repo = self.api.repository_with_id(repo_id)
hooks = (hook.id for hook in gh_repo.hooks()
if hook.config.get('url', '') == s... | [
"def",
"sync_repo_hook",
"(",
"self",
",",
"repo_id",
")",
":",
"# Get the hook that we may have set in the past",
"gh_repo",
"=",
"self",
".",
"api",
".",
"repository_with_id",
"(",
"repo_id",
")",
"hooks",
"=",
"(",
"hook",
".",
"id",
"for",
"hook",
"in",
"g... | Sync a GitHub repo's hook with the locally stored repo. | [
"Sync",
"a",
"GitHub",
"repo",
"s",
"hook",
"with",
"the",
"locally",
"stored",
"repo",
"."
] | train | https://github.com/inveniosoftware/invenio-github/blob/ec42fd6a06079310dcbe2c46d9fd79d5197bbe26/invenio_github/api.py#L204-L222 |
inveniosoftware/invenio-github | invenio_github/api.py | GitHubAPI.check_sync | def check_sync(self):
"""Check if sync is required based on last sync date."""
# If refresh interval is not specified, we should refresh every time.
expiration = utcnow()
refresh_td = current_app.config.get('GITHUB_REFRESH_TIMEDELTA')
if refresh_td:
expiration -= refr... | python | def check_sync(self):
"""Check if sync is required based on last sync date."""
# If refresh interval is not specified, we should refresh every time.
expiration = utcnow()
refresh_td = current_app.config.get('GITHUB_REFRESH_TIMEDELTA')
if refresh_td:
expiration -= refr... | [
"def",
"check_sync",
"(",
"self",
")",
":",
"# If refresh interval is not specified, we should refresh every time.",
"expiration",
"=",
"utcnow",
"(",
")",
"refresh_td",
"=",
"current_app",
".",
"config",
".",
"get",
"(",
"'GITHUB_REFRESH_TIMEDELTA'",
")",
"if",
"refres... | Check if sync is required based on last sync date. | [
"Check",
"if",
"sync",
"is",
"required",
"based",
"on",
"last",
"sync",
"date",
"."
] | train | https://github.com/inveniosoftware/invenio-github/blob/ec42fd6a06079310dcbe2c46d9fd79d5197bbe26/invenio_github/api.py#L224-L232 |
inveniosoftware/invenio-github | invenio_github/api.py | GitHubAPI.create_hook | def create_hook(self, repo_id, repo_name):
"""Create repository hook."""
config = dict(
url=self.webhook_url,
content_type='json',
secret=current_app.config['GITHUB_SHARED_SECRET'],
insecure_ssl='1' if current_app.config['GITHUB_INSECURE_SSL']
... | python | def create_hook(self, repo_id, repo_name):
"""Create repository hook."""
config = dict(
url=self.webhook_url,
content_type='json',
secret=current_app.config['GITHUB_SHARED_SECRET'],
insecure_ssl='1' if current_app.config['GITHUB_INSECURE_SSL']
... | [
"def",
"create_hook",
"(",
"self",
",",
"repo_id",
",",
"repo_name",
")",
":",
"config",
"=",
"dict",
"(",
"url",
"=",
"self",
".",
"webhook_url",
",",
"content_type",
"=",
"'json'",
",",
"secret",
"=",
"current_app",
".",
"config",
"[",
"'GITHUB_SHARED_SE... | Create repository hook. | [
"Create",
"repository",
"hook",
"."
] | train | https://github.com/inveniosoftware/invenio-github/blob/ec42fd6a06079310dcbe2c46d9fd79d5197bbe26/invenio_github/api.py#L234-L270 |
inveniosoftware/invenio-github | invenio_github/api.py | GitHubAPI.remove_hook | def remove_hook(self, repo_id, name):
"""Remove repository hook."""
ghrepo = self.api.repository_with_id(repo_id)
if ghrepo:
hooks = (h for h in ghrepo.hooks()
if h.config.get('url', '') == self.webhook_url)
hook = next(hooks, None)
if not... | python | def remove_hook(self, repo_id, name):
"""Remove repository hook."""
ghrepo = self.api.repository_with_id(repo_id)
if ghrepo:
hooks = (h for h in ghrepo.hooks()
if h.config.get('url', '') == self.webhook_url)
hook = next(hooks, None)
if not... | [
"def",
"remove_hook",
"(",
"self",
",",
"repo_id",
",",
"name",
")",
":",
"ghrepo",
"=",
"self",
".",
"api",
".",
"repository_with_id",
"(",
"repo_id",
")",
"if",
"ghrepo",
":",
"hooks",
"=",
"(",
"h",
"for",
"h",
"in",
"ghrepo",
".",
"hooks",
"(",
... | Remove repository hook. | [
"Remove",
"repository",
"hook",
"."
] | train | https://github.com/inveniosoftware/invenio-github/blob/ec42fd6a06079310dcbe2c46d9fd79d5197bbe26/invenio_github/api.py#L272-L284 |
inveniosoftware/invenio-github | invenio_github/api.py | GitHubAPI._dev_api | def _dev_api(cls):
"""Get a developer instance for GitHub API access."""
gh = github3.GitHub()
gh.set_client_id(cls.remote.consumer_key, cls.remote.consumer_secret)
return gh | python | def _dev_api(cls):
"""Get a developer instance for GitHub API access."""
gh = github3.GitHub()
gh.set_client_id(cls.remote.consumer_key, cls.remote.consumer_secret)
return gh | [
"def",
"_dev_api",
"(",
"cls",
")",
":",
"gh",
"=",
"github3",
".",
"GitHub",
"(",
")",
"gh",
".",
"set_client_id",
"(",
"cls",
".",
"remote",
".",
"consumer_key",
",",
"cls",
".",
"remote",
".",
"consumer_secret",
")",
"return",
"gh"
] | Get a developer instance for GitHub API access. | [
"Get",
"a",
"developer",
"instance",
"for",
"GitHub",
"API",
"access",
"."
] | train | https://github.com/inveniosoftware/invenio-github/blob/ec42fd6a06079310dcbe2c46d9fd79d5197bbe26/invenio_github/api.py#L287-L291 |
inveniosoftware/invenio-github | invenio_github/api.py | GitHubRelease.deposit_class | def deposit_class(self):
"""Return a class implementing `publish` method."""
cls = current_app.config['GITHUB_DEPOSIT_CLASS']
if isinstance(cls, string_types):
cls = import_string(cls)
assert isinstance(cls, type)
return cls | python | def deposit_class(self):
"""Return a class implementing `publish` method."""
cls = current_app.config['GITHUB_DEPOSIT_CLASS']
if isinstance(cls, string_types):
cls = import_string(cls)
assert isinstance(cls, type)
return cls | [
"def",
"deposit_class",
"(",
"self",
")",
":",
"cls",
"=",
"current_app",
".",
"config",
"[",
"'GITHUB_DEPOSIT_CLASS'",
"]",
"if",
"isinstance",
"(",
"cls",
",",
"string_types",
")",
":",
"cls",
"=",
"import_string",
"(",
"cls",
")",
"assert",
"isinstance",
... | Return a class implementing `publish` method. | [
"Return",
"a",
"class",
"implementing",
"publish",
"method",
"."
] | train | https://github.com/inveniosoftware/invenio-github/blob/ec42fd6a06079310dcbe2c46d9fd79d5197bbe26/invenio_github/api.py#L317-L323 |
inveniosoftware/invenio-github | invenio_github/api.py | GitHubRelease.repo_model | def repo_model(self):
"""Return repository model from database."""
return Repository.query.filter_by(
user_id=self.event.user_id,
github_id=self.repository['id'],
).one() | python | def repo_model(self):
"""Return repository model from database."""
return Repository.query.filter_by(
user_id=self.event.user_id,
github_id=self.repository['id'],
).one() | [
"def",
"repo_model",
"(",
"self",
")",
":",
"return",
"Repository",
".",
"query",
".",
"filter_by",
"(",
"user_id",
"=",
"self",
".",
"event",
".",
"user_id",
",",
"github_id",
"=",
"self",
".",
"repository",
"[",
"'id'",
"]",
",",
")",
".",
"one",
"... | Return repository model from database. | [
"Return",
"repository",
"model",
"from",
"database",
"."
] | train | https://github.com/inveniosoftware/invenio-github/blob/ec42fd6a06079310dcbe2c46d9fd79d5197bbe26/invenio_github/api.py#L346-L351 |
inveniosoftware/invenio-github | invenio_github/api.py | GitHubRelease.title | def title(self):
"""Extract title from a release."""
if self.event:
if self.release['name']:
return u'{0}: {1}'.format(
self.repository['full_name'], self.release['name']
)
return u'{0} {1}'.format(self.repo_model.name, self.model.t... | python | def title(self):
"""Extract title from a release."""
if self.event:
if self.release['name']:
return u'{0}: {1}'.format(
self.repository['full_name'], self.release['name']
)
return u'{0} {1}'.format(self.repo_model.name, self.model.t... | [
"def",
"title",
"(",
"self",
")",
":",
"if",
"self",
".",
"event",
":",
"if",
"self",
".",
"release",
"[",
"'name'",
"]",
":",
"return",
"u'{0}: {1}'",
".",
"format",
"(",
"self",
".",
"repository",
"[",
"'full_name'",
"]",
",",
"self",
".",
"release... | Extract title from a release. | [
"Extract",
"title",
"from",
"a",
"release",
"."
] | train | https://github.com/inveniosoftware/invenio-github/blob/ec42fd6a06079310dcbe2c46d9fd79d5197bbe26/invenio_github/api.py#L354-L361 |
inveniosoftware/invenio-github | invenio_github/api.py | GitHubRelease.description | def description(self):
"""Extract description from a release."""
if self.release.get('body'):
return markdown(self.release['body'])
elif self.repository.get('description'):
return self.repository['description']
return 'No description provided.' | python | def description(self):
"""Extract description from a release."""
if self.release.get('body'):
return markdown(self.release['body'])
elif self.repository.get('description'):
return self.repository['description']
return 'No description provided.' | [
"def",
"description",
"(",
"self",
")",
":",
"if",
"self",
".",
"release",
".",
"get",
"(",
"'body'",
")",
":",
"return",
"markdown",
"(",
"self",
".",
"release",
"[",
"'body'",
"]",
")",
"elif",
"self",
".",
"repository",
".",
"get",
"(",
"'descript... | Extract description from a release. | [
"Extract",
"description",
"from",
"a",
"release",
"."
] | train | https://github.com/inveniosoftware/invenio-github/blob/ec42fd6a06079310dcbe2c46d9fd79d5197bbe26/invenio_github/api.py#L364-L370 |
inveniosoftware/invenio-github | invenio_github/api.py | GitHubRelease.related_identifiers | def related_identifiers(self):
"""Yield related identifiers."""
yield dict(
identifier=u'https://github.com/{0}/tree/{1}'.format(
self.repository['full_name'], self.release['tag_name']
),
relation='isSupplementTo',
) | python | def related_identifiers(self):
"""Yield related identifiers."""
yield dict(
identifier=u'https://github.com/{0}/tree/{1}'.format(
self.repository['full_name'], self.release['tag_name']
),
relation='isSupplementTo',
) | [
"def",
"related_identifiers",
"(",
"self",
")",
":",
"yield",
"dict",
"(",
"identifier",
"=",
"u'https://github.com/{0}/tree/{1}'",
".",
"format",
"(",
"self",
".",
"repository",
"[",
"'full_name'",
"]",
",",
"self",
".",
"release",
"[",
"'tag_name'",
"]",
")"... | Yield related identifiers. | [
"Yield",
"related",
"identifiers",
"."
] | train | https://github.com/inveniosoftware/invenio-github/blob/ec42fd6a06079310dcbe2c46d9fd79d5197bbe26/invenio_github/api.py#L378-L385 |
inveniosoftware/invenio-github | invenio_github/api.py | GitHubRelease.defaults | def defaults(self):
"""Return default metadata."""
return dict(
access_right='open',
description=self.description,
license='other-open',
publication_date=self.release['published_at'][:10],
related_identifiers=list(self.related_identifiers),
... | python | def defaults(self):
"""Return default metadata."""
return dict(
access_right='open',
description=self.description,
license='other-open',
publication_date=self.release['published_at'][:10],
related_identifiers=list(self.related_identifiers),
... | [
"def",
"defaults",
"(",
"self",
")",
":",
"return",
"dict",
"(",
"access_right",
"=",
"'open'",
",",
"description",
"=",
"self",
".",
"description",
",",
"license",
"=",
"'other-open'",
",",
"publication_date",
"=",
"self",
".",
"release",
"[",
"'published_a... | Return default metadata. | [
"Return",
"default",
"metadata",
"."
] | train | https://github.com/inveniosoftware/invenio-github/blob/ec42fd6a06079310dcbe2c46d9fd79d5197bbe26/invenio_github/api.py#L393-L404 |
inveniosoftware/invenio-github | invenio_github/api.py | GitHubRelease.extra_metadata | def extra_metadata(self):
"""Get extra metadata for file in repository."""
return get_extra_metadata(
self.gh.api,
self.repository['owner']['login'],
self.repository['name'],
self.release['tag_name'],
) | python | def extra_metadata(self):
"""Get extra metadata for file in repository."""
return get_extra_metadata(
self.gh.api,
self.repository['owner']['login'],
self.repository['name'],
self.release['tag_name'],
) | [
"def",
"extra_metadata",
"(",
"self",
")",
":",
"return",
"get_extra_metadata",
"(",
"self",
".",
"gh",
".",
"api",
",",
"self",
".",
"repository",
"[",
"'owner'",
"]",
"[",
"'login'",
"]",
",",
"self",
".",
"repository",
"[",
"'name'",
"]",
",",
"self... | Get extra metadata for file in repository. | [
"Get",
"extra",
"metadata",
"for",
"file",
"in",
"repository",
"."
] | train | https://github.com/inveniosoftware/invenio-github/blob/ec42fd6a06079310dcbe2c46d9fd79d5197bbe26/invenio_github/api.py#L407-L414 |
inveniosoftware/invenio-github | invenio_github/api.py | GitHubRelease.files | def files(self):
"""Extract files to download from GitHub payload."""
tag_name = self.release['tag_name']
repo_name = self.repository['full_name']
zipball_url = self.release['zipball_url']
filename = u'{name}-{tag}.zip'.format(name=repo_name, tag=tag_name)
response = se... | python | def files(self):
"""Extract files to download from GitHub payload."""
tag_name = self.release['tag_name']
repo_name = self.repository['full_name']
zipball_url = self.release['zipball_url']
filename = u'{name}-{tag}.zip'.format(name=repo_name, tag=tag_name)
response = se... | [
"def",
"files",
"(",
"self",
")",
":",
"tag_name",
"=",
"self",
".",
"release",
"[",
"'tag_name'",
"]",
"repo_name",
"=",
"self",
".",
"repository",
"[",
"'full_name'",
"]",
"zipball_url",
"=",
"self",
".",
"release",
"[",
"'zipball_url'",
"]",
"filename",... | Extract files to download from GitHub payload. | [
"Extract",
"files",
"to",
"download",
"from",
"GitHub",
"payload",
"."
] | train | https://github.com/inveniosoftware/invenio-github/blob/ec42fd6a06079310dcbe2c46d9fd79d5197bbe26/invenio_github/api.py#L417-L429 |
inveniosoftware/invenio-github | invenio_github/api.py | GitHubRelease.metadata | def metadata(self):
"""Return extracted metadata."""
output = dict(self.defaults)
output.update(self.extra_metadata)
return output | python | def metadata(self):
"""Return extracted metadata."""
output = dict(self.defaults)
output.update(self.extra_metadata)
return output | [
"def",
"metadata",
"(",
"self",
")",
":",
"output",
"=",
"dict",
"(",
"self",
".",
"defaults",
")",
"output",
".",
"update",
"(",
"self",
".",
"extra_metadata",
")",
"return",
"output"
] | Return extracted metadata. | [
"Return",
"extracted",
"metadata",
"."
] | train | https://github.com/inveniosoftware/invenio-github/blob/ec42fd6a06079310dcbe2c46d9fd79d5197bbe26/invenio_github/api.py#L432-L436 |
inveniosoftware/invenio-github | invenio_github/api.py | GitHubRelease.pid | def pid(self):
"""Get PID object for the Release record."""
if self.model.status == ReleaseStatus.PUBLISHED and self.record:
fetcher = current_pidstore.fetchers[
current_app.config.get('GITHUB_PID_FETCHER')]
return fetcher(self.record.id, self.record) | python | def pid(self):
"""Get PID object for the Release record."""
if self.model.status == ReleaseStatus.PUBLISHED and self.record:
fetcher = current_pidstore.fetchers[
current_app.config.get('GITHUB_PID_FETCHER')]
return fetcher(self.record.id, self.record) | [
"def",
"pid",
"(",
"self",
")",
":",
"if",
"self",
".",
"model",
".",
"status",
"==",
"ReleaseStatus",
".",
"PUBLISHED",
"and",
"self",
".",
"record",
":",
"fetcher",
"=",
"current_pidstore",
".",
"fetchers",
"[",
"current_app",
".",
"config",
".",
"get"... | Get PID object for the Release record. | [
"Get",
"PID",
"object",
"for",
"the",
"Release",
"record",
"."
] | train | https://github.com/inveniosoftware/invenio-github/blob/ec42fd6a06079310dcbe2c46d9fd79d5197bbe26/invenio_github/api.py#L449-L454 |
inveniosoftware/invenio-github | invenio_github/api.py | GitHubRelease.publish | def publish(self):
"""Publish GitHub release as record."""
with db.session.begin_nested():
deposit = self.deposit_class.create(self.metadata)
deposit['_deposit']['created_by'] = self.event.user_id
deposit['_deposit']['owners'] = [self.event.user_id]
# Fet... | python | def publish(self):
"""Publish GitHub release as record."""
with db.session.begin_nested():
deposit = self.deposit_class.create(self.metadata)
deposit['_deposit']['created_by'] = self.event.user_id
deposit['_deposit']['owners'] = [self.event.user_id]
# Fet... | [
"def",
"publish",
"(",
"self",
")",
":",
"with",
"db",
".",
"session",
".",
"begin_nested",
"(",
")",
":",
"deposit",
"=",
"self",
".",
"deposit_class",
".",
"create",
"(",
"self",
".",
"metadata",
")",
"deposit",
"[",
"'_deposit'",
"]",
"[",
"'created... | Publish GitHub release as record. | [
"Publish",
"GitHub",
"release",
"as",
"record",
"."
] | train | https://github.com/inveniosoftware/invenio-github/blob/ec42fd6a06079310dcbe2c46d9fd79d5197bbe26/invenio_github/api.py#L461-L475 |
inveniosoftware/invenio-github | invenio_github/receivers.py | GitHubReceiver.run | def run(self, event):
"""Process an event.
.. note::
We should only do basic server side operation here, since we send
the rest of the processing to a Celery task which will be mainly
accessing the GitHub API.
"""
repo_id = event.payload['repository'... | python | def run(self, event):
"""Process an event.
.. note::
We should only do basic server side operation here, since we send
the rest of the processing to a Celery task which will be mainly
accessing the GitHub API.
"""
repo_id = event.payload['repository'... | [
"def",
"run",
"(",
"self",
",",
"event",
")",
":",
"repo_id",
"=",
"event",
".",
"payload",
"[",
"'repository'",
"]",
"[",
"'id'",
"]",
"# Ping event - update the ping timestamp of the repository",
"if",
"'hook_id'",
"in",
"event",
".",
"payload",
"and",
"'zen'"... | Process an event.
.. note::
We should only do basic server side operation here, since we send
the rest of the processing to a Celery task which will be mainly
accessing the GitHub API. | [
"Process",
"an",
"event",
"."
] | train | https://github.com/inveniosoftware/invenio-github/blob/ec42fd6a06079310dcbe2c46d9fd79d5197bbe26/invenio_github/receivers.py#L43-L82 |
inveniosoftware/invenio-github | invenio_github/utils.py | parse_timestamp | def parse_timestamp(x):
"""Parse ISO8601 formatted timestamp."""
dt = dateutil.parser.parse(x)
if dt.tzinfo is None:
dt = dt.replace(tzinfo=pytz.utc)
return dt | python | def parse_timestamp(x):
"""Parse ISO8601 formatted timestamp."""
dt = dateutil.parser.parse(x)
if dt.tzinfo is None:
dt = dt.replace(tzinfo=pytz.utc)
return dt | [
"def",
"parse_timestamp",
"(",
"x",
")",
":",
"dt",
"=",
"dateutil",
".",
"parser",
".",
"parse",
"(",
"x",
")",
"if",
"dt",
".",
"tzinfo",
"is",
"None",
":",
"dt",
"=",
"dt",
".",
"replace",
"(",
"tzinfo",
"=",
"pytz",
".",
"utc",
")",
"return",... | Parse ISO8601 formatted timestamp. | [
"Parse",
"ISO8601",
"formatted",
"timestamp",
"."
] | train | https://github.com/inveniosoftware/invenio-github/blob/ec42fd6a06079310dcbe2c46d9fd79d5197bbe26/invenio_github/utils.py#L44-L49 |
inveniosoftware/invenio-github | invenio_github/utils.py | get_extra_metadata | def get_extra_metadata(gh, owner, repo_name, ref):
"""Get the metadata file."""
try:
content = gh.repository(owner, repo_name).file_contents(
path=current_app.config['GITHUB_METADATA_FILE'], ref=ref
)
if not content:
# File does not exists in the given ref
... | python | def get_extra_metadata(gh, owner, repo_name, ref):
"""Get the metadata file."""
try:
content = gh.repository(owner, repo_name).file_contents(
path=current_app.config['GITHUB_METADATA_FILE'], ref=ref
)
if not content:
# File does not exists in the given ref
... | [
"def",
"get_extra_metadata",
"(",
"gh",
",",
"owner",
",",
"repo_name",
",",
"ref",
")",
":",
"try",
":",
"content",
"=",
"gh",
".",
"repository",
"(",
"owner",
",",
"repo_name",
")",
".",
"file_contents",
"(",
"path",
"=",
"current_app",
".",
"config",
... | Get the metadata file. | [
"Get",
"the",
"metadata",
"file",
"."
] | train | https://github.com/inveniosoftware/invenio-github/blob/ec42fd6a06079310dcbe2c46d9fd79d5197bbe26/invenio_github/utils.py#L52-L66 |
inveniosoftware/invenio-github | invenio_github/utils.py | get_owner | def get_owner(gh, owner):
"""Get owner of repository as a creator."""
try:
u = gh.user(owner)
name = u.name or u.login
company = u.company or ''
return [dict(name=name, affiliation=company)]
except Exception:
return None | python | def get_owner(gh, owner):
"""Get owner of repository as a creator."""
try:
u = gh.user(owner)
name = u.name or u.login
company = u.company or ''
return [dict(name=name, affiliation=company)]
except Exception:
return None | [
"def",
"get_owner",
"(",
"gh",
",",
"owner",
")",
":",
"try",
":",
"u",
"=",
"gh",
".",
"user",
"(",
"owner",
")",
"name",
"=",
"u",
".",
"name",
"or",
"u",
".",
"login",
"company",
"=",
"u",
".",
"company",
"or",
"''",
"return",
"[",
"dict",
... | Get owner of repository as a creator. | [
"Get",
"owner",
"of",
"repository",
"as",
"a",
"creator",
"."
] | train | https://github.com/inveniosoftware/invenio-github/blob/ec42fd6a06079310dcbe2c46d9fd79d5197bbe26/invenio_github/utils.py#L69-L77 |
inveniosoftware/invenio-github | invenio_github/utils.py | get_contributors | def get_contributors(gh, repo_id):
"""Get list of contributors to a repository."""
try:
# FIXME: Use `github3.Repository.contributors` to get this information
contrib_url = gh.repository_with_id(repo_id).contributors_url
r = requests.get(contrib_url)
if r.status_code == 200:
... | python | def get_contributors(gh, repo_id):
"""Get list of contributors to a repository."""
try:
# FIXME: Use `github3.Repository.contributors` to get this information
contrib_url = gh.repository_with_id(repo_id).contributors_url
r = requests.get(contrib_url)
if r.status_code == 200:
... | [
"def",
"get_contributors",
"(",
"gh",
",",
"repo_id",
")",
":",
"try",
":",
"# FIXME: Use `github3.Repository.contributors` to get this information",
"contrib_url",
"=",
"gh",
".",
"repository_with_id",
"(",
"repo_id",
")",
".",
"contributors_url",
"r",
"=",
"requests",... | Get list of contributors to a repository. | [
"Get",
"list",
"of",
"contributors",
"to",
"a",
"repository",
"."
] | train | https://github.com/inveniosoftware/invenio-github/blob/ec42fd6a06079310dcbe2c46d9fd79d5197bbe26/invenio_github/utils.py#L80-L108 |
inveniosoftware/invenio-github | invenio_github/handlers.py | account_setup | def account_setup(remote, token=None, response=None,
account_setup=None):
"""Setup user account."""
gh = GitHubAPI(user_id=token.remote_account.user_id)
with db.session.begin_nested():
gh.init_account()
# Create user <-> external id link.
oauth_link_external_id(
... | python | def account_setup(remote, token=None, response=None,
account_setup=None):
"""Setup user account."""
gh = GitHubAPI(user_id=token.remote_account.user_id)
with db.session.begin_nested():
gh.init_account()
# Create user <-> external id link.
oauth_link_external_id(
... | [
"def",
"account_setup",
"(",
"remote",
",",
"token",
"=",
"None",
",",
"response",
"=",
"None",
",",
"account_setup",
"=",
"None",
")",
":",
"gh",
"=",
"GitHubAPI",
"(",
"user_id",
"=",
"token",
".",
"remote_account",
".",
"user_id",
")",
"with",
"db",
... | Setup user account. | [
"Setup",
"user",
"account",
"."
] | train | https://github.com/inveniosoftware/invenio-github/blob/ec42fd6a06079310dcbe2c46d9fd79d5197bbe26/invenio_github/handlers.py#L41-L52 |
inveniosoftware/invenio-github | invenio_github/handlers.py | account_post_init | def account_post_init(remote, token=None):
"""Perform post initialization."""
gh = GitHubAPI(user_id=token.remote_account.user_id)
repos = [r.id for r in gh.api.repositories() if r.permissions['admin']]
sync_hooks.delay(token.remote_account.user_id, repos) | python | def account_post_init(remote, token=None):
"""Perform post initialization."""
gh = GitHubAPI(user_id=token.remote_account.user_id)
repos = [r.id for r in gh.api.repositories() if r.permissions['admin']]
sync_hooks.delay(token.remote_account.user_id, repos) | [
"def",
"account_post_init",
"(",
"remote",
",",
"token",
"=",
"None",
")",
":",
"gh",
"=",
"GitHubAPI",
"(",
"user_id",
"=",
"token",
".",
"remote_account",
".",
"user_id",
")",
"repos",
"=",
"[",
"r",
".",
"id",
"for",
"r",
"in",
"gh",
".",
"api",
... | Perform post initialization. | [
"Perform",
"post",
"initialization",
"."
] | train | https://github.com/inveniosoftware/invenio-github/blob/ec42fd6a06079310dcbe2c46d9fd79d5197bbe26/invenio_github/handlers.py#L55-L59 |
inveniosoftware/invenio-github | invenio_github/handlers.py | disconnect | def disconnect(remote):
"""Disconnect callback handler for GitHub."""
# User must be authenticated
if not current_user.is_authenticated:
return current_app.login_manager.unauthorized()
external_method = 'github'
external_ids = [i.id for i in current_user.external_identifiers
... | python | def disconnect(remote):
"""Disconnect callback handler for GitHub."""
# User must be authenticated
if not current_user.is_authenticated:
return current_app.login_manager.unauthorized()
external_method = 'github'
external_ids = [i.id for i in current_user.external_identifiers
... | [
"def",
"disconnect",
"(",
"remote",
")",
":",
"# User must be authenticated",
"if",
"not",
"current_user",
".",
"is_authenticated",
":",
"return",
"current_app",
".",
"login_manager",
".",
"unauthorized",
"(",
")",
"external_method",
"=",
"'github'",
"external_ids",
... | Disconnect callback handler for GitHub. | [
"Disconnect",
"callback",
"handler",
"for",
"GitHub",
"."
] | train | https://github.com/inveniosoftware/invenio-github/blob/ec42fd6a06079310dcbe2c46d9fd79d5197bbe26/invenio_github/handlers.py#L62-L103 |
django-fluent/django-fluent-comments | fluent_comments/moderation.py | moderate_model | def moderate_model(ParentModel, publication_date_field=None, enable_comments_field=None):
"""
Register a parent model (e.g. ``Blog`` or ``Article``) that should receive comment moderation.
:param ParentModel: The parent model, e.g. a ``Blog`` or ``Article`` model.
:param publication_date_field: The fie... | python | def moderate_model(ParentModel, publication_date_field=None, enable_comments_field=None):
"""
Register a parent model (e.g. ``Blog`` or ``Article``) that should receive comment moderation.
:param ParentModel: The parent model, e.g. a ``Blog`` or ``Article`` model.
:param publication_date_field: The fie... | [
"def",
"moderate_model",
"(",
"ParentModel",
",",
"publication_date_field",
"=",
"None",
",",
"enable_comments_field",
"=",
"None",
")",
":",
"attrs",
"=",
"{",
"'auto_close_field'",
":",
"publication_date_field",
",",
"'auto_moderate_field'",
":",
"publication_date_fie... | Register a parent model (e.g. ``Blog`` or ``Article``) that should receive comment moderation.
:param ParentModel: The parent model, e.g. a ``Blog`` or ``Article`` model.
:param publication_date_field: The field name of a :class:`~django.db.models.DateTimeField` in the parent model which stores the publication... | [
"Register",
"a",
"parent",
"model",
"(",
"e",
".",
"g",
".",
"Blog",
"or",
"Article",
")",
"that",
"should",
"receive",
"comment",
"moderation",
"."
] | train | https://github.com/django-fluent/django-fluent-comments/blob/bfe98d55b56fedd8ca2e2659eed53a6390e53adf/fluent_comments/moderation.py#L154-L170 |
django-fluent/django-fluent-comments | fluent_comments/moderation.py | comments_are_open | def comments_are_open(content_object):
"""
Return whether comments are still open for a given target object.
"""
moderator = get_model_moderator(content_object.__class__)
if moderator is None:
return True
# Check the 'enable_field', 'auto_close_field' and 'close_after',
# by reusing... | python | def comments_are_open(content_object):
"""
Return whether comments are still open for a given target object.
"""
moderator = get_model_moderator(content_object.__class__)
if moderator is None:
return True
# Check the 'enable_field', 'auto_close_field' and 'close_after',
# by reusing... | [
"def",
"comments_are_open",
"(",
"content_object",
")",
":",
"moderator",
"=",
"get_model_moderator",
"(",
"content_object",
".",
"__class__",
")",
"if",
"moderator",
"is",
"None",
":",
"return",
"True",
"# Check the 'enable_field', 'auto_close_field' and 'close_after',",
... | Return whether comments are still open for a given target object. | [
"Return",
"whether",
"comments",
"are",
"still",
"open",
"for",
"a",
"given",
"target",
"object",
"."
] | train | https://github.com/django-fluent/django-fluent-comments/blob/bfe98d55b56fedd8ca2e2659eed53a6390e53adf/fluent_comments/moderation.py#L189-L199 |
django-fluent/django-fluent-comments | fluent_comments/moderation.py | comments_are_moderated | def comments_are_moderated(content_object):
"""
Return whether comments are moderated for a given target object.
"""
moderator = get_model_moderator(content_object.__class__)
if moderator is None:
return False
# Check the 'auto_moderate_field', 'moderate_after',
# by reusing the bas... | python | def comments_are_moderated(content_object):
"""
Return whether comments are moderated for a given target object.
"""
moderator = get_model_moderator(content_object.__class__)
if moderator is None:
return False
# Check the 'auto_moderate_field', 'moderate_after',
# by reusing the bas... | [
"def",
"comments_are_moderated",
"(",
"content_object",
")",
":",
"moderator",
"=",
"get_model_moderator",
"(",
"content_object",
".",
"__class__",
")",
"if",
"moderator",
"is",
"None",
":",
"return",
"False",
"# Check the 'auto_moderate_field', 'moderate_after',",
"# by ... | Return whether comments are moderated for a given target object. | [
"Return",
"whether",
"comments",
"are",
"moderated",
"for",
"a",
"given",
"target",
"object",
"."
] | train | https://github.com/django-fluent/django-fluent-comments/blob/bfe98d55b56fedd8ca2e2659eed53a6390e53adf/fluent_comments/moderation.py#L202-L212 |
django-fluent/django-fluent-comments | fluent_comments/moderation.py | FluentCommentsModerator.allow | def allow(self, comment, content_object, request):
"""
Determine whether a given comment is allowed to be posted on a given object.
Returns ``True`` if the comment should be allowed, ``False`` otherwise.
"""
# Parent class check
if not super(FluentCommentsModerator, self... | python | def allow(self, comment, content_object, request):
"""
Determine whether a given comment is allowed to be posted on a given object.
Returns ``True`` if the comment should be allowed, ``False`` otherwise.
"""
# Parent class check
if not super(FluentCommentsModerator, self... | [
"def",
"allow",
"(",
"self",
",",
"comment",
",",
"content_object",
",",
"request",
")",
":",
"# Parent class check",
"if",
"not",
"super",
"(",
"FluentCommentsModerator",
",",
"self",
")",
".",
"allow",
"(",
"comment",
",",
"content_object",
",",
"request",
... | Determine whether a given comment is allowed to be posted on a given object.
Returns ``True`` if the comment should be allowed, ``False`` otherwise. | [
"Determine",
"whether",
"a",
"given",
"comment",
"is",
"allowed",
"to",
"be",
"posted",
"on",
"a",
"given",
"object",
"."
] | train | https://github.com/django-fluent/django-fluent-comments/blob/bfe98d55b56fedd8ca2e2659eed53a6390e53adf/fluent_comments/moderation.py#L46-L64 |
django-fluent/django-fluent-comments | fluent_comments/moderation.py | FluentCommentsModerator.moderate | def moderate(self, comment, content_object, request):
"""
Determine whether a given comment on a given object should be allowed to show up immediately,
or should be marked non-public and await approval.
Returns ``True`` if the comment should be moderated (marked non-public), ``False`` o... | python | def moderate(self, comment, content_object, request):
"""
Determine whether a given comment on a given object should be allowed to show up immediately,
or should be marked non-public and await approval.
Returns ``True`` if the comment should be moderated (marked non-public), ``False`` o... | [
"def",
"moderate",
"(",
"self",
",",
"comment",
",",
"content_object",
",",
"request",
")",
":",
"# Soft delete checks are done first, so these comments are not mistakenly \"just moderated\"",
"# for expiring the `close_after` date, but correctly get marked as spam instead.",
"# This hel... | Determine whether a given comment on a given object should be allowed to show up immediately,
or should be marked non-public and await approval.
Returns ``True`` if the comment should be moderated (marked non-public), ``False`` otherwise. | [
"Determine",
"whether",
"a",
"given",
"comment",
"on",
"a",
"given",
"object",
"should",
"be",
"allowed",
"to",
"show",
"up",
"immediately",
"or",
"should",
"be",
"marked",
"non",
"-",
"public",
"and",
"await",
"approval",
"."
] | train | https://github.com/django-fluent/django-fluent-comments/blob/bfe98d55b56fedd8ca2e2659eed53a6390e53adf/fluent_comments/moderation.py#L66-L104 |
django-fluent/django-fluent-comments | fluent_comments/moderation.py | FluentCommentsModerator.email | def email(self, comment, content_object, request):
"""
Overwritten for a better email notification.
"""
if not self.email_notification:
return
send_comment_posted(comment, request) | python | def email(self, comment, content_object, request):
"""
Overwritten for a better email notification.
"""
if not self.email_notification:
return
send_comment_posted(comment, request) | [
"def",
"email",
"(",
"self",
",",
"comment",
",",
"content_object",
",",
"request",
")",
":",
"if",
"not",
"self",
".",
"email_notification",
":",
"return",
"send_comment_posted",
"(",
"comment",
",",
"request",
")"
] | Overwritten for a better email notification. | [
"Overwritten",
"for",
"a",
"better",
"email",
"notification",
"."
] | train | https://github.com/django-fluent/django-fluent-comments/blob/bfe98d55b56fedd8ca2e2659eed53a6390e53adf/fluent_comments/moderation.py#L106-L113 |
django-fluent/django-fluent-comments | fluent_comments/email.py | send_comment_posted | def send_comment_posted(comment, request):
"""
Send the email to staff that an comment was posted.
While the django_comments module has email support,
it doesn't pass the 'request' to the context.
This also changes the subject to show the page title.
"""
recipient_list = [manager_tuple[1] f... | python | def send_comment_posted(comment, request):
"""
Send the email to staff that an comment was posted.
While the django_comments module has email support,
it doesn't pass the 'request' to the context.
This also changes the subject to show the page title.
"""
recipient_list = [manager_tuple[1] f... | [
"def",
"send_comment_posted",
"(",
"comment",
",",
"request",
")",
":",
"recipient_list",
"=",
"[",
"manager_tuple",
"[",
"1",
"]",
"for",
"manager_tuple",
"in",
"settings",
".",
"MANAGERS",
"]",
"site",
"=",
"get_current_site",
"(",
"request",
")",
"content_o... | Send the email to staff that an comment was posted.
While the django_comments module has email support,
it doesn't pass the 'request' to the context.
This also changes the subject to show the page title. | [
"Send",
"the",
"email",
"to",
"staff",
"that",
"an",
"comment",
"was",
"posted",
"."
] | train | https://github.com/django-fluent/django-fluent-comments/blob/bfe98d55b56fedd8ca2e2659eed53a6390e53adf/fluent_comments/email.py#L9-L42 |
django-fluent/django-fluent-comments | fluent_comments/templatetags/fluent_comments_tags.py | AjaxCommentTags.parse | def parse(cls, parser, token):
"""
Custom parsing for the ``{% ajax_comment_tags for ... %}`` tag.
"""
# Process the template line.
tag_name, args, kwargs = parse_token_kwargs(
parser, token,
allowed_kwargs=cls.allowed_kwargs,
compile_args=Fals... | python | def parse(cls, parser, token):
"""
Custom parsing for the ``{% ajax_comment_tags for ... %}`` tag.
"""
# Process the template line.
tag_name, args, kwargs = parse_token_kwargs(
parser, token,
allowed_kwargs=cls.allowed_kwargs,
compile_args=Fals... | [
"def",
"parse",
"(",
"cls",
",",
"parser",
",",
"token",
")",
":",
"# Process the template line.",
"tag_name",
",",
"args",
",",
"kwargs",
"=",
"parse_token_kwargs",
"(",
"parser",
",",
"token",
",",
"allowed_kwargs",
"=",
"cls",
".",
"allowed_kwargs",
",",
... | Custom parsing for the ``{% ajax_comment_tags for ... %}`` tag. | [
"Custom",
"parsing",
"for",
"the",
"{",
"%",
"ajax_comment_tags",
"for",
"...",
"%",
"}",
"tag",
"."
] | train | https://github.com/django-fluent/django-fluent-comments/blob/bfe98d55b56fedd8ca2e2659eed53a6390e53adf/fluent_comments/templatetags/fluent_comments_tags.py#L26-L47 |
django-fluent/django-fluent-comments | fluent_comments/templatetags/fluent_comments_tags.py | AjaxCommentTags.get_context_data | def get_context_data(self, parent_context, *tag_args, **tag_kwargs):
"""
The main logic for the inclusion node, analogous to ``@register.inclusion_node``.
"""
target_object = tag_args[0] # moved one spot due to .pop(0)
new_context = {
'STATIC_URL': parent_context.get... | python | def get_context_data(self, parent_context, *tag_args, **tag_kwargs):
"""
The main logic for the inclusion node, analogous to ``@register.inclusion_node``.
"""
target_object = tag_args[0] # moved one spot due to .pop(0)
new_context = {
'STATIC_URL': parent_context.get... | [
"def",
"get_context_data",
"(",
"self",
",",
"parent_context",
",",
"*",
"tag_args",
",",
"*",
"*",
"tag_kwargs",
")",
":",
"target_object",
"=",
"tag_args",
"[",
"0",
"]",
"# moved one spot due to .pop(0)",
"new_context",
"=",
"{",
"'STATIC_URL'",
":",
"parent_... | The main logic for the inclusion node, analogous to ``@register.inclusion_node``. | [
"The",
"main",
"logic",
"for",
"the",
"inclusion",
"node",
"analogous",
"to"
] | train | https://github.com/django-fluent/django-fluent-comments/blob/bfe98d55b56fedd8ca2e2659eed53a6390e53adf/fluent_comments/templatetags/fluent_comments_tags.py#L49-L69 |
django-fluent/django-fluent-comments | fluent_comments/utils.py | get_comment_template_name | def get_comment_template_name(comment):
"""
Internal function for the rendering of comments.
"""
ctype = ContentType.objects.get_for_id(comment.content_type_id)
return [
"comments/%s/%s/comment.html" % (ctype.app_label, ctype.model),
"comments/%s/comment.html" % ctype.app_label,
... | python | def get_comment_template_name(comment):
"""
Internal function for the rendering of comments.
"""
ctype = ContentType.objects.get_for_id(comment.content_type_id)
return [
"comments/%s/%s/comment.html" % (ctype.app_label, ctype.model),
"comments/%s/comment.html" % ctype.app_label,
... | [
"def",
"get_comment_template_name",
"(",
"comment",
")",
":",
"ctype",
"=",
"ContentType",
".",
"objects",
".",
"get_for_id",
"(",
"comment",
".",
"content_type_id",
")",
"return",
"[",
"\"comments/%s/%s/comment.html\"",
"%",
"(",
"ctype",
".",
"app_label",
",",
... | Internal function for the rendering of comments. | [
"Internal",
"function",
"for",
"the",
"rendering",
"of",
"comments",
"."
] | train | https://github.com/django-fluent/django-fluent-comments/blob/bfe98d55b56fedd8ca2e2659eed53a6390e53adf/fluent_comments/utils.py#L14-L23 |
django-fluent/django-fluent-comments | fluent_comments/forms/helper.py | CompactLabelsCommentFormHelper.render_layout | def render_layout(self, form, context, template_pack=TEMPLATE_PACK):
"""
Copy any field label to the ``placeholder`` attribute.
Note, this method is called when :attr:`layout` is defined.
"""
# Writing the label values into the field placeholders.
# This is done at render... | python | def render_layout(self, form, context, template_pack=TEMPLATE_PACK):
"""
Copy any field label to the ``placeholder`` attribute.
Note, this method is called when :attr:`layout` is defined.
"""
# Writing the label values into the field placeholders.
# This is done at render... | [
"def",
"render_layout",
"(",
"self",
",",
"form",
",",
"context",
",",
"template_pack",
"=",
"TEMPLATE_PACK",
")",
":",
"# Writing the label values into the field placeholders.",
"# This is done at rendering time, so the Form.__init__() could update any labels before.",
"# Django 1.1... | Copy any field label to the ``placeholder`` attribute.
Note, this method is called when :attr:`layout` is defined. | [
"Copy",
"any",
"field",
"label",
"to",
"the",
"placeholder",
"attribute",
".",
"Note",
"this",
"method",
"is",
"called",
"when",
":",
"attr",
":",
"layout",
"is",
"defined",
"."
] | train | https://github.com/django-fluent/django-fluent-comments/blob/bfe98d55b56fedd8ca2e2659eed53a6390e53adf/fluent_comments/forms/helper.py#L67-L82 |
django-fluent/django-fluent-comments | fluent_comments/models.py | get_comments_for_model | def get_comments_for_model(content_object, include_moderated=False):
"""
Return the QuerySet with all comments for a given model.
"""
qs = get_comments_model().objects.for_model(content_object)
if not include_moderated:
qs = qs.filter(is_public=True, is_removed=False)
return qs | python | def get_comments_for_model(content_object, include_moderated=False):
"""
Return the QuerySet with all comments for a given model.
"""
qs = get_comments_model().objects.for_model(content_object)
if not include_moderated:
qs = qs.filter(is_public=True, is_removed=False)
return qs | [
"def",
"get_comments_for_model",
"(",
"content_object",
",",
"include_moderated",
"=",
"False",
")",
":",
"qs",
"=",
"get_comments_model",
"(",
")",
".",
"objects",
".",
"for_model",
"(",
"content_object",
")",
"if",
"not",
"include_moderated",
":",
"qs",
"=",
... | Return the QuerySet with all comments for a given model. | [
"Return",
"the",
"QuerySet",
"with",
"all",
"comments",
"for",
"a",
"given",
"model",
"."
] | train | https://github.com/django-fluent/django-fluent-comments/blob/bfe98d55b56fedd8ca2e2659eed53a6390e53adf/fluent_comments/models.py#L36-L45 |
django-fluent/django-fluent-comments | fluent_comments/forms/_captcha.py | CaptchaFormMixin._reorder_fields | def _reorder_fields(self, ordering):
"""
Test that the 'captcha' field is really present.
This could be broken by a bad FLUENT_COMMENTS_FIELD_ORDER configuration.
"""
if 'captcha' not in ordering:
raise ImproperlyConfigured(
"When using 'FLUENT_COMMENT... | python | def _reorder_fields(self, ordering):
"""
Test that the 'captcha' field is really present.
This could be broken by a bad FLUENT_COMMENTS_FIELD_ORDER configuration.
"""
if 'captcha' not in ordering:
raise ImproperlyConfigured(
"When using 'FLUENT_COMMENT... | [
"def",
"_reorder_fields",
"(",
"self",
",",
"ordering",
")",
":",
"if",
"'captcha'",
"not",
"in",
"ordering",
":",
"raise",
"ImproperlyConfigured",
"(",
"\"When using 'FLUENT_COMMENTS_FIELD_ORDER', \"",
"\"make sure the 'captcha' field included too to use '{}' form. \"",
".",
... | Test that the 'captcha' field is really present.
This could be broken by a bad FLUENT_COMMENTS_FIELD_ORDER configuration. | [
"Test",
"that",
"the",
"captcha",
"field",
"is",
"really",
"present",
".",
"This",
"could",
"be",
"broken",
"by",
"a",
"bad",
"FLUENT_COMMENTS_FIELD_ORDER",
"configuration",
"."
] | train | https://github.com/django-fluent/django-fluent-comments/blob/bfe98d55b56fedd8ca2e2659eed53a6390e53adf/fluent_comments/forms/_captcha.py#L5-L21 |
django-fluent/django-fluent-comments | fluent_comments/views.py | post_comment_ajax | def post_comment_ajax(request, using=None):
"""
Post a comment, via an Ajax call.
"""
if not request.is_ajax():
return HttpResponseBadRequest("Expecting Ajax call")
# This is copied from django_comments.
# Basically that view does too much, and doesn't offer a hook to change the renderi... | python | def post_comment_ajax(request, using=None):
"""
Post a comment, via an Ajax call.
"""
if not request.is_ajax():
return HttpResponseBadRequest("Expecting Ajax call")
# This is copied from django_comments.
# Basically that view does too much, and doesn't offer a hook to change the renderi... | [
"def",
"post_comment_ajax",
"(",
"request",
",",
"using",
"=",
"None",
")",
":",
"if",
"not",
"request",
".",
"is_ajax",
"(",
")",
":",
"return",
"HttpResponseBadRequest",
"(",
"\"Expecting Ajax call\"",
")",
"# This is copied from django_comments.",
"# Basically that... | Post a comment, via an Ajax call. | [
"Post",
"a",
"comment",
"via",
"an",
"Ajax",
"call",
"."
] | train | https://github.com/django-fluent/django-fluent-comments/blob/bfe98d55b56fedd8ca2e2659eed53a6390e53adf/fluent_comments/views.py#L24-L107 |
django-fluent/django-fluent-comments | fluent_comments/views.py | _render_errors | def _render_errors(field):
"""
Render form errors in crispy-forms style.
"""
template = '{0}/layout/field_errors.html'.format(appsettings.CRISPY_TEMPLATE_PACK)
return render_to_string(template, {
'field': field,
'form_show_errors': True,
}) | python | def _render_errors(field):
"""
Render form errors in crispy-forms style.
"""
template = '{0}/layout/field_errors.html'.format(appsettings.CRISPY_TEMPLATE_PACK)
return render_to_string(template, {
'field': field,
'form_show_errors': True,
}) | [
"def",
"_render_errors",
"(",
"field",
")",
":",
"template",
"=",
"'{0}/layout/field_errors.html'",
".",
"format",
"(",
"appsettings",
".",
"CRISPY_TEMPLATE_PACK",
")",
"return",
"render_to_string",
"(",
"template",
",",
"{",
"'field'",
":",
"field",
",",
"'form_s... | Render form errors in crispy-forms style. | [
"Render",
"form",
"errors",
"in",
"crispy",
"-",
"forms",
"style",
"."
] | train | https://github.com/django-fluent/django-fluent-comments/blob/bfe98d55b56fedd8ca2e2659eed53a6390e53adf/fluent_comments/views.py#L154-L162 |
django-fluent/django-fluent-comments | fluent_comments/__init__.py | get_form | def get_form():
"""
Return the form to use for commenting.
"""
global form_class
from fluent_comments import appsettings
if form_class is None:
if appsettings.FLUENT_COMMENTS_FORM_CLASS:
from django.utils.module_loading import import_string
form_class = import_str... | python | def get_form():
"""
Return the form to use for commenting.
"""
global form_class
from fluent_comments import appsettings
if form_class is None:
if appsettings.FLUENT_COMMENTS_FORM_CLASS:
from django.utils.module_loading import import_string
form_class = import_str... | [
"def",
"get_form",
"(",
")",
":",
"global",
"form_class",
"from",
"fluent_comments",
"import",
"appsettings",
"if",
"form_class",
"is",
"None",
":",
"if",
"appsettings",
".",
"FLUENT_COMMENTS_FORM_CLASS",
":",
"from",
"django",
".",
"utils",
".",
"module_loading",... | Return the form to use for commenting. | [
"Return",
"the",
"form",
"to",
"use",
"for",
"commenting",
"."
] | train | https://github.com/django-fluent/django-fluent-comments/blob/bfe98d55b56fedd8ca2e2659eed53a6390e53adf/fluent_comments/__init__.py#L26-L40 |
django-fluent/django-fluent-comments | fluent_comments/receivers.py | load_default_moderator | def load_default_moderator():
"""
Find a moderator object
"""
if appsettings.FLUENT_COMMENTS_DEFAULT_MODERATOR == 'default':
# Perform spam checks
return moderation.FluentCommentsModerator(None)
elif appsettings.FLUENT_COMMENTS_DEFAULT_MODERATOR == 'deny':
# Deny all comments... | python | def load_default_moderator():
"""
Find a moderator object
"""
if appsettings.FLUENT_COMMENTS_DEFAULT_MODERATOR == 'default':
# Perform spam checks
return moderation.FluentCommentsModerator(None)
elif appsettings.FLUENT_COMMENTS_DEFAULT_MODERATOR == 'deny':
# Deny all comments... | [
"def",
"load_default_moderator",
"(",
")",
":",
"if",
"appsettings",
".",
"FLUENT_COMMENTS_DEFAULT_MODERATOR",
"==",
"'default'",
":",
"# Perform spam checks",
"return",
"moderation",
".",
"FluentCommentsModerator",
"(",
"None",
")",
"elif",
"appsettings",
".",
"FLUENT_... | Find a moderator object | [
"Find",
"a",
"moderator",
"object"
] | train | https://github.com/django-fluent/django-fluent-comments/blob/bfe98d55b56fedd8ca2e2659eed53a6390e53adf/fluent_comments/receivers.py#L24-L42 |
django-fluent/django-fluent-comments | fluent_comments/receivers.py | on_comment_will_be_posted | def on_comment_will_be_posted(sender, comment, request, **kwargs):
"""
Make sure both the Ajax and regular comments are checked for moderation.
This signal is also used to link moderators to the comment posting.
"""
content_object = comment.content_object
moderator = moderation.get_model_moderat... | python | def on_comment_will_be_posted(sender, comment, request, **kwargs):
"""
Make sure both the Ajax and regular comments are checked for moderation.
This signal is also used to link moderators to the comment posting.
"""
content_object = comment.content_object
moderator = moderation.get_model_moderat... | [
"def",
"on_comment_will_be_posted",
"(",
"sender",
",",
"comment",
",",
"request",
",",
"*",
"*",
"kwargs",
")",
":",
"content_object",
"=",
"comment",
".",
"content_object",
"moderator",
"=",
"moderation",
".",
"get_model_moderator",
"(",
"content_object",
".",
... | Make sure both the Ajax and regular comments are checked for moderation.
This signal is also used to link moderators to the comment posting. | [
"Make",
"sure",
"both",
"the",
"Ajax",
"and",
"regular",
"comments",
"are",
"checked",
"for",
"moderation",
".",
"This",
"signal",
"is",
"also",
"used",
"to",
"link",
"moderators",
"to",
"the",
"comment",
"posting",
"."
] | train | https://github.com/django-fluent/django-fluent-comments/blob/bfe98d55b56fedd8ca2e2659eed53a6390e53adf/fluent_comments/receivers.py#L50-L74 |
django-fluent/django-fluent-comments | fluent_comments/receivers.py | _run_default_moderator | def _run_default_moderator(comment, content_object, request):
"""
Run the default moderator
"""
# The default moderator will likely not check things like "auto close".
# It can still provide akismet and bad word checking.
if not default_moderator.allow(comment, content_object, request):
... | python | def _run_default_moderator(comment, content_object, request):
"""
Run the default moderator
"""
# The default moderator will likely not check things like "auto close".
# It can still provide akismet and bad word checking.
if not default_moderator.allow(comment, content_object, request):
... | [
"def",
"_run_default_moderator",
"(",
"comment",
",",
"content_object",
",",
"request",
")",
":",
"# The default moderator will likely not check things like \"auto close\".",
"# It can still provide akismet and bad word checking.",
"if",
"not",
"default_moderator",
".",
"allow",
"(... | Run the default moderator | [
"Run",
"the",
"default",
"moderator"
] | train | https://github.com/django-fluent/django-fluent-comments/blob/bfe98d55b56fedd8ca2e2659eed53a6390e53adf/fluent_comments/receivers.py#L77-L88 |
django-fluent/django-fluent-comments | fluent_comments/receivers.py | on_comment_posted | def on_comment_posted(sender, comment, request, **kwargs):
"""
Send email notification of a new comment to site staff when email notifications have been requested.
"""
content_object = comment.content_object
moderator = moderation.get_model_moderator(content_object.__class__)
if moderator is No... | python | def on_comment_posted(sender, comment, request, **kwargs):
"""
Send email notification of a new comment to site staff when email notifications have been requested.
"""
content_object = comment.content_object
moderator = moderation.get_model_moderator(content_object.__class__)
if moderator is No... | [
"def",
"on_comment_posted",
"(",
"sender",
",",
"comment",
",",
"request",
",",
"*",
"*",
"kwargs",
")",
":",
"content_object",
"=",
"comment",
".",
"content_object",
"moderator",
"=",
"moderation",
".",
"get_model_moderator",
"(",
"content_object",
".",
"__clas... | Send email notification of a new comment to site staff when email notifications have been requested. | [
"Send",
"email",
"notification",
"of",
"a",
"new",
"comment",
"to",
"site",
"staff",
"when",
"email",
"notifications",
"have",
"been",
"requested",
"."
] | train | https://github.com/django-fluent/django-fluent-comments/blob/bfe98d55b56fedd8ca2e2659eed53a6390e53adf/fluent_comments/receivers.py#L92-L102 |
django-fluent/django-fluent-comments | fluent_comments/akismet.py | akismet_check | def akismet_check(comment, content_object, request):
"""
Connects to Akismet and evaluates to True if Akismet marks this comment as spam.
:rtype: akismet.SpamStatus
"""
# Return previously cached response
akismet_result = getattr(comment, '_akismet_result_', None)
if akismet_result is not N... | python | def akismet_check(comment, content_object, request):
"""
Connects to Akismet and evaluates to True if Akismet marks this comment as spam.
:rtype: akismet.SpamStatus
"""
# Return previously cached response
akismet_result = getattr(comment, '_akismet_result_', None)
if akismet_result is not N... | [
"def",
"akismet_check",
"(",
"comment",
",",
"content_object",
",",
"request",
")",
":",
"# Return previously cached response",
"akismet_result",
"=",
"getattr",
"(",
"comment",
",",
"'_akismet_result_'",
",",
"None",
")",
"if",
"akismet_result",
"is",
"not",
"None"... | Connects to Akismet and evaluates to True if Akismet marks this comment as spam.
:rtype: akismet.SpamStatus | [
"Connects",
"to",
"Akismet",
"and",
"evaluates",
"to",
"True",
"if",
"Akismet",
"marks",
"this",
"comment",
"as",
"spam",
"."
] | train | https://github.com/django-fluent/django-fluent-comments/blob/bfe98d55b56fedd8ca2e2659eed53a6390e53adf/fluent_comments/akismet.py#L17-L47 |
DinoTools/python-overpy | overpy/__init__.py | Overpass._handle_remark_msg | def _handle_remark_msg(self, msg):
"""
Try to parse the message provided with the remark tag or element.
:param str msg: The message
:raises overpy.exception.OverpassRuntimeError: If message starts with 'runtime error:'
:raises overpy.exception.OverpassRuntimeRemark: If message ... | python | def _handle_remark_msg(self, msg):
"""
Try to parse the message provided with the remark tag or element.
:param str msg: The message
:raises overpy.exception.OverpassRuntimeError: If message starts with 'runtime error:'
:raises overpy.exception.OverpassRuntimeRemark: If message ... | [
"def",
"_handle_remark_msg",
"(",
"self",
",",
"msg",
")",
":",
"msg",
"=",
"msg",
".",
"strip",
"(",
")",
"if",
"msg",
".",
"startswith",
"(",
"\"runtime error:\"",
")",
":",
"raise",
"exception",
".",
"OverpassRuntimeError",
"(",
"msg",
"=",
"msg",
")"... | Try to parse the message provided with the remark tag or element.
:param str msg: The message
:raises overpy.exception.OverpassRuntimeError: If message starts with 'runtime error:'
:raises overpy.exception.OverpassRuntimeRemark: If message starts with 'runtime remark:'
:raises overpy.ex... | [
"Try",
"to",
"parse",
"the",
"message",
"provided",
"with",
"the",
"remark",
"tag",
"or",
"element",
"."
] | train | https://github.com/DinoTools/python-overpy/blob/db8f80eeb1b4d1405816bd62c16ddb3364e0c46d/overpy/__init__.py#L97-L111 |
DinoTools/python-overpy | overpy/__init__.py | Overpass.query | def query(self, query):
"""
Query the Overpass API
:param String|Bytes query: The query string in Overpass QL
:return: The parsed result
:rtype: overpy.Result
"""
if not isinstance(query, bytes):
query = query.encode("utf-8")
retry_num = 0
... | python | def query(self, query):
"""
Query the Overpass API
:param String|Bytes query: The query string in Overpass QL
:return: The parsed result
:rtype: overpy.Result
"""
if not isinstance(query, bytes):
query = query.encode("utf-8")
retry_num = 0
... | [
"def",
"query",
"(",
"self",
",",
"query",
")",
":",
"if",
"not",
"isinstance",
"(",
"query",
",",
"bytes",
")",
":",
"query",
"=",
"query",
".",
"encode",
"(",
"\"utf-8\"",
")",
"retry_num",
"=",
"0",
"retry_exceptions",
"=",
"[",
"]",
"do_retry",
"... | Query the Overpass API
:param String|Bytes query: The query string in Overpass QL
:return: The parsed result
:rtype: overpy.Result | [
"Query",
"the",
"Overpass",
"API"
] | train | https://github.com/DinoTools/python-overpy/blob/db8f80eeb1b4d1405816bd62c16ddb3364e0c46d/overpy/__init__.py#L113-L202 |
DinoTools/python-overpy | overpy/__init__.py | Overpass.parse_json | def parse_json(self, data, encoding="utf-8"):
"""
Parse raw response from Overpass service.
:param data: Raw JSON Data
:type data: String or Bytes
:param encoding: Encoding to decode byte string
:type encoding: String
:return: Result object
:rtype: overpy... | python | def parse_json(self, data, encoding="utf-8"):
"""
Parse raw response from Overpass service.
:param data: Raw JSON Data
:type data: String or Bytes
:param encoding: Encoding to decode byte string
:type encoding: String
:return: Result object
:rtype: overpy... | [
"def",
"parse_json",
"(",
"self",
",",
"data",
",",
"encoding",
"=",
"\"utf-8\"",
")",
":",
"if",
"isinstance",
"(",
"data",
",",
"bytes",
")",
":",
"data",
"=",
"data",
".",
"decode",
"(",
"encoding",
")",
"data",
"=",
"json",
".",
"loads",
"(",
"... | Parse raw response from Overpass service.
:param data: Raw JSON Data
:type data: String or Bytes
:param encoding: Encoding to decode byte string
:type encoding: String
:return: Result object
:rtype: overpy.Result | [
"Parse",
"raw",
"response",
"from",
"Overpass",
"service",
"."
] | train | https://github.com/DinoTools/python-overpy/blob/db8f80eeb1b4d1405816bd62c16ddb3364e0c46d/overpy/__init__.py#L204-L220 |
DinoTools/python-overpy | overpy/__init__.py | Result.expand | def expand(self, other):
"""
Add all elements from an other result to the list of elements of this result object.
It is used by the auto resolve feature.
:param other: Expand the result with the elements from this result.
:type other: overpy.Result
:raises ValueError: I... | python | def expand(self, other):
"""
Add all elements from an other result to the list of elements of this result object.
It is used by the auto resolve feature.
:param other: Expand the result with the elements from this result.
:type other: overpy.Result
:raises ValueError: I... | [
"def",
"expand",
"(",
"self",
",",
"other",
")",
":",
"if",
"not",
"isinstance",
"(",
"other",
",",
"Result",
")",
":",
"raise",
"ValueError",
"(",
"\"Provided argument has to be instance of overpy:Result()\"",
")",
"other_collection_map",
"=",
"{",
"Node",
":",
... | Add all elements from an other result to the list of elements of this result object.
It is used by the auto resolve feature.
:param other: Expand the result with the elements from this result.
:type other: overpy.Result
:raises ValueError: If provided parameter is not instance of :clas... | [
"Add",
"all",
"elements",
"from",
"an",
"other",
"result",
"to",
"the",
"list",
"of",
"elements",
"of",
"this",
"result",
"object",
"."
] | train | https://github.com/DinoTools/python-overpy/blob/db8f80eeb1b4d1405816bd62c16ddb3364e0c46d/overpy/__init__.py#L270-L287 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.