repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1
value | code stringlengths 75 19.8k | code_tokens list | docstring stringlengths 3 17.3k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 87 242 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
erdc/RAPIDpy | RAPIDpy/gis/taudem.py | TauDEM.rasterToPolygon | def rasterToPolygon(raster_file, polygon_file):
"""
Converts watershed raster to polygon and then dissolves it.
It dissolves features based on the LINKNO attribute.
"""
log("Process: Raster to Polygon ...")
time_start = datetime.utcnow()
temp_polygon_file = \
... | python | def rasterToPolygon(raster_file, polygon_file):
"""
Converts watershed raster to polygon and then dissolves it.
It dissolves features based on the LINKNO attribute.
"""
log("Process: Raster to Polygon ...")
time_start = datetime.utcnow()
temp_polygon_file = \
... | [
"def",
"rasterToPolygon",
"(",
"raster_file",
",",
"polygon_file",
")",
":",
"log",
"(",
"\"Process: Raster to Polygon ...\"",
")",
"time_start",
"=",
"datetime",
".",
"utcnow",
"(",
")",
"temp_polygon_file",
"=",
"\"{0}_temp.shp\"",
".",
"format",
"(",
"os",
".",... | Converts watershed raster to polygon and then dissolves it.
It dissolves features based on the LINKNO attribute. | [
"Converts",
"watershed",
"raster",
"to",
"polygon",
"and",
"then",
"dissolves",
"it",
".",
"It",
"dissolves",
"features",
"based",
"on",
"the",
"LINKNO",
"attribute",
"."
] | 50e14e130554b254a00ff23b226cd7e4c6cfe91a | https://github.com/erdc/RAPIDpy/blob/50e14e130554b254a00ff23b226cd7e4c6cfe91a/RAPIDpy/gis/taudem.py#L453-L525 | train |
erdc/RAPIDpy | RAPIDpy/gis/taudem.py | TauDEM.pitRemove | def pitRemove(self,
elevation_grid,
pit_filled_elevation_grid,
input_depression_mask_grid=None,
consider4way=False,
):
"""
Remove low spots from DEM.
"""
log("PROCESS: PitRemove")
self.pit_f... | python | def pitRemove(self,
elevation_grid,
pit_filled_elevation_grid,
input_depression_mask_grid=None,
consider4way=False,
):
"""
Remove low spots from DEM.
"""
log("PROCESS: PitRemove")
self.pit_f... | [
"def",
"pitRemove",
"(",
"self",
",",
"elevation_grid",
",",
"pit_filled_elevation_grid",
",",
"input_depression_mask_grid",
"=",
"None",
",",
"consider4way",
"=",
"False",
",",
")",
":",
"log",
"(",
"\"PROCESS: PitRemove\"",
")",
"self",
".",
"pit_filled_elevation_... | Remove low spots from DEM. | [
"Remove",
"low",
"spots",
"from",
"DEM",
"."
] | 50e14e130554b254a00ff23b226cd7e4c6cfe91a | https://github.com/erdc/RAPIDpy/blob/50e14e130554b254a00ff23b226cd7e4c6cfe91a/RAPIDpy/gis/taudem.py#L592-L619 | train |
erdc/RAPIDpy | RAPIDpy/gis/taudem.py | TauDEM.dinfFlowDirection | def dinfFlowDirection(self,
flow_dir_grid,
slope_grid,
pit_filled_elevation_grid=None):
"""
Calculates flow direction with Dinf method
"""
log("PROCESS: DinfFlowDirection")
if pit_filled_elevation_grid:... | python | def dinfFlowDirection(self,
flow_dir_grid,
slope_grid,
pit_filled_elevation_grid=None):
"""
Calculates flow direction with Dinf method
"""
log("PROCESS: DinfFlowDirection")
if pit_filled_elevation_grid:... | [
"def",
"dinfFlowDirection",
"(",
"self",
",",
"flow_dir_grid",
",",
"slope_grid",
",",
"pit_filled_elevation_grid",
"=",
"None",
")",
":",
"log",
"(",
"\"PROCESS: DinfFlowDirection\"",
")",
"if",
"pit_filled_elevation_grid",
":",
"self",
".",
"pit_filled_elevation_grid"... | Calculates flow direction with Dinf method | [
"Calculates",
"flow",
"direction",
"with",
"Dinf",
"method"
] | 50e14e130554b254a00ff23b226cd7e4c6cfe91a | https://github.com/erdc/RAPIDpy/blob/50e14e130554b254a00ff23b226cd7e4c6cfe91a/RAPIDpy/gis/taudem.py#L621-L645 | train |
erdc/RAPIDpy | RAPIDpy/gis/taudem.py | TauDEM.dinfContributingArea | def dinfContributingArea(self,
contributing_area_grid,
flow_dir_grid,
outlet_shapefile=None,
weight_grid=None,
edge_contamination=False,
):
... | python | def dinfContributingArea(self,
contributing_area_grid,
flow_dir_grid,
outlet_shapefile=None,
weight_grid=None,
edge_contamination=False,
):
... | [
"def",
"dinfContributingArea",
"(",
"self",
",",
"contributing_area_grid",
",",
"flow_dir_grid",
",",
"outlet_shapefile",
"=",
"None",
",",
"weight_grid",
"=",
"None",
",",
"edge_contamination",
"=",
"False",
",",
")",
":",
"log",
"(",
"\"PROCESS: DinfContributingAr... | Calculates contributing area with Dinf method. | [
"Calculates",
"contributing",
"area",
"with",
"Dinf",
"method",
"."
] | 50e14e130554b254a00ff23b226cd7e4c6cfe91a | https://github.com/erdc/RAPIDpy/blob/50e14e130554b254a00ff23b226cd7e4c6cfe91a/RAPIDpy/gis/taudem.py#L675-L704 | train |
erdc/RAPIDpy | RAPIDpy/gis/taudem.py | TauDEM.streamDefByThreshold | def streamDefByThreshold(self,
stream_raster_grid,
threshold,
contributing_area_grid,
mask_grid=None,
):
"""
Calculates the stream definition by threshold.
... | python | def streamDefByThreshold(self,
stream_raster_grid,
threshold,
contributing_area_grid,
mask_grid=None,
):
"""
Calculates the stream definition by threshold.
... | [
"def",
"streamDefByThreshold",
"(",
"self",
",",
"stream_raster_grid",
",",
"threshold",
",",
"contributing_area_grid",
",",
"mask_grid",
"=",
"None",
",",
")",
":",
"log",
"(",
"\"PROCESS: StreamDefByThreshold\"",
")",
"self",
".",
"stream_raster_grid",
"=",
"strea... | Calculates the stream definition by threshold. | [
"Calculates",
"the",
"stream",
"definition",
"by",
"threshold",
"."
] | 50e14e130554b254a00ff23b226cd7e4c6cfe91a | https://github.com/erdc/RAPIDpy/blob/50e14e130554b254a00ff23b226cd7e4c6cfe91a/RAPIDpy/gis/taudem.py#L739-L765 | train |
erdc/RAPIDpy | RAPIDpy/gis/taudem.py | TauDEM.streamReachAndWatershed | def streamReachAndWatershed(self,
delineate,
out_stream_order_grid,
out_network_connectivity_tree,
out_network_coordinates,
out_stream_reach_file,
... | python | def streamReachAndWatershed(self,
delineate,
out_stream_order_grid,
out_network_connectivity_tree,
out_network_coordinates,
out_stream_reach_file,
... | [
"def",
"streamReachAndWatershed",
"(",
"self",
",",
"delineate",
",",
"out_stream_order_grid",
",",
"out_network_connectivity_tree",
",",
"out_network_coordinates",
",",
"out_stream_reach_file",
",",
"out_watershed_grid",
",",
"pit_filled_elevation_grid",
"=",
"None",
",",
... | Creates vector network and shapefile from stream raster grid | [
"Creates",
"vector",
"network",
"and",
"shapefile",
"from",
"stream",
"raster",
"grid"
] | 50e14e130554b254a00ff23b226cd7e4c6cfe91a | https://github.com/erdc/RAPIDpy/blob/50e14e130554b254a00ff23b226cd7e4c6cfe91a/RAPIDpy/gis/taudem.py#L767-L819 | train |
erdc/RAPIDpy | RAPIDpy/gis/taudem.py | TauDEM.demToStreamNetwork | def demToStreamNetwork(self,
output_directory,
raw_elevation_dem="",
pit_filled_elevation_grid="",
flow_dir_grid_d8="",
contributing_area_grid_d8="",
flow_dir... | python | def demToStreamNetwork(self,
output_directory,
raw_elevation_dem="",
pit_filled_elevation_grid="",
flow_dir_grid_d8="",
contributing_area_grid_d8="",
flow_dir... | [
"def",
"demToStreamNetwork",
"(",
"self",
",",
"output_directory",
",",
"raw_elevation_dem",
"=",
"\"\"",
",",
"pit_filled_elevation_grid",
"=",
"\"\"",
",",
"flow_dir_grid_d8",
"=",
"\"\"",
",",
"contributing_area_grid_d8",
"=",
"\"\"",
",",
"flow_dir_grid_dinf",
"="... | This function will run all of the TauDEM processes to generate
a stream network from an elevation raster.
.. note:: For information about the stream reach and watershed process:
http://hydrology.usu.edu/taudem/taudem5/help53/StreamReachAndWatershed.html
.. note:: For informat... | [
"This",
"function",
"will",
"run",
"all",
"of",
"the",
"TauDEM",
"processes",
"to",
"generate",
"a",
"stream",
"network",
"from",
"an",
"elevation",
"raster",
"."
] | 50e14e130554b254a00ff23b226cd7e4c6cfe91a | https://github.com/erdc/RAPIDpy/blob/50e14e130554b254a00ff23b226cd7e4c6cfe91a/RAPIDpy/gis/taudem.py#L821-L963 | train |
ic-labs/django-icekit | icekit/plugins/iiif/utils.py | build_iiif_file_storage_path | def build_iiif_file_storage_path(url_path, ik_image, iiif_storage):
"""
Return the file storage path for a given IIIF Image API URL path.
NOTE: The returned file storage path includes the given ``Image``
instance's ID to ensure the path is unique and identifiable, and its
modified timestamp to act ... | python | def build_iiif_file_storage_path(url_path, ik_image, iiif_storage):
"""
Return the file storage path for a given IIIF Image API URL path.
NOTE: The returned file storage path includes the given ``Image``
instance's ID to ensure the path is unique and identifiable, and its
modified timestamp to act ... | [
"def",
"build_iiif_file_storage_path",
"(",
"url_path",
",",
"ik_image",
",",
"iiif_storage",
")",
":",
"storage_path",
"=",
"url_path",
"[",
"1",
":",
"]",
"if",
"storage_path",
".",
"startswith",
"(",
"'iiif/'",
")",
":",
"storage_path",
"=",
"storage_path",
... | Return the file storage path for a given IIIF Image API URL path.
NOTE: The returned file storage path includes the given ``Image``
instance's ID to ensure the path is unique and identifiable, and its
modified timestamp to act as a primitive cache-busting mechanism for
when the image is changed but the... | [
"Return",
"the",
"file",
"storage",
"path",
"for",
"a",
"given",
"IIIF",
"Image",
"API",
"URL",
"path",
"."
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit/plugins/iiif/utils.py#L277-L321 | train |
ic-labs/django-icekit | glamkit_collections/contrib/work_creator/models.py | CreatorBase.get_roles | def get_roles(self):
"""Return the m2m relations connecting me to works"""
work_ids = self.get_works().values_list('id', flat=True)
return self.works.through.objects.filter(
creator=self.get_draft(),
work_id__in=work_ids,
).select_related('role') | python | def get_roles(self):
"""Return the m2m relations connecting me to works"""
work_ids = self.get_works().values_list('id', flat=True)
return self.works.through.objects.filter(
creator=self.get_draft(),
work_id__in=work_ids,
).select_related('role') | [
"def",
"get_roles",
"(",
"self",
")",
":",
"work_ids",
"=",
"self",
".",
"get_works",
"(",
")",
".",
"values_list",
"(",
"'id'",
",",
"flat",
"=",
"True",
")",
"return",
"self",
".",
"works",
".",
"through",
".",
"objects",
".",
"filter",
"(",
"creat... | Return the m2m relations connecting me to works | [
"Return",
"the",
"m2m",
"relations",
"connecting",
"me",
"to",
"works"
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/glamkit_collections/contrib/work_creator/models.py#L271-L277 | train |
ic-labs/django-icekit | glamkit_collections/contrib/work_creator/models.py | WorkBase.derive_and_set_slug | def derive_and_set_slug(self, set_name_sort=True, set_slug=True):
"""
Derive `slug` field from `title` unless it is set in its own right.
This method is called during `save()`
"""
# `title` is the primary required name field. It must be set.
if is_empty(self.title):
... | python | def derive_and_set_slug(self, set_name_sort=True, set_slug=True):
"""
Derive `slug` field from `title` unless it is set in its own right.
This method is called during `save()`
"""
# `title` is the primary required name field. It must be set.
if is_empty(self.title):
... | [
"def",
"derive_and_set_slug",
"(",
"self",
",",
"set_name_sort",
"=",
"True",
",",
"set_slug",
"=",
"True",
")",
":",
"if",
"is_empty",
"(",
"self",
".",
"title",
")",
":",
"raise",
"ValueError",
"(",
"u\"%s.title cannot be empty at save\"",
"%",
"type",
"(",
... | Derive `slug` field from `title` unless it is set in its own right.
This method is called during `save()` | [
"Derive",
"slug",
"field",
"from",
"title",
"unless",
"it",
"is",
"set",
"in",
"its",
"own",
"right",
"."
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/glamkit_collections/contrib/work_creator/models.py#L414-L426 | train |
ic-labs/django-icekit | glamkit_collections/contrib/work_creator/models.py | WorkBase.get_roles | def get_roles(self):
"""
Return the m2m relations connecting me to creators.
There's some publishing-related complexity here. The role relations
(self.creators.through) connect to draft objects, which then need to
be modified to point to visible() objects.
"""
... | python | def get_roles(self):
"""
Return the m2m relations connecting me to creators.
There's some publishing-related complexity here. The role relations
(self.creators.through) connect to draft objects, which then need to
be modified to point to visible() objects.
"""
... | [
"def",
"get_roles",
"(",
"self",
")",
":",
"creator_ids",
"=",
"self",
".",
"get_creators",
"(",
")",
".",
"values_list",
"(",
"'id'",
",",
"flat",
"=",
"True",
")",
"return",
"self",
".",
"creators",
".",
"through",
".",
"objects",
".",
"filter",
"(",... | Return the m2m relations connecting me to creators.
There's some publishing-related complexity here. The role relations
(self.creators.through) connect to draft objects, which then need to
be modified to point to visible() objects. | [
"Return",
"the",
"m2m",
"relations",
"connecting",
"me",
"to",
"creators",
"."
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/glamkit_collections/contrib/work_creator/models.py#L467-L482 | train |
ic-labs/django-icekit | icekit_events/admin.py | EventAdmin.get_urls | def get_urls(self):
"""
Add a calendar URL.
"""
from django.conf.urls import patterns, url
urls = super(EventAdmin, self).get_urls()
my_urls = patterns(
'',
url(
r'^calendar/$',
self.admin_site.admin_view(self.calend... | python | def get_urls(self):
"""
Add a calendar URL.
"""
from django.conf.urls import patterns, url
urls = super(EventAdmin, self).get_urls()
my_urls = patterns(
'',
url(
r'^calendar/$',
self.admin_site.admin_view(self.calend... | [
"def",
"get_urls",
"(",
"self",
")",
":",
"from",
"django",
".",
"conf",
".",
"urls",
"import",
"patterns",
",",
"url",
"urls",
"=",
"super",
"(",
"EventAdmin",
",",
"self",
")",
".",
"get_urls",
"(",
")",
"my_urls",
"=",
"patterns",
"(",
"''",
",",
... | Add a calendar URL. | [
"Add",
"a",
"calendar",
"URL",
"."
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit_events/admin.py#L224-L243 | train |
ic-labs/django-icekit | icekit_events/admin.py | EventAdmin.calendar | def calendar(self, request):
"""
Return a calendar page to be loaded in an iframe.
"""
context = {
'is_popup': bool(int(request.GET.get('_popup', 0))),
}
return TemplateResponse(
request, 'admin/icekit_events/eventbase/calendar.html', context) | python | def calendar(self, request):
"""
Return a calendar page to be loaded in an iframe.
"""
context = {
'is_popup': bool(int(request.GET.get('_popup', 0))),
}
return TemplateResponse(
request, 'admin/icekit_events/eventbase/calendar.html', context) | [
"def",
"calendar",
"(",
"self",
",",
"request",
")",
":",
"context",
"=",
"{",
"'is_popup'",
":",
"bool",
"(",
"int",
"(",
"request",
".",
"GET",
".",
"get",
"(",
"'_popup'",
",",
"0",
")",
")",
")",
",",
"}",
"return",
"TemplateResponse",
"(",
"re... | Return a calendar page to be loaded in an iframe. | [
"Return",
"a",
"calendar",
"page",
"to",
"be",
"loaded",
"in",
"an",
"iframe",
"."
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit_events/admin.py#L245-L253 | train |
ic-labs/django-icekit | icekit_events/admin.py | EventAdmin.calendar_data | def calendar_data(self, request):
"""
Return event data in JSON format for AJAX requests, or a calendar page
to be loaded in an iframe.
"""
# mutable copy
request.GET = request.GET.copy()
if 'timezone' in request.GET:
tz = djtz.get(request.GET.pop('t... | python | def calendar_data(self, request):
"""
Return event data in JSON format for AJAX requests, or a calendar page
to be loaded in an iframe.
"""
# mutable copy
request.GET = request.GET.copy()
if 'timezone' in request.GET:
tz = djtz.get(request.GET.pop('t... | [
"def",
"calendar_data",
"(",
"self",
",",
"request",
")",
":",
"request",
".",
"GET",
"=",
"request",
".",
"GET",
".",
"copy",
"(",
")",
"if",
"'timezone'",
"in",
"request",
".",
"GET",
":",
"tz",
"=",
"djtz",
".",
"get",
"(",
"request",
".",
"GET"... | Return event data in JSON format for AJAX requests, or a calendar page
to be loaded in an iframe. | [
"Return",
"event",
"data",
"in",
"JSON",
"format",
"for",
"AJAX",
"requests",
"or",
"a",
"calendar",
"page",
"to",
"be",
"loaded",
"in",
"an",
"iframe",
"."
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit_events/admin.py#L255-L300 | train |
ic-labs/django-icekit | icekit_events/admin.py | EventAdmin._calendar_json_for_occurrence | def _calendar_json_for_occurrence(self, occurrence):
"""
Return JSON for a single Occurrence
"""
# Slugify the plugin's verbose name for use as a class name.
if occurrence.is_all_day:
start = occurrence.start
# `end` is exclusive according to the doc in
... | python | def _calendar_json_for_occurrence(self, occurrence):
"""
Return JSON for a single Occurrence
"""
# Slugify the plugin's verbose name for use as a class name.
if occurrence.is_all_day:
start = occurrence.start
# `end` is exclusive according to the doc in
... | [
"def",
"_calendar_json_for_occurrence",
"(",
"self",
",",
"occurrence",
")",
":",
"if",
"occurrence",
".",
"is_all_day",
":",
"start",
"=",
"occurrence",
".",
"start",
"end",
"=",
"occurrence",
".",
"start",
"+",
"timedelta",
"(",
"days",
"=",
"1",
")",
"e... | Return JSON for a single Occurrence | [
"Return",
"JSON",
"for",
"a",
"single",
"Occurrence"
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit_events/admin.py#L313-L347 | train |
ic-labs/django-icekit | icekit_events/admin.py | EventAdmin._calendar_classes_for_occurrence | def _calendar_classes_for_occurrence(self, occurrence):
"""
Return css classes to be used in admin calendar JSON
"""
classes = [slugify(occurrence.event.polymorphic_ctype.name)]
# Add a class name for the type of event.
if occurrence.is_all_day:
classes.appen... | python | def _calendar_classes_for_occurrence(self, occurrence):
"""
Return css classes to be used in admin calendar JSON
"""
classes = [slugify(occurrence.event.polymorphic_ctype.name)]
# Add a class name for the type of event.
if occurrence.is_all_day:
classes.appen... | [
"def",
"_calendar_classes_for_occurrence",
"(",
"self",
",",
"occurrence",
")",
":",
"classes",
"=",
"[",
"slugify",
"(",
"occurrence",
".",
"event",
".",
"polymorphic_ctype",
".",
"name",
")",
"]",
"if",
"occurrence",
".",
"is_all_day",
":",
"classes",
".",
... | Return css classes to be used in admin calendar JSON | [
"Return",
"css",
"classes",
"to",
"be",
"used",
"in",
"admin",
"calendar",
"JSON"
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit_events/admin.py#L349-L371 | train |
ic-labs/django-icekit | icekit_events/admin.py | RecurrenceRuleAdmin.get_urls | def get_urls(self):
"""
Add a preview URL.
"""
from django.conf.urls import patterns, url
urls = super(RecurrenceRuleAdmin, self).get_urls()
my_urls = patterns(
'',
url(
r'^preview/$',
self.admin_site.admin_view(self... | python | def get_urls(self):
"""
Add a preview URL.
"""
from django.conf.urls import patterns, url
urls = super(RecurrenceRuleAdmin, self).get_urls()
my_urls = patterns(
'',
url(
r'^preview/$',
self.admin_site.admin_view(self... | [
"def",
"get_urls",
"(",
"self",
")",
":",
"from",
"django",
".",
"conf",
".",
"urls",
"import",
"patterns",
",",
"url",
"urls",
"=",
"super",
"(",
"RecurrenceRuleAdmin",
",",
"self",
")",
".",
"get_urls",
"(",
")",
"my_urls",
"=",
"patterns",
"(",
"''"... | Add a preview URL. | [
"Add",
"a",
"preview",
"URL",
"."
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit_events/admin.py#L391-L405 | train |
ic-labs/django-icekit | icekit_events/admin.py | RecurrenceRuleAdmin.preview | def preview(self, request):
"""
Return a occurrences in JSON format up until the configured limit.
"""
recurrence_rule = request.POST.get('recurrence_rule')
limit = int(request.POST.get('limit', 10))
try:
rruleset = rrule.rrulestr(
recurrence_r... | python | def preview(self, request):
"""
Return a occurrences in JSON format up until the configured limit.
"""
recurrence_rule = request.POST.get('recurrence_rule')
limit = int(request.POST.get('limit', 10))
try:
rruleset = rrule.rrulestr(
recurrence_r... | [
"def",
"preview",
"(",
"self",
",",
"request",
")",
":",
"recurrence_rule",
"=",
"request",
".",
"POST",
".",
"get",
"(",
"'recurrence_rule'",
")",
"limit",
"=",
"int",
"(",
"request",
".",
"POST",
".",
"get",
"(",
"'limit'",
",",
"10",
")",
")",
"tr... | Return a occurrences in JSON format up until the configured limit. | [
"Return",
"a",
"occurrences",
"in",
"JSON",
"format",
"up",
"until",
"the",
"configured",
"limit",
"."
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit_events/admin.py#L408-L425 | train |
ic-labs/django-icekit | icekit_events/page_types/advancedeventlisting/models.py | AbstractAdvancedEventListingPage.parse_primary_types | def parse_primary_types(self, request):
"""
Return primary event types that occurrences must belong to, or `None`
if there is no constraint on primary type.
"""
if request.GET.getlist('primary_types'):
return EventType.objects.get(
slug__in=request.GET... | python | def parse_primary_types(self, request):
"""
Return primary event types that occurrences must belong to, or `None`
if there is no constraint on primary type.
"""
if request.GET.getlist('primary_types'):
return EventType.objects.get(
slug__in=request.GET... | [
"def",
"parse_primary_types",
"(",
"self",
",",
"request",
")",
":",
"if",
"request",
".",
"GET",
".",
"getlist",
"(",
"'primary_types'",
")",
":",
"return",
"EventType",
".",
"objects",
".",
"get",
"(",
"slug__in",
"=",
"request",
".",
"GET",
".",
"getl... | Return primary event types that occurrences must belong to, or `None`
if there is no constraint on primary type. | [
"Return",
"primary",
"event",
"types",
"that",
"occurrences",
"must",
"belong",
"to",
"or",
"None",
"if",
"there",
"is",
"no",
"constraint",
"on",
"primary",
"type",
"."
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit_events/page_types/advancedeventlisting/models.py#L101-L109 | train |
ic-labs/django-icekit | icekit_events/page_types/advancedeventlisting/models.py | AbstractAdvancedEventListingPage.parse_secondary_types | def parse_secondary_types(self, request):
"""
Return secondary event types that occurrences must belong to, or `None`
if there is no constraint on secondary type.
"""
if request.GET.getlist('secondary_types'):
return EventType.objects.filter(
slug__in=... | python | def parse_secondary_types(self, request):
"""
Return secondary event types that occurrences must belong to, or `None`
if there is no constraint on secondary type.
"""
if request.GET.getlist('secondary_types'):
return EventType.objects.filter(
slug__in=... | [
"def",
"parse_secondary_types",
"(",
"self",
",",
"request",
")",
":",
"if",
"request",
".",
"GET",
".",
"getlist",
"(",
"'secondary_types'",
")",
":",
"return",
"EventType",
".",
"objects",
".",
"filter",
"(",
"slug__in",
"=",
"request",
".",
"GET",
".",
... | Return secondary event types that occurrences must belong to, or `None`
if there is no constraint on secondary type. | [
"Return",
"secondary",
"event",
"types",
"that",
"occurrences",
"must",
"belong",
"to",
"or",
"None",
"if",
"there",
"is",
"no",
"constraint",
"on",
"secondary",
"type",
"."
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit_events/page_types/advancedeventlisting/models.py#L111-L119 | train |
ic-labs/django-icekit | icekit/admin_tools/forms.py | PasswordResetForm.get_users | def get_users(self, email):
"""
Make sure users are staff users.
Additionally to the other PasswordResetForm conditions ensure
that the user is a staff user before sending them a password
reset email.
:param email: Textual email address.
:return: List of users.
... | python | def get_users(self, email):
"""
Make sure users are staff users.
Additionally to the other PasswordResetForm conditions ensure
that the user is a staff user before sending them a password
reset email.
:param email: Textual email address.
:return: List of users.
... | [
"def",
"get_users",
"(",
"self",
",",
"email",
")",
":",
"if",
"hasattr",
"(",
"super",
"(",
"PasswordResetForm",
",",
"self",
")",
",",
"'get_users'",
")",
":",
"return",
"(",
"u",
"for",
"u",
"in",
"super",
"(",
"PasswordResetForm",
",",
"self",
")",... | Make sure users are staff users.
Additionally to the other PasswordResetForm conditions ensure
that the user is a staff user before sending them a password
reset email.
:param email: Textual email address.
:return: List of users. | [
"Make",
"sure",
"users",
"are",
"staff",
"users",
"."
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit/admin_tools/forms.py#L12-L32 | train |
ic-labs/django-icekit | icekit/workflow/models.py | send_email_notifications_for_workflow_state_change | def send_email_notifications_for_workflow_state_change(
sender, instance, *args, **kwargs
):
"""
Send email notifications for save events on ``WorkflowState`` based on
settings in this module's `appsettings`.
"""
# Short-circuit processing if we have no notification targets
if not appsetting... | python | def send_email_notifications_for_workflow_state_change(
sender, instance, *args, **kwargs
):
"""
Send email notifications for save events on ``WorkflowState`` based on
settings in this module's `appsettings`.
"""
# Short-circuit processing if we have no notification targets
if not appsetting... | [
"def",
"send_email_notifications_for_workflow_state_change",
"(",
"sender",
",",
"instance",
",",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"if",
"not",
"appsettings",
".",
"WORKFLOW_EMAIL_NOTIFICATION_TARGETS",
":",
"return",
"obj",
"=",
"instance",
".",
"content... | Send email notifications for save events on ``WorkflowState`` based on
settings in this module's `appsettings`. | [
"Send",
"email",
"notifications",
"for",
"save",
"events",
"on",
"WorkflowState",
"based",
"on",
"settings",
"in",
"this",
"module",
"s",
"appsettings",
"."
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit/workflow/models.py#L86-L155 | train |
ic-labs/django-icekit | icekit/plugins/iiif/views.py | _get_image_or_404 | def _get_image_or_404(identifier, load_image=False):
"""
Return image matching `identifier`.
The `identifier` is expected to be a raw image ID for now, but may be
more complex later.
"""
try:
image_id = int(identifier)
except ValueError:
raise Http404()
ik_image = get_o... | python | def _get_image_or_404(identifier, load_image=False):
"""
Return image matching `identifier`.
The `identifier` is expected to be a raw image ID for now, but may be
more complex later.
"""
try:
image_id = int(identifier)
except ValueError:
raise Http404()
ik_image = get_o... | [
"def",
"_get_image_or_404",
"(",
"identifier",
",",
"load_image",
"=",
"False",
")",
":",
"try",
":",
"image_id",
"=",
"int",
"(",
"identifier",
")",
"except",
"ValueError",
":",
"raise",
"Http404",
"(",
")",
"ik_image",
"=",
"get_object_or_404",
"(",
"ICEki... | Return image matching `identifier`.
The `identifier` is expected to be a raw image ID for now, but may be
more complex later. | [
"Return",
"image",
"matching",
"identifier",
"."
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit/plugins/iiif/views.py#L40-L72 | train |
ic-labs/django-icekit | icekit/plugins/iiif/views.py | iiif_image_api | def iiif_image_api(request, identifier_param, region_param, size_param,
rotation_param, quality_param, format_param):
""" Image repurposing endpoint for IIIF Image API 2.1 """
ik_image, image = _get_image_or_404(identifier_param, load_image=True)
is_transparent = et_utils.is_transparent(... | python | def iiif_image_api(request, identifier_param, region_param, size_param,
rotation_param, quality_param, format_param):
""" Image repurposing endpoint for IIIF Image API 2.1 """
ik_image, image = _get_image_or_404(identifier_param, load_image=True)
is_transparent = et_utils.is_transparent(... | [
"def",
"iiif_image_api",
"(",
"request",
",",
"identifier_param",
",",
"region_param",
",",
"size_param",
",",
"rotation_param",
",",
"quality_param",
",",
"format_param",
")",
":",
"ik_image",
",",
"image",
"=",
"_get_image_or_404",
"(",
"identifier_param",
",",
... | Image repurposing endpoint for IIIF Image API 2.1 | [
"Image",
"repurposing",
"endpoint",
"for",
"IIIF",
"Image",
"API",
"2",
".",
"1"
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit/plugins/iiif/views.py#L116-L240 | train |
ic-labs/django-icekit | icekit/plugins/instagram_embed/forms.py | InstagramEmbedAdminForm.clean_url | def clean_url(self):
"""
Make sure the URL provided matches the instagram URL format.
"""
url = self.cleaned_data['url']
if url:
pattern = re.compile(r'https?://(www\.)?instagr(\.am|am\.com)/p/\S+')
if not pattern.match(url):
raise forms.V... | python | def clean_url(self):
"""
Make sure the URL provided matches the instagram URL format.
"""
url = self.cleaned_data['url']
if url:
pattern = re.compile(r'https?://(www\.)?instagr(\.am|am\.com)/p/\S+')
if not pattern.match(url):
raise forms.V... | [
"def",
"clean_url",
"(",
"self",
")",
":",
"url",
"=",
"self",
".",
"cleaned_data",
"[",
"'url'",
"]",
"if",
"url",
":",
"pattern",
"=",
"re",
".",
"compile",
"(",
"r'https?://(www\\.)?instagr(\\.am|am\\.com)/p/\\S+'",
")",
"if",
"not",
"pattern",
".",
"matc... | Make sure the URL provided matches the instagram URL format. | [
"Make",
"sure",
"the",
"URL",
"provided",
"matches",
"the",
"instagram",
"URL",
"format",
"."
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit/plugins/instagram_embed/forms.py#L8-L19 | train |
ic-labs/django-icekit | icekit/api/base_views.py | RedirectViewset.retrieve | def retrieve(self, request, *args, **kwargs):
"""
If the URL slug doesn't match an object, try slugifying the URL param
and searching alt_url for that.
If found, redirect to the canonical URL.
If still not found, raise 404.
"""
try:
instance = self.ge... | python | def retrieve(self, request, *args, **kwargs):
"""
If the URL slug doesn't match an object, try slugifying the URL param
and searching alt_url for that.
If found, redirect to the canonical URL.
If still not found, raise 404.
"""
try:
instance = self.ge... | [
"def",
"retrieve",
"(",
"self",
",",
"request",
",",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"try",
":",
"instance",
"=",
"self",
".",
"get_object",
"(",
")",
"serializer",
"=",
"self",
".",
"get_serializer",
"(",
"instance",
")",
"return",
"Respon... | If the URL slug doesn't match an object, try slugifying the URL param
and searching alt_url for that.
If found, redirect to the canonical URL.
If still not found, raise 404. | [
"If",
"the",
"URL",
"slug",
"doesn",
"t",
"match",
"an",
"object",
"try",
"slugifying",
"the",
"URL",
"param",
"and",
"searching",
"alt_url",
"for",
"that",
".",
"If",
"found",
"redirect",
"to",
"the",
"canonical",
"URL",
".",
"If",
"still",
"not",
"foun... | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit/api/base_views.py#L22-L71 | train |
ic-labs/django-icekit | icekit_events/sample_data/migrations/0001_initial.py | forwards | def forwards(apps, schema_editor):
"""
Create sample events.
"""
starts = timeutils.round_datetime(
when=timezone.now(),
precision=timedelta(days=1),
rounding=timeutils.ROUND_DOWN)
ends = starts + appsettings.DEFAULT_ENDS_DELTA
recurrence_rules = dict(
Recurrence... | python | def forwards(apps, schema_editor):
"""
Create sample events.
"""
starts = timeutils.round_datetime(
when=timezone.now(),
precision=timedelta(days=1),
rounding=timeutils.ROUND_DOWN)
ends = starts + appsettings.DEFAULT_ENDS_DELTA
recurrence_rules = dict(
Recurrence... | [
"def",
"forwards",
"(",
"apps",
",",
"schema_editor",
")",
":",
"starts",
"=",
"timeutils",
".",
"round_datetime",
"(",
"when",
"=",
"timezone",
".",
"now",
"(",
")",
",",
"precision",
"=",
"timedelta",
"(",
"days",
"=",
"1",
")",
",",
"rounding",
"=",... | Create sample events. | [
"Create",
"sample",
"events",
"."
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit_events/sample_data/migrations/0001_initial.py#L15-L80 | train |
ic-labs/django-icekit | icekit_events/sample_data/migrations/0001_initial.py | backwards | def backwards(apps, schema_editor):
"""
Delete sample events, including derivative repeat and variation events.
"""
titles = [
'Daily Event',
'Weekday Event',
'Weekend Event',
'Weekly Event',
'Monthly Event',
'Yearly Event',
]
samples = EventBase.o... | python | def backwards(apps, schema_editor):
"""
Delete sample events, including derivative repeat and variation events.
"""
titles = [
'Daily Event',
'Weekday Event',
'Weekend Event',
'Weekly Event',
'Monthly Event',
'Yearly Event',
]
samples = EventBase.o... | [
"def",
"backwards",
"(",
"apps",
",",
"schema_editor",
")",
":",
"titles",
"=",
"[",
"'Daily Event'",
",",
"'Weekday Event'",
",",
"'Weekend Event'",
",",
"'Weekly Event'",
",",
"'Monthly Event'",
",",
"'Yearly Event'",
",",
"]",
"samples",
"=",
"EventBase",
"."... | Delete sample events, including derivative repeat and variation events. | [
"Delete",
"sample",
"events",
"including",
"derivative",
"repeat",
"and",
"variation",
"events",
"."
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit_events/sample_data/migrations/0001_initial.py#L83-L96 | train |
ic-labs/django-icekit | icekit/api/management/commands/dump_collection_api.py | dump_viewset | def dump_viewset(viewset_class, root_folder, folder_fn=lambda i: ".", sample_size=None):
"""
Dump the contents of a rest-api queryset to a folder structure.
:param viewset_class: A rest-api viewset to iterate through
:param root_folder: The root folder to write results to.
:param folder_fn: A funct... | python | def dump_viewset(viewset_class, root_folder, folder_fn=lambda i: ".", sample_size=None):
"""
Dump the contents of a rest-api queryset to a folder structure.
:param viewset_class: A rest-api viewset to iterate through
:param root_folder: The root folder to write results to.
:param folder_fn: A funct... | [
"def",
"dump_viewset",
"(",
"viewset_class",
",",
"root_folder",
",",
"folder_fn",
"=",
"lambda",
"i",
":",
"\".\"",
",",
"sample_size",
"=",
"None",
")",
":",
"if",
"os",
".",
"path",
".",
"exists",
"(",
"root_folder",
")",
":",
"shutil",
".",
"rmtree",... | Dump the contents of a rest-api queryset to a folder structure.
:param viewset_class: A rest-api viewset to iterate through
:param root_folder: The root folder to write results to.
:param folder_fn: A function to generate a subfolder name for the instance.
:param sample_size: Number of items to process... | [
"Dump",
"the",
"contents",
"of",
"a",
"rest",
"-",
"api",
"queryset",
"to",
"a",
"folder",
"structure",
"."
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit/api/management/commands/dump_collection_api.py#L28-L61 | train |
ic-labs/django-icekit | icekit/api/management/commands/dump_collection_api.py | concatenate_json | def concatenate_json(source_folder, destination_file):
"""
Concatenate all the json files in a folder to one big JSON file.
"""
matches = []
for root, dirnames, filenames in os.walk(source_folder):
for filename in fnmatch.filter(filenames, '*.json'):
matches.append(os.path.join(r... | python | def concatenate_json(source_folder, destination_file):
"""
Concatenate all the json files in a folder to one big JSON file.
"""
matches = []
for root, dirnames, filenames in os.walk(source_folder):
for filename in fnmatch.filter(filenames, '*.json'):
matches.append(os.path.join(r... | [
"def",
"concatenate_json",
"(",
"source_folder",
",",
"destination_file",
")",
":",
"matches",
"=",
"[",
"]",
"for",
"root",
",",
"dirnames",
",",
"filenames",
"in",
"os",
".",
"walk",
"(",
"source_folder",
")",
":",
"for",
"filename",
"in",
"fnmatch",
"."... | Concatenate all the json files in a folder to one big JSON file. | [
"Concatenate",
"all",
"the",
"json",
"files",
"in",
"a",
"folder",
"to",
"one",
"big",
"JSON",
"file",
"."
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit/api/management/commands/dump_collection_api.py#L63-L78 | train |
ic-labs/django-icekit | icekit/content_collections/abstract_models.py | TitleSlugMixin.validate_unique_slug | def validate_unique_slug(self):
"""
Ensure slug is unique for this model. This check is aware of publishing
but is otherwise fairly basic and will need to be customised for
situations where models with slugs are not in a flat hierarchy etc.
"""
clashes_qs = type(self).obj... | python | def validate_unique_slug(self):
"""
Ensure slug is unique for this model. This check is aware of publishing
but is otherwise fairly basic and will need to be customised for
situations where models with slugs are not in a flat hierarchy etc.
"""
clashes_qs = type(self).obj... | [
"def",
"validate_unique_slug",
"(",
"self",
")",
":",
"clashes_qs",
"=",
"type",
"(",
"self",
")",
".",
"objects",
".",
"filter",
"(",
"slug",
"=",
"self",
".",
"slug",
")",
"if",
"self",
".",
"pk",
":",
"clashes_qs",
"=",
"clashes_qs",
".",
"exclude",... | Ensure slug is unique for this model. This check is aware of publishing
but is otherwise fairly basic and will need to be customised for
situations where models with slugs are not in a flat hierarchy etc. | [
"Ensure",
"slug",
"is",
"unique",
"for",
"this",
"model",
".",
"This",
"check",
"is",
"aware",
"of",
"publishing",
"but",
"is",
"otherwise",
"fairly",
"basic",
"and",
"will",
"need",
"to",
"be",
"customised",
"for",
"situations",
"where",
"models",
"with",
... | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit/content_collections/abstract_models.py#L31-L46 | train |
ic-labs/django-icekit | icekit/content_collections/abstract_models.py | AbstractCollectedContent.get_absolute_url | def get_absolute_url(self):
"""
The majority of the time, the URL is the parent's URL plus the slug.
If not, override this function.
"""
# Get the appropriate draft or published parent object for the current
# item, otherwise we risk mixing the draft parent URL with a pub... | python | def get_absolute_url(self):
"""
The majority of the time, the URL is the parent's URL plus the slug.
If not, override this function.
"""
# Get the appropriate draft or published parent object for the current
# item, otherwise we risk mixing the draft parent URL with a pub... | [
"def",
"get_absolute_url",
"(",
"self",
")",
":",
"if",
"self",
".",
"is_draft",
":",
"visible_parent",
"=",
"self",
".",
"parent",
".",
"get_draft",
"(",
")",
"else",
":",
"visible_parent",
"=",
"self",
".",
"parent",
".",
"get_published",
"(",
")",
"or... | The majority of the time, the URL is the parent's URL plus the slug.
If not, override this function. | [
"The",
"majority",
"of",
"the",
"time",
"the",
"URL",
"is",
"the",
"parent",
"s",
"URL",
"plus",
"the",
"slug",
".",
"If",
"not",
"override",
"this",
"function",
"."
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit/content_collections/abstract_models.py#L140-L157 | train |
ic-labs/django-icekit | icekit/content_collections/abstract_models.py | AbstractCollectedContent.get_response | def get_response(self, request, parent, *args, **kwargs):
"""
Render this collected content to a response.
:param request: the request
:param parent: the parent collection
:param args:
:param kwargs:
:return:
"""
context = {
'page': se... | python | def get_response(self, request, parent, *args, **kwargs):
"""
Render this collected content to a response.
:param request: the request
:param parent: the parent collection
:param args:
:param kwargs:
:return:
"""
context = {
'page': se... | [
"def",
"get_response",
"(",
"self",
",",
"request",
",",
"parent",
",",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"context",
"=",
"{",
"'page'",
":",
"self",
",",
"}",
"try",
":",
"return",
"TemplateResponse",
"(",
"request",
",",
"self",
".",
"get... | Render this collected content to a response.
:param request: the request
:param parent: the parent collection
:param args:
:param kwargs:
:return: | [
"Render",
"this",
"collected",
"content",
"to",
"a",
"response",
"."
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit/content_collections/abstract_models.py#L159-L181 | train |
ic-labs/django-icekit | icekit_events/migrations/0029_fix_malformed_rrules_20170830_1101.py | forwards_migration | def forwards_migration(apps, schema_editor):
"""
"0002_recurrence_rules" added malformed recurrence with trailing
semi-colons. While the JS parser on the front-end handles them,
the python parser will crash
"""
RecurrenceRule = apps.get_model('icekit_events', 'RecurrenceRule')
for rrule in R... | python | def forwards_migration(apps, schema_editor):
"""
"0002_recurrence_rules" added malformed recurrence with trailing
semi-colons. While the JS parser on the front-end handles them,
the python parser will crash
"""
RecurrenceRule = apps.get_model('icekit_events', 'RecurrenceRule')
for rrule in R... | [
"def",
"forwards_migration",
"(",
"apps",
",",
"schema_editor",
")",
":",
"RecurrenceRule",
"=",
"apps",
".",
"get_model",
"(",
"'icekit_events'",
",",
"'RecurrenceRule'",
")",
"for",
"rrule",
"in",
"RecurrenceRule",
".",
"objects",
".",
"all",
"(",
")",
":",
... | "0002_recurrence_rules" added malformed recurrence with trailing
semi-colons. While the JS parser on the front-end handles them,
the python parser will crash | [
"0002_recurrence_rules",
"added",
"malformed",
"recurrence",
"with",
"trailing",
"semi",
"-",
"colons",
".",
"While",
"the",
"JS",
"parser",
"on",
"the",
"front",
"-",
"end",
"handles",
"them",
"the",
"python",
"parser",
"will",
"crash"
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit_events/migrations/0029_fix_malformed_rrules_20170830_1101.py#L7-L18 | train |
ic-labs/django-icekit | icekit/response_pages/views.py | get_response_page | def get_response_page(request, return_type, template_location, response_page_type):
"""
Helper function to get an appropriate response page if it exists.
This function is not designed to be used directly as a view. It is
a helper function which can be called to check if a ResponsePage
exists for a ... | python | def get_response_page(request, return_type, template_location, response_page_type):
"""
Helper function to get an appropriate response page if it exists.
This function is not designed to be used directly as a view. It is
a helper function which can be called to check if a ResponsePage
exists for a ... | [
"def",
"get_response_page",
"(",
"request",
",",
"return_type",
",",
"template_location",
",",
"response_page_type",
")",
":",
"try",
":",
"page",
"=",
"models",
".",
"ResponsePage",
".",
"objects",
".",
"get",
"(",
"is_active",
"=",
"True",
",",
"type",
"="... | Helper function to get an appropriate response page if it exists.
This function is not designed to be used directly as a view. It is
a helper function which can be called to check if a ResponsePage
exists for a ResponsePage type (which is also active).
:param request:
:param return_type:
:para... | [
"Helper",
"function",
"to",
"get",
"an",
"appropriate",
"response",
"page",
"if",
"it",
"exists",
"."
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit/response_pages/views.py#L13-L40 | train |
ic-labs/django-icekit | icekit/response_pages/views.py | server_error | def server_error(request, template_name='500.html'):
"""
Custom 500 error handler.
The exception clause is so broad to capture any 500 errors that
may have been generated from getting the response page e.g. if the
database was down. If they were not handled they would cause a 500
themselves and... | python | def server_error(request, template_name='500.html'):
"""
Custom 500 error handler.
The exception clause is so broad to capture any 500 errors that
may have been generated from getting the response page e.g. if the
database was down. If they were not handled they would cause a 500
themselves and... | [
"def",
"server_error",
"(",
"request",
",",
"template_name",
"=",
"'500.html'",
")",
":",
"try",
":",
"rendered_page",
"=",
"get_response_page",
"(",
"request",
",",
"http",
".",
"HttpResponseServerError",
",",
"'icekit/response_pages/500.html'",
",",
"abstract_models... | Custom 500 error handler.
The exception clause is so broad to capture any 500 errors that
may have been generated from getting the response page e.g. if the
database was down. If they were not handled they would cause a 500
themselves and form an infinite loop.
If no ResponsePage exists for with t... | [
"Custom",
"500",
"error",
"handler",
"."
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit/response_pages/views.py#L73-L102 | train |
ic-labs/django-icekit | icekit_events/utils/permissions.py | allowed_to_preview | def allowed_to_preview(user):
"""
Is the user allowed to view the preview?
Users are only allowed to view the preview if they are authenticated, active and staff.
:param user: A User object instance.
:return: Boolean.
"""
if (
user.is_authenticated and
user.is_active and
... | python | def allowed_to_preview(user):
"""
Is the user allowed to view the preview?
Users are only allowed to view the preview if they are authenticated, active and staff.
:param user: A User object instance.
:return: Boolean.
"""
if (
user.is_authenticated and
user.is_active and
... | [
"def",
"allowed_to_preview",
"(",
"user",
")",
":",
"if",
"(",
"user",
".",
"is_authenticated",
"and",
"user",
".",
"is_active",
"and",
"user",
".",
"is_staff",
")",
":",
"return",
"True",
"return",
"False"
] | Is the user allowed to view the preview?
Users are only allowed to view the preview if they are authenticated, active and staff.
:param user: A User object instance.
:return: Boolean. | [
"Is",
"the",
"user",
"allowed",
"to",
"view",
"the",
"preview?"
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit_events/utils/permissions.py#L1-L16 | train |
ic-labs/django-icekit | icekit/admin_tools/polymorphic.py | ChildModelPluginPolymorphicParentModelAdmin.get_child_type_choices | def get_child_type_choices(self, request, action):
"""
Override choice labels with ``verbose_name`` from plugins and sort.
"""
# Get choices from the super class to check permissions.
choices = super(ChildModelPluginPolymorphicParentModelAdmin, self) \
.get_child_type... | python | def get_child_type_choices(self, request, action):
"""
Override choice labels with ``verbose_name`` from plugins and sort.
"""
# Get choices from the super class to check permissions.
choices = super(ChildModelPluginPolymorphicParentModelAdmin, self) \
.get_child_type... | [
"def",
"get_child_type_choices",
"(",
"self",
",",
"request",
",",
"action",
")",
":",
"choices",
"=",
"super",
"(",
"ChildModelPluginPolymorphicParentModelAdmin",
",",
"self",
")",
".",
"get_child_type_choices",
"(",
"request",
",",
"action",
")",
"plugins",
"=",... | Override choice labels with ``verbose_name`` from plugins and sort. | [
"Override",
"choice",
"labels",
"with",
"verbose_name",
"from",
"plugins",
"and",
"sort",
"."
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit/admin_tools/polymorphic.py#L44-L70 | train |
ic-labs/django-icekit | icekit/admin_tools/polymorphic.py | ChildModelPluginPolymorphicParentModelAdmin.get_child_models | def get_child_models(self):
"""
Get child models from registered plugins. Fallback to the child model
admin and its base model if no plugins are registered.
"""
child_models = []
for plugin in self.child_model_plugin_class.get_plugins():
child_models.append((p... | python | def get_child_models(self):
"""
Get child models from registered plugins. Fallback to the child model
admin and its base model if no plugins are registered.
"""
child_models = []
for plugin in self.child_model_plugin_class.get_plugins():
child_models.append((p... | [
"def",
"get_child_models",
"(",
"self",
")",
":",
"child_models",
"=",
"[",
"]",
"for",
"plugin",
"in",
"self",
".",
"child_model_plugin_class",
".",
"get_plugins",
"(",
")",
":",
"child_models",
".",
"append",
"(",
"(",
"plugin",
".",
"model",
",",
"plugi... | Get child models from registered plugins. Fallback to the child model
admin and its base model if no plugins are registered. | [
"Get",
"child",
"models",
"from",
"registered",
"plugins",
".",
"Fallback",
"to",
"the",
"child",
"model",
"admin",
"and",
"its",
"base",
"model",
"if",
"no",
"plugins",
"are",
"registered",
"."
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit/admin_tools/polymorphic.py#L72-L85 | train |
ic-labs/django-icekit | icekit/admin_tools/polymorphic.py | PolymorphicAdminRawIdFix._get_child_admin_site | def _get_child_admin_site(self, rel):
"""
Returns the separate AdminSite instance that django-polymorphic
maintains for child models.
This admin site needs to be passed to the widget so that it passes the
check of whether the field is pointing to a model that's registered
... | python | def _get_child_admin_site(self, rel):
"""
Returns the separate AdminSite instance that django-polymorphic
maintains for child models.
This admin site needs to be passed to the widget so that it passes the
check of whether the field is pointing to a model that's registered
... | [
"def",
"_get_child_admin_site",
"(",
"self",
",",
"rel",
")",
":",
"if",
"rel",
".",
"to",
"not",
"in",
"self",
".",
"admin_site",
".",
"_registry",
":",
"for",
"parent",
"in",
"rel",
".",
"to",
".",
"mro",
"(",
")",
":",
"if",
"parent",
"in",
"sel... | Returns the separate AdminSite instance that django-polymorphic
maintains for child models.
This admin site needs to be passed to the widget so that it passes the
check of whether the field is pointing to a model that's registered
in the admin.
The hackiness of this implementat... | [
"Returns",
"the",
"separate",
"AdminSite",
"instance",
"that",
"django",
"-",
"polymorphic",
"maintains",
"for",
"child",
"models",
"."
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit/admin_tools/polymorphic.py#L97-L117 | train |
ic-labs/django-icekit | icekit/admin_tools/polymorphic.py | PolymorphicAdminRawIdFix.formfield_for_foreignkey | def formfield_for_foreignkey(self, db_field, request=None, **kwargs):
"""
Replicates the logic in ModelAdmin.forfield_for_foreignkey, replacing
the widget with the patched one above, initialising it with the child
admin site.
"""
db = kwargs.get('using')
if db_fie... | python | def formfield_for_foreignkey(self, db_field, request=None, **kwargs):
"""
Replicates the logic in ModelAdmin.forfield_for_foreignkey, replacing
the widget with the patched one above, initialising it with the child
admin site.
"""
db = kwargs.get('using')
if db_fie... | [
"def",
"formfield_for_foreignkey",
"(",
"self",
",",
"db_field",
",",
"request",
"=",
"None",
",",
"**",
"kwargs",
")",
":",
"db",
"=",
"kwargs",
".",
"get",
"(",
"'using'",
")",
"if",
"db_field",
".",
"name",
"in",
"self",
".",
"raw_id_fields",
":",
"... | Replicates the logic in ModelAdmin.forfield_for_foreignkey, replacing
the widget with the patched one above, initialising it with the child
admin site. | [
"Replicates",
"the",
"logic",
"in",
"ModelAdmin",
".",
"forfield_for_foreignkey",
"replacing",
"the",
"widget",
"with",
"the",
"patched",
"one",
"above",
"initialising",
"it",
"with",
"the",
"child",
"admin",
"site",
"."
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit/admin_tools/polymorphic.py#L119-L138 | train |
ic-labs/django-icekit | glamkit_collections/utils.py | wikipedia_slugify | def wikipedia_slugify(value, do_unidecode=False):
"""
Converts to ASCII via unidecode.
Converts spaces to underscore.
Removes characters that
aren't alphanumerics, underscores, or hyphens.
Preserve case.
Also strips leading and trailing whitespace.
"""
if do_unidecode:
val... | python | def wikipedia_slugify(value, do_unidecode=False):
"""
Converts to ASCII via unidecode.
Converts spaces to underscore.
Removes characters that
aren't alphanumerics, underscores, or hyphens.
Preserve case.
Also strips leading and trailing whitespace.
"""
if do_unidecode:
val... | [
"def",
"wikipedia_slugify",
"(",
"value",
",",
"do_unidecode",
"=",
"False",
")",
":",
"if",
"do_unidecode",
":",
"value",
"=",
"unidecode",
"(",
"value",
")",
"value",
"=",
"value",
".",
"strip",
"(",
")",
"return",
"mark_safe",
"(",
"re",
".",
"sub",
... | Converts to ASCII via unidecode.
Converts spaces to underscore.
Removes characters that
aren't alphanumerics, underscores, or hyphens.
Preserve case.
Also strips leading and trailing whitespace. | [
"Converts",
"to",
"ASCII",
"via",
"unidecode",
".",
"Converts",
"spaces",
"to",
"underscore",
"."
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/glamkit_collections/utils.py#L13-L28 | train |
ic-labs/django-icekit | glamkit_collections/utils.py | ensure_unique | def ensure_unique(qs, field_name, value, exclude_id=None):
"""
Makes sure that `value` is unique on model.fieldname. And nonempty.
"""
orig = value
if not value:
value = "None"
for x in itertools.count(1):
if not qs.exclude(id=exclude_id).filter(**{field_name: value}).exists():
... | python | def ensure_unique(qs, field_name, value, exclude_id=None):
"""
Makes sure that `value` is unique on model.fieldname. And nonempty.
"""
orig = value
if not value:
value = "None"
for x in itertools.count(1):
if not qs.exclude(id=exclude_id).filter(**{field_name: value}).exists():
... | [
"def",
"ensure_unique",
"(",
"qs",
",",
"field_name",
",",
"value",
",",
"exclude_id",
"=",
"None",
")",
":",
"orig",
"=",
"value",
"if",
"not",
"value",
":",
"value",
"=",
"\"None\"",
"for",
"x",
"in",
"itertools",
".",
"count",
"(",
"1",
")",
":",
... | Makes sure that `value` is unique on model.fieldname. And nonempty. | [
"Makes",
"sure",
"that",
"value",
"is",
"unique",
"on",
"model",
".",
"fieldname",
".",
"And",
"nonempty",
"."
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/glamkit_collections/utils.py#L40-L55 | train |
ic-labs/django-icekit | glamkit_collections/utils.py | fix_line_breaks | def fix_line_breaks(s):
"""
Convert \r\n and \r to \n chars. Strip any leading or trailing whitespace
on each line. Remove blank lines.
"""
l = s.splitlines()
x = [i.strip() for i in l]
x = [i for i in x if i] # remove blank lines
return "\n".join(x) | python | def fix_line_breaks(s):
"""
Convert \r\n and \r to \n chars. Strip any leading or trailing whitespace
on each line. Remove blank lines.
"""
l = s.splitlines()
x = [i.strip() for i in l]
x = [i for i in x if i] # remove blank lines
return "\n".join(x) | [
"def",
"fix_line_breaks",
"(",
"s",
")",
":",
"l",
"=",
"s",
".",
"splitlines",
"(",
")",
"x",
"=",
"[",
"i",
".",
"strip",
"(",
")",
"for",
"i",
"in",
"l",
"]",
"x",
"=",
"[",
"i",
"for",
"i",
"in",
"x",
"if",
"i",
"]",
"return",
"\"\\n\""... | Convert \r\n and \r to \n chars. Strip any leading or trailing whitespace
on each line. Remove blank lines. | [
"Convert",
"\\",
"r",
"\\",
"n",
"and",
"\\",
"r",
"to",
"\\",
"n",
"chars",
".",
"Strip",
"any",
"leading",
"or",
"trailing",
"whitespace",
"on",
"each",
"line",
".",
"Remove",
"blank",
"lines",
"."
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/glamkit_collections/utils.py#L69-L77 | train |
ic-labs/django-icekit | glamkit_collections/management/commands/analyze_json.py | update_json_analysis | def update_json_analysis(analysis, j):
"""
Step through the items in a piece of json, and update an analysis dict
with the values found.
"""
def _analyze_list(l, parent=""):
for v in l:
if isinstance(v, (dict, CaseInsensitiveDict)):
_analyze_json(v, parent=parent)... | python | def update_json_analysis(analysis, j):
"""
Step through the items in a piece of json, and update an analysis dict
with the values found.
"""
def _analyze_list(l, parent=""):
for v in l:
if isinstance(v, (dict, CaseInsensitiveDict)):
_analyze_json(v, parent=parent)... | [
"def",
"update_json_analysis",
"(",
"analysis",
",",
"j",
")",
":",
"def",
"_analyze_list",
"(",
"l",
",",
"parent",
"=",
"\"\"",
")",
":",
"for",
"v",
"in",
"l",
":",
"if",
"isinstance",
"(",
"v",
",",
"(",
"dict",
",",
"CaseInsensitiveDict",
")",
"... | Step through the items in a piece of json, and update an analysis dict
with the values found. | [
"Step",
"through",
"the",
"items",
"in",
"a",
"piece",
"of",
"json",
"and",
"update",
"an",
"analysis",
"dict",
"with",
"the",
"values",
"found",
"."
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/glamkit_collections/management/commands/analyze_json.py#L8-L39 | train |
ic-labs/django-icekit | icekit/mixins.py | LayoutFieldMixin.add_missing_placeholders | def add_missing_placeholders(self):
"""
Add missing placeholders from templates. Return `True` if any missing
placeholders were created.
"""
content_type = ContentType.objects.get_for_model(self)
result = False
if self.layout:
for data in self.layout.g... | python | def add_missing_placeholders(self):
"""
Add missing placeholders from templates. Return `True` if any missing
placeholders were created.
"""
content_type = ContentType.objects.get_for_model(self)
result = False
if self.layout:
for data in self.layout.g... | [
"def",
"add_missing_placeholders",
"(",
"self",
")",
":",
"content_type",
"=",
"ContentType",
".",
"objects",
".",
"get_for_model",
"(",
"self",
")",
"result",
"=",
"False",
"if",
"self",
".",
"layout",
":",
"for",
"data",
"in",
"self",
".",
"layout",
".",... | Add missing placeholders from templates. Return `True` if any missing
placeholders were created. | [
"Add",
"missing",
"placeholders",
"from",
"templates",
".",
"Return",
"True",
"if",
"any",
"missing",
"placeholders",
"were",
"created",
"."
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit/mixins.py#L55-L73 | train |
ic-labs/django-icekit | icekit/mixins.py | ListableMixin.get_og_title | def get_og_title(self):
"""
return meta_title if exists otherwise fall back to title
"""
if hasattr(self, 'meta_title') and self.meta_title:
return self.meta_title
return self.get_title() | python | def get_og_title(self):
"""
return meta_title if exists otherwise fall back to title
"""
if hasattr(self, 'meta_title') and self.meta_title:
return self.meta_title
return self.get_title() | [
"def",
"get_og_title",
"(",
"self",
")",
":",
"if",
"hasattr",
"(",
"self",
",",
"'meta_title'",
")",
"and",
"self",
".",
"meta_title",
":",
"return",
"self",
".",
"meta_title",
"return",
"self",
".",
"get_title",
"(",
")"
] | return meta_title if exists otherwise fall back to title | [
"return",
"meta_title",
"if",
"exists",
"otherwise",
"fall",
"back",
"to",
"title"
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit/mixins.py#L213-L219 | train |
ic-labs/django-icekit | icekit/mixins.py | GoogleMapMixin.get_map_data | def get_map_data(self):
"""
Returns a serializable data set describing the map location
"""
return {
'containerSelector': '#' + self.get_map_element_id(),
'center': self.map_center_description,
'marker': self.map_marker_description or self.map_center_... | python | def get_map_data(self):
"""
Returns a serializable data set describing the map location
"""
return {
'containerSelector': '#' + self.get_map_element_id(),
'center': self.map_center_description,
'marker': self.map_marker_description or self.map_center_... | [
"def",
"get_map_data",
"(",
"self",
")",
":",
"return",
"{",
"'containerSelector'",
":",
"'#'",
"+",
"self",
".",
"get_map_element_id",
"(",
")",
",",
"'center'",
":",
"self",
".",
"map_center_description",
",",
"'marker'",
":",
"self",
".",
"map_marker_descri... | Returns a serializable data set describing the map location | [
"Returns",
"a",
"serializable",
"data",
"set",
"describing",
"the",
"map",
"location"
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit/mixins.py#L434-L451 | train |
ic-labs/django-icekit | icekit/mixins.py | GoogleMapMixin.get_map_href | def get_map_href(self):
"""
Returns a link to an external view of the map
"""
if self.map_center_lat and self.map_center_long:
params = {
'll': '%s,%s' % (self.map_center_lat, self.map_center_long)
}
else:
params = {'q': self.ma... | python | def get_map_href(self):
"""
Returns a link to an external view of the map
"""
if self.map_center_lat and self.map_center_long:
params = {
'll': '%s,%s' % (self.map_center_lat, self.map_center_long)
}
else:
params = {'q': self.ma... | [
"def",
"get_map_href",
"(",
"self",
")",
":",
"if",
"self",
".",
"map_center_lat",
"and",
"self",
".",
"map_center_long",
":",
"params",
"=",
"{",
"'ll'",
":",
"'%s,%s'",
"%",
"(",
"self",
".",
"map_center_lat",
",",
"self",
".",
"map_center_long",
")",
... | Returns a link to an external view of the map | [
"Returns",
"a",
"link",
"to",
"an",
"external",
"view",
"of",
"the",
"map"
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit/mixins.py#L453-L464 | train |
ic-labs/django-icekit | icekit_events/utils/timeutils.py | round_datetime | def round_datetime(when=None, precision=60, rounding=ROUND_NEAREST):
"""
Round a datetime object to a time that matches the given precision.
when (datetime), default now
The datetime object to be rounded.
precision (int, timedelta, str), default 60
The number of seconds... | python | def round_datetime(when=None, precision=60, rounding=ROUND_NEAREST):
"""
Round a datetime object to a time that matches the given precision.
when (datetime), default now
The datetime object to be rounded.
precision (int, timedelta, str), default 60
The number of seconds... | [
"def",
"round_datetime",
"(",
"when",
"=",
"None",
",",
"precision",
"=",
"60",
",",
"rounding",
"=",
"ROUND_NEAREST",
")",
":",
"when",
"=",
"when",
"or",
"djtz",
".",
"now",
"(",
")",
"weekday",
"=",
"WEEKDAYS",
".",
"get",
"(",
"precision",
",",
"... | Round a datetime object to a time that matches the given precision.
when (datetime), default now
The datetime object to be rounded.
precision (int, timedelta, str), default 60
The number of seconds, weekday (MON, TUE, WED, etc.) or timedelta
object to which the date... | [
"Round",
"a",
"datetime",
"object",
"to",
"a",
"time",
"that",
"matches",
"the",
"given",
"precision",
"."
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit_events/utils/timeutils.py#L31-L67 | train |
ic-labs/django-icekit | icekit_events/utils/timeutils.py | coerce_dt_awareness | def coerce_dt_awareness(date_or_datetime, tz=None, t=None):
"""
Coerce the given `datetime` or `date` object into a timezone-aware or
timezone-naive `datetime` result, depending on which is appropriate for
the project's settings.
"""
if isinstance(date_or_datetime, datetime):
dt = date_o... | python | def coerce_dt_awareness(date_or_datetime, tz=None, t=None):
"""
Coerce the given `datetime` or `date` object into a timezone-aware or
timezone-naive `datetime` result, depending on which is appropriate for
the project's settings.
"""
if isinstance(date_or_datetime, datetime):
dt = date_o... | [
"def",
"coerce_dt_awareness",
"(",
"date_or_datetime",
",",
"tz",
"=",
"None",
",",
"t",
"=",
"None",
")",
":",
"if",
"isinstance",
"(",
"date_or_datetime",
",",
"datetime",
")",
":",
"dt",
"=",
"date_or_datetime",
"else",
":",
"dt",
"=",
"datetime",
".",
... | Coerce the given `datetime` or `date` object into a timezone-aware or
timezone-naive `datetime` result, depending on which is appropriate for
the project's settings. | [
"Coerce",
"the",
"given",
"datetime",
"or",
"date",
"object",
"into",
"a",
"timezone",
"-",
"aware",
"or",
"timezone",
"-",
"naive",
"datetime",
"result",
"depending",
"on",
"which",
"is",
"appropriate",
"for",
"the",
"project",
"s",
"settings",
"."
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit_events/utils/timeutils.py#L80-L96 | train |
ic-labs/django-icekit | icekit/publishing/utils.py | get_draft_secret_key | def get_draft_secret_key():
"""
Return the secret key used to generate draft mode HMACs. It will be
randomly generated on first access. Existing draft URLs can be invalidated
by deleting or updating the ``DRAFT_SECRET_KEY`` setting.
"""
# TODO: Per URL secret keys, so we can invalidate draft URL... | python | def get_draft_secret_key():
"""
Return the secret key used to generate draft mode HMACs. It will be
randomly generated on first access. Existing draft URLs can be invalidated
by deleting or updating the ``DRAFT_SECRET_KEY`` setting.
"""
# TODO: Per URL secret keys, so we can invalidate draft URL... | [
"def",
"get_draft_secret_key",
"(",
")",
":",
"draft_secret_key",
",",
"created",
"=",
"Text",
".",
"objects",
".",
"get_or_create",
"(",
"name",
"=",
"'DRAFT_SECRET_KEY'",
",",
"defaults",
"=",
"dict",
"(",
"value",
"=",
"get_random_string",
"(",
"50",
")",
... | Return the secret key used to generate draft mode HMACs. It will be
randomly generated on first access. Existing draft URLs can be invalidated
by deleting or updating the ``DRAFT_SECRET_KEY`` setting. | [
"Return",
"the",
"secret",
"key",
"used",
"to",
"generate",
"draft",
"mode",
"HMACs",
".",
"It",
"will",
"be",
"randomly",
"generated",
"on",
"first",
"access",
".",
"Existing",
"draft",
"URLs",
"can",
"be",
"invalidated",
"by",
"deleting",
"or",
"updating",... | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit/publishing/utils.py#L49-L62 | train |
ic-labs/django-icekit | icekit/publishing/utils.py | get_draft_url | def get_draft_url(url):
"""
Return the given URL with a draft mode HMAC in its querystring.
"""
if verify_draft_url(url):
# Nothing to do. Already a valid draft URL.
return url
# Parse querystring and add draft mode HMAC.
url = urlparse.urlparse(url)
salt = get_random_string(... | python | def get_draft_url(url):
"""
Return the given URL with a draft mode HMAC in its querystring.
"""
if verify_draft_url(url):
# Nothing to do. Already a valid draft URL.
return url
# Parse querystring and add draft mode HMAC.
url = urlparse.urlparse(url)
salt = get_random_string(... | [
"def",
"get_draft_url",
"(",
"url",
")",
":",
"if",
"verify_draft_url",
"(",
"url",
")",
":",
"return",
"url",
"url",
"=",
"urlparse",
".",
"urlparse",
"(",
"url",
")",
"salt",
"=",
"get_random_string",
"(",
"5",
")",
"query",
"=",
"QueryDict",
"(",
"f... | Return the given URL with a draft mode HMAC in its querystring. | [
"Return",
"the",
"given",
"URL",
"with",
"a",
"draft",
"mode",
"HMAC",
"in",
"its",
"querystring",
"."
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit/publishing/utils.py#L65-L81 | train |
ic-labs/django-icekit | icekit/publishing/utils.py | verify_draft_url | def verify_draft_url(url):
"""
Return ``True`` if the given URL has a valid draft mode HMAC in its
querystring.
"""
url = urlparse.urlparse(url)
# QueryDict requires a bytestring as its first argument
query = QueryDict(force_bytes(url.query))
# TODO Support legacy 'edit' param name for n... | python | def verify_draft_url(url):
"""
Return ``True`` if the given URL has a valid draft mode HMAC in its
querystring.
"""
url = urlparse.urlparse(url)
# QueryDict requires a bytestring as its first argument
query = QueryDict(force_bytes(url.query))
# TODO Support legacy 'edit' param name for n... | [
"def",
"verify_draft_url",
"(",
"url",
")",
":",
"url",
"=",
"urlparse",
".",
"urlparse",
"(",
"url",
")",
"query",
"=",
"QueryDict",
"(",
"force_bytes",
"(",
"url",
".",
"query",
")",
")",
"preview_hmac",
"=",
"query",
".",
"get",
"(",
"'preview'",
")... | Return ``True`` if the given URL has a valid draft mode HMAC in its
querystring. | [
"Return",
"True",
"if",
"the",
"given",
"URL",
"has",
"a",
"valid",
"draft",
"mode",
"HMAC",
"in",
"its",
"querystring",
"."
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit/publishing/utils.py#L84-L97 | train |
ic-labs/django-icekit | icekit/plugins/descriptors.py | contribute_to_class | def contribute_to_class(model_class, name='slots', descriptor=None):
"""
Function that adds a description to a model Class.
:param model_class: The model class the descriptor is to be added
to.
:param name: The attribute name the descriptor will be assigned to.
:param descriptor: The descriptor... | python | def contribute_to_class(model_class, name='slots', descriptor=None):
"""
Function that adds a description to a model Class.
:param model_class: The model class the descriptor is to be added
to.
:param name: The attribute name the descriptor will be assigned to.
:param descriptor: The descriptor... | [
"def",
"contribute_to_class",
"(",
"model_class",
",",
"name",
"=",
"'slots'",
",",
"descriptor",
"=",
"None",
")",
":",
"rel_obj",
"=",
"descriptor",
"or",
"PlaceholderDescriptor",
"(",
")",
"rel_obj",
".",
"contribute_to_class",
"(",
"model_class",
",",
"name"... | Function that adds a description to a model Class.
:param model_class: The model class the descriptor is to be added
to.
:param name: The attribute name the descriptor will be assigned to.
:param descriptor: The descriptor instance to be used. If none is
specified it will default to
``icekit.pl... | [
"Function",
"that",
"adds",
"a",
"description",
"to",
"a",
"model",
"Class",
"."
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit/plugins/descriptors.py#L100-L115 | train |
ic-labs/django-icekit | icekit/plugins/descriptors.py | PlaceholderDescriptor.create_placeholder_access_object | def create_placeholder_access_object(self, instance):
"""
Created objects with placeholder slots as properties.
Each placeholder created for an object will be added to a
`PlaceHolderAccess` object as a set property.
"""
related_model = self.related_model
def get... | python | def create_placeholder_access_object(self, instance):
"""
Created objects with placeholder slots as properties.
Each placeholder created for an object will be added to a
`PlaceHolderAccess` object as a set property.
"""
related_model = self.related_model
def get... | [
"def",
"create_placeholder_access_object",
"(",
"self",
",",
"instance",
")",
":",
"related_model",
"=",
"self",
".",
"related_model",
"def",
"get_related_model_objects",
"(",
"name",
")",
":",
"return",
"related_model",
".",
"objects",
".",
"get",
"(",
"parent_ty... | Created objects with placeholder slots as properties.
Each placeholder created for an object will be added to a
`PlaceHolderAccess` object as a set property. | [
"Created",
"objects",
"with",
"placeholder",
"slots",
"as",
"properties",
"."
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit/plugins/descriptors.py#L33-L97 | train |
ic-labs/django-icekit | icekit/workflow/admin.py | get_users_for_assigned_to | def get_users_for_assigned_to():
""" Return a list of users who can be assigned to workflow states """
User = get_user_model()
return User.objects.filter(is_active=True, is_staff=True) | python | def get_users_for_assigned_to():
""" Return a list of users who can be assigned to workflow states """
User = get_user_model()
return User.objects.filter(is_active=True, is_staff=True) | [
"def",
"get_users_for_assigned_to",
"(",
")",
":",
"User",
"=",
"get_user_model",
"(",
")",
"return",
"User",
".",
"objects",
".",
"filter",
"(",
"is_active",
"=",
"True",
",",
"is_staff",
"=",
"True",
")"
] | Return a list of users who can be assigned to workflow states | [
"Return",
"a",
"list",
"of",
"users",
"who",
"can",
"be",
"assigned",
"to",
"workflow",
"states"
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit/workflow/admin.py#L11-L14 | train |
ic-labs/django-icekit | icekit/workflow/admin.py | WorkflowMixinAdmin._get_obj_ct | def _get_obj_ct(self, obj):
""" Look up and return object's content type and cache for reuse """
if not hasattr(obj, '_wfct'):
# Use polymorpic content type if available
if hasattr(obj, 'polymorphic_ctype'):
obj._wfct = obj.polymorphic_ctype
else:
... | python | def _get_obj_ct(self, obj):
""" Look up and return object's content type and cache for reuse """
if not hasattr(obj, '_wfct'):
# Use polymorpic content type if available
if hasattr(obj, 'polymorphic_ctype'):
obj._wfct = obj.polymorphic_ctype
else:
... | [
"def",
"_get_obj_ct",
"(",
"self",
",",
"obj",
")",
":",
"if",
"not",
"hasattr",
"(",
"obj",
",",
"'_wfct'",
")",
":",
"if",
"hasattr",
"(",
"obj",
",",
"'polymorphic_ctype'",
")",
":",
"obj",
".",
"_wfct",
"=",
"obj",
".",
"polymorphic_ctype",
"else",... | Look up and return object's content type and cache for reuse | [
"Look",
"up",
"and",
"return",
"object",
"s",
"content",
"type",
"and",
"cache",
"for",
"reuse"
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit/workflow/admin.py#L116-L124 | train |
ic-labs/django-icekit | icekit/workflow/admin.py | WorkflowMixinAdmin.workflow_states_column | def workflow_states_column(self, obj):
""" Return text description of workflow states assigned to object """
workflow_states = models.WorkflowState.objects.filter(
content_type=self._get_obj_ct(obj),
object_id=obj.pk,
)
return ', '.join([unicode(wfs) for wfs in wo... | python | def workflow_states_column(self, obj):
""" Return text description of workflow states assigned to object """
workflow_states = models.WorkflowState.objects.filter(
content_type=self._get_obj_ct(obj),
object_id=obj.pk,
)
return ', '.join([unicode(wfs) for wfs in wo... | [
"def",
"workflow_states_column",
"(",
"self",
",",
"obj",
")",
":",
"workflow_states",
"=",
"models",
".",
"WorkflowState",
".",
"objects",
".",
"filter",
"(",
"content_type",
"=",
"self",
".",
"_get_obj_ct",
"(",
"obj",
")",
",",
"object_id",
"=",
"obj",
... | Return text description of workflow states assigned to object | [
"Return",
"text",
"description",
"of",
"workflow",
"states",
"assigned",
"to",
"object"
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit/workflow/admin.py#L126-L132 | train |
ic-labs/django-icekit | icekit/workflow/admin.py | WorkflowMixinAdmin.created_by_column | def created_by_column(self, obj):
""" Return user who first created an item in Django admin """
try:
first_addition_logentry = admin.models.LogEntry.objects.filter(
object_id=obj.pk,
content_type_id=self._get_obj_ct(obj).pk,
action_flag=admin.m... | python | def created_by_column(self, obj):
""" Return user who first created an item in Django admin """
try:
first_addition_logentry = admin.models.LogEntry.objects.filter(
object_id=obj.pk,
content_type_id=self._get_obj_ct(obj).pk,
action_flag=admin.m... | [
"def",
"created_by_column",
"(",
"self",
",",
"obj",
")",
":",
"try",
":",
"first_addition_logentry",
"=",
"admin",
".",
"models",
".",
"LogEntry",
".",
"objects",
".",
"filter",
"(",
"object_id",
"=",
"obj",
".",
"pk",
",",
"content_type_id",
"=",
"self",... | Return user who first created an item in Django admin | [
"Return",
"user",
"who",
"first",
"created",
"an",
"item",
"in",
"Django",
"admin"
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit/workflow/admin.py#L135-L145 | train |
ic-labs/django-icekit | icekit/utils/fluent_contents.py | create_content_instance | def create_content_instance(content_plugin_class, page, placeholder_name='main', **kwargs):
"""
Creates a content instance from a content plugin class.
:param content_plugin_class: The class of the content plugin.
:param page: The fluent_page instance to create the content
instance one.
:param ... | python | def create_content_instance(content_plugin_class, page, placeholder_name='main', **kwargs):
"""
Creates a content instance from a content plugin class.
:param content_plugin_class: The class of the content plugin.
:param page: The fluent_page instance to create the content
instance one.
:param ... | [
"def",
"create_content_instance",
"(",
"content_plugin_class",
",",
"page",
",",
"placeholder_name",
"=",
"'main'",
",",
"**",
"kwargs",
")",
":",
"placeholders",
"=",
"page",
".",
"get_placeholder_by_slot",
"(",
"placeholder_name",
")",
"if",
"placeholders",
".",
... | Creates a content instance from a content plugin class.
:param content_plugin_class: The class of the content plugin.
:param page: The fluent_page instance to create the content
instance one.
:param placeholder_name: The placeholder name defined in the
template. [DEFAULT: main]
:param kwargs: A... | [
"Creates",
"a",
"content",
"instance",
"from",
"a",
"content",
"plugin",
"class",
"."
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit/utils/fluent_contents.py#L7-L46 | train |
peterbe/hashin | hashin.py | expand_python_version | def expand_python_version(version):
"""
Expand Python versions to all identifiers used on PyPI.
>>> expand_python_version('3.5')
['3.5', 'py3', 'py2.py3', 'cp35']
"""
if not re.match(r"^\d\.\d$", version):
return [version]
major, minor = version.split(".")
patterns = [
... | python | def expand_python_version(version):
"""
Expand Python versions to all identifiers used on PyPI.
>>> expand_python_version('3.5')
['3.5', 'py3', 'py2.py3', 'cp35']
"""
if not re.match(r"^\d\.\d$", version):
return [version]
major, minor = version.split(".")
patterns = [
... | [
"def",
"expand_python_version",
"(",
"version",
")",
":",
"if",
"not",
"re",
".",
"match",
"(",
"r\"^\\d\\.\\d$\"",
",",
"version",
")",
":",
"return",
"[",
"version",
"]",
"major",
",",
"minor",
"=",
"version",
".",
"split",
"(",
"\".\"",
")",
"patterns... | Expand Python versions to all identifiers used on PyPI.
>>> expand_python_version('3.5')
['3.5', 'py3', 'py2.py3', 'cp35'] | [
"Expand",
"Python",
"versions",
"to",
"all",
"identifiers",
"used",
"on",
"PyPI",
"."
] | c3efcba050961257622c475114c087efe675c58a | https://github.com/peterbe/hashin/blob/c3efcba050961257622c475114c087efe675c58a/hashin.py#L464-L484 | train |
peterbe/hashin | hashin.py | get_package_hashes | def get_package_hashes(
package,
version=None,
algorithm=DEFAULT_ALGORITHM,
python_versions=(),
verbose=False,
include_prereleases=False,
lookup_memory=None,
index_url=DEFAULT_INDEX_URL,
):
"""
Gets the hashes for the given package.
>>> get_package_hashes('hashin')
{
... | python | def get_package_hashes(
package,
version=None,
algorithm=DEFAULT_ALGORITHM,
python_versions=(),
verbose=False,
include_prereleases=False,
lookup_memory=None,
index_url=DEFAULT_INDEX_URL,
):
"""
Gets the hashes for the given package.
>>> get_package_hashes('hashin')
{
... | [
"def",
"get_package_hashes",
"(",
"package",
",",
"version",
"=",
"None",
",",
"algorithm",
"=",
"DEFAULT_ALGORITHM",
",",
"python_versions",
"=",
"(",
")",
",",
"verbose",
"=",
"False",
",",
"include_prereleases",
"=",
"False",
",",
"lookup_memory",
"=",
"Non... | Gets the hashes for the given package.
>>> get_package_hashes('hashin')
{
'package': 'hashin',
'version': '0.10',
'hashes': [
{
'url': 'https://pypi.org/packages/[...]',
'hash': '45d1c5d2237a3b4f78b4198709fb2ecf[...]'
},
... | [
"Gets",
"the",
"hashes",
"for",
"the",
"given",
"package",
"."
] | c3efcba050961257622c475114c087efe675c58a | https://github.com/peterbe/hashin/blob/c3efcba050961257622c475114c087efe675c58a/hashin.py#L621-L688 | train |
ic-labs/django-icekit | icekit/fields.py | TemplateNameField.formfield | def formfield(self, **kwargs):
"""
Get choices from plugins, if necessary.
"""
if self.plugin_class:
self._choices = self.plugin_class.get_all_choices(field=self)
return super(TemplateNameField, self).formfield(**kwargs) | python | def formfield(self, **kwargs):
"""
Get choices from plugins, if necessary.
"""
if self.plugin_class:
self._choices = self.plugin_class.get_all_choices(field=self)
return super(TemplateNameField, self).formfield(**kwargs) | [
"def",
"formfield",
"(",
"self",
",",
"**",
"kwargs",
")",
":",
"if",
"self",
".",
"plugin_class",
":",
"self",
".",
"_choices",
"=",
"self",
".",
"plugin_class",
".",
"get_all_choices",
"(",
"field",
"=",
"self",
")",
"return",
"super",
"(",
"TemplateNa... | Get choices from plugins, if necessary. | [
"Get",
"choices",
"from",
"plugins",
"if",
"necessary",
"."
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit/fields.py#L39-L45 | train |
ic-labs/django-icekit | icekit/fields.py | ICEkitURLField.register_model_once | def register_model_once(cls, ModelClass, **kwargs):
"""
Tweaked version of `AnyUrlField.register_model` that only registers the
given model after checking that it is not already registered.
"""
if cls._static_registry.get_for_model(ModelClass) is None:
logger.warn("Mo... | python | def register_model_once(cls, ModelClass, **kwargs):
"""
Tweaked version of `AnyUrlField.register_model` that only registers the
given model after checking that it is not already registered.
"""
if cls._static_registry.get_for_model(ModelClass) is None:
logger.warn("Mo... | [
"def",
"register_model_once",
"(",
"cls",
",",
"ModelClass",
",",
"**",
"kwargs",
")",
":",
"if",
"cls",
".",
"_static_registry",
".",
"get_for_model",
"(",
"ModelClass",
")",
"is",
"None",
":",
"logger",
".",
"warn",
"(",
"\"Model is already registered with {0}... | Tweaked version of `AnyUrlField.register_model` that only registers the
given model after checking that it is not already registered. | [
"Tweaked",
"version",
"of",
"AnyUrlField",
".",
"register_model",
"that",
"only",
"registers",
"the",
"given",
"model",
"after",
"checking",
"that",
"it",
"is",
"not",
"already",
"registered",
"."
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit/fields.py#L54-L63 | train |
ic-labs/django-icekit | icekit/admin_tools/templatetags/dashboard_tags.py | filter_featured_apps | def filter_featured_apps(admin_apps, request):
"""
Given a list of apps return a set of pseudo-apps considered featured.
Apps are considered featured if the are defined in the settings
property called `DASHBOARD_FEATURED_APPS` which contains a list of the apps
that are considered to be featured.
... | python | def filter_featured_apps(admin_apps, request):
"""
Given a list of apps return a set of pseudo-apps considered featured.
Apps are considered featured if the are defined in the settings
property called `DASHBOARD_FEATURED_APPS` which contains a list of the apps
that are considered to be featured.
... | [
"def",
"filter_featured_apps",
"(",
"admin_apps",
",",
"request",
")",
":",
"featured_apps",
"=",
"[",
"]",
"for",
"orig_app_spec",
"in",
"appsettings",
".",
"DASHBOARD_FEATURED_APPS",
":",
"app_spec",
"=",
"orig_app_spec",
".",
"copy",
"(",
")",
"if",
"\"verbos... | Given a list of apps return a set of pseudo-apps considered featured.
Apps are considered featured if the are defined in the settings
property called `DASHBOARD_FEATURED_APPS` which contains a list of the apps
that are considered to be featured.
:param admin_apps: A list of apps.
:param request: D... | [
"Given",
"a",
"list",
"of",
"apps",
"return",
"a",
"set",
"of",
"pseudo",
"-",
"apps",
"considered",
"featured",
"."
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit/admin_tools/templatetags/dashboard_tags.py#L63-L109 | train |
ic-labs/django-icekit | icekit/admin_tools/templatetags/dashboard_tags.py | _remove_app_models | def _remove_app_models(all_apps, models_to_remove):
"""
Remove the model specs in models_to_remove from the models specs in the
apps in all_apps. If an app has no models left, don't include it in the
output.
This has the side-effect that the app view e.g. /admin/app/ may not be
accessible from ... | python | def _remove_app_models(all_apps, models_to_remove):
"""
Remove the model specs in models_to_remove from the models specs in the
apps in all_apps. If an app has no models left, don't include it in the
output.
This has the side-effect that the app view e.g. /admin/app/ may not be
accessible from ... | [
"def",
"_remove_app_models",
"(",
"all_apps",
",",
"models_to_remove",
")",
":",
"filtered_apps",
"=",
"[",
"]",
"for",
"app",
"in",
"all_apps",
":",
"models",
"=",
"[",
"x",
"for",
"x",
"in",
"app",
"[",
"'models'",
"]",
"if",
"x",
"not",
"in",
"model... | Remove the model specs in models_to_remove from the models specs in the
apps in all_apps. If an app has no models left, don't include it in the
output.
This has the side-effect that the app view e.g. /admin/app/ may not be
accessible from the dashboard, only the breadcrumbs. | [
"Remove",
"the",
"model",
"specs",
"in",
"models_to_remove",
"from",
"the",
"models",
"specs",
"in",
"the",
"apps",
"in",
"all_apps",
".",
"If",
"an",
"app",
"has",
"no",
"models",
"left",
"don",
"t",
"include",
"it",
"in",
"the",
"output",
"."
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit/admin_tools/templatetags/dashboard_tags.py#L112-L130 | train |
ic-labs/django-icekit | icekit/admin_tools/templatetags/dashboard_tags.py | filter_sorted_apps | def filter_sorted_apps(admin_apps, request):
"""
Filter admin_apps to show the ones in ``DASHBOARD_SORTED_APPS`` first,
and remove them from the subsequent listings.
"""
sorted_apps = []
for orig_app_spec in appsettings.DASHBOARD_SORTED_APPS:
# make a copy that we can write to, to fix ... | python | def filter_sorted_apps(admin_apps, request):
"""
Filter admin_apps to show the ones in ``DASHBOARD_SORTED_APPS`` first,
and remove them from the subsequent listings.
"""
sorted_apps = []
for orig_app_spec in appsettings.DASHBOARD_SORTED_APPS:
# make a copy that we can write to, to fix ... | [
"def",
"filter_sorted_apps",
"(",
"admin_apps",
",",
"request",
")",
":",
"sorted_apps",
"=",
"[",
"]",
"for",
"orig_app_spec",
"in",
"appsettings",
".",
"DASHBOARD_SORTED_APPS",
":",
"app_spec",
"=",
"orig_app_spec",
".",
"copy",
"(",
")",
"app_spec",
"[",
"'... | Filter admin_apps to show the ones in ``DASHBOARD_SORTED_APPS`` first,
and remove them from the subsequent listings. | [
"Filter",
"admin_apps",
"to",
"show",
"the",
"ones",
"in",
"DASHBOARD_SORTED_APPS",
"first",
"and",
"remove",
"them",
"from",
"the",
"subsequent",
"listings",
"."
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit/admin_tools/templatetags/dashboard_tags.py#L134-L160 | train |
ic-labs/django-icekit | icekit/admin_tools/mixins.py | FluentLayoutsMixin.formfield_for_foreignkey | def formfield_for_foreignkey(self, db_field, *args, **kwargs):
"""
Update queryset for ``layout`` field.
"""
formfield = super(FluentLayoutsMixin, self).formfield_for_foreignkey(
db_field, *args, **kwargs)
if db_field.name == 'layout':
formfield.queryset =... | python | def formfield_for_foreignkey(self, db_field, *args, **kwargs):
"""
Update queryset for ``layout`` field.
"""
formfield = super(FluentLayoutsMixin, self).formfield_for_foreignkey(
db_field, *args, **kwargs)
if db_field.name == 'layout':
formfield.queryset =... | [
"def",
"formfield_for_foreignkey",
"(",
"self",
",",
"db_field",
",",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"formfield",
"=",
"super",
"(",
"FluentLayoutsMixin",
",",
"self",
")",
".",
"formfield_for_foreignkey",
"(",
"db_field",
",",
"*",
"args",
",",... | Update queryset for ``layout`` field. | [
"Update",
"queryset",
"for",
"layout",
"field",
"."
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit/admin_tools/mixins.py#L36-L44 | train |
ic-labs/django-icekit | icekit/admin_tools/mixins.py | FluentLayoutsMixin.get_placeholder_data | def get_placeholder_data(self, request, obj):
"""
Get placeholder data from layout.
"""
if not obj or not getattr(obj, 'layout', None):
data = [PlaceholderData(slot='main', role='m', title='Main')]
else:
data = obj.layout.get_placeholder_data()
ret... | python | def get_placeholder_data(self, request, obj):
"""
Get placeholder data from layout.
"""
if not obj or not getattr(obj, 'layout', None):
data = [PlaceholderData(slot='main', role='m', title='Main')]
else:
data = obj.layout.get_placeholder_data()
ret... | [
"def",
"get_placeholder_data",
"(",
"self",
",",
"request",
",",
"obj",
")",
":",
"if",
"not",
"obj",
"or",
"not",
"getattr",
"(",
"obj",
",",
"'layout'",
",",
"None",
")",
":",
"data",
"=",
"[",
"PlaceholderData",
"(",
"slot",
"=",
"'main'",
",",
"r... | Get placeholder data from layout. | [
"Get",
"placeholder",
"data",
"from",
"layout",
"."
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit/admin_tools/mixins.py#L46-L54 | train |
ic-labs/django-icekit | icekit/admin_tools/mixins.py | ThumbnailAdminMixin.get_thumbnail_source | def get_thumbnail_source(self, obj):
"""
Obtains the source image field for the thumbnail.
:param obj: An object with a thumbnail_field defined.
:return: Image field for thumbnail or None if not found.
"""
if hasattr(self, 'thumbnail_field') and self.thumbnail_field:
... | python | def get_thumbnail_source(self, obj):
"""
Obtains the source image field for the thumbnail.
:param obj: An object with a thumbnail_field defined.
:return: Image field for thumbnail or None if not found.
"""
if hasattr(self, 'thumbnail_field') and self.thumbnail_field:
... | [
"def",
"get_thumbnail_source",
"(",
"self",
",",
"obj",
")",
":",
"if",
"hasattr",
"(",
"self",
",",
"'thumbnail_field'",
")",
"and",
"self",
".",
"thumbnail_field",
":",
"return",
"resolve",
"(",
"obj",
",",
"self",
".",
"thumbnail_field",
")",
"if",
"has... | Obtains the source image field for the thumbnail.
:param obj: An object with a thumbnail_field defined.
:return: Image field for thumbnail or None if not found. | [
"Obtains",
"the",
"source",
"image",
"field",
"for",
"the",
"thumbnail",
"."
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit/admin_tools/mixins.py#L134-L149 | train |
ic-labs/django-icekit | icekit/admin_tools/mixins.py | ThumbnailAdminMixin.preview | def preview(self, obj, request=None):
"""
Generate the HTML to display for the image.
:param obj: An object with a thumbnail_field defined.
:return: HTML for image display.
"""
source = self.get_thumbnail_source(obj)
if source:
try:
fr... | python | def preview(self, obj, request=None):
"""
Generate the HTML to display for the image.
:param obj: An object with a thumbnail_field defined.
:return: HTML for image display.
"""
source = self.get_thumbnail_source(obj)
if source:
try:
fr... | [
"def",
"preview",
"(",
"self",
",",
"obj",
",",
"request",
"=",
"None",
")",
":",
"source",
"=",
"self",
".",
"get_thumbnail_source",
"(",
"obj",
")",
"if",
"source",
":",
"try",
":",
"from",
"easy_thumbnails",
".",
"files",
"import",
"get_thumbnailer",
... | Generate the HTML to display for the image.
:param obj: An object with a thumbnail_field defined.
:return: HTML for image display. | [
"Generate",
"the",
"HTML",
"to",
"display",
"for",
"the",
"image",
"."
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit/admin_tools/mixins.py#L151-L181 | train |
ic-labs/django-icekit | icekit/tasks.py | one_instance | def one_instance(function=None, key='', timeout=DEFAULT_ONE_INSTANCE_TIMEOUT):
"""
Decorator to enforce only one Celery task execution at a time when multiple
workers are available.
See http://loose-bits.com/2010/10/distributed-task-locking-in-celery.html
"""
def _dec(run_func):
def _ca... | python | def one_instance(function=None, key='', timeout=DEFAULT_ONE_INSTANCE_TIMEOUT):
"""
Decorator to enforce only one Celery task execution at a time when multiple
workers are available.
See http://loose-bits.com/2010/10/distributed-task-locking-in-celery.html
"""
def _dec(run_func):
def _ca... | [
"def",
"one_instance",
"(",
"function",
"=",
"None",
",",
"key",
"=",
"''",
",",
"timeout",
"=",
"DEFAULT_ONE_INSTANCE_TIMEOUT",
")",
":",
"def",
"_dec",
"(",
"run_func",
")",
":",
"def",
"_caller",
"(",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"ret... | Decorator to enforce only one Celery task execution at a time when multiple
workers are available.
See http://loose-bits.com/2010/10/distributed-task-locking-in-celery.html | [
"Decorator",
"to",
"enforce",
"only",
"one",
"Celery",
"task",
"execution",
"at",
"a",
"time",
"when",
"multiple",
"workers",
"are",
"available",
"."
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit/tasks.py#L28-L63 | train |
ic-labs/django-icekit | icekit/search_indexes.py | PageIndex.index_queryset | def index_queryset(self, using=None):
"""
Index current language translation of published objects.
TODO: Find a way to index all translations of the given model, not just
the current site language's translation.
"""
translation.activate(settings.LANGUAGE_CODE)
re... | python | def index_queryset(self, using=None):
"""
Index current language translation of published objects.
TODO: Find a way to index all translations of the given model, not just
the current site language's translation.
"""
translation.activate(settings.LANGUAGE_CODE)
re... | [
"def",
"index_queryset",
"(",
"self",
",",
"using",
"=",
"None",
")",
":",
"translation",
".",
"activate",
"(",
"settings",
".",
"LANGUAGE_CODE",
")",
"return",
"self",
".",
"get_model",
"(",
")",
".",
"objects",
".",
"filter",
"(",
"status",
"=",
"UrlNo... | Index current language translation of published objects.
TODO: Find a way to index all translations of the given model, not just
the current site language's translation. | [
"Index",
"current",
"language",
"translation",
"of",
"published",
"objects",
"."
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit/search_indexes.py#L15-L23 | train |
ic-labs/django-icekit | icekit/content_collections/page_type_plugins.py | ListingPagePlugin.get_context | def get_context(self, request, page, **kwargs):
""" Include in context items to be visible on listing page """
context = super(ListingPagePlugin, self).get_context(
request, page, **kwargs)
context['items_to_list'] = page.get_items_to_list(request)
return context | python | def get_context(self, request, page, **kwargs):
""" Include in context items to be visible on listing page """
context = super(ListingPagePlugin, self).get_context(
request, page, **kwargs)
context['items_to_list'] = page.get_items_to_list(request)
return context | [
"def",
"get_context",
"(",
"self",
",",
"request",
",",
"page",
",",
"**",
"kwargs",
")",
":",
"context",
"=",
"super",
"(",
"ListingPagePlugin",
",",
"self",
")",
".",
"get_context",
"(",
"request",
",",
"page",
",",
"**",
"kwargs",
")",
"context",
"[... | Include in context items to be visible on listing page | [
"Include",
"in",
"context",
"items",
"to",
"be",
"visible",
"on",
"listing",
"page"
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit/content_collections/page_type_plugins.py#L13-L18 | train |
ic-labs/django-icekit | icekit/content_collections/page_type_plugins.py | ListingPagePlugin.get_view_response | def get_view_response(self, request, page, view_func, view_args, view_kwargs):
"""
Render the custom view that was exposed by the extra plugin URL patterns.
This gives the ability to add extra middleware logic.
"""
return view_func(request, page, *view_args, **view_kwargs) | python | def get_view_response(self, request, page, view_func, view_args, view_kwargs):
"""
Render the custom view that was exposed by the extra plugin URL patterns.
This gives the ability to add extra middleware logic.
"""
return view_func(request, page, *view_args, **view_kwargs) | [
"def",
"get_view_response",
"(",
"self",
",",
"request",
",",
"page",
",",
"view_func",
",",
"view_args",
",",
"view_kwargs",
")",
":",
"return",
"view_func",
"(",
"request",
",",
"page",
",",
"*",
"view_args",
",",
"**",
"view_kwargs",
")"
] | Render the custom view that was exposed by the extra plugin URL patterns.
This gives the ability to add extra middleware logic. | [
"Render",
"the",
"custom",
"view",
"that",
"was",
"exposed",
"by",
"the",
"extra",
"plugin",
"URL",
"patterns",
".",
"This",
"gives",
"the",
"ability",
"to",
"add",
"extra",
"middleware",
"logic",
"."
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit/content_collections/page_type_plugins.py#L20-L25 | train |
ic-labs/django-icekit | icekit/publishing/admin.py | PublishingAdminForm.clean | def clean(self):
"""
Additional clean data checks for path and keys.
These are not cleaned in their respective methods e.g.
`clean_slug` as they depend upon other field data.
:return: Cleaned data.
"""
data = super(PublishingAdminForm, self).clean()
clea... | python | def clean(self):
"""
Additional clean data checks for path and keys.
These are not cleaned in their respective methods e.g.
`clean_slug` as they depend upon other field data.
:return: Cleaned data.
"""
data = super(PublishingAdminForm, self).clean()
clea... | [
"def",
"clean",
"(",
"self",
")",
":",
"data",
"=",
"super",
"(",
"PublishingAdminForm",
",",
"self",
")",
".",
"clean",
"(",
")",
"cleaned_data",
"=",
"self",
".",
"cleaned_data",
"instance",
"=",
"self",
".",
"instance",
"unique_fields_set",
"=",
"instan... | Additional clean data checks for path and keys.
These are not cleaned in their respective methods e.g.
`clean_slug` as they depend upon other field data.
:return: Cleaned data. | [
"Additional",
"clean",
"data",
"checks",
"for",
"path",
"and",
"keys",
"."
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit/publishing/admin.py#L189-L235 | train |
ic-labs/django-icekit | icekit/publishing/admin.py | _PublishingHelpersMixin.has_publish_permission | def has_publish_permission(self, request, obj=None):
"""
Determines if the user has permissions to publish.
:param request: Django request object.
:param obj: The object to determine if the user has
permissions to publish.
:return: Boolean.
"""
# If auto-... | python | def has_publish_permission(self, request, obj=None):
"""
Determines if the user has permissions to publish.
:param request: Django request object.
:param obj: The object to determine if the user has
permissions to publish.
:return: Boolean.
"""
# If auto-... | [
"def",
"has_publish_permission",
"(",
"self",
",",
"request",
",",
"obj",
"=",
"None",
")",
":",
"if",
"is_automatic_publishing_enabled",
"(",
"self",
".",
"model",
")",
":",
"return",
"False",
"user_obj",
"=",
"request",
".",
"user",
"if",
"not",
"user_obj"... | Determines if the user has permissions to publish.
:param request: Django request object.
:param obj: The object to determine if the user has
permissions to publish.
:return: Boolean. | [
"Determines",
"if",
"the",
"user",
"has",
"permissions",
"to",
"publish",
"."
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit/publishing/admin.py#L283-L310 | train |
ic-labs/django-icekit | icekit/publishing/admin.py | _PublishingHelpersMixin.has_preview_permission | def has_preview_permission(self, request, obj=None):
"""
Return `True` if the user has permissions to preview a publishable
item.
NOTE: this method does not actually change who can or cannot preview
any particular item, just whether to show the preview link. The real
dci... | python | def has_preview_permission(self, request, obj=None):
"""
Return `True` if the user has permissions to preview a publishable
item.
NOTE: this method does not actually change who can or cannot preview
any particular item, just whether to show the preview link. The real
dci... | [
"def",
"has_preview_permission",
"(",
"self",
",",
"request",
",",
"obj",
"=",
"None",
")",
":",
"if",
"self",
".",
"has_publish_permission",
"(",
"request",
",",
"obj",
"=",
"obj",
")",
":",
"return",
"True",
"user_obj",
"=",
"request",
".",
"user",
"if... | Return `True` if the user has permissions to preview a publishable
item.
NOTE: this method does not actually change who can or cannot preview
any particular item, just whether to show the preview link. The real
dcision is made by a combination of:
- `PublishingMiddleware` which... | [
"Return",
"True",
"if",
"the",
"user",
"has",
"permissions",
"to",
"preview",
"a",
"publishable",
"item",
"."
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit/publishing/admin.py#L312-L337 | train |
ic-labs/django-icekit | icekit/publishing/admin.py | _PublishingHelpersMixin.publishing_column | def publishing_column(self, obj):
"""
Render publishing-related status icons and view links for display in
the admin.
"""
# TODO Hack to convert polymorphic objects to real instances
if hasattr(obj, 'get_real_instance'):
obj = obj.get_real_instance()
... | python | def publishing_column(self, obj):
"""
Render publishing-related status icons and view links for display in
the admin.
"""
# TODO Hack to convert polymorphic objects to real instances
if hasattr(obj, 'get_real_instance'):
obj = obj.get_real_instance()
... | [
"def",
"publishing_column",
"(",
"self",
",",
"obj",
")",
":",
"if",
"hasattr",
"(",
"obj",
",",
"'get_real_instance'",
")",
":",
"obj",
"=",
"obj",
".",
"get_real_instance",
"(",
")",
"try",
":",
"object_url",
"=",
"obj",
".",
"get_absolute_url",
"(",
"... | Render publishing-related status icons and view links for display in
the admin. | [
"Render",
"publishing",
"-",
"related",
"status",
"icons",
"and",
"view",
"links",
"for",
"display",
"in",
"the",
"admin",
"."
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit/publishing/admin.py#L339-L371 | train |
ic-labs/django-icekit | icekit/publishing/admin.py | _PublishingHelpersMixin.publish | def publish(self, request, qs):
""" Publish bulk action """
# Convert polymorphic queryset instances to real ones if/when necessary
try:
qs = self.model.objects.get_real_instances(qs)
except AttributeError:
pass
for q in qs:
if self.has_publish... | python | def publish(self, request, qs):
""" Publish bulk action """
# Convert polymorphic queryset instances to real ones if/when necessary
try:
qs = self.model.objects.get_real_instances(qs)
except AttributeError:
pass
for q in qs:
if self.has_publish... | [
"def",
"publish",
"(",
"self",
",",
"request",
",",
"qs",
")",
":",
"try",
":",
"qs",
"=",
"self",
".",
"model",
".",
"objects",
".",
"get_real_instances",
"(",
"qs",
")",
"except",
"AttributeError",
":",
"pass",
"for",
"q",
"in",
"qs",
":",
"if",
... | Publish bulk action | [
"Publish",
"bulk",
"action"
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit/publishing/admin.py#L375-L384 | train |
ic-labs/django-icekit | icekit/publishing/admin.py | _PublishingHelpersMixin.unpublish | def unpublish(self, request, qs):
""" Unpublish bulk action """
# Convert polymorphic queryset instances to real ones if/when necessary
try:
qs = self.model.objects.get_real_instances(qs)
except AttributeError:
pass
for q in qs:
q.unpublish() | python | def unpublish(self, request, qs):
""" Unpublish bulk action """
# Convert polymorphic queryset instances to real ones if/when necessary
try:
qs = self.model.objects.get_real_instances(qs)
except AttributeError:
pass
for q in qs:
q.unpublish() | [
"def",
"unpublish",
"(",
"self",
",",
"request",
",",
"qs",
")",
":",
"try",
":",
"qs",
"=",
"self",
".",
"model",
".",
"objects",
".",
"get_real_instances",
"(",
"qs",
")",
"except",
"AttributeError",
":",
"pass",
"for",
"q",
"in",
"qs",
":",
"q",
... | Unpublish bulk action | [
"Unpublish",
"bulk",
"action"
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit/publishing/admin.py#L386-L394 | train |
ic-labs/django-icekit | icekit/publishing/admin.py | PublishingAdmin.find_first_available_template | def find_first_available_template(self, template_name_list):
"""
Given a list of template names, find the first one that actually exists
and is available.
"""
if isinstance(template_name_list, six.string_types):
return template_name_list
else:
# Ta... | python | def find_first_available_template(self, template_name_list):
"""
Given a list of template names, find the first one that actually exists
and is available.
"""
if isinstance(template_name_list, six.string_types):
return template_name_list
else:
# Ta... | [
"def",
"find_first_available_template",
"(",
"self",
",",
"template_name_list",
")",
":",
"if",
"isinstance",
"(",
"template_name_list",
",",
"six",
".",
"string_types",
")",
":",
"return",
"template_name_list",
"else",
":",
"return",
"_select_template_name",
"(",
"... | Given a list of template names, find the first one that actually exists
and is available. | [
"Given",
"a",
"list",
"of",
"template",
"names",
"find",
"the",
"first",
"one",
"that",
"actually",
"exists",
"and",
"is",
"available",
"."
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit/publishing/admin.py#L436-L445 | train |
ic-labs/django-icekit | icekit/publishing/admin.py | PublishingAdmin.get_queryset | def get_queryset(self, request):
"""
The queryset to use for the administration list page.
:param request: Django request object.
:return: QuerySet.
"""
# TODO Can we remove this hack?
self.request = request
# Obtain the full queryset defined on the regi... | python | def get_queryset(self, request):
"""
The queryset to use for the administration list page.
:param request: Django request object.
:return: QuerySet.
"""
# TODO Can we remove this hack?
self.request = request
# Obtain the full queryset defined on the regi... | [
"def",
"get_queryset",
"(",
"self",
",",
"request",
")",
":",
"self",
".",
"request",
"=",
"request",
"qs",
"=",
"self",
".",
"model",
".",
"objects",
"try",
":",
"qs_language",
"=",
"self",
".",
"get_queryset_language",
"(",
"request",
")",
"if",
"qs_la... | The queryset to use for the administration list page.
:param request: Django request object.
:return: QuerySet. | [
"The",
"queryset",
"to",
"use",
"for",
"the",
"administration",
"list",
"page",
"."
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit/publishing/admin.py#L455-L486 | train |
ic-labs/django-icekit | icekit/publishing/admin.py | PublishingAdmin.save_related | def save_related(self, request, form, *args, **kwargs):
"""
Send the signal `publishing_post_save_related` when a draft copy is
saved and all its relationships have also been created.
"""
result = super(PublishingAdmin, self) \
.save_related(request, form, *args, **kw... | python | def save_related(self, request, form, *args, **kwargs):
"""
Send the signal `publishing_post_save_related` when a draft copy is
saved and all its relationships have also been created.
"""
result = super(PublishingAdmin, self) \
.save_related(request, form, *args, **kw... | [
"def",
"save_related",
"(",
"self",
",",
"request",
",",
"form",
",",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"result",
"=",
"super",
"(",
"PublishingAdmin",
",",
"self",
")",
".",
"save_related",
"(",
"request",
",",
"form",
",",
"*",
"args",
",... | Send the signal `publishing_post_save_related` when a draft copy is
saved and all its relationships have also been created. | [
"Send",
"the",
"signal",
"publishing_post_save_related",
"when",
"a",
"draft",
"copy",
"is",
"saved",
"and",
"all",
"its",
"relationships",
"have",
"also",
"been",
"created",
"."
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit/publishing/admin.py#L577-L588 | train |
ic-labs/django-icekit | icekit/publishing/admin.py | PublishingAdmin.render_change_form | def render_change_form(self, request, context, add=False, change=False,
form_url='', obj=None):
"""
Provides the context and rendering for the admin change form.
:param request: Django request object.
:param context: The context dictionary to be passed to the ... | python | def render_change_form(self, request, context, add=False, change=False,
form_url='', obj=None):
"""
Provides the context and rendering for the admin change form.
:param request: Django request object.
:param context: The context dictionary to be passed to the ... | [
"def",
"render_change_form",
"(",
"self",
",",
"request",
",",
"context",
",",
"add",
"=",
"False",
",",
"change",
"=",
"False",
",",
"form_url",
"=",
"''",
",",
"obj",
"=",
"None",
")",
":",
"obj",
"=",
"context",
".",
"get",
"(",
"'original'",
",",... | Provides the context and rendering for the admin change form.
:param request: Django request object.
:param context: The context dictionary to be passed to the template.
:param add: Should the add form be rendered? Boolean input.
:param change: Should the change for be rendered? Boolean... | [
"Provides",
"the",
"context",
"and",
"rendering",
"for",
"the",
"admin",
"change",
"form",
"."
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit/publishing/admin.py#L590-L724 | train |
ic-labs/django-icekit | icekit/publishing/admin.py | PublishingFluentPagesParentAdminMixin.get_queryset | def get_queryset(self, request):
"""
Show only DRAFT Fluent page items in admin.
NOTE: We rely on the `UrlNode.status` to recognise DRAFT versus
PUBLISHED objects, since there the top-level `UrlNode` model and
queryset don't know about ICEKit publishing.
"""
self... | python | def get_queryset(self, request):
"""
Show only DRAFT Fluent page items in admin.
NOTE: We rely on the `UrlNode.status` to recognise DRAFT versus
PUBLISHED objects, since there the top-level `UrlNode` model and
queryset don't know about ICEKit publishing.
"""
self... | [
"def",
"get_queryset",
"(",
"self",
",",
"request",
")",
":",
"self",
".",
"request",
"=",
"request",
"qs",
"=",
"super",
"(",
"PublishingFluentPagesParentAdminMixin",
",",
"self",
")",
".",
"get_queryset",
"(",
"request",
")",
"qs",
"=",
"qs",
".",
"filte... | Show only DRAFT Fluent page items in admin.
NOTE: We rely on the `UrlNode.status` to recognise DRAFT versus
PUBLISHED objects, since there the top-level `UrlNode` model and
queryset don't know about ICEKit publishing. | [
"Show",
"only",
"DRAFT",
"Fluent",
"page",
"items",
"in",
"admin",
"."
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit/publishing/admin.py#L729-L742 | train |
ic-labs/django-icekit | icekit/management/commands/import_site_map.py | Command.find_existing_page | def find_existing_page(self, titles_hierarchy):
"""
Find and return existing page matching the given titles hierarchy
"""
# Step backwards through import doc's titles hierarchy with a parent
# count which is the offset from the current level to each ancestor
titles_filter... | python | def find_existing_page(self, titles_hierarchy):
"""
Find and return existing page matching the given titles hierarchy
"""
# Step backwards through import doc's titles hierarchy with a parent
# count which is the offset from the current level to each ancestor
titles_filter... | [
"def",
"find_existing_page",
"(",
"self",
",",
"titles_hierarchy",
")",
":",
"titles_filters",
"=",
"{",
"'publishing_is_draft'",
":",
"True",
"}",
"for",
"parent_count",
",",
"ancestor_title",
"in",
"enumerate",
"(",
"titles_hierarchy",
"[",
":",
":",
"-",
"1",... | Find and return existing page matching the given titles hierarchy | [
"Find",
"and",
"return",
"existing",
"page",
"matching",
"the",
"given",
"titles",
"hierarchy"
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit/management/commands/import_site_map.py#L49-L71 | train |
ic-labs/django-icekit | icekit/utils/search/facets.py | Facet.apply_request_and_page_to_values | def apply_request_and_page_to_values(self, request, page=None):
"""
Use the request and page config to figure out which values are active
"""
value_is_set = False
for value in self._values:
value.apply_request_and_page(request, page) | python | def apply_request_and_page_to_values(self, request, page=None):
"""
Use the request and page config to figure out which values are active
"""
value_is_set = False
for value in self._values:
value.apply_request_and_page(request, page) | [
"def",
"apply_request_and_page_to_values",
"(",
"self",
",",
"request",
",",
"page",
"=",
"None",
")",
":",
"value_is_set",
"=",
"False",
"for",
"value",
"in",
"self",
".",
"_values",
":",
"value",
".",
"apply_request_and_page",
"(",
"request",
",",
"page",
... | Use the request and page config to figure out which values are active | [
"Use",
"the",
"request",
"and",
"page",
"config",
"to",
"figure",
"out",
"which",
"values",
"are",
"active"
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit/utils/search/facets.py#L81-L87 | train |
ic-labs/django-icekit | icekit/utils/search/facets.py | Facet.get_applicable_values | def get_applicable_values(self):
"""Return selected values that will affect the search result"""
return [v for v in self._values if v.is_active and not v.is_all_results] | python | def get_applicable_values(self):
"""Return selected values that will affect the search result"""
return [v for v in self._values if v.is_active and not v.is_all_results] | [
"def",
"get_applicable_values",
"(",
"self",
")",
":",
"return",
"[",
"v",
"for",
"v",
"in",
"self",
".",
"_values",
"if",
"v",
".",
"is_active",
"and",
"not",
"v",
".",
"is_all_results",
"]"
] | Return selected values that will affect the search result | [
"Return",
"selected",
"values",
"that",
"will",
"affect",
"the",
"search",
"result"
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit/utils/search/facets.py#L118-L120 | train |
ic-labs/django-icekit | icekit/utils/search/facets.py | Facet.get_value | def get_value(self):
"""Returns the label of the first value"""
try:
return self.get_applicable_values()[0]
except IndexError:
if not self.select_many and self.get_values():
return self.get_values()[0] | python | def get_value(self):
"""Returns the label of the first value"""
try:
return self.get_applicable_values()[0]
except IndexError:
if not self.select_many and self.get_values():
return self.get_values()[0] | [
"def",
"get_value",
"(",
"self",
")",
":",
"try",
":",
"return",
"self",
".",
"get_applicable_values",
"(",
")",
"[",
"0",
"]",
"except",
"IndexError",
":",
"if",
"not",
"self",
".",
"select_many",
"and",
"self",
".",
"get_values",
"(",
")",
":",
"retu... | Returns the label of the first value | [
"Returns",
"the",
"label",
"of",
"the",
"first",
"value"
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit/utils/search/facets.py#L122-L128 | train |
ic-labs/django-icekit | icekit/utils/search/facets.py | Facet.is_default | def is_default(self):
"""Return True if no active values, or if the active value is the default"""
if not self.get_applicable_values():
return True
if self.get_value().is_default:
return True
return False | python | def is_default(self):
"""Return True if no active values, or if the active value is the default"""
if not self.get_applicable_values():
return True
if self.get_value().is_default:
return True
return False | [
"def",
"is_default",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"get_applicable_values",
"(",
")",
":",
"return",
"True",
"if",
"self",
".",
"get_value",
"(",
")",
".",
"is_default",
":",
"return",
"True",
"return",
"False"
] | Return True if no active values, or if the active value is the default | [
"Return",
"True",
"if",
"no",
"active",
"values",
"or",
"if",
"the",
"active",
"value",
"is",
"the",
"default"
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit/utils/search/facets.py#L131-L139 | train |
ic-labs/django-icekit | icekit/abstract_models.py | AbstractBaseModel.save | def save(self, *args, **kwargs):
"""
Update ``self.modified``.
"""
self.modified = timezone.now()
super(AbstractBaseModel, self).save(*args, **kwargs) | python | def save(self, *args, **kwargs):
"""
Update ``self.modified``.
"""
self.modified = timezone.now()
super(AbstractBaseModel, self).save(*args, **kwargs) | [
"def",
"save",
"(",
"self",
",",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"self",
".",
"modified",
"=",
"timezone",
".",
"now",
"(",
")",
"super",
"(",
"AbstractBaseModel",
",",
"self",
")",
".",
"save",
"(",
"*",
"args",
",",
"**",
"kwargs",
... | Update ``self.modified``. | [
"Update",
"self",
".",
"modified",
"."
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit/abstract_models.py#L32-L37 | train |
ic-labs/django-icekit | icekit/publishing/models.py | publishing_set_update_time | def publishing_set_update_time(sender, instance, **kwargs):
""" Update the time modified before saving a publishable object. """
if hasattr(instance, 'publishing_linked'):
# Hack to avoid updating `publishing_modified_at` field when a draft
# publishable item is saved as part of a `publish` oper... | python | def publishing_set_update_time(sender, instance, **kwargs):
""" Update the time modified before saving a publishable object. """
if hasattr(instance, 'publishing_linked'):
# Hack to avoid updating `publishing_modified_at` field when a draft
# publishable item is saved as part of a `publish` oper... | [
"def",
"publishing_set_update_time",
"(",
"sender",
",",
"instance",
",",
"**",
"kwargs",
")",
":",
"if",
"hasattr",
"(",
"instance",
",",
"'publishing_linked'",
")",
":",
"if",
"getattr",
"(",
"instance",
",",
"'_skip_update_publishing_modified_at'",
",",
"False"... | Update the time modified before saving a publishable object. | [
"Update",
"the",
"time",
"modified",
"before",
"saving",
"a",
"publishable",
"object",
"."
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit/publishing/models.py#L724-L736 | train |
ic-labs/django-icekit | icekit/publishing/models.py | handle_publishable_m2m_changed | def handle_publishable_m2m_changed(
sender, instance, action, reverse, model, pk_set, **kwargs):
"""
Cache related published objects in `pre_clear` so they can be restored in
`post_clear`.
"""
# Do nothing if the target model is not publishable.
if not issubclass(model, PublishingModel):... | python | def handle_publishable_m2m_changed(
sender, instance, action, reverse, model, pk_set, **kwargs):
"""
Cache related published objects in `pre_clear` so they can be restored in
`post_clear`.
"""
# Do nothing if the target model is not publishable.
if not issubclass(model, PublishingModel):... | [
"def",
"handle_publishable_m2m_changed",
"(",
"sender",
",",
"instance",
",",
"action",
",",
"reverse",
",",
"model",
",",
"pk_set",
",",
"**",
"kwargs",
")",
":",
"if",
"not",
"issubclass",
"(",
"model",
",",
"PublishingModel",
")",
":",
"return",
"if",
"... | Cache related published objects in `pre_clear` so they can be restored in
`post_clear`. | [
"Cache",
"related",
"published",
"objects",
"in",
"pre_clear",
"so",
"they",
"can",
"be",
"restored",
"in",
"post_clear",
"."
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit/publishing/models.py#L740-L768 | train |
ic-labs/django-icekit | icekit/publishing/models.py | sync_mptt_tree_fields_from_draft_to_published_post_save | def sync_mptt_tree_fields_from_draft_to_published_post_save(
sender, instance, **kwargs):
"""
Post save trigger to immediately sync MPTT tree structure field changes
made to draft copies to their corresponding published copy.
"""
mptt_opts = getattr(instance, '_mptt_meta', None)
publishe... | python | def sync_mptt_tree_fields_from_draft_to_published_post_save(
sender, instance, **kwargs):
"""
Post save trigger to immediately sync MPTT tree structure field changes
made to draft copies to their corresponding published copy.
"""
mptt_opts = getattr(instance, '_mptt_meta', None)
publishe... | [
"def",
"sync_mptt_tree_fields_from_draft_to_published_post_save",
"(",
"sender",
",",
"instance",
",",
"**",
"kwargs",
")",
":",
"mptt_opts",
"=",
"getattr",
"(",
"instance",
",",
"'_mptt_meta'",
",",
"None",
")",
"published_copy",
"=",
"getattr",
"(",
"instance",
... | Post save trigger to immediately sync MPTT tree structure field changes
made to draft copies to their corresponding published copy. | [
"Post",
"save",
"trigger",
"to",
"immediately",
"sync",
"MPTT",
"tree",
"structure",
"field",
"changes",
"made",
"to",
"draft",
"copies",
"to",
"their",
"corresponding",
"published",
"copy",
"."
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit/publishing/models.py#L780-L789 | train |
ic-labs/django-icekit | icekit/publishing/models.py | sync_mptt_tree_fields_from_draft_to_published | def sync_mptt_tree_fields_from_draft_to_published(
draft_copy, dry_run=False, force_update_cached_urls=False):
"""
Sync tree structure changes from a draft publishable object to its
published copy, and updates the published copy's Fluent cached URLs when
necessary. Or simulates doing this if ``d... | python | def sync_mptt_tree_fields_from_draft_to_published(
draft_copy, dry_run=False, force_update_cached_urls=False):
"""
Sync tree structure changes from a draft publishable object to its
published copy, and updates the published copy's Fluent cached URLs when
necessary. Or simulates doing this if ``d... | [
"def",
"sync_mptt_tree_fields_from_draft_to_published",
"(",
"draft_copy",
",",
"dry_run",
"=",
"False",
",",
"force_update_cached_urls",
"=",
"False",
")",
":",
"mptt_opts",
"=",
"getattr",
"(",
"draft_copy",
",",
"'_mptt_meta'",
",",
"None",
")",
"published_copy",
... | Sync tree structure changes from a draft publishable object to its
published copy, and updates the published copy's Fluent cached URLs when
necessary. Or simulates doing this if ``dry_run`` is ``True``.
Syncs both actual structural changes (i.e. different parent) and MPTT's
fields which are a cached re... | [
"Sync",
"tree",
"structure",
"changes",
"from",
"a",
"draft",
"publishable",
"object",
"to",
"its",
"published",
"copy",
"and",
"updates",
"the",
"published",
"copy",
"s",
"Fluent",
"cached",
"URLs",
"when",
"necessary",
".",
"Or",
"simulates",
"doing",
"this"... | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit/publishing/models.py#L792-L843 | train |
ic-labs/django-icekit | icekit/publishing/models.py | create_can_publish_and_can_republish_permissions | def create_can_publish_and_can_republish_permissions(sender, **kwargs):
"""
Add `can_publish` and `ca_nrepublish` permissions for each publishable
model in the system.
"""
for model in sender.get_models():
if not issubclass(model, PublishingModel):
continue
content_type =... | python | def create_can_publish_and_can_republish_permissions(sender, **kwargs):
"""
Add `can_publish` and `ca_nrepublish` permissions for each publishable
model in the system.
"""
for model in sender.get_models():
if not issubclass(model, PublishingModel):
continue
content_type =... | [
"def",
"create_can_publish_and_can_republish_permissions",
"(",
"sender",
",",
"**",
"kwargs",
")",
":",
"for",
"model",
"in",
"sender",
".",
"get_models",
"(",
")",
":",
"if",
"not",
"issubclass",
"(",
"model",
",",
"PublishingModel",
")",
":",
"continue",
"c... | Add `can_publish` and `ca_nrepublish` permissions for each publishable
model in the system. | [
"Add",
"can_publish",
"and",
"ca_nrepublish",
"permissions",
"for",
"each",
"publishable",
"model",
"in",
"the",
"system",
"."
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit/publishing/models.py#L896-L910 | train |
ic-labs/django-icekit | icekit/publishing/models.py | maybe_automatically_publish_drafts_on_save | def maybe_automatically_publish_drafts_on_save(sender, instance, **kwargs):
"""
If automatic publishing is enabled, immediately publish a draft copy after
it has been saved.
"""
# Skip processing if auto-publishing is not enabled
if not is_automatic_publishing_enabled(sender):
return
... | python | def maybe_automatically_publish_drafts_on_save(sender, instance, **kwargs):
"""
If automatic publishing is enabled, immediately publish a draft copy after
it has been saved.
"""
# Skip processing if auto-publishing is not enabled
if not is_automatic_publishing_enabled(sender):
return
... | [
"def",
"maybe_automatically_publish_drafts_on_save",
"(",
"sender",
",",
"instance",
",",
"**",
"kwargs",
")",
":",
"if",
"not",
"is_automatic_publishing_enabled",
"(",
"sender",
")",
":",
"return",
"if",
"not",
"instance",
"or",
"not",
"hasattr",
"(",
"instance",... | If automatic publishing is enabled, immediately publish a draft copy after
it has been saved. | [
"If",
"automatic",
"publishing",
"is",
"enabled",
"immediately",
"publish",
"a",
"draft",
"copy",
"after",
"it",
"has",
"been",
"saved",
"."
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit/publishing/models.py#L914-L932 | train |
ic-labs/django-icekit | icekit/publishing/models.py | PublishingModel.has_been_published | def has_been_published(self):
"""
Return True if the item is either published itself, or has an
associated published copy.
This is in contrast to ``is_published`` which only returns True if
the specific object is a published copy, and will return False for
a draft object... | python | def has_been_published(self):
"""
Return True if the item is either published itself, or has an
associated published copy.
This is in contrast to ``is_published`` which only returns True if
the specific object is a published copy, and will return False for
a draft object... | [
"def",
"has_been_published",
"(",
"self",
")",
":",
"if",
"self",
".",
"is_published",
":",
"return",
"True",
"elif",
"self",
".",
"is_draft",
":",
"return",
"self",
".",
"publishing_linked_id",
"is",
"not",
"None",
"raise",
"ValueError",
"(",
"\"Publishable o... | Return True if the item is either published itself, or has an
associated published copy.
This is in contrast to ``is_published`` which only returns True if
the specific object is a published copy, and will return False for
a draft object that has an associated published copy. | [
"Return",
"True",
"if",
"the",
"item",
"is",
"either",
"published",
"itself",
"or",
"has",
"an",
"associated",
"published",
"copy",
"."
] | c507ea5b1864303732c53ad7c5800571fca5fa94 | https://github.com/ic-labs/django-icekit/blob/c507ea5b1864303732c53ad7c5800571fca5fa94/icekit/publishing/models.py#L127-L141 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.