_id stringlengths 2 7 | title stringlengths 1 88 | partition stringclasses 3
values | text stringlengths 31 13.1k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q247700 | _load_library | train | def _load_library(library_names, library_file_extensions,
library_search_paths, version_check_callback):
"""
Finds, loads and returns the most recent version of the library.
"""
candidates = _find_library_candidates(library_names,
library_file_... | python | {
"resource": ""
} |
q247701 | _get_library_search_paths | train | def _get_library_search_paths():
"""
Returns a list of library search paths, considering of the current working
directory, default paths and paths from environment variables.
"""
search_paths = [
'',
'/usr/lib64',
'/usr/local/lib64',
'/usr/lib', '/usr/local/lib',
... | python | {
"resource": ""
} |
q247702 | _prepare_errcheck | train | def _prepare_errcheck():
"""
This function sets the errcheck attribute of all ctypes wrapped functions
to evaluate the _exc_info_from_callback global variable and re-raise any
exceptions that might have been raised in callbacks.
It also modifies all callback types to automatically wrap the function
... | python | {
"resource": ""
} |
q247703 | init | train | def init():
"""
Initializes the GLFW library.
Wrapper for:
int glfwInit(void);
"""
cwd = | python | {
"resource": ""
} |
q247704 | terminate | train | def terminate():
"""
Terminates the GLFW library.
Wrapper for:
void glfwTerminate(void);
"""
for callback_repository in _callback_repositories:
| python | {
"resource": ""
} |
q247705 | get_version | train | def get_version():
"""
Retrieves the version of the GLFW library.
Wrapper for:
void glfwGetVersion(int* major, int* minor, int* rev);
"""
major_value = ctypes.c_int(0)
major = ctypes.pointer(major_value)
minor_value = ctypes.c_int(0)
| python | {
"resource": ""
} |
q247706 | _raise_glfw_errors_as_exceptions | train | def _raise_glfw_errors_as_exceptions(error_code, description):
"""
Default error callback that raises GLFWError exceptions for glfw errors.
Set an alternative error callback or set glfw.ERROR_REPORTING to False to
disable this behavior.
| python | {
"resource": ""
} |
q247707 | get_monitors | train | def get_monitors():
"""
Returns the currently connected monitors.
Wrapper for:
GLFWmonitor** glfwGetMonitors(int* count);
"""
count_value = ctypes.c_int(0)
count = | python | {
"resource": ""
} |
q247708 | get_monitor_pos | train | def get_monitor_pos(monitor):
"""
Returns the position of the monitor's viewport on the virtual screen.
Wrapper for:
void glfwGetMonitorPos(GLFWmonitor* monitor, int* xpos, int* ypos);
"""
xpos_value = ctypes.c_int(0)
| python | {
"resource": ""
} |
q247709 | get_monitor_physical_size | train | def get_monitor_physical_size(monitor):
"""
Returns the physical size of the monitor.
Wrapper for:
void glfwGetMonitorPhysicalSize(GLFWmonitor* monitor, int* width, int* height);
| python | {
"resource": ""
} |
q247710 | set_monitor_callback | train | def set_monitor_callback(cbfun):
"""
Sets the monitor configuration callback.
Wrapper for:
GLFWmonitorfun glfwSetMonitorCallback(GLFWmonitorfun cbfun);
"""
global _monitor_callback
previous_callback = _monitor_callback
if cbfun is None:
cbfun = 0
c_cbfun = _GLFWmonitorfu... | python | {
"resource": ""
} |
q247711 | get_video_modes | train | def get_video_modes(monitor):
"""
Returns the available video modes for the specified monitor.
Wrapper for:
const GLFWvidmode* glfwGetVideoModes(GLFWmonitor* monitor, int* count);
"""
count_value = ctypes.c_int(0)
| python | {
"resource": ""
} |
q247712 | set_gamma_ramp | train | def set_gamma_ramp(monitor, ramp):
"""
Sets the current gamma ramp for the specified monitor.
Wrapper for:
void glfwSetGammaRamp(GLFWmonitor* | python | {
"resource": ""
} |
q247713 | create_window | train | def create_window(width, height, title, monitor, share):
"""
Creates a window and its associated context.
Wrapper for:
GLFWwindow* glfwCreateWindow(int width, int height, const char* title, GLFWmonitor* monitor, GLFWwindow* share);
"""
| python | {
"resource": ""
} |
q247714 | get_window_pos | train | def get_window_pos(window):
"""
Retrieves the position of the client area of the specified window.
Wrapper for:
void glfwGetWindowPos(GLFWwindow* window, int* xpos, int* ypos);
"""
xpos_value = ctypes.c_int(0)
| python | {
"resource": ""
} |
q247715 | get_window_size | train | def get_window_size(window):
"""
Retrieves the size of the client area of the specified window.
Wrapper for:
void glfwGetWindowSize(GLFWwindow* window, int* width, int* height); | python | {
"resource": ""
} |
q247716 | get_framebuffer_size | train | def get_framebuffer_size(window):
"""
Retrieves the size of the framebuffer of the specified window.
Wrapper for:
void glfwGetFramebufferSize(GLFWwindow* window, int* width, int* height); | python | {
"resource": ""
} |
q247717 | set_window_user_pointer | train | def set_window_user_pointer(window, pointer):
"""
Sets the user pointer of the specified window. You may pass a normal python object into this function and it will
be wrapped automatically. The object will be kept in existence until the pointer is set to something else or
until the window is destroyed.
... | python | {
"resource": ""
} |
q247718 | get_window_user_pointer | train | def get_window_user_pointer(window):
"""
Returns the user pointer of the specified window.
Wrapper for:
void* glfwGetWindowUserPointer(GLFWwindow* window);
"""
window_addr = ctypes.cast(ctypes.pointer(window),
ctypes.POINTER(ctypes.c_long)).contents.value
| python | {
"resource": ""
} |
q247719 | set_window_pos_callback | train | def set_window_pos_callback(window, cbfun):
"""
Sets the position callback for the specified window.
Wrapper for:
GLFWwindowposfun glfwSetWindowPosCallback(GLFWwindow* window, GLFWwindowposfun cbfun);
"""
window_addr = ctypes.cast(ctypes.pointer(window),
ctypes... | python | {
"resource": ""
} |
q247720 | set_window_size_callback | train | def set_window_size_callback(window, cbfun):
"""
Sets the size callback for the specified window.
Wrapper for:
GLFWwindowsizefun glfwSetWindowSizeCallback(GLFWwindow* window, GLFWwindowsizefun cbfun);
"""
window_addr = ctypes.cast(ctypes.pointer(window),
ctypes... | python | {
"resource": ""
} |
q247721 | set_window_close_callback | train | def set_window_close_callback(window, cbfun):
"""
Sets the close callback for the specified window.
Wrapper for:
GLFWwindowclosefun glfwSetWindowCloseCallback(GLFWwindow* window, GLFWwindowclosefun cbfun);
"""
window_addr = ctypes.cast(ctypes.pointer(window),
c... | python | {
"resource": ""
} |
q247722 | set_window_refresh_callback | train | def set_window_refresh_callback(window, cbfun):
"""
Sets the refresh callback for the specified window.
Wrapper for:
GLFWwindowrefreshfun glfwSetWindowRefreshCallback(GLFWwindow* window, GLFWwindowrefreshfun cbfun);
"""
window_addr = ctypes.cast(ctypes.pointer(window),
... | python | {
"resource": ""
} |
q247723 | set_window_focus_callback | train | def set_window_focus_callback(window, cbfun):
"""
Sets the focus callback for the specified window.
Wrapper for:
GLFWwindowfocusfun glfwSetWindowFocusCallback(GLFWwindow* window, GLFWwindowfocusfun cbfun);
"""
window_addr = ctypes.cast(ctypes.pointer(window),
c... | python | {
"resource": ""
} |
q247724 | set_window_iconify_callback | train | def set_window_iconify_callback(window, cbfun):
"""
Sets the iconify callback for the specified window.
Wrapper for:
GLFWwindowiconifyfun glfwSetWindowIconifyCallback(GLFWwindow* window, GLFWwindowiconifyfun cbfun);
"""
window_addr = ctypes.cast(ctypes.pointer(window),
... | python | {
"resource": ""
} |
q247725 | set_framebuffer_size_callback | train | def set_framebuffer_size_callback(window, cbfun):
"""
Sets the framebuffer resize callback for the specified window.
Wrapper for:
GLFWframebuffersizefun glfwSetFramebufferSizeCallback(GLFWwindow* window, GLFWframebuffersizefun cbfun);
"""
window_addr = ctypes.cast(ctypes.pointer(window),
... | python | {
"resource": ""
} |
q247726 | get_cursor_pos | train | def get_cursor_pos(window):
"""
Retrieves the last reported cursor position, relative to the client
area of the window.
Wrapper for:
void glfwGetCursorPos(GLFWwindow* window, double* xpos, double* ypos);
"""
xpos_value = ctypes.c_double(0.0)
| python | {
"resource": ""
} |
q247727 | set_key_callback | train | def set_key_callback(window, cbfun):
"""
Sets the key callback.
Wrapper for:
GLFWkeyfun glfwSetKeyCallback(GLFWwindow* window, GLFWkeyfun cbfun);
"""
window_addr = ctypes.cast(ctypes.pointer(window),
ctypes.POINTER(ctypes.c_long)).contents.value
if window_a... | python | {
"resource": ""
} |
q247728 | set_char_callback | train | def set_char_callback(window, cbfun):
"""
Sets the Unicode character callback.
Wrapper for:
GLFWcharfun glfwSetCharCallback(GLFWwindow* window, GLFWcharfun cbfun);
"""
window_addr = ctypes.cast(ctypes.pointer(window),
ctypes.POINTER(ctypes.c_long)).contents.val... | python | {
"resource": ""
} |
q247729 | set_mouse_button_callback | train | def set_mouse_button_callback(window, cbfun):
"""
Sets the mouse button callback.
Wrapper for:
GLFWmousebuttonfun glfwSetMouseButtonCallback(GLFWwindow* window, GLFWmousebuttonfun cbfun);
"""
window_addr = ctypes.cast(ctypes.pointer(window),
ctypes.POINTER(ctyp... | python | {
"resource": ""
} |
q247730 | set_cursor_pos_callback | train | def set_cursor_pos_callback(window, cbfun):
"""
Sets the cursor position callback.
Wrapper for:
GLFWcursorposfun glfwSetCursorPosCallback(GLFWwindow* window, GLFWcursorposfun cbfun);
"""
window_addr = ctypes.cast(ctypes.pointer(window),
ctypes.POINTER(ctypes.c_... | python | {
"resource": ""
} |
q247731 | set_scroll_callback | train | def set_scroll_callback(window, cbfun):
"""
Sets the scroll callback.
Wrapper for:
GLFWscrollfun glfwSetScrollCallback(GLFWwindow* window, GLFWscrollfun cbfun);
"""
window_addr = ctypes.cast(ctypes.pointer(window),
ctypes.POINTER(ctypes.c_long)).contents.value
... | python | {
"resource": ""
} |
q247732 | get_joystick_axes | train | def get_joystick_axes(joy):
"""
Returns the values of all axes of the specified joystick.
Wrapper for:
const float* glfwGetJoystickAxes(int joy, int* count);
"""
count_value = ctypes.c_int(0)
| python | {
"resource": ""
} |
q247733 | get_joystick_buttons | train | def get_joystick_buttons(joy):
"""
Returns the state of all buttons of the specified joystick.
Wrapper for:
const unsigned char* glfwGetJoystickButtons(int joy, int* count);
"""
count_value = ctypes.c_int(0)
| python | {
"resource": ""
} |
q247734 | _GLFWvidmode.unwrap | train | def unwrap(self):
"""
Returns a GLFWvidmode object.
"""
size = self.Size(self.width, self.height)
| python | {
"resource": ""
} |
q247735 | _GLFWgammaramp.unwrap | train | def unwrap(self):
"""
Returns a GLFWgammaramp object.
"""
red = [self.red[i] for i in range(self.size)]
green = [self.green[i] for i in range(self.size)]
blue = [self.blue[i] for i in range(self.size)]
if NORMALIZE_GAMMA_RAMPS:
red = [value / 65535.0 f... | python | {
"resource": ""
} |
q247736 | _GLFWimage.unwrap | train | def unwrap(self):
"""
Returns a GLFWimage object.
"""
pixels = [[[int(c) for c in p] for p in | python | {
"resource": ""
} |
q247737 | GPS3mechanism.stream_data | train | def stream_data(self, host=HOST, port=GPSD_PORT, enable=True, gpsd_protocol=PROTOCOL, devicepath=None):
""" Connect and command, point and shoot, flail and bail
""" | python | {
"resource": ""
} |
q247738 | GPS3mechanism.unpack_data | train | def unpack_data(self, usnap=.2): # 2/10th second sleep between empty requests
""" Iterates over socket response and unpacks values of object attributes.
Sleeping | python | {
"resource": ""
} |
q247739 | GPS3mechanism.run_thread | train | def run_thread(self, usnap=.2, daemon=True):
"""run thread with data
"""
# self.stream_data() # Unless other changes are made this would limit to localhost only.
try:
gps3_data_thread = Thread(target=self.unpack_data, | python | {
"resource": ""
} |
q247740 | add_args | train | def add_args():
"""Adds commandline arguments and formatted Help"""
parser = argparse.ArgumentParser()
parser.add_argument('-host', action='store', dest='host', default='127.0.0.1', help='DEFAULT "127.0.0.1"')
parser.add_argument('-port', action='store', dest='port', default='2947', help='DEFAULT 2947'... | python | {
"resource": ""
} |
q247741 | make_time | train | def make_time(gps_datetime_str):
"""Makes datetime object from string object"""
if not 'n/a' == gps_datetime_str:
datetime_string = gps_datetime_str
| python | {
"resource": ""
} |
q247742 | elapsed_time_from | train | def elapsed_time_from(start_time):
"""calculate time delta from latched time and current time"""
time_then = make_time(start_time)
time_now = datetime.utcnow().replace(microsecond=0)
| python | {
"resource": ""
} |
q247743 | unit_conversion | train | def unit_conversion(thing, units, length=False):
"""converts base data between metric, imperial, or nautical units"""
if 'n/a' == thing: | python | {
"resource": ""
} |
q247744 | shut_down | train | def shut_down():
"""Closes connection and restores terminal"""
curses.nocbreak()
curses.echo()
curses.endwin()
| python | {
"resource": ""
} |
q247745 | GPSDSocket.close | train | def close(self):
"""turn off stream and close socket"""
if self.streamSock:
self.watch(enable=False)
| python | {
"resource": ""
} |
q247746 | show_nmea | train | def show_nmea():
"""NMEA output in curses terminal"""
data_window = curses.newwin(24, 79, 0, 0)
for new_data in gpsd_socket:
if new_data:
screen.nodelay(1)
key_press = screen.getch()
if key_press == ord('q'):
shut_down()
elif key_press... | python | {
"resource": ""
} |
q247747 | register_widget | train | def register_widget(widget):
"""
Register the given widget as a candidate to use in placeholder.
"""
if widget in registry:
raise WidgetAlreadyRegistered(
| python | {
"resource": ""
} |
q247748 | get_widget | train | def get_widget(name):
"""
Give back a widget class according to his name.
"""
for widget in registry:
| python | {
"resource": ""
} |
q247749 | get_setting | train | def get_setting(*args, **kwargs):
"""Get a setting and raise an appropriate user friendly error if
the setting is not found."""
for name in args:
if hasattr(settings, name):
return getattr(settings, name)
| python | {
"resource": ""
} |
q247750 | get_page_templates | train | def get_page_templates():
"""The callable that is used by the CMS."""
PAGE_TEMPLATES = get_setting('PAGE_TEMPLATES',
| python | {
"resource": ""
} |
q247751 | change_status | train | def change_status(request, page_id):
"""
Switch the status of a page.
"""
perm = request.user.has_perm('pages.change_page')
if perm and request.method == 'POST':
page = Page.objects.get(pk=page_id)
| python | {
"resource": ""
} |
q247752 | get_last_content | train | def get_last_content(request, page_id):
"""Get the latest content for a particular type"""
content_type = request.GET.get('content_type')
language_id = request.GET.get('language_id')
page = get_object_or_404(Page, pk=page_id)
placeholders = get_placeholders(page.get_template())
_template = templ... | python | {
"resource": ""
} |
q247753 | traduction | train | def traduction(request, page_id, language_id):
"""Traduction helper."""
page = Page.objects.get(pk=page_id)
lang = language_id
placeholders = get_placeholders(page.get_template())
language_error = (
Content.objects.get_content(page, language_id, "title")
is None
)
return rend... | python | {
"resource": ""
} |
q247754 | get_content | train | def get_content(request, page_id, content_id):
"""Get the content for a particular page"""
content = | python | {
"resource": ""
} |
q247755 | get_media_url | train | def get_media_url(request, media_id):
"""Get media URL."""
| python | {
"resource": ""
} |
q247756 | media | train | def media(request):
"""Adds media-related variables to the `context`."""
return {
'PAGES_MEDIA_URL': settings.PAGES_MEDIA_URL,
'PAGES_STATIC_URL': settings.PAGES_STATIC_URL,
'PAGE_USE_SITE_ID': settings.PAGE_USE_SITE_ID, | python | {
"resource": ""
} |
q247757 | normalize_url | train | def normalize_url(url):
"""Return a normalized url with trailing and without leading slash.
>>> normalize_url(None)
'/'
>>> normalize_url('/')
'/'
>>> normalize_url('/foo/bar')
'/foo/bar'
>>> normalize_url('foo/bar')
'/foo/bar'
>>> normalize_url('/foo/bar/')
'/foo/... | python | {
"resource": ""
} |
q247758 | page_templates_loading_check | train | def page_templates_loading_check(app_configs, **kwargs):
""" Check if any page template can't be loaded. """
errors = []
for page_template in settings.get_page_templates():
try:
loader.get_template(page_template[0])
except template.TemplateDoesNotExist:
errors.append... | python | {
"resource": ""
} |
q247759 | _get_content | train | def _get_content(context, page, content_type, lang, fallback=True):
"""Helper function used by ``PlaceholderNode``."""
if not page:
return ''
if not lang and 'lang' in context:
lang = context.get('lang', pages_settings.PAGE_DEFAULT_LANGUAGE)
| python | {
"resource": ""
} |
q247760 | has_content_in | train | def has_content_in(page, language):
"""Fitler that return ``True`` if the page has any content in a
particular language.
:param page: the current page
:param language: the language you want to look at
| python | {
"resource": ""
} |
q247761 | pages_menu | train | def pages_menu(context, page, url='/'):
"""Render a nested list of all the descendents of the given page,
including this page.
:param page: the page where to start the menu from.
:param url: not used anymore.
"""
lang = context.get('lang', pages_settings.PAGE_DEFAULT_LANGUAGE)
| python | {
"resource": ""
} |
q247762 | pages_sub_menu | train | def pages_sub_menu(context, page, url='/'):
"""Get the root page of the given page and
render a nested list of all root's children pages.
Good for rendering a secondary menu.
:param page: the page where to start the menu from. | python | {
"resource": ""
} |
q247763 | show_content | train | def show_content(context, page, content_type, lang=None, fallback=True):
"""Display a content type from a page.
Example::
{% show_content page_object "title" %}
You can also use the slug of a page::
{% show_content "my-page-slug" "title" %}
Or even the id of a page::
{% sho... | python | {
"resource": ""
} |
q247764 | show_absolute_url | train | def show_absolute_url(context, page, lang=None):
"""
Show the url of a page in the right language
Example ::
{% show_absolute_url page_object %}
You can also use the slug of a page::
{% show_absolute_url "my-page-slug" %}
Keyword arguments:
:param page: the page object, slug... | python | {
"resource": ""
} |
q247765 | pages_dynamic_tree_menu | train | def pages_dynamic_tree_menu(context, page, url='/'):
"""
Render a "dynamic" tree menu, with all nodes expanded which are either
ancestors or the current page itself.
Override ``pages/dynamic_tree_menu.html`` if you want to change the
design.
:param page: the current page
:param url: not us... | python | {
"resource": ""
} |
q247766 | pages_breadcrumb | train | def pages_breadcrumb(context, page, url='/'):
"""
Render a breadcrumb like menu.
Override ``pages/breadcrumb.html`` if you want to change the
design.
:param page: the current page
:param url: not used anymore
"""
lang = context.get('lang', pages_settings.PAGE_DEFAULT_LANGUAGE)
| python | {
"resource": ""
} |
q247767 | do_get_page | train | def do_get_page(parser, token):
"""Retrieve a page and insert into the template's context.
Example::
{% get_page "news" as news_page %}
:param page: the page object, slug or id
:param name: name of the context variable to store the page in
"""
bits = token.split_contents()
if 4 !=... | python | {
"resource": ""
} |
q247768 | do_get_content | train | def do_get_content(parser, token):
"""Retrieve a Content object and insert it into the template's context.
Example::
{% get_content page_object "title" as content %}
You can also use the slug of a page::
{% get_content "my-page-slug" "title" as content %}
Syntax::
{% get_co... | python | {
"resource": ""
} |
q247769 | do_placeholder | train | def do_placeholder(parser, token):
"""
Method that parse the placeholder template tag.
Syntax::
{% placeholder <name> [on <page>] [with <widget>] \
[parsed] [as <varname>] %}
Example usage::
{% placeholder about %}
{% placeholder body with TextArea as body_text %}
{% ... | python | {
"resource": ""
} |
q247770 | do_markdownlaceholder | train | def do_markdownlaceholder(parser, token):
"""
Method that parse the markdownplaceholder template tag.
"""
| python | {
"resource": ""
} |
q247771 | do_fileplaceholder | train | def do_fileplaceholder(parser, token):
"""
Method that parse the fileplaceholder template tag.
"""
| python | {
"resource": ""
} |
q247772 | do_page_has_content | train | def do_page_has_content(parser, token):
"""
Conditional tag that only renders its nodes if the page
has content for a particular content type. By default the
current page is used.
Syntax::
{% page_has_content <content_type> [<page var name>] %}
...
{%_end page_has_conte... | python | {
"resource": ""
} |
q247773 | get_request_mock | train | def get_request_mock():
"""Build a ``request`` mock up for tests"""
from django.test.client import RequestFactory
from django.core.handlers.base import BaseHandler
| python | {
"resource": ""
} |
q247774 | remove_slug | train | def remove_slug(path):
"""
Return the remainin part of the path
>>> remove_slug('/test/some/function/')
test/some
"""
if path.endswith('/'):
path = path[:-1]
if path.startswith('/'):
path = path[1:]
| python | {
"resource": ""
} |
q247775 | get_language_from_request | train | def get_language_from_request(request):
"""Return the most obvious language according the request."""
language = request.GET.get('language', None)
if language:
return language
if hasattr(request, 'LANGUAGE_CODE'):
lang = settings.PAGE_LANGUAGE_MAPPING(str(request.LANGUAGE_CODE))
| python | {
"resource": ""
} |
q247776 | ContentManager.get_content | train | def get_content(self, page, language, ctype, language_fallback=False):
"""Gets the latest content string for a particular page, language and
placeholder.
:param page: the concerned page object.
:param language: the wanted language.
:param ctype: the content type.
:param ... | python | {
"resource": ""
} |
q247777 | ContentManager.get_page_ids_by_slug | train | def get_page_ids_by_slug(self, slug):
"""Return all page's id matching the given slug.
This function also returns pages that have an old slug
that match.
| python | {
"resource": ""
} |
q247778 | Details.resolve_page | train | def resolve_page(self, request, context, is_staff):
"""Return the appropriate page according to the path."""
path = context['path']
lang = context['lang']
page = Page.objects.from_path(
path, lang,
exclude_drafts=(not is_staff))
if page:
return... | python | {
"resource": ""
} |
q247779 | Details.resolve_redirection | train | def resolve_redirection(self, request, context):
"""Check for redirections."""
current_page = context['current_page']
lang = context['lang']
if current_page.redirect_to_url:
return HttpResponsePermanentRedirect(current_page.redirect_to_url)
| python | {
"resource": ""
} |
q247780 | Details.choose_language | train | def choose_language(self, lang, request):
"""Deal with the multiple corner case of choosing the language."""
# Can be an empty string or None
if not lang:
lang = get_language_from_request(request)
# Raise a 404 if the language is not in not in the list
if lang not i... | python | {
"resource": ""
} |
q247781 | Details.extra_context | train | def extra_context(self, request, context):
"""Call the PAGE_EXTRA_CONTEXT function if there is one."""
| python | {
"resource": ""
} |
q247782 | Page.get_children | train | def get_children(self):
"""Cache superclass result"""
key = self.CHILDREN_KEY % self.pk
#children = cache.get(key, None)
# if children is None:
| python | {
"resource": ""
} |
q247783 | Page.move_to | train | def move_to(self, target, position='first-child'):
"""Invalidate cache when moving"""
# Invalidate both in case position matters,
# otherwise only target is needed.
| python | {
"resource": ""
} |
q247784 | Page.get_content | train | def get_content(self, language, ctype, language_fallback=False):
"""Shortcut method for retrieving a piece of page content
:param language: wanted language, if not defined default is | python | {
"resource": ""
} |
q247785 | Page.get_url_path | train | def get_url_path(self, language=None):
"""Return the URL's path component. Add the language prefix if
``PAGE_USE_LANGUAGE_PREFIX`` setting is set to ``True``.
:param language: the wanted url language.
"""
if self.is_first_root():
# this is used to allow users to chan... | python | {
"resource": ""
} |
q247786 | Page.slug_with_level | train | def slug_with_level(self, language=None):
"""Display the slug of the page prepended with insecable
spaces to simluate the level of page in the hierarchy."""
level = ''
if self.level:
| python | {
"resource": ""
} |
q247787 | Page.title | train | def title(self, language=None, fallback=True):
"""
Return the title of the page depending on the given language.
:param language: wanted language, if not defined default is used.
:param fallback: if ``True``, the slug will also be searched in \
other languages.
| python | {
"resource": ""
} |
q247788 | unique_slug_required | train | def unique_slug_required(form, slug):
"""Enforce a unique slug accross all pages and websistes."""
if hasattr(form, 'instance') and form.instance.id:
if Content.objects.exclude(page=form.instance).filter(
| python | {
"resource": ""
} |
q247789 | intersect_sites_method | train | def intersect_sites_method(form):
"""Return a method to intersect sites."""
if settings.PAGE_USE_SITE_ID:
if settings.PAGE_HIDE_SITES:
site_ids = [global_settings.SITE_ID]
else:
site_ids = [int(x) for x in form.data.getlist('sites')]
| python | {
"resource": ""
} |
q247790 | PageLinkWidget._has_changed | train | def _has_changed(self, initial, data):
"""Need to be reimplemented to be correct."""
if data == initial:
| python | {
"resource": ""
} |
q247791 | update_redirect_to_from_json | train | def update_redirect_to_from_json(page, redirect_to_complete_slugs):
"""
The second pass of create_and_update_from_json_data
used to update the redirect_to field.
Returns a messages list to be appended to the messages from the
first pass.
| python | {
"resource": ""
} |
q247792 | get_filename | train | def get_filename(page, content_type, data):
"""
Generate a stable filename using the original filename of the type.
"""
avoid_collision = uuid.uuid4().hex[:8]
name_parts = data.name.split('.')
if len(name_parts) > 1:
name = slugify('.'.join(name_parts[:-1]), allow_unicode=True)
... | python | {
"resource": ""
} |
q247793 | PlaceholderNode.get_field | train | def get_field(self, page, language, initial=None):
"""The field that will be shown within the admin."""
if self.parsed:
help_text = _('Note: This field is evaluated as template code.')
else:
help_text = ''
| python | {
"resource": ""
} |
q247794 | PlaceholderNode.render | train | def render(self, context):
"""Output the content of the `PlaceholdeNode` as a template."""
content = self.get_render_content(context)
request = context.get('request')
render_edit_tag = False
if request and request.user.is_staff and request.COOKIES.get('enable_edit_mode'):
... | python | {
"resource": ""
} |
q247795 | MarkdownPlaceholderNode.render | train | def render(self, context):
"""Render markdown."""
import markdown
| python | {
"resource": ""
} |
q247796 | Command.handle | train | def handle(self, user, **options):
"""
Import pages in JSON format. When creating a page and the original
author does not exist, use user as the new author. User may be
specified by username, id or email address.
"""
monkeypatch_remove_pages_site_restrictions()
... | python | {
"resource": ""
} |
q247797 | prepare | train | def prepare(value, should_escape):
"""
Prepares a value to be added to the result
:param value:
The value to add to the result
:param should_escape:
If the string should be HTML-escaped
:return:
A unicode string or strlist
"""
if value is None:
return u''
... | python | {
"resource": ""
} |
q247798 | strlist.grow | train | def grow(self, thing):
"""Make the list longer, appending for unicode, extending otherwise."""
if type(thing) == str_class:
self.append(thing)
# This will only ever match in Python 2 since str_class is str in
# Python 3.
elif type(thing) == str:
| python | {
"resource": ""
} |
q247799 | Compiler._extract_word | train | def _extract_word(self, source, position):
"""
Extracts the word that falls at or around a specific position
:param source:
The template source as a unicode string
:param position:
The position where the word falls
:return:
The word
"... | python | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.