Search is not available for this dataset
identifier stringlengths 1 155 | parameters stringlengths 2 6.09k | docstring stringlengths 11 63.4k | docstring_summary stringlengths 0 63.4k | function stringlengths 29 99.8k | function_tokens list | start_point list | end_point list | language stringclasses 1
value | docstring_language stringlengths 2 7 | docstring_language_predictions stringlengths 18 23 | is_langid_reliable stringclasses 2
values |
|---|---|---|---|---|---|---|---|---|---|---|---|
ordinal | (value) |
Converts an integer to its ordinal as a string. 1 is '1st', 2 is '2nd',
3 is '3rd', etc. Works for any integer.
|
Converts an integer to its ordinal as a string. 1 is '1st', 2 is '2nd',
3 is '3rd', etc. Works for any integer.
| def ordinal(value):
"""
Converts an integer to its ordinal as a string. 1 is '1st', 2 is '2nd',
3 is '3rd', etc. Works for any integer.
"""
try:
value = int(value)
except (TypeError, ValueError):
return value
suffixes = (_('th'), _('st'), _('nd'), _('rd'), _('th'), _('th'), _... | [
"def",
"ordinal",
"(",
"value",
")",
":",
"try",
":",
"value",
"=",
"int",
"(",
"value",
")",
"except",
"(",
"TypeError",
",",
"ValueError",
")",
":",
"return",
"value",
"suffixes",
"=",
"(",
"_",
"(",
"'th'",
")",
",",
"_",
"(",
"'st'",
")",
","... | [
20,
0
] | [
33,
60
] | python | en | ['en', 'error', 'th'] | False |
intcomma | (value, use_l10n=True) |
Converts an integer to a string containing commas every three digits.
For example, 3000 becomes '3,000' and 45000 becomes '45,000'.
|
Converts an integer to a string containing commas every three digits.
For example, 3000 becomes '3,000' and 45000 becomes '45,000'.
| def intcomma(value, use_l10n=True):
"""
Converts an integer to a string containing commas every three digits.
For example, 3000 becomes '3,000' and 45000 becomes '45,000'.
"""
if settings.USE_L10N and use_l10n:
try:
if not isinstance(value, (float, Decimal)):
valu... | [
"def",
"intcomma",
"(",
"value",
",",
"use_l10n",
"=",
"True",
")",
":",
"if",
"settings",
".",
"USE_L10N",
"and",
"use_l10n",
":",
"try",
":",
"if",
"not",
"isinstance",
"(",
"value",
",",
"(",
"float",
",",
"Decimal",
")",
")",
":",
"value",
"=",
... | [
37,
0
] | [
55,
38
] | python | en | ['en', 'error', 'th'] | False |
intword | (value) |
Converts a large integer to a friendly text representation. Works best
for numbers over 1 million. For example, 1000000 becomes '1.0 million',
1200000 becomes '1.2 million' and '1200000000' becomes '1.2 billion'.
|
Converts a large integer to a friendly text representation. Works best
for numbers over 1 million. For example, 1000000 becomes '1.0 million',
1200000 becomes '1.2 million' and '1200000000' becomes '1.2 billion'.
| def intword(value):
"""
Converts a large integer to a friendly text representation. Works best
for numbers over 1 million. For example, 1000000 becomes '1.0 million',
1200000 becomes '1.2 million' and '1200000000' becomes '1.2 billion'.
"""
try:
value = int(value)
except (TypeError, ... | [
"def",
"intword",
"(",
"value",
")",
":",
"try",
":",
"value",
"=",
"int",
"(",
"value",
")",
"except",
"(",
"TypeError",
",",
"ValueError",
")",
":",
"return",
"value",
"if",
"value",
"<",
"1000000",
":",
"return",
"value",
"def",
"_check_for_i18n",
"... | [
107,
0
] | [
137,
16
] | python | en | ['en', 'error', 'th'] | False |
apnumber | (value) |
For numbers 1-9, returns the number spelled out. Otherwise, returns the
number. This follows Associated Press style.
|
For numbers 1-9, returns the number spelled out. Otherwise, returns the
number. This follows Associated Press style.
| def apnumber(value):
"""
For numbers 1-9, returns the number spelled out. Otherwise, returns the
number. This follows Associated Press style.
"""
try:
value = int(value)
except (TypeError, ValueError):
return value
if not 0 < value < 10:
return value
return (_('on... | [
"def",
"apnumber",
"(",
"value",
")",
":",
"try",
":",
"value",
"=",
"int",
"(",
"value",
")",
"except",
"(",
"TypeError",
",",
"ValueError",
")",
":",
"return",
"value",
"if",
"not",
"0",
"<",
"value",
"<",
"10",
":",
"return",
"value",
"return",
... | [
141,
0
] | [
153,
67
] | python | en | ['en', 'error', 'th'] | False |
naturalday | (value, arg=None) |
For date values that are tomorrow, today or yesterday compared to
present day returns representing string. Otherwise, returns a string
formatted according to settings.DATE_FORMAT.
|
For date values that are tomorrow, today or yesterday compared to
present day returns representing string. Otherwise, returns a string
formatted according to settings.DATE_FORMAT.
| def naturalday(value, arg=None):
"""
For date values that are tomorrow, today or yesterday compared to
present day returns representing string. Otherwise, returns a string
formatted according to settings.DATE_FORMAT.
"""
try:
tzinfo = getattr(value, 'tzinfo', None)
value = date(v... | [
"def",
"naturalday",
"(",
"value",
",",
"arg",
"=",
"None",
")",
":",
"try",
":",
"tzinfo",
"=",
"getattr",
"(",
"value",
",",
"'tzinfo'",
",",
"None",
")",
"value",
"=",
"date",
"(",
"value",
".",
"year",
",",
"value",
".",
"month",
",",
"value",
... | [
159,
0
] | [
182,
42
] | python | en | ['en', 'error', 'th'] | False |
naturaltime | (value) |
For date and time values shows how many seconds, minutes or hours ago
compared to current timestamp returns representing string.
|
For date and time values shows how many seconds, minutes or hours ago
compared to current timestamp returns representing string.
| def naturaltime(value):
"""
For date and time values shows how many seconds, minutes or hours ago
compared to current timestamp returns representing string.
"""
if not isinstance(value, date): # datetime is a subclass of date
return value
now = datetime.now(utc if is_aware(value) else ... | [
"def",
"naturaltime",
"(",
"value",
")",
":",
"if",
"not",
"isinstance",
"(",
"value",
",",
"date",
")",
":",
"# datetime is a subclass of date",
"return",
"value",
"now",
"=",
"datetime",
".",
"now",
"(",
"utc",
"if",
"is_aware",
"(",
"value",
")",
"else"... | [
188,
0
] | [
252,
32
] | python | en | ['en', 'error', 'th'] | False |
flatpage | (request, url) |
Public interface to the flat page view.
Models: `flatpages.flatpages`
Templates: Uses the template defined by the ``template_name`` field,
or :template:`flatpages/default.html` if template_name is not defined.
Context:
flatpage
`flatpages.flatpages` object
|
Public interface to the flat page view. | def flatpage(request, url):
"""
Public interface to the flat page view.
Models: `flatpages.flatpages`
Templates: Uses the template defined by the ``template_name`` field,
or :template:`flatpages/default.html` if template_name is not defined.
Context:
flatpage
`flatpages.... | [
"def",
"flatpage",
"(",
"request",
",",
"url",
")",
":",
"if",
"not",
"url",
".",
"startswith",
"(",
"'/'",
")",
":",
"url",
"=",
"'/'",
"+",
"url",
"site_id",
"=",
"get_current_site",
"(",
"request",
")",
".",
"id",
"try",
":",
"f",
"=",
"get_obje... | [
21,
0
] | [
46,
38
] | python | en | ['en', 'error', 'th'] | False |
render_flatpage | (request, f) |
Internal interface to the flat page view.
|
Internal interface to the flat page view.
| def render_flatpage(request, f):
"""
Internal interface to the flat page view.
"""
# If registration is required for accessing this page, and the user isn't
# logged in, redirect to the login page.
if f.registration_required and not request.user.is_authenticated():
from django.contrib.au... | [
"def",
"render_flatpage",
"(",
"request",
",",
"f",
")",
":",
"# If registration is required for accessing this page, and the user isn't",
"# logged in, redirect to the login page.",
"if",
"f",
".",
"registration_required",
"and",
"not",
"request",
".",
"user",
".",
"is_authe... | [
50,
0
] | [
74,
19
] | python | en | ['en', 'error', 'th'] | False |
mock_checks | (mocker) | Mock VSCode Template Checks | Mock VSCode Template Checks | def mock_checks(mocker):
"""Mock VSCode Template Checks"""
m_run = mocker.patch.object(micropy.project.checks.subproc, "run").return_value
type(m_run).stdout = mocker.PropertyMock(return_value="\n".join(mock_vscode_exts))
return m_run | [
"def",
"mock_checks",
"(",
"mocker",
")",
":",
"m_run",
"=",
"mocker",
".",
"patch",
".",
"object",
"(",
"micropy",
".",
"project",
".",
"checks",
".",
"subproc",
",",
"\"run\"",
")",
".",
"return_value",
"type",
"(",
"m_run",
")",
".",
"stdout",
"=",
... | [
189,
0
] | [
193,
16
] | python | en | ['en', 'no', 'en'] | True |
mock_pkg | (mocker, tmp_path) | return mock package | return mock package | def mock_pkg(mocker, tmp_path):
"""return mock package"""
from micropy import packages
tmp_pkg = tmp_path / "tmp_pkg"
tmp_pkg.mkdir()
(tmp_pkg / "module.py").touch()
(tmp_pkg / "file.py").touch()
mocker.patch.object(packages.source_package.utils, "ensure_valid_url")
mock_tarbytes = mock... | [
"def",
"mock_pkg",
"(",
"mocker",
",",
"tmp_path",
")",
":",
"from",
"micropy",
"import",
"packages",
"tmp_pkg",
"=",
"tmp_path",
"/",
"\"tmp_pkg\"",
"tmp_pkg",
".",
"mkdir",
"(",
")",
"(",
"tmp_pkg",
"/",
"\"module.py\"",
")",
".",
"touch",
"(",
")",
"(... | [
197,
0
] | [
212,
18
] | python | en | ['en', 'af', 'en'] | True |
AssertUtils.str_path | (self, path, absolute=False) | x-platform path strings helper | x-platform path strings helper | def str_path(self, path, absolute=False):
"""x-platform path strings helper"""
path = Path(path)
if absolute:
path = path.absolute()
return str(path) | [
"def",
"str_path",
"(",
"self",
",",
"path",
",",
"absolute",
"=",
"False",
")",
":",
"path",
"=",
"Path",
"(",
"path",
")",
"if",
"absolute",
":",
"path",
"=",
"path",
".",
"absolute",
"(",
")",
"return",
"str",
"(",
"path",
")"
] | [
266,
4
] | [
271,
24
] | python | en | ['en', 'af', 'en'] | True |
SystemChecksTestCase.test_custom_modelforms_with_fields_fieldsets | (self) |
# Regression test for #8027: custom ModelForms with fields/fieldsets
|
# Regression test for #8027: custom ModelForms with fields/fieldsets
| def test_custom_modelforms_with_fields_fieldsets(self):
"""
# Regression test for #8027: custom ModelForms with fields/fieldsets
"""
errors = ValidFields.check(model=Song)
self.assertEqual(errors, []) | [
"def",
"test_custom_modelforms_with_fields_fieldsets",
"(",
"self",
")",
":",
"errors",
"=",
"ValidFields",
".",
"check",
"(",
"model",
"=",
"Song",
")",
"self",
".",
"assertEqual",
"(",
"errors",
",",
"[",
"]",
")"
] | [
88,
4
] | [
94,
36
] | python | en | ['en', 'error', 'th'] | False |
SystemChecksTestCase.test_custom_get_form_with_fieldsets | (self) |
Ensure that the fieldsets checks are skipped when the ModelAdmin.get_form() method
is overridden.
Refs #19445.
|
Ensure that the fieldsets checks are skipped when the ModelAdmin.get_form() method
is overridden.
Refs #19445.
| def test_custom_get_form_with_fieldsets(self):
"""
Ensure that the fieldsets checks are skipped when the ModelAdmin.get_form() method
is overridden.
Refs #19445.
"""
errors = ValidFormFieldsets.check(model=Song)
self.assertEqual(errors, []) | [
"def",
"test_custom_get_form_with_fieldsets",
"(",
"self",
")",
":",
"errors",
"=",
"ValidFormFieldsets",
".",
"check",
"(",
"model",
"=",
"Song",
")",
"self",
".",
"assertEqual",
"(",
"errors",
",",
"[",
"]",
")"
] | [
96,
4
] | [
104,
36
] | python | en | ['en', 'error', 'th'] | False |
SystemChecksTestCase.test_exclude_values | (self) |
Tests for basic system checks of 'exclude' option values (#12689)
|
Tests for basic system checks of 'exclude' option values (#12689)
| def test_exclude_values(self):
"""
Tests for basic system checks of 'exclude' option values (#12689)
"""
class ExcludedFields1(admin.ModelAdmin):
exclude = 'foo'
errors = ExcludedFields1.check(model=Book)
expected = [
checks.Error(
... | [
"def",
"test_exclude_values",
"(",
"self",
")",
":",
"class",
"ExcludedFields1",
"(",
"admin",
".",
"ModelAdmin",
")",
":",
"exclude",
"=",
"'foo'",
"errors",
"=",
"ExcludedFields1",
".",
"check",
"(",
"model",
"=",
"Book",
")",
"expected",
"=",
"[",
"chec... | [
106,
4
] | [
123,
42
] | python | en | ['en', 'error', 'th'] | False |
SystemChecksTestCase.test_exclude_inline_model_admin | (self) |
Regression test for #9932 - exclude in InlineModelAdmin should not
contain the ForeignKey field used in ModelAdmin.model
|
Regression test for #9932 - exclude in InlineModelAdmin should not
contain the ForeignKey field used in ModelAdmin.model
| def test_exclude_inline_model_admin(self):
"""
Regression test for #9932 - exclude in InlineModelAdmin should not
contain the ForeignKey field used in ModelAdmin.model
"""
class SongInline(admin.StackedInline):
model = Song
exclude = ['album']
cl... | [
"def",
"test_exclude_inline_model_admin",
"(",
"self",
")",
":",
"class",
"SongInline",
"(",
"admin",
".",
"StackedInline",
")",
":",
"model",
"=",
"Song",
"exclude",
"=",
"[",
"'album'",
"]",
"class",
"AlbumAdmin",
"(",
"admin",
".",
"ModelAdmin",
")",
":",... | [
160,
4
] | [
184,
42
] | python | en | ['en', 'error', 'th'] | False |
SystemChecksTestCase.test_valid_generic_inline_model_admin | (self) |
Regression test for #22034 - check that generic inlines don't look for
normal ForeignKey relations.
|
Regression test for #22034 - check that generic inlines don't look for
normal ForeignKey relations.
| def test_valid_generic_inline_model_admin(self):
"""
Regression test for #22034 - check that generic inlines don't look for
normal ForeignKey relations.
"""
class InfluenceInline(GenericStackedInline):
model = Influence
class SongAdmin(admin.ModelAdmin):
... | [
"def",
"test_valid_generic_inline_model_admin",
"(",
"self",
")",
":",
"class",
"InfluenceInline",
"(",
"GenericStackedInline",
")",
":",
"model",
"=",
"Influence",
"class",
"SongAdmin",
"(",
"admin",
".",
"ModelAdmin",
")",
":",
"inlines",
"=",
"[",
"InfluenceInl... | [
186,
4
] | [
199,
36
] | python | en | ['en', 'error', 'th'] | False |
SystemChecksTestCase.test_generic_inline_model_admin_non_generic_model | (self) |
Ensure that a model without a GenericForeignKey raises problems if it's included
in an GenericInlineModelAdmin definition.
|
Ensure that a model without a GenericForeignKey raises problems if it's included
in an GenericInlineModelAdmin definition.
| def test_generic_inline_model_admin_non_generic_model(self):
"""
Ensure that a model without a GenericForeignKey raises problems if it's included
in an GenericInlineModelAdmin definition.
"""
class BookInline(GenericStackedInline):
model = Book
class SongAdm... | [
"def",
"test_generic_inline_model_admin_non_generic_model",
"(",
"self",
")",
":",
"class",
"BookInline",
"(",
"GenericStackedInline",
")",
":",
"model",
"=",
"Book",
"class",
"SongAdmin",
"(",
"admin",
".",
"ModelAdmin",
")",
":",
"inlines",
"=",
"[",
"BookInline... | [
201,
4
] | [
222,
42
] | python | en | ['en', 'error', 'th'] | False |
SystemChecksTestCase.test_generic_inline_model_admin_bad_ct_field | (self) | A GenericInlineModelAdmin raises problems if the ct_field points to a non-existent field. | A GenericInlineModelAdmin raises problems if the ct_field points to a non-existent field. | def test_generic_inline_model_admin_bad_ct_field(self):
"A GenericInlineModelAdmin raises problems if the ct_field points to a non-existent field."
class InfluenceInline(GenericStackedInline):
model = Influence
ct_field = 'nonexistent'
class SongAdmin(admin.ModelAdmin):... | [
"def",
"test_generic_inline_model_admin_bad_ct_field",
"(",
"self",
")",
":",
"class",
"InfluenceInline",
"(",
"GenericStackedInline",
")",
":",
"model",
"=",
"Influence",
"ct_field",
"=",
"'nonexistent'",
"class",
"SongAdmin",
"(",
"admin",
".",
"ModelAdmin",
")",
... | [
224,
4
] | [
243,
42
] | python | en | ['en', 'en', 'en'] | True |
SystemChecksTestCase.test_generic_inline_model_admin_bad_fk_field | (self) | A GenericInlineModelAdmin raises problems if the ct_fk_field points to a non-existent field. | A GenericInlineModelAdmin raises problems if the ct_fk_field points to a non-existent field. | def test_generic_inline_model_admin_bad_fk_field(self):
"A GenericInlineModelAdmin raises problems if the ct_fk_field points to a non-existent field."
class InfluenceInline(GenericStackedInline):
model = Influence
ct_fk_field = 'nonexistent'
class SongAdmin(admin.ModelA... | [
"def",
"test_generic_inline_model_admin_bad_fk_field",
"(",
"self",
")",
":",
"class",
"InfluenceInline",
"(",
"GenericStackedInline",
")",
":",
"model",
"=",
"Influence",
"ct_fk_field",
"=",
"'nonexistent'",
"class",
"SongAdmin",
"(",
"admin",
".",
"ModelAdmin",
")",... | [
245,
4
] | [
264,
42
] | python | en | ['en', 'en', 'en'] | True |
SystemChecksTestCase.test_generic_inline_model_admin_non_gfk_ct_field | (self) | A GenericInlineModelAdmin raises problems if the ct_field points to a field that isn't part of a GenericForeignKey | A GenericInlineModelAdmin raises problems if the ct_field points to a field that isn't part of a GenericForeignKey | def test_generic_inline_model_admin_non_gfk_ct_field(self):
"A GenericInlineModelAdmin raises problems if the ct_field points to a field that isn't part of a GenericForeignKey"
class InfluenceInline(GenericStackedInline):
model = Influence
ct_field = 'name'
class SongAd... | [
"def",
"test_generic_inline_model_admin_non_gfk_ct_field",
"(",
"self",
")",
":",
"class",
"InfluenceInline",
"(",
"GenericStackedInline",
")",
":",
"model",
"=",
"Influence",
"ct_field",
"=",
"'name'",
"class",
"SongAdmin",
"(",
"admin",
".",
"ModelAdmin",
")",
":"... | [
266,
4
] | [
285,
42
] | python | en | ['en', 'en', 'en'] | True |
SystemChecksTestCase.test_generic_inline_model_admin_non_gfk_fk_field | (self) | A GenericInlineModelAdmin raises problems if the ct_fk_field points to a field that isn't part of a GenericForeignKey | A GenericInlineModelAdmin raises problems if the ct_fk_field points to a field that isn't part of a GenericForeignKey | def test_generic_inline_model_admin_non_gfk_fk_field(self):
"A GenericInlineModelAdmin raises problems if the ct_fk_field points to a field that isn't part of a GenericForeignKey"
class InfluenceInline(GenericStackedInline):
model = Influence
ct_fk_field = 'name'
class ... | [
"def",
"test_generic_inline_model_admin_non_gfk_fk_field",
"(",
"self",
")",
":",
"class",
"InfluenceInline",
"(",
"GenericStackedInline",
")",
":",
"model",
"=",
"Influence",
"ct_fk_field",
"=",
"'name'",
"class",
"SongAdmin",
"(",
"admin",
".",
"ModelAdmin",
")",
... | [
287,
4
] | [
306,
42
] | python | en | ['en', 'en', 'en'] | True |
SystemChecksTestCase.test_app_label_in_admin_checks | (self) |
Regression test for #15669 - Include app label in admin system check messages
|
Regression test for #15669 - Include app label in admin system check messages
| def test_app_label_in_admin_checks(self):
"""
Regression test for #15669 - Include app label in admin system check messages
"""
class RawIdNonexistingAdmin(admin.ModelAdmin):
raw_id_fields = ('nonexisting',)
errors = RawIdNonexistingAdmin.check(model=Album)
... | [
"def",
"test_app_label_in_admin_checks",
"(",
"self",
")",
":",
"class",
"RawIdNonexistingAdmin",
"(",
"admin",
".",
"ModelAdmin",
")",
":",
"raw_id_fields",
"=",
"(",
"'nonexisting'",
",",
")",
"errors",
"=",
"RawIdNonexistingAdmin",
".",
"check",
"(",
"model",
... | [
308,
4
] | [
326,
42
] | python | en | ['en', 'error', 'th'] | False |
SystemChecksTestCase.test_fk_exclusion | (self) |
Regression test for #11709 - when testing for fk excluding (when exclude is
given) make sure fk_name is honored or things blow up when there is more
than one fk to the parent model.
|
Regression test for #11709 - when testing for fk excluding (when exclude is
given) make sure fk_name is honored or things blow up when there is more
than one fk to the parent model.
| def test_fk_exclusion(self):
"""
Regression test for #11709 - when testing for fk excluding (when exclude is
given) make sure fk_name is honored or things blow up when there is more
than one fk to the parent model.
"""
class TwoAlbumFKAndAnEInline(admin.TabularInline):
... | [
"def",
"test_fk_exclusion",
"(",
"self",
")",
":",
"class",
"TwoAlbumFKAndAnEInline",
"(",
"admin",
".",
"TabularInline",
")",
":",
"model",
"=",
"TwoAlbumFKAndAnE",
"exclude",
"=",
"(",
"\"e\"",
",",
")",
"fk_name",
"=",
"\"album1\"",
"class",
"MyAdmin",
"(",... | [
328,
4
] | [
344,
36
] | python | en | ['en', 'error', 'th'] | False |
SystemChecksTestCase.test_graceful_m2m_fail | (self) |
Regression test for #12203/#12237 - Fail more gracefully when a M2M field that
specifies the 'through' option is included in the 'fields' or the 'fieldsets'
ModelAdmin options.
|
Regression test for #12203/#12237 - Fail more gracefully when a M2M field that
specifies the 'through' option is included in the 'fields' or the 'fieldsets'
ModelAdmin options.
| def test_graceful_m2m_fail(self):
"""
Regression test for #12203/#12237 - Fail more gracefully when a M2M field that
specifies the 'through' option is included in the 'fields' or the 'fieldsets'
ModelAdmin options.
"""
class BookAdmin(admin.ModelAdmin):
field... | [
"def",
"test_graceful_m2m_fail",
"(",
"self",
")",
":",
"class",
"BookAdmin",
"(",
"admin",
".",
"ModelAdmin",
")",
":",
"fields",
"=",
"[",
"'authors'",
"]",
"errors",
"=",
"BookAdmin",
".",
"check",
"(",
"model",
"=",
"Book",
")",
"expected",
"=",
"[",... | [
459,
4
] | [
479,
42
] | python | en | ['en', 'error', 'th'] | False |
SystemChecksTestCase.test_explicit_through_override | (self) |
Regression test for #12209 -- If the explicitly provided through model
is specified as a string, the admin should still be able use
Model.m2m_field.through
|
Regression test for #12209 -- If the explicitly provided through model
is specified as a string, the admin should still be able use
Model.m2m_field.through
| def test_explicit_through_override(self):
"""
Regression test for #12209 -- If the explicitly provided through model
is specified as a string, the admin should still be able use
Model.m2m_field.through
"""
class AuthorsInline(admin.TabularInline):
model = Boo... | [
"def",
"test_explicit_through_override",
"(",
"self",
")",
":",
"class",
"AuthorsInline",
"(",
"admin",
".",
"TabularInline",
")",
":",
"model",
"=",
"Book",
".",
"authors",
".",
"through",
"class",
"BookAdmin",
"(",
"admin",
".",
"ModelAdmin",
")",
":",
"in... | [
516,
4
] | [
530,
36
] | python | en | ['en', 'error', 'th'] | False |
SystemChecksTestCase.test_non_model_fields | (self) |
Regression for ensuring ModelAdmin.fields can contain non-model fields
that broke with r11737
|
Regression for ensuring ModelAdmin.fields can contain non-model fields
that broke with r11737
| def test_non_model_fields(self):
"""
Regression for ensuring ModelAdmin.fields can contain non-model fields
that broke with r11737
"""
class SongForm(forms.ModelForm):
extra_data = forms.CharField()
class FieldsOnFormOnlyAdmin(admin.ModelAdmin):
... | [
"def",
"test_non_model_fields",
"(",
"self",
")",
":",
"class",
"SongForm",
"(",
"forms",
".",
"ModelForm",
")",
":",
"extra_data",
"=",
"forms",
".",
"CharField",
"(",
")",
"class",
"FieldsOnFormOnlyAdmin",
"(",
"admin",
".",
"ModelAdmin",
")",
":",
"form",... | [
532,
4
] | [
546,
36
] | python | en | ['en', 'error', 'th'] | False |
SystemChecksTestCase.test_non_model_first_field | (self) |
Regression for ensuring ModelAdmin.field can handle first elem being a
non-model field (test fix for UnboundLocalError introduced with r16225).
|
Regression for ensuring ModelAdmin.field can handle first elem being a
non-model field (test fix for UnboundLocalError introduced with r16225).
| def test_non_model_first_field(self):
"""
Regression for ensuring ModelAdmin.field can handle first elem being a
non-model field (test fix for UnboundLocalError introduced with r16225).
"""
class SongForm(forms.ModelForm):
extra_data = forms.CharField()
... | [
"def",
"test_non_model_first_field",
"(",
"self",
")",
":",
"class",
"SongForm",
"(",
"forms",
".",
"ModelForm",
")",
":",
"extra_data",
"=",
"forms",
".",
"CharField",
"(",
")",
"class",
"Meta",
":",
"model",
"=",
"Song",
"fields",
"=",
"'__all__'",
"clas... | [
548,
4
] | [
566,
36
] | python | en | ['en', 'error', 'th'] | False |
SimpleQueueClient.ensure_queue | (self, queue_name: str, callback: Callable[[BlockingChannel], None]) | Ensure that a given queue has been declared, and then call
the callback with no arguments. | Ensure that a given queue has been declared, and then call
the callback with no arguments. | def ensure_queue(self, queue_name: str, callback: Callable[[BlockingChannel], None]) -> None:
"""Ensure that a given queue has been declared, and then call
the callback with no arguments."""
if self.connection is None or not self.connection.is_open:
self._connect()
assert se... | [
"def",
"ensure_queue",
"(",
"self",
",",
"queue_name",
":",
"str",
",",
"callback",
":",
"Callable",
"[",
"[",
"BlockingChannel",
"]",
",",
"None",
"]",
")",
"->",
"None",
":",
"if",
"self",
".",
"connection",
"is",
"None",
"or",
"not",
"self",
".",
... | [
106,
4
] | [
116,
30
] | python | en | ['en', 'en', 'en'] | True |
import_string | (dotted_path) |
Import a dotted module path and return the attribute/class designated by the
last name in the path. Raise ImportError if the import failed.
|
Import a dotted module path and return the attribute/class designated by the
last name in the path. Raise ImportError if the import failed.
| def import_string(dotted_path):
"""
Import a dotted module path and return the attribute/class designated by the
last name in the path. Raise ImportError if the import failed.
"""
try:
module_path, class_name = dotted_path.rsplit('.', 1)
except ValueError:
msg = "%s doesn't look ... | [
"def",
"import_string",
"(",
"dotted_path",
")",
":",
"try",
":",
"module_path",
",",
"class_name",
"=",
"dotted_path",
".",
"rsplit",
"(",
"'.'",
",",
"1",
")",
"except",
"ValueError",
":",
"msg",
"=",
"\"%s doesn't look like a module path\"",
"%",
"dotted_path... | [
13,
0
] | [
31,
69
] | python | en | ['en', 'error', 'th'] | False |
import_by_path | (dotted_path, error_prefix='') |
Import a dotted module path and return the attribute/class designated by the
last name in the path. Raise ImproperlyConfigured if something goes wrong.
|
Import a dotted module path and return the attribute/class designated by the
last name in the path. Raise ImproperlyConfigured if something goes wrong.
| def import_by_path(dotted_path, error_prefix=''):
"""
Import a dotted module path and return the attribute/class designated by the
last name in the path. Raise ImproperlyConfigured if something goes wrong.
"""
warnings.warn(
'import_by_path() has been deprecated. Use import_string() instead.... | [
"def",
"import_by_path",
"(",
"dotted_path",
",",
"error_prefix",
"=",
"''",
")",
":",
"warnings",
".",
"warn",
"(",
"'import_by_path() has been deprecated. Use import_string() instead.'",
",",
"RemovedInDjango19Warning",
",",
"stacklevel",
"=",
"2",
")",
"try",
":",
... | [
34,
0
] | [
49,
15
] | python | en | ['en', 'error', 'th'] | False |
autodiscover_modules | (*args, **kwargs) |
Auto-discover INSTALLED_APPS modules and fail silently when
not present. This forces an import on them to register any admin bits they
may want.
You may provide a register_to keyword parameter as a way to access a
registry. This register_to object must have a _registry instance variable
to acc... |
Auto-discover INSTALLED_APPS modules and fail silently when
not present. This forces an import on them to register any admin bits they
may want. | def autodiscover_modules(*args, **kwargs):
"""
Auto-discover INSTALLED_APPS modules and fail silently when
not present. This forces an import on them to register any admin bits they
may want.
You may provide a register_to keyword parameter as a way to access a
registry. This register_to object ... | [
"def",
"autodiscover_modules",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"from",
"django",
".",
"apps",
"import",
"apps",
"register_to",
"=",
"kwargs",
".",
"get",
"(",
"'register_to'",
")",
"for",
"app_config",
"in",
"apps",
".",
"get_app_confi... | [
52,
0
] | [
85,
21
] | python | en | ['en', 'error', 'th'] | False |
Aggregate.__init__ | (self, col, source=None, is_summary=False, **extra) | Instantiate an SQL aggregate
* col is a column reference describing the subject field
of the aggregate. It can be an alias, or a tuple describing
a table and column name.
* source is the underlying field or aggregate definition for
the column reference. If the aggrega... | Instantiate an SQL aggregate | def __init__(self, col, source=None, is_summary=False, **extra):
"""Instantiate an SQL aggregate
* col is a column reference describing the subject field
of the aggregate. It can be an alias, or a tuple describing
a table and column name.
* source is the underlying field... | [
"def",
"__init__",
"(",
"self",
",",
"col",
",",
"source",
"=",
"None",
",",
"is_summary",
"=",
"False",
",",
"*",
"*",
"extra",
")",
":",
"self",
".",
"col",
"=",
"col",
"self",
".",
"source",
"=",
"source",
"self",
".",
"is_summary",
"=",
"is_sum... | [
21,
4
] | [
65,
24
] | python | co | ['en', 'co', 'nl'] | False |
Aggregate.as_sql | (self, qn, connection) | Return the aggregate, rendered as SQL with parameters. | Return the aggregate, rendered as SQL with parameters. | def as_sql(self, qn, connection):
"Return the aggregate, rendered as SQL with parameters."
params = []
if hasattr(self.col, 'as_sql'):
field_name, params = self.col.as_sql(qn, connection)
elif isinstance(self.col, (list, tuple)):
field_name = '.'.join(qn(c) for c... | [
"def",
"as_sql",
"(",
"self",
",",
"qn",
",",
"connection",
")",
":",
"params",
"=",
"[",
"]",
"if",
"hasattr",
"(",
"self",
".",
"col",
",",
"'as_sql'",
")",
":",
"field_name",
",",
"params",
"=",
"self",
".",
"col",
".",
"as_sql",
"(",
"qn",
",... | [
82,
4
] | [
99,
56
] | python | en | ['en', 'en', 'en'] | True |
implicit_namespace_packages | (
directory: str, ignored_dirnames: Optional[List[str]] = None
) | Discovers namespace packages implemented using the 'native namespace packages' method.
AKA 'implicit namespace packages', which has been supported since Python 3.3.
See: https://packaging.python.org/guides/packaging-namespace-packages/#native-namespace-packages
Args:
directory: The root directory ... | Discovers namespace packages implemented using the 'native namespace packages' method. | def implicit_namespace_packages(
directory: str, ignored_dirnames: Optional[List[str]] = None
) -> Set[str]:
"""Discovers namespace packages implemented using the 'native namespace packages' method.
AKA 'implicit namespace packages', which has been supported since Python 3.3.
See: https://packaging.pyt... | [
"def",
"implicit_namespace_packages",
"(",
"directory",
":",
"str",
",",
"ignored_dirnames",
":",
"Optional",
"[",
"List",
"[",
"str",
"]",
"]",
"=",
"None",
")",
"->",
"Set",
"[",
"str",
"]",
":",
"namespace_pkg_dirs",
"=",
"set",
"(",
")",
"for",
"dirp... | [
8,
0
] | [
43,
29
] | python | en | ['en', 'en', 'en'] | True |
add_pkgutil_style_namespace_pkg_init | (dir_path: str) | Adds 'pkgutil-style namespace packages' init file to the given directory
See: https://packaging.python.org/guides/packaging-namespace-packages/#pkgutil-style-namespace-packages
Args:
dir_path: The directory to create an __init__.py for.
Raises:
ValueError: If the directory already contain... | Adds 'pkgutil-style namespace packages' init file to the given directory | def add_pkgutil_style_namespace_pkg_init(dir_path: str) -> None:
"""Adds 'pkgutil-style namespace packages' init file to the given directory
See: https://packaging.python.org/guides/packaging-namespace-packages/#pkgutil-style-namespace-packages
Args:
dir_path: The directory to create an __init__.p... | [
"def",
"add_pkgutil_style_namespace_pkg_init",
"(",
"dir_path",
":",
"str",
")",
"->",
"None",
":",
"ns_pkg_init_filepath",
"=",
"os",
".",
"path",
".",
"join",
"(",
"dir_path",
",",
"\"__init__.py\"",
")",
"if",
"os",
".",
"path",
".",
"isfile",
"(",
"ns_pk... | [
46,
0
] | [
71,
9
] | python | en | ['en', 'en', 'en'] | True |
SettingHelpExtension.extendMarkdown | (self, md: Markdown) | Add SettingHelpExtension to the Markdown instance. | Add SettingHelpExtension to the Markdown instance. | def extendMarkdown(self, md: Markdown) -> None:
""" Add SettingHelpExtension to the Markdown instance. """
md.registerExtension(self)
md.preprocessors.register(Setting(), "setting", 515) | [
"def",
"extendMarkdown",
"(",
"self",
",",
"md",
":",
"Markdown",
")",
"->",
"None",
":",
"md",
".",
"registerExtension",
"(",
"self",
")",
"md",
".",
"preprocessors",
".",
"register",
"(",
"Setting",
"(",
")",
",",
"\"setting\"",
",",
"515",
")"
] | [
92,
4
] | [
95,
60
] | python | en | ['en', 'en', 'en'] | True |
ModifyingSaveData.save | (self, *args, **kwargs) |
A save method that modifies the data in the object.
Verifies that a user-defined save() method isn't called when objects
are deserialized (#4459).
|
A save method that modifies the data in the object.
Verifies that a user-defined save() method isn't called when objects
are deserialized (#4459).
| def save(self, *args, **kwargs):
"""
A save method that modifies the data in the object.
Verifies that a user-defined save() method isn't called when objects
are deserialized (#4459).
"""
self.data = 666
super(ModifyingSaveData, self).save(*args, **kwargs) | [
"def",
"save",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"data",
"=",
"666",
"super",
"(",
"ModifyingSaveData",
",",
"self",
")",
".",
"save",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")"
] | [
303,
4
] | [
310,
60
] | python | en | ['en', 'error', 'th'] | False |
create_adv_by_name | (model, x, attack_type, sess, dataset, y=None, **kwargs) |
Creates the symbolic graph of an adversarial example given the name of
an attack. Simplifies creating the symbolic graph of an attack by defining
dataset-specific parameters.
Dataset-specific default parameters are used unless a different value is
given in kwargs.
:param model: an object of Mo... |
Creates the symbolic graph of an adversarial example given the name of
an attack. Simplifies creating the symbolic graph of an attack by defining
dataset-specific parameters.
Dataset-specific default parameters are used unless a different value is
given in kwargs. | def create_adv_by_name(model, x, attack_type, sess, dataset, y=None, **kwargs):
"""
Creates the symbolic graph of an adversarial example given the name of
an attack. Simplifies creating the symbolic graph of an attack by defining
dataset-specific parameters.
Dataset-specific default parameters are u... | [
"def",
"create_adv_by_name",
"(",
"model",
",",
"x",
",",
"attack_type",
",",
"sess",
",",
"dataset",
",",
"y",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"# TODO: black box attacks",
"attack_names",
"=",
"{",
"\"FGSM\"",
":",
"FastGradientMethod",
",",... | [
15,
0
] | [
76,
16
] | python | en | ['en', 'error', 'th'] | False |
Evaluator.__init__ | (
self, sess, model, batch_size, x_pre, x, y, data, writer, hparams=None
) |
:param sess: Tensorflow session.
:param model: an object of Model class
:param batch_size: batch_size for evaluation.
:param x_pre: placeholder for input before preprocessing.
:param x: symbolic input to model.
:param y: symbolic variable for the label.
:param da... |
:param sess: Tensorflow session.
:param model: an object of Model class
:param batch_size: batch_size for evaluation.
:param x_pre: placeholder for input before preprocessing.
:param x: symbolic input to model.
:param y: symbolic variable for the label.
:param da... | def __init__(
self, sess, model, batch_size, x_pre, x, y, data, writer, hparams=None
):
"""
:param sess: Tensorflow session.
:param model: an object of Model class
:param batch_size: batch_size for evaluation.
:param x_pre: placeholder for input before preprocessing.
... | [
"def",
"__init__",
"(",
"self",
",",
"sess",
",",
"model",
",",
"batch_size",
",",
"x_pre",
",",
"x",
",",
"y",
",",
"data",
",",
"writer",
",",
"hparams",
"=",
"None",
")",
":",
"if",
"hparams",
"is",
"None",
":",
"hparams",
"=",
"{",
"}",
"mode... | [
84,
4
] | [
137,
44
] | python | en | ['en', 'error', 'th'] | False |
Evaluator.log_value | (self, tag, val, desc="") |
Log values to standard output and Tensorflow summary.
:param tag: summary tag.
:param val: (required float or numpy array) value to be logged.
:param desc: (optional) additional description to be printed.
|
Log values to standard output and Tensorflow summary. | def log_value(self, tag, val, desc=""):
"""
Log values to standard output and Tensorflow summary.
:param tag: summary tag.
:param val: (required float or numpy array) value to be logged.
:param desc: (optional) additional description to be printed.
"""
logging.in... | [
"def",
"log_value",
"(",
"self",
",",
"tag",
",",
"val",
",",
"desc",
"=",
"\"\"",
")",
":",
"logging",
".",
"info",
"(",
"\"%s (%s): %.4f\"",
"%",
"(",
"desc",
",",
"tag",
",",
"val",
")",
")",
"self",
".",
"summary",
".",
"value",
".",
"add",
"... | [
139,
4
] | [
148,
57
] | python | en | ['en', 'error', 'th'] | False |
Evaluator.eval_advs | (self, x, y, preds_adv, X_test, Y_test, att_type) |
Evaluate the accuracy of the model on adversarial examples
:param x: symbolic input to model.
:param y: symbolic variable for the label.
:param preds_adv: symbolic variable for the prediction on an
adversarial example.
:param X_test: NumPy array of tes... |
Evaluate the accuracy of the model on adversarial examples | def eval_advs(self, x, y, preds_adv, X_test, Y_test, att_type):
"""
Evaluate the accuracy of the model on adversarial examples
:param x: symbolic input to model.
:param y: symbolic variable for the label.
:param preds_adv: symbolic variable for the prediction on an
... | [
"def",
"eval_advs",
"(",
"self",
",",
"x",
",",
"y",
",",
"preds_adv",
",",
"X_test",
",",
"Y_test",
",",
"att_type",
")",
":",
"end",
"=",
"(",
"len",
"(",
"X_test",
")",
"//",
"self",
".",
"batch_size",
")",
"*",
"self",
".",
"batch_size",
"if",
... | [
150,
4
] | [
179,
18
] | python | en | ['en', 'error', 'th'] | False |
Evaluator.eval_multi | (self, inc_epoch=True) |
Run the evaluation on multiple attacks.
|
Run the evaluation on multiple attacks.
| def eval_multi(self, inc_epoch=True):
"""
Run the evaluation on multiple attacks.
"""
sess = self.sess
preds = self.preds
x = self.x_pre
y = self.y
X_train = self.X_train
Y_train = self.Y_train
X_test = self.X_test
Y_test = self.Y_t... | [
"def",
"eval_multi",
"(",
"self",
",",
"inc_epoch",
"=",
"True",
")",
":",
"sess",
"=",
"self",
".",
"sess",
"preds",
"=",
"self",
".",
"preds",
"x",
"=",
"self",
".",
"x_pre",
"y",
"=",
"self",
".",
"y",
"X_train",
"=",
"self",
".",
"X_train",
"... | [
181,
4
] | [
242,
21
] | python | en | ['en', 'error', 'th'] | False |
GoogleMap.render | (self) |
Generates the JavaScript necessary for displaying this Google Map.
|
Generates the JavaScript necessary for displaying this Google Map.
| def render(self):
"""
Generates the JavaScript necessary for displaying this Google Map.
"""
params = {'calc_zoom': self.calc_zoom,
'center': self.center,
'dom_id': self.dom_id,
'js_module': self.js_module,
'kml_urls... | [
"def",
"render",
"(",
"self",
")",
":",
"params",
"=",
"{",
"'calc_zoom'",
":",
"self",
".",
"calc_zoom",
",",
"'center'",
":",
"self",
".",
"center",
",",
"'dom_id'",
":",
"self",
".",
"dom_id",
",",
"'js_module'",
":",
"self",
".",
"js_module",
",",
... | [
102,
4
] | [
118,
54
] | python | en | ['en', 'error', 'th'] | False |
GoogleMap.body | (self) | Returns HTML body tag for loading and unloading Google Maps javascript. | Returns HTML body tag for loading and unloading Google Maps javascript. | def body(self):
"Returns HTML body tag for loading and unloading Google Maps javascript."
return format_html('<body {0} {1}>', self.onload, self.onunload) | [
"def",
"body",
"(",
"self",
")",
":",
"return",
"format_html",
"(",
"'<body {0} {1}>'",
",",
"self",
".",
"onload",
",",
"self",
".",
"onunload",
")"
] | [
121,
4
] | [
123,
72
] | python | en | ['en', 'en', 'en'] | True |
GoogleMap.onload | (self) | Returns the `onload` HTML <body> attribute. | Returns the `onload` HTML <body> attribute. | def onload(self):
"Returns the `onload` HTML <body> attribute."
return format_html('onload="{0}.{1}_load()"', self.js_module, self.dom_id) | [
"def",
"onload",
"(",
"self",
")",
":",
"return",
"format_html",
"(",
"'onload=\"{0}.{1}_load()\"'",
",",
"self",
".",
"js_module",
",",
"self",
".",
"dom_id",
")"
] | [
126,
4
] | [
128,
82
] | python | en | ['en', 'en', 'en'] | True |
GoogleMap.api_script | (self) | Returns the <script> tag for the Google Maps API javascript. | Returns the <script> tag for the Google Maps API javascript. | def api_script(self):
"Returns the <script> tag for the Google Maps API javascript."
return format_html('<script src="{0}{1}" type="text/javascript"></script>',
self.api_url, self.key) | [
"def",
"api_script",
"(",
"self",
")",
":",
"return",
"format_html",
"(",
"'<script src=\"{0}{1}\" type=\"text/javascript\"></script>'",
",",
"self",
".",
"api_url",
",",
"self",
".",
"key",
")"
] | [
131,
4
] | [
134,
50
] | python | en | ['en', 'sq', 'en'] | True |
GoogleMap.js | (self) | Returns only the generated Google Maps JavaScript (no <script> tags). | Returns only the generated Google Maps JavaScript (no <script> tags). | def js(self):
"Returns only the generated Google Maps JavaScript (no <script> tags)."
return self.render() | [
"def",
"js",
"(",
"self",
")",
":",
"return",
"self",
".",
"render",
"(",
")"
] | [
137,
4
] | [
139,
28
] | python | en | ['en', 'en', 'en'] | True |
GoogleMap.scripts | (self) | Returns all <script></script> tags required with Google Maps JavaScript. | Returns all <script></script> tags required with Google Maps JavaScript. | def scripts(self):
"Returns all <script></script> tags required with Google Maps JavaScript."
return format_html('{0}\n <script type="text/javascript">\n//<![CDATA[\n{1}//]]>\n </script>',
self.api_script, mark_safe(self.js)) | [
"def",
"scripts",
"(",
"self",
")",
":",
"return",
"format_html",
"(",
"'{0}\\n <script type=\"text/javascript\">\\n//<![CDATA[\\n{1}//]]>\\n </script>'",
",",
"self",
".",
"api_script",
",",
"mark_safe",
"(",
"self",
".",
"js",
")",
")"
] | [
142,
4
] | [
145,
63
] | python | en | ['en', 'en', 'en'] | True |
GoogleMap.style | (self) | Returns additional CSS styling needed for Google Maps on IE. | Returns additional CSS styling needed for Google Maps on IE. | def style(self):
"Returns additional CSS styling needed for Google Maps on IE."
return format_html('<style type="text/css">{0}</style>', self.vml_css) | [
"def",
"style",
"(",
"self",
")",
":",
"return",
"format_html",
"(",
"'<style type=\"text/css\">{0}</style>'",
",",
"self",
".",
"vml_css",
")"
] | [
148,
4
] | [
150,
78
] | python | en | ['en', 'en', 'en'] | True |
GoogleMap.xhtml | (self) | Returns XHTML information needed for IE VML overlays. | Returns XHTML information needed for IE VML overlays. | def xhtml(self):
"Returns XHTML information needed for IE VML overlays."
return format_html('<html xmlns="http://www.w3.org/1999/xhtml" {0}>', self.xmlns) | [
"def",
"xhtml",
"(",
"self",
")",
":",
"return",
"format_html",
"(",
"'<html xmlns=\"http://www.w3.org/1999/xhtml\" {0}>'",
",",
"self",
".",
"xmlns",
")"
] | [
153,
4
] | [
155,
89
] | python | en | ['en', 'en', 'en'] | True |
GoogleMap.icons | (self) | Returns a sequence of GIcon objects in this map. | Returns a sequence of GIcon objects in this map. | def icons(self):
"Returns a sequence of GIcon objects in this map."
return set(marker.icon for marker in self.markers if marker.icon) | [
"def",
"icons",
"(",
"self",
")",
":",
"return",
"set",
"(",
"marker",
".",
"icon",
"for",
"marker",
"in",
"self",
".",
"markers",
"if",
"marker",
".",
"icon",
")"
] | [
158,
4
] | [
160,
73
] | python | en | ['en', 'en', 'en'] | True |
GoogleMapSet.__init__ | (self, *args, **kwargs) |
A class for generating sets of Google Maps that will be shown on the
same page together.
Example:
gmapset = GoogleMapSet( GoogleMap( ... ), GoogleMap( ... ) )
gmapset = GoogleMapSet( [ gmap1, gmap2] )
|
A class for generating sets of Google Maps that will be shown on the
same page together. | def __init__(self, *args, **kwargs):
"""
A class for generating sets of Google Maps that will be shown on the
same page together.
Example:
gmapset = GoogleMapSet( GoogleMap( ... ), GoogleMap( ... ) )
gmapset = GoogleMapSet( [ gmap1, gmap2] )
"""
# The `... | [
"def",
"__init__",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"# The `google-multi.js` template is used instead of `google-single.js`",
"# by default.",
"template",
"=",
"kwargs",
".",
"pop",
"(",
"'template'",
",",
"'gis/google/google-multi.js'",... | [
165,
4
] | [
194,
68
] | python | en | ['en', 'error', 'th'] | False |
GoogleMapSet.load_map_js | (self) |
Returns JavaScript containing all of the loading routines for each
map in this set.
|
Returns JavaScript containing all of the loading routines for each
map in this set.
| def load_map_js(self):
"""
Returns JavaScript containing all of the loading routines for each
map in this set.
"""
result = []
for dom_id, gmap in zip(self.dom_ids, self.maps):
# Backup copies the GoogleMap DOM id and template attributes.
# They ar... | [
"def",
"load_map_js",
"(",
"self",
")",
":",
"result",
"=",
"[",
"]",
"for",
"dom_id",
",",
"gmap",
"in",
"zip",
"(",
"self",
".",
"dom_ids",
",",
"self",
".",
"maps",
")",
":",
"# Backup copies the GoogleMap DOM id and template attributes.",
"# They are overrid... | [
196,
4
] | [
213,
41
] | python | en | ['en', 'error', 'th'] | False |
GoogleMapSet.render | (self) |
Generates the JavaScript for the collection of Google Maps in
this set.
|
Generates the JavaScript for the collection of Google Maps in
this set.
| def render(self):
"""
Generates the JavaScript for the collection of Google Maps in
this set.
"""
params = {'js_module': self.js_module,
'dom_ids': self.dom_ids,
'load_map_js': self.load_map_js(),
'icons': self.icons,
... | [
"def",
"render",
"(",
"self",
")",
":",
"params",
"=",
"{",
"'js_module'",
":",
"self",
".",
"js_module",
",",
"'dom_ids'",
":",
"self",
".",
"dom_ids",
",",
"'load_map_js'",
":",
"self",
".",
"load_map_js",
"(",
")",
",",
"'icons'",
":",
"self",
".",
... | [
215,
4
] | [
226,
54
] | python | en | ['en', 'error', 'th'] | False |
GoogleMapSet.onload | (self) | Returns the `onload` HTML <body> attribute. | Returns the `onload` HTML <body> attribute. | def onload(self):
"Returns the `onload` HTML <body> attribute."
# Overloaded to use the `load` function defined in the
# `google-multi.js`, which calls the load routines for
# each one of the individual maps in the set.
return mark_safe('onload="%s.load()"' % self.js_module) | [
"def",
"onload",
"(",
"self",
")",
":",
"# Overloaded to use the `load` function defined in the",
"# `google-multi.js`, which calls the load routines for",
"# each one of the individual maps in the set.",
"return",
"mark_safe",
"(",
"'onload=\"%s.load()\"'",
"%",
"self",
".",
"js_mod... | [
229,
4
] | [
234,
63
] | python | en | ['en', 'en', 'en'] | True |
GoogleMapSet.icons | (self) | Returns a sequence of all icons in each map of the set. | Returns a sequence of all icons in each map of the set. | def icons(self):
"Returns a sequence of all icons in each map of the set."
icons = set()
for map in self.maps:
icons |= map.icons
return icons | [
"def",
"icons",
"(",
"self",
")",
":",
"icons",
"=",
"set",
"(",
")",
"for",
"map",
"in",
"self",
".",
"maps",
":",
"icons",
"|=",
"map",
".",
"icons",
"return",
"icons"
] | [
237,
4
] | [
242,
20
] | python | en | ['en', 'en', 'en'] | True |
OrderableAggMixin._get_ordering_expressions_index | (self) | Return the index at which the ordering expressions start. | Return the index at which the ordering expressions start. | def _get_ordering_expressions_index(self):
"""Return the index at which the ordering expressions start."""
source_expressions = self.get_source_expressions()
return len(source_expressions) - len(self.ordering) | [
"def",
"_get_ordering_expressions_index",
"(",
"self",
")",
":",
"source_expressions",
"=",
"self",
".",
"get_source_expressions",
"(",
")",
"return",
"len",
"(",
"source_expressions",
")",
"-",
"len",
"(",
"self",
".",
"ordering",
")"
] | [
44,
4
] | [
47,
59
] | python | en | ['en', 'en', 'en'] | True |
report_error | (
request: HttpRequest,
user_profile: UserProfile,
message: str = REQ(),
stacktrace: str = REQ(),
ui_message: bool = REQ(json_validator=check_bool),
user_agent: str = REQ(),
href: str = REQ(),
log: str = REQ(),
more_info: Mapping[str, Any] = REQ(json_validator=check_dict([]), default... | Accepts an error report and stores in a queue for processing. The
actual error reports are later handled by do_report_error | Accepts an error report and stores in a queue for processing. The
actual error reports are later handled by do_report_error | def report_error(
request: HttpRequest,
user_profile: UserProfile,
message: str = REQ(),
stacktrace: str = REQ(),
ui_message: bool = REQ(json_validator=check_bool),
user_agent: str = REQ(),
href: str = REQ(),
log: str = REQ(),
more_info: Mapping[str, Any] = REQ(json_validator=check_d... | [
"def",
"report_error",
"(",
"request",
":",
"HttpRequest",
",",
"user_profile",
":",
"UserProfile",
",",
"message",
":",
"str",
"=",
"REQ",
"(",
")",
",",
"stacktrace",
":",
"str",
"=",
"REQ",
"(",
")",
",",
"ui_message",
":",
"bool",
"=",
"REQ",
"(",
... | [
106,
0
] | [
173,
25
] | python | en | ['en', 'en', 'en'] | True |
Timestamp.__init__ | (self, seconds, nanoseconds=0) | Initialize a Timestamp object.
:param int seconds:
Number of seconds since the UNIX epoch (00:00:00 UTC Jan 1 1970, minus leap seconds).
May be negative.
:param int nanoseconds:
Number of nanoseconds to add to `seconds` to get fractional time.
Maximum is... | Initialize a Timestamp object. | def __init__(self, seconds, nanoseconds=0):
"""Initialize a Timestamp object.
:param int seconds:
Number of seconds since the UNIX epoch (00:00:00 UTC Jan 1 1970, minus leap seconds).
May be negative.
:param int nanoseconds:
Number of nanoseconds to add to `... | [
"def",
"__init__",
"(",
"self",
",",
"seconds",
",",
"nanoseconds",
"=",
"0",
")",
":",
"if",
"not",
"isinstance",
"(",
"seconds",
",",
"int_types",
")",
":",
"raise",
"TypeError",
"(",
"\"seconds must be an interger\"",
")",
"if",
"not",
"isinstance",
"(",
... | [
44,
4
] | [
66,
38
] | python | en | ['en', 'en', 'en'] | True |
Timestamp.__repr__ | (self) | String representation of Timestamp. | String representation of Timestamp. | def __repr__(self):
"""String representation of Timestamp."""
return "Timestamp(seconds={0}, nanoseconds={1})".format(
self.seconds, self.nanoseconds
) | [
"def",
"__repr__",
"(",
"self",
")",
":",
"return",
"\"Timestamp(seconds={0}, nanoseconds={1})\"",
".",
"format",
"(",
"self",
".",
"seconds",
",",
"self",
".",
"nanoseconds",
")"
] | [
68,
4
] | [
72,
9
] | python | en | ['en', 'kk', 'en'] | True |
Timestamp.__eq__ | (self, other) | Check for equality with another Timestamp object | Check for equality with another Timestamp object | def __eq__(self, other):
"""Check for equality with another Timestamp object"""
if type(other) is self.__class__:
return (
self.seconds == other.seconds and self.nanoseconds == other.nanoseconds
)
return False | [
"def",
"__eq__",
"(",
"self",
",",
"other",
")",
":",
"if",
"type",
"(",
"other",
")",
"is",
"self",
".",
"__class__",
":",
"return",
"(",
"self",
".",
"seconds",
"==",
"other",
".",
"seconds",
"and",
"self",
".",
"nanoseconds",
"==",
"other",
".",
... | [
74,
4
] | [
80,
20
] | python | en | ['en', 'en', 'en'] | True |
Timestamp.__ne__ | (self, other) | not-equals method (see :func:`__eq__()`) | not-equals method (see :func:`__eq__()`) | def __ne__(self, other):
"""not-equals method (see :func:`__eq__()`)"""
return not self.__eq__(other) | [
"def",
"__ne__",
"(",
"self",
",",
"other",
")",
":",
"return",
"not",
"self",
".",
"__eq__",
"(",
"other",
")"
] | [
82,
4
] | [
84,
37
] | python | en | ['en', 'en', 'en'] | True |
Timestamp.from_bytes | (b) | Unpack bytes into a `Timestamp` object.
Used for pure-Python msgpack unpacking.
:param b: Payload from msgpack ext message with code -1
:type b: bytes
:returns: Timestamp object unpacked from msgpack ext payload
:rtype: Timestamp
| Unpack bytes into a `Timestamp` object. | def from_bytes(b):
"""Unpack bytes into a `Timestamp` object.
Used for pure-Python msgpack unpacking.
:param b: Payload from msgpack ext message with code -1
:type b: bytes
:returns: Timestamp object unpacked from msgpack ext payload
:rtype: Timestamp
"""
... | [
"def",
"from_bytes",
"(",
"b",
")",
":",
"if",
"len",
"(",
"b",
")",
"==",
"4",
":",
"seconds",
"=",
"struct",
".",
"unpack",
"(",
"\"!L\"",
",",
"b",
")",
"[",
"0",
"]",
"nanoseconds",
"=",
"0",
"elif",
"len",
"(",
"b",
")",
"==",
"8",
":",
... | [
90,
4
] | [
114,
46
] | python | en | ['pt', 'en', 'en'] | True |
Timestamp.to_bytes | (self) | Pack this Timestamp object into bytes.
Used for pure-Python msgpack packing.
:returns data: Payload for EXT message with code -1 (timestamp type)
:rtype: bytes
| Pack this Timestamp object into bytes. | def to_bytes(self):
"""Pack this Timestamp object into bytes.
Used for pure-Python msgpack packing.
:returns data: Payload for EXT message with code -1 (timestamp type)
:rtype: bytes
"""
if (self.seconds >> 34) == 0: # seconds is non-negative and fits in 34 bits
... | [
"def",
"to_bytes",
"(",
"self",
")",
":",
"if",
"(",
"self",
".",
"seconds",
">>",
"34",
")",
"==",
"0",
":",
"# seconds is non-negative and fits in 34 bits",
"data64",
"=",
"self",
".",
"nanoseconds",
"<<",
"34",
"|",
"self",
".",
"seconds",
"if",
"data64... | [
116,
4
] | [
135,
19
] | python | en | ['en', 'en', 'en'] | True |
Timestamp.from_unix | (unix_sec) | Create a Timestamp from posix timestamp in seconds.
:param unix_float: Posix timestamp in seconds.
:type unix_float: int or float.
| Create a Timestamp from posix timestamp in seconds. | def from_unix(unix_sec):
"""Create a Timestamp from posix timestamp in seconds.
:param unix_float: Posix timestamp in seconds.
:type unix_float: int or float.
"""
seconds = int(unix_sec // 1)
nanoseconds = int((unix_sec % 1) * 10 ** 9)
return Timestamp(seconds, n... | [
"def",
"from_unix",
"(",
"unix_sec",
")",
":",
"seconds",
"=",
"int",
"(",
"unix_sec",
"//",
"1",
")",
"nanoseconds",
"=",
"int",
"(",
"(",
"unix_sec",
"%",
"1",
")",
"*",
"10",
"**",
"9",
")",
"return",
"Timestamp",
"(",
"seconds",
",",
"nanoseconds... | [
138,
4
] | [
146,
46
] | python | en | ['en', 'en', 'en'] | True |
Timestamp.to_unix | (self) | Get the timestamp as a floating-point value.
:returns: posix timestamp
:rtype: float
| Get the timestamp as a floating-point value. | def to_unix(self):
"""Get the timestamp as a floating-point value.
:returns: posix timestamp
:rtype: float
"""
return self.seconds + self.nanoseconds / 1e9 | [
"def",
"to_unix",
"(",
"self",
")",
":",
"return",
"self",
".",
"seconds",
"+",
"self",
".",
"nanoseconds",
"/",
"1e9"
] | [
148,
4
] | [
154,
52
] | python | en | ['en', 'en', 'en'] | True |
Timestamp.from_unix_nano | (unix_ns) | Create a Timestamp from posix timestamp in nanoseconds.
:param int unix_ns: Posix timestamp in nanoseconds.
:rtype: Timestamp
| Create a Timestamp from posix timestamp in nanoseconds. | def from_unix_nano(unix_ns):
"""Create a Timestamp from posix timestamp in nanoseconds.
:param int unix_ns: Posix timestamp in nanoseconds.
:rtype: Timestamp
"""
return Timestamp(*divmod(unix_ns, 10 ** 9)) | [
"def",
"from_unix_nano",
"(",
"unix_ns",
")",
":",
"return",
"Timestamp",
"(",
"*",
"divmod",
"(",
"unix_ns",
",",
"10",
"**",
"9",
")",
")"
] | [
157,
4
] | [
163,
51
] | python | en | ['en', 'en', 'en'] | True |
Timestamp.to_unix_nano | (self) | Get the timestamp as a unixtime in nanoseconds.
:returns: posix timestamp in nanoseconds
:rtype: int
| Get the timestamp as a unixtime in nanoseconds. | def to_unix_nano(self):
"""Get the timestamp as a unixtime in nanoseconds.
:returns: posix timestamp in nanoseconds
:rtype: int
"""
return self.seconds * 10 ** 9 + self.nanoseconds | [
"def",
"to_unix_nano",
"(",
"self",
")",
":",
"return",
"self",
".",
"seconds",
"*",
"10",
"**",
"9",
"+",
"self",
".",
"nanoseconds"
] | [
165,
4
] | [
171,
56
] | python | en | ['en', 'en', 'en'] | True |
Timestamp.to_datetime | (self) | Get the timestamp as a UTC datetime.
Python 2 is not supported.
:rtype: datetime.
| Get the timestamp as a UTC datetime. | def to_datetime(self):
"""Get the timestamp as a UTC datetime.
Python 2 is not supported.
:rtype: datetime.
"""
return datetime.datetime.fromtimestamp(self.to_unix(), _utc) | [
"def",
"to_datetime",
"(",
"self",
")",
":",
"return",
"datetime",
".",
"datetime",
".",
"fromtimestamp",
"(",
"self",
".",
"to_unix",
"(",
")",
",",
"_utc",
")"
] | [
173,
4
] | [
180,
68
] | python | en | ['en', 'en', 'en'] | True |
Timestamp.from_datetime | (dt) | Create a Timestamp from datetime with tzinfo.
Python 2 is not supported.
:rtype: Timestamp
| Create a Timestamp from datetime with tzinfo. | def from_datetime(dt):
"""Create a Timestamp from datetime with tzinfo.
Python 2 is not supported.
:rtype: Timestamp
"""
return Timestamp.from_unix(dt.timestamp()) | [
"def",
"from_datetime",
"(",
"dt",
")",
":",
"return",
"Timestamp",
".",
"from_unix",
"(",
"dt",
".",
"timestamp",
"(",
")",
")"
] | [
183,
4
] | [
190,
50
] | python | en | ['en', 'en', 'en'] | True |
EmoticonTranslationsHelpExtension.extendMarkdown | (self, md: Markdown) | Add SettingHelpExtension to the Markdown instance. | Add SettingHelpExtension to the Markdown instance. | def extendMarkdown(self, md: Markdown) -> None:
""" Add SettingHelpExtension to the Markdown instance. """
md.registerExtension(self)
md.preprocessors.register(EmoticonTranslation(), "emoticon_translations", -505) | [
"def",
"extendMarkdown",
"(",
"self",
",",
"md",
":",
"Markdown",
")",
"->",
"None",
":",
"md",
".",
"registerExtension",
"(",
"self",
")",
"md",
".",
"preprocessors",
".",
"register",
"(",
"EmoticonTranslation",
"(",
")",
",",
"\"emoticon_translations\"",
"... | [
39,
4
] | [
42,
87
] | python | en | ['en', 'en', 'en'] | True |
set_seed | (method) |
Set seed and number of repetitions. Both depend on the type of the data set. For example a different seed is used
for test and training set
:param method: type of the data set [string]
:return: number of [int]
|
Set seed and number of repetitions. Both depend on the type of the data set. For example a different seed is used
for test and training set
:param method: type of the data set [string]
:return: number of [int]
| def set_seed(method):
"""
Set seed and number of repetitions. Both depend on the type of the data set. For example a different seed is used
for test and training set
:param method: type of the data set [string]
:return: number of [int]
"""
if method.endswith("val"):
np.random.seed(0)... | [
"def",
"set_seed",
"(",
"method",
")",
":",
"if",
"method",
".",
"endswith",
"(",
"\"val\"",
")",
":",
"np",
".",
"random",
".",
"seed",
"(",
"0",
")",
"num_elem",
"=",
"1400",
"elif",
"method",
".",
"endswith",
"(",
"\"test\"",
")",
":",
"np",
"."... | [
29,
0
] | [
45,
19
] | python | en | ['en', 'error', 'th'] | False |
getbg_otf | (image, contrast="random") |
This function can be used to add a background image for training data on-the-fly
:param image: input image
:param contrast: either 0 or "random"
:return: output image
|
This function can be used to add a background image for training data on-the-fly
:param image: input image
:param contrast: either 0 or "random"
:return: output image
| def getbg_otf(image, contrast="random"):
"""
This function can be used to add a background image for training data on-the-fly
:param image: input image
:param contrast: either 0 or "random"
:return: output image
"""
if contrast == "random":
# be careful: slow! if you want to use rand... | [
"def",
"getbg_otf",
"(",
"image",
",",
"contrast",
"=",
"\"random\"",
")",
":",
"if",
"contrast",
"==",
"\"random\"",
":",
"# be careful: slow! if you want to use random change this:",
"# load imagenet in the main script and give the image to the function",
"imagenet_data",
"=",
... | [
48,
0
] | [
97,
14
] | python | en | ['en', 'error', 'th'] | False |
make_full_dataset | (top_dir, set_num, debug, all_contrast_levels, imagenet_data) |
generate and save the full data set for a specified variation
:param top_dir: where to save the images [string]
:param set_num: number that specifies the variation [int]
:param debug: generate only seven images [bool]
:param all_contrast_levels: do all contrast levels? [bool]
:param imagenet_da... |
generate and save the full data set for a specified variation
:param top_dir: where to save the images [string]
:param set_num: number that specifies the variation [int]
:param debug: generate only seven images [bool]
:param all_contrast_levels: do all contrast levels? [bool]
:param imagenet_da... | def make_full_dataset(top_dir, set_num, debug, all_contrast_levels, imagenet_data):
"""
generate and save the full data set for a specified variation
:param top_dir: where to save the images [string]
:param set_num: number that specifies the variation [int]
:param debug: generate only seven images [... | [
"def",
"make_full_dataset",
"(",
"top_dir",
",",
"set_num",
",",
"debug",
",",
"all_contrast_levels",
",",
"imagenet_data",
")",
":",
"stim_folder",
"=",
"top_dir",
"+",
"\"/set\"",
"+",
"str",
"(",
"set_num",
")",
"+",
"\"/\"",
"if",
"set_num",
"==",
"4",
... | [
100,
0
] | [
327,
82
] | python | en | ['en', 'error', 'th'] | False |
get_level_tags | () |
Returns the message level tags.
|
Returns the message level tags.
| def get_level_tags():
"""
Returns the message level tags.
"""
level_tags = constants.DEFAULT_TAGS.copy()
level_tags.update(getattr(settings, 'MESSAGE_TAGS', {}))
return level_tags | [
"def",
"get_level_tags",
"(",
")",
":",
"level_tags",
"=",
"constants",
".",
"DEFAULT_TAGS",
".",
"copy",
"(",
")",
"level_tags",
".",
"update",
"(",
"getattr",
"(",
"settings",
",",
"'MESSAGE_TAGS'",
",",
"{",
"}",
")",
")",
"return",
"level_tags"
] | [
4,
0
] | [
10,
21
] | python | en | ['en', 'error', 'th'] | False |
SQLCommandsTestCase.test_sql_create_check | (self) | Regression test for #23416 -- Check that db_params['check'] is respected. | Regression test for #23416 -- Check that db_params['check'] is respected. | def test_sql_create_check(self):
"""Regression test for #23416 -- Check that db_params['check'] is respected."""
app_config = apps.get_app_config('commands_sql')
output = sql_create(app_config, no_style(), connections[DEFAULT_DB_ALIAS])
success = False
for statement in output:
... | [
"def",
"test_sql_create_check",
"(",
"self",
")",
":",
"app_config",
"=",
"apps",
".",
"get_app_config",
"(",
"'commands_sql'",
")",
"output",
"=",
"sql_create",
"(",
"app_config",
",",
"no_style",
"(",
")",
",",
"connections",
"[",
"DEFAULT_DB_ALIAS",
"]",
")... | [
47,
4
] | [
56,
63
] | python | en | ['en', 'en', 'en'] | True |
TestRunnerMultiGPU.help_test_runner | (self, ninputs, niter) |
Tests the MultiGPU runner by feeding in random Tensors for `ninputs`
steps. Then validating the output after `niter-1` steps.
|
Tests the MultiGPU runner by feeding in random Tensors for `ninputs`
steps. Then validating the output after `niter-1` steps.
| def help_test_runner(self, ninputs, niter):
"""
Tests the MultiGPU runner by feeding in random Tensors for `ninputs`
steps. Then validating the output after `niter-1` steps.
"""
v_val = []
w_val = []
for i in range(ninputs):
v_val += [np.random.rand(10... | [
"def",
"help_test_runner",
"(",
"self",
",",
"ninputs",
",",
"niter",
")",
":",
"v_val",
"=",
"[",
"]",
"w_val",
"=",
"[",
"]",
"for",
"i",
"in",
"range",
"(",
"ninputs",
")",
":",
"v_val",
"+=",
"[",
"np",
".",
"random",
".",
"rand",
"(",
"100",... | [
35,
4
] | [
62,
50
] | python | en | ['en', 'error', 'th'] | False |
topology | (func, *args, **kwargs) | For GEOS unary topology functions. | For GEOS unary topology functions. | def topology(func, *args, **kwargs):
"For GEOS unary topology functions."
argtypes = [GEOM_PTR]
if args:
argtypes += args
func.argtypes = argtypes
func.restype = kwargs.get('restype', GEOM_PTR)
func.errcheck = kwargs.get('errcheck', check_geom)
return func | [
"def",
"topology",
"(",
"func",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"argtypes",
"=",
"[",
"GEOM_PTR",
"]",
"if",
"args",
":",
"argtypes",
"+=",
"args",
"func",
".",
"argtypes",
"=",
"argtypes",
"func",
".",
"restype",
"=",
"kwargs",
... | [
19,
0
] | [
27,
15
] | python | en | ['en', 'en', 'en'] | True |
AppConfig._path_from_module | (self, module) | Attempt to determine app's filesystem path from its module. | Attempt to determine app's filesystem path from its module. | def _path_from_module(self, module):
"""Attempt to determine app's filesystem path from its module."""
# See #21874 for extended discussion of the behavior of this method in
# various cases.
# Convert paths to list because Python 3.3 _NamespacePath does not
# support indexing.
... | [
"def",
"_path_from_module",
"(",
"self",
",",
"module",
")",
":",
"# See #21874 for extended discussion of the behavior of this method in",
"# various cases.",
"# Convert paths to list because Python 3.3 _NamespacePath does not",
"# support indexing.",
"paths",
"=",
"list",
"(",
"get... | [
54,
4
] | [
75,
30
] | python | en | ['en', 'en', 'en'] | True |
AppConfig.create | (cls, entry) |
Factory that creates an app config from an entry in INSTALLED_APPS.
|
Factory that creates an app config from an entry in INSTALLED_APPS.
| def create(cls, entry):
"""
Factory that creates an app config from an entry in INSTALLED_APPS.
"""
try:
# If import_module succeeds, entry is a path to an app module,
# which may specify an app config class with default_app_config.
# Otherwise, entry ... | [
"def",
"create",
"(",
"cls",
",",
"entry",
")",
":",
"try",
":",
"# If import_module succeeds, entry is a path to an app module,",
"# which may specify an app config class with default_app_config.",
"# Otherwise, entry is a path to an app config class or an error.",
"module",
"=",
"imp... | [
78,
4
] | [
144,
40
] | python | en | ['en', 'error', 'th'] | False |
AppConfig.check_models_ready | (self) |
Raises an exception if models haven't been imported yet.
|
Raises an exception if models haven't been imported yet.
| def check_models_ready(self):
"""
Raises an exception if models haven't been imported yet.
"""
if self.models is None:
raise AppRegistryNotReady(
"Models for app '%s' haven't been imported yet." % self.label) | [
"def",
"check_models_ready",
"(",
"self",
")",
":",
"if",
"self",
".",
"models",
"is",
"None",
":",
"raise",
"AppRegistryNotReady",
"(",
"\"Models for app '%s' haven't been imported yet.\"",
"%",
"self",
".",
"label",
")"
] | [
146,
4
] | [
152,
78
] | python | en | ['en', 'error', 'th'] | False |
AppConfig.get_model | (self, model_name) |
Returns the model with the given case-insensitive model_name.
Raises LookupError if no model exists with this name.
|
Returns the model with the given case-insensitive model_name. | def get_model(self, model_name):
"""
Returns the model with the given case-insensitive model_name.
Raises LookupError if no model exists with this name.
"""
self.check_models_ready()
try:
return self.models[model_name.lower()]
except KeyError:
... | [
"def",
"get_model",
"(",
"self",
",",
"model_name",
")",
":",
"self",
".",
"check_models_ready",
"(",
")",
"try",
":",
"return",
"self",
".",
"models",
"[",
"model_name",
".",
"lower",
"(",
")",
"]",
"except",
"KeyError",
":",
"raise",
"LookupError",
"("... | [
154,
4
] | [
165,
81
] | python | en | ['en', 'error', 'th'] | False |
AppConfig.get_models | (self, include_auto_created=False,
include_deferred=False, include_swapped=False) |
Returns an iterable of models.
By default, the following models aren't included:
- auto-created models for many-to-many relations without
an explicit intermediate table,
- models created to satisfy deferred attribute queries,
- models that have been swapped out.
... |
Returns an iterable of models. | def get_models(self, include_auto_created=False,
include_deferred=False, include_swapped=False):
"""
Returns an iterable of models.
By default, the following models aren't included:
- auto-created models for many-to-many relations without
an explicit interm... | [
"def",
"get_models",
"(",
"self",
",",
"include_auto_created",
"=",
"False",
",",
"include_deferred",
"=",
"False",
",",
"include_swapped",
"=",
"False",
")",
":",
"self",
".",
"check_models_ready",
"(",
")",
"for",
"model",
"in",
"self",
".",
"models",
".",... | [
167,
4
] | [
190,
23
] | python | en | ['en', 'error', 'th'] | False |
AppConfig.ready | (self) |
Override this method in subclasses to run code when Django starts.
|
Override this method in subclasses to run code when Django starts.
| def ready(self):
"""
Override this method in subclasses to run code when Django starts.
""" | [
"def",
"ready",
"(",
"self",
")",
":"
] | [
203,
4
] | [
206,
11
] | python | en | ['en', 'error', 'th'] | False |
check_setting_language_code | (app_configs, **kwargs) | Error if LANGUAGE_CODE setting is invalid. | Error if LANGUAGE_CODE setting is invalid. | def check_setting_language_code(app_configs, **kwargs):
"""Error if LANGUAGE_CODE setting is invalid."""
tag = settings.LANGUAGE_CODE
if not isinstance(tag, str) or not language_code_re.match(tag):
return [Error(E001.msg.format(tag), id=E001.id)]
return [] | [
"def",
"check_setting_language_code",
"(",
"app_configs",
",",
"*",
"*",
"kwargs",
")",
":",
"tag",
"=",
"settings",
".",
"LANGUAGE_CODE",
"if",
"not",
"isinstance",
"(",
"tag",
",",
"str",
")",
"or",
"not",
"language_code_re",
".",
"match",
"(",
"tag",
")... | [
29,
0
] | [
34,
13
] | python | en | ['en', 'ja', 'en'] | True |
check_setting_languages | (app_configs, **kwargs) | Error if LANGUAGES setting is invalid. | Error if LANGUAGES setting is invalid. | def check_setting_languages(app_configs, **kwargs):
"""Error if LANGUAGES setting is invalid."""
return [
Error(E002.msg.format(tag), id=E002.id)
for tag, _ in settings.LANGUAGES if not isinstance(tag, str) or not language_code_re.match(tag)
] | [
"def",
"check_setting_languages",
"(",
"app_configs",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"[",
"Error",
"(",
"E002",
".",
"msg",
".",
"format",
"(",
"tag",
")",
",",
"id",
"=",
"E002",
".",
"id",
")",
"for",
"tag",
",",
"_",
"in",
"setting... | [
38,
0
] | [
43,
5
] | python | en | ['en', 'en', 'en'] | True |
check_setting_languages_bidi | (app_configs, **kwargs) | Error if LANGUAGES_BIDI setting is invalid. | Error if LANGUAGES_BIDI setting is invalid. | def check_setting_languages_bidi(app_configs, **kwargs):
"""Error if LANGUAGES_BIDI setting is invalid."""
return [
Error(E003.msg.format(tag), id=E003.id)
for tag in settings.LANGUAGES_BIDI if not isinstance(tag, str) or not language_code_re.match(tag)
] | [
"def",
"check_setting_languages_bidi",
"(",
"app_configs",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"[",
"Error",
"(",
"E003",
".",
"msg",
".",
"format",
"(",
"tag",
")",
",",
"id",
"=",
"E003",
".",
"id",
")",
"for",
"tag",
"in",
"settings",
"."... | [
47,
0
] | [
52,
5
] | python | en | ['en', 'et', 'en'] | True |
check_language_settings_consistent | (app_configs, **kwargs) | Error if language settings are not consistent with each other. | Error if language settings are not consistent with each other. | def check_language_settings_consistent(app_configs, **kwargs):
"""Error if language settings are not consistent with each other."""
try:
get_supported_language_variant(settings.LANGUAGE_CODE)
except LookupError:
return [E004]
else:
return [] | [
"def",
"check_language_settings_consistent",
"(",
"app_configs",
",",
"*",
"*",
"kwargs",
")",
":",
"try",
":",
"get_supported_language_variant",
"(",
"settings",
".",
"LANGUAGE_CODE",
")",
"except",
"LookupError",
":",
"return",
"[",
"E004",
"]",
"else",
":",
"... | [
56,
0
] | [
63,
17
] | python | en | ['en', 'en', 'en'] | True |
validate_password | (password, user=None, password_validators=None) |
Validate whether the password meets all validator requirements.
If the password is valid, return ``None``.
If the password is invalid, raise ValidationError with all error messages.
|
Validate whether the password meets all validator requirements. | def validate_password(password, user=None, password_validators=None):
"""
Validate whether the password meets all validator requirements.
If the password is valid, return ``None``.
If the password is invalid, raise ValidationError with all error messages.
"""
errors = []
if password_validat... | [
"def",
"validate_password",
"(",
"password",
",",
"user",
"=",
"None",
",",
"password_validators",
"=",
"None",
")",
":",
"errors",
"=",
"[",
"]",
"if",
"password_validators",
"is",
"None",
":",
"password_validators",
"=",
"get_default_password_validators",
"(",
... | [
34,
0
] | [
50,
37
] | python | en | ['en', 'error', 'th'] | False |
password_changed | (password, user=None, password_validators=None) |
Inform all validators that have implemented a password_changed() method
that the password has been changed.
|
Inform all validators that have implemented a password_changed() method
that the password has been changed.
| def password_changed(password, user=None, password_validators=None):
"""
Inform all validators that have implemented a password_changed() method
that the password has been changed.
"""
if password_validators is None:
password_validators = get_default_password_validators()
for validator i... | [
"def",
"password_changed",
"(",
"password",
",",
"user",
"=",
"None",
",",
"password_validators",
"=",
"None",
")",
":",
"if",
"password_validators",
"is",
"None",
":",
"password_validators",
"=",
"get_default_password_validators",
"(",
")",
"for",
"validator",
"i... | [
53,
0
] | [
62,
40
] | python | en | ['en', 'error', 'th'] | False |
password_validators_help_texts | (password_validators=None) |
Return a list of all help texts of all configured validators.
|
Return a list of all help texts of all configured validators.
| def password_validators_help_texts(password_validators=None):
"""
Return a list of all help texts of all configured validators.
"""
help_texts = []
if password_validators is None:
password_validators = get_default_password_validators()
for validator in password_validators:
help_t... | [
"def",
"password_validators_help_texts",
"(",
"password_validators",
"=",
"None",
")",
":",
"help_texts",
"=",
"[",
"]",
"if",
"password_validators",
"is",
"None",
":",
"password_validators",
"=",
"get_default_password_validators",
"(",
")",
"for",
"validator",
"in",
... | [
65,
0
] | [
74,
21
] | python | en | ['en', 'error', 'th'] | False |
_password_validators_help_text_html | (password_validators=None) |
Return an HTML string with all help texts of all configured validators
in an <ul>.
|
Return an HTML string with all help texts of all configured validators
in an <ul>.
| def _password_validators_help_text_html(password_validators=None):
"""
Return an HTML string with all help texts of all configured validators
in an <ul>.
"""
help_texts = password_validators_help_texts(password_validators)
help_items = format_html_join('', '<li>{}</li>', ((help_text,) for help_t... | [
"def",
"_password_validators_help_text_html",
"(",
"password_validators",
"=",
"None",
")",
":",
"help_texts",
"=",
"password_validators_help_texts",
"(",
"password_validators",
")",
"help_items",
"=",
"format_html_join",
"(",
"''",
",",
"'<li>{}</li>'",
",",
"(",
"(",
... | [
77,
0
] | [
84,
71
] | python | en | ['en', 'error', 'th'] | False |
EmailBackend.send_messages | (self, messages) | Redirect messages to the dummy outbox | Redirect messages to the dummy outbox | def send_messages(self, messages):
"""Redirect messages to the dummy outbox"""
msg_count = 0
for message in messages: # .message() triggers header validation
message.message()
mail.outbox.append(message)
msg_count += 1
return msg_count | [
"def",
"send_messages",
"(",
"self",
",",
"messages",
")",
":",
"msg_count",
"=",
"0",
"for",
"message",
"in",
"messages",
":",
"# .message() triggers header validation",
"message",
".",
"message",
"(",
")",
"mail",
".",
"outbox",
".",
"append",
"(",
"message"... | [
22,
4
] | [
29,
24
] | python | en | ['en', 'en', 'en'] | True |
GetOldMessagesTest.test_content_types | (self) |
Test old `/json/messages` returns reactions.
|
Test old `/json/messages` returns reactions.
| def test_content_types(self) -> None:
"""
Test old `/json/messages` returns reactions.
"""
self.login("hamlet")
def get_content_type(apply_markdown: bool) -> str:
req: Dict[str, Any] = dict(
apply_markdown=orjson.dumps(apply_markdown).decode(),
... | [
"def",
"test_content_types",
"(",
"self",
")",
"->",
"None",
":",
"self",
".",
"login",
"(",
"\"hamlet\"",
")",
"def",
"get_content_type",
"(",
"apply_markdown",
":",
"bool",
")",
"->",
"str",
":",
"req",
":",
"Dict",
"[",
"str",
",",
"Any",
"]",
"=",
... | [
1380,
4
] | [
1402,
9
] | python | en | ['en', 'error', 'th'] | False |
GetOldMessagesTest.test_successful_get_messages_reaction | (self) |
Test old `/json/messages` returns reactions.
|
Test old `/json/messages` returns reactions.
| def test_successful_get_messages_reaction(self) -> None:
"""
Test old `/json/messages` returns reactions.
"""
self.login("hamlet")
messages = self.get_and_check_messages({})
message_id = messages["messages"][0]["id"]
self.login("othello")
reaction_name = ... | [
"def",
"test_successful_get_messages_reaction",
"(",
"self",
")",
"->",
"None",
":",
"self",
".",
"login",
"(",
"\"hamlet\"",
")",
"messages",
"=",
"self",
".",
"get_and_check_messages",
"(",
"{",
"}",
")",
"message_id",
"=",
"messages",
"[",
"\"messages\"",
"... | [
1404,
4
] | [
1431,
88
] | python | en | ['en', 'error', 'th'] | False |
GetOldMessagesTest.test_successful_get_messages | (self) |
A call to GET /json/messages with valid parameters returns a list of
messages.
|
A call to GET /json/messages with valid parameters returns a list of
messages.
| def test_successful_get_messages(self) -> None:
"""
A call to GET /json/messages with valid parameters returns a list of
messages.
"""
self.login("hamlet")
self.get_and_check_messages({})
othello_email = self.example_user("othello").email
# We have to su... | [
"def",
"test_successful_get_messages",
"(",
"self",
")",
"->",
"None",
":",
"self",
".",
"login",
"(",
"\"hamlet\"",
")",
"self",
".",
"get_and_check_messages",
"(",
"{",
"}",
")",
"othello_email",
"=",
"self",
".",
"example_user",
"(",
"\"othello\"",
")",
"... | [
1433,
4
] | [
1459,
9
] | python | en | ['en', 'error', 'th'] | False |
GetOldMessagesTest.test_unauthenticated_get_messages_without_web_public | (self) |
An unauthenticated call to GET /json/messages with valid parameters
returns a 401.
|
An unauthenticated call to GET /json/messages with valid parameters
returns a 401.
| def test_unauthenticated_get_messages_without_web_public(self) -> None:
"""
An unauthenticated call to GET /json/messages with valid parameters
returns a 401.
"""
post_params = {
"anchor": 1,
"num_before": 1,
"num_after": 1,
"narrow... | [
"def",
"test_unauthenticated_get_messages_without_web_public",
"(",
"self",
")",
"->",
"None",
":",
"post_params",
"=",
"{",
"\"anchor\"",
":",
"1",
",",
"\"num_before\"",
":",
"1",
",",
"\"num_after\"",
":",
"1",
",",
"\"narrow\"",
":",
"orjson",
".",
"dumps",
... | [
1473,
4
] | [
1497,
9
] | python | en | ['en', 'error', 'th'] | False |
GetOldMessagesTest.test_unauthenticated_get_messages_with_web_public | (self) |
An unauthenticated call to GET /json/messages without valid
parameters in the `streams:web-public` narrow returns a 401.
|
An unauthenticated call to GET /json/messages without valid
parameters in the `streams:web-public` narrow returns a 401.
| def test_unauthenticated_get_messages_with_web_public(self) -> None:
"""
An unauthenticated call to GET /json/messages without valid
parameters in the `streams:web-public` narrow returns a 401.
"""
post_params: Dict[str, Union[int, str, bool]] = {
"anchor": 1,
... | [
"def",
"test_unauthenticated_get_messages_with_web_public",
"(",
"self",
")",
"->",
"None",
":",
"post_params",
":",
"Dict",
"[",
"str",
",",
"Union",
"[",
"int",
",",
"str",
",",
"bool",
"]",
"]",
"=",
"{",
"\"anchor\"",
":",
"1",
",",
"\"num_before\"",
"... | [
1499,
4
] | [
1519,
9
] | python | en | ['en', 'error', 'th'] | False |
GetOldMessagesTest.test_unauthenticated_narrow_to_non_web_public_streams_without_web_public | (self) |
An unauthenticated call to GET /json/messages without `streams:web-public` narrow returns a 401.
|
An unauthenticated call to GET /json/messages without `streams:web-public` narrow returns a 401.
| def test_unauthenticated_narrow_to_non_web_public_streams_without_web_public(self) -> None:
"""
An unauthenticated call to GET /json/messages without `streams:web-public` narrow returns a 401.
"""
post_params: Dict[str, Union[int, str, bool]] = {
"anchor": 1,
"num... | [
"def",
"test_unauthenticated_narrow_to_non_web_public_streams_without_web_public",
"(",
"self",
")",
"->",
"None",
":",
"post_params",
":",
"Dict",
"[",
"str",
",",
"Union",
"[",
"int",
",",
"str",
",",
"bool",
"]",
"]",
"=",
"{",
"\"anchor\"",
":",
"1",
",",
... | [
1521,
4
] | [
1534,
9
] | python | en | ['en', 'error', 'th'] | False |
GetOldMessagesTest.test_unauthenticated_narrow_to_non_web_public_streams_with_web_public | (self) |
An unauthenticated call to GET /json/messages with valid
parameters in the `streams:web-public` narrow + narrow to stream returns
a 400 if the target stream is not web-public.
|
An unauthenticated call to GET /json/messages with valid
parameters in the `streams:web-public` narrow + narrow to stream returns
a 400 if the target stream is not web-public.
| def test_unauthenticated_narrow_to_non_web_public_streams_with_web_public(self) -> None:
"""
An unauthenticated call to GET /json/messages with valid
parameters in the `streams:web-public` narrow + narrow to stream returns
a 400 if the target stream is not web-public.
"""
... | [
"def",
"test_unauthenticated_narrow_to_non_web_public_streams_with_web_public",
"(",
"self",
")",
"->",
"None",
":",
"post_params",
":",
"Dict",
"[",
"str",
",",
"Union",
"[",
"int",
",",
"str",
",",
"bool",
"]",
"]",
"=",
"{",
"\"anchor\"",
":",
"1",
",",
"... | [
1536,
4
] | [
1556,
9
] | python | en | ['en', 'error', 'th'] | False |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.