The Base Controller API
Provides controller classes for subclassing.
Bases: pylons.controllers.core.WSGIController
The Bare Bones extension of a WSGIController needed for this app to function
Bases: mediadrop.lib.base.BareBonesController
The BaseController for all our controllers.
Adds functionality for fetching and updating an externally generated template.
Conditionally fetch and cache the remote template.
This method will only work on *nix systems.
Parameters: |
|
---|---|
Return type: | bool |
Returns: | True if updated successfully, False if unnecessary. |
Raises Exception: | |
If update fails unexpectedly due to IO problems. |
Bases: mediadrop.lib.base.BaseController
Dumb controller for display and saving basic settings forms
This maps forms from mediadrop.forms.admin.settings to our model Setting. This controller doesn’t care what settings are used, the form dictates everything. The form field names should exactly match the name in the model, regardless of it’s nesting in the form.
If and when setting values need to be altered for display purposes, or before it is saved to the database, it should be done with a field validator instead of adding complexity here.
Bases: genshi.template.loader.TemplateLoader
Load the template with the given name.
XXX: This code copied and modified from Genshi 0.6
If the filename parameter is relative, this method searches the search path trying to locate a template matching the given name. If the file name is an absolute path, the search path is ignored.
If the requested template is not found, a TemplateNotFound exception is raised. Otherwise, a Template object is returned that represents the parsed template.
Template instances are cached to avoid having to parse the same template file more than once. Thus, subsequent calls of this method with the same template file name will return the same Template object (unless the auto_reload option is enabled and the file was changed since the last parse.)
If the relative_to parameter is provided, the filename is interpreted as being relative to that path.
Parameters: |
|
---|---|
Returns: | the loaded Template instance |
Raises TemplateNotFound: | |
if a template with the given name could not be found |
Bases: genshi.output.XHTMLSerializer
XHTML+HTML5 Serializer that produces XHTML text from an event stream.
This serializer is aware that <source/> tags are empty, which is required for it to be valid (working) HTML5 in some browsers.
Generate a markup stream from the given template and vars.
Parameters: |
|
---|---|
Return type: | genshi.Stream or genshi.Markup |
Returns: | An iterable markup stream, or a serialized markup string if method was not None. |
Render the given stream to a unicode Markup string.
We substitute the standard XHTMLSerializer with our own XHTMLPlusSerializer which is (more) HTML5-aware.
Parameters: |
|
---|---|
Return type: | genshi.Markup |
Returns: | A subclassed unicode object. |
Bases: mediadrop.lib.players.AbstractPlayer
Abstract Embed Player for third-party services like YouTube
Typically embed players will play only their own content, and that is the only way such content can be played. Therefore each embed type has been given its own scheme which uniquely identifies it.
For example, mediadrop.lib.storage.YoutubeStorage.get_uris() returns URIs with a scheme of ‘youtube’, and the special YoutubePlayer would overload scheme to also be ‘youtube’. This would allow the Youtube player to play only those URIs.
Test all the given URIs to see if they can be played by this player.
This is a class method, not an instance or static method.
Parameters: | uris (list) – A collection of StorageURI tuples to test. |
---|---|
Return type: | tuple |
Returns: | Boolean result for each of the given URIs. |
The StorageURI.scheme which uniquely identifies this embed type.
Bases: mediadrop.lib.players.FlashRenderMixin, mediadrop.lib.players.AbstractEmbedPlayer
Simple Abstract Flash Embed Player
Provides sane defaults for most flash-based embed players from third-party vendors, which typically never need any flashvars or special configuration.
Return a python dict of flashvars for this player.
Return the flash player URL.
Bases: mediadrop.lib.players.FileSupportMixin, mediadrop.lib.players.FlashRenderMixin, mediadrop.lib.players.AbstractPlayer
Base Class for standard Flash Players.
This does not typically include flash players from other vendors such as embed types.
Return a python dict of flashvars for this player.
Return the flash player URL.
Bases: mediadrop.lib.players.FileSupportMixin, mediadrop.lib.players.AbstractPlayer
HTML5 <audio> / <video> tag.
References:
Render the XHTML markup for this player instance.
Parameters: | error_text – Optional error text that should be included in the final markup if appropriate for the player. |
---|---|
Return type: | unicode or genshi.core.Markup |
Returns: | XHTML that will not be escaped by Genshi. |
Bases: mediadrop.lib.players.AbstractEmbedPlayer
Abstract Embed Player for services that provide an iframe player.
Render a javascript string to instantiate a javascript player.
Each player has a client-side component to provide a consistent way of initializing and interacting with the player. For more information see mediadrop/public/scripts/mcore/players/.
Return type: | unicode |
---|---|
Returns: | A javascript string which will evaluate to an instance of a JS player class. For example: new mcore.Html5Player(). |
Bases: mediadrop.plugin.abc.AbstractClass
Player Base Class that all players must implement.
Return the desired viewable height + the height of the controls.
Return the desired viewable width + any extra for the player.
Test all the given URIs to see if they can be played by this player.
This is a class method, not an instance or static method.
Parameters: | uris (list) – A collection of StorageURI tuples to test. |
---|---|
Return type: | tuple |
Returns: | Boolean result for each of the given URIs. |
An optional default data dictionary for user preferences.
A unicode display name for the class, to be used in the settings UI.
Return a subset of the uris for this player.
This allows for easy filtering of URIs by feeding any number of kwargs to this function. See mediadrop.lib.uri.pick_uris().
A unicode string identifier for this class.
Render a javascript string to instantiate a javascript player.
Each player has a client-side component to provide a consistent way of initializing and interacting with the player. For more information see mediadrop/public/scripts/mcore/players/.
Return type: | unicode |
---|---|
Returns: | A javascript string which will evaluate to an instance of a JS player class. For example: new mcore.Html5Player(). |
Render the XHTML markup for this player instance.
Parameters: | error_text – Optional error text that should be included in the final markup if appropriate for the player. |
---|---|
Return type: | unicode or genshi.core.Markup |
Returns: | XHTML that will not be escaped by Genshi. |
An optional mediadrop.forms.admin.players.PlayerPrefsForm.
A flag that allows us to mark the few players that can’t be resized.
Setting this to False ensures that the resize (expand/shrink) controls will not be shown in our player control bar.
Bases: mediadrop.lib.players.AbstractFlashPlayer
Dummy Base Class for Flash Players that can stream over RTMP.
Bases: mediadrop.lib.players.AbstractFlashEmbedPlayer
BlipTV Player
This simple player handles media with files that stored using mediadrop.lib.storage.BlipTVStorage.
A unicode display name for the class, to be used in the settings UI.
A unicode string identifier for this class.
The StorageURI.scheme which uniquely identifies this embed type.
Bases: mediadrop.lib.players.AbstractIframeEmbedPlayer
Daily Motion Universal Player
This simple player handles media with files that stored using mediadrop.lib.storage.DailyMotionStorage.
This player has seamless HTML5 and Flash support.
A unicode display name for the class, to be used in the settings UI.
A unicode string identifier for this class.
Render the XHTML markup for this player instance.
Parameters: | error_text – Optional error text that should be included in the final markup if appropriate for the player. |
---|---|
Return type: | unicode or genshi.core.Markup |
Returns: | XHTML that will not be escaped by Genshi. |
The StorageURI.scheme which uniquely identifies this embed type.
Bases: object
Mixin that provides a can_play test on a number of common parameters.
Test all the given URIs to see if they can be played by this player.
This is a class method, not an instance or static method.
Parameters: | uris (list) – A collection of StorageURI tuples to test. |
---|---|
Return type: | tuple |
Returns: | Boolean result for each of the given URIs. |
Bases: object
Mixin for rendering flash players. Used by embedtypes as well as flash.
Render a javascript string to instantiate a javascript player.
Each player has a client-side component to provide a consistent way of initializing and interacting with the player. For more information see mediadrop/public/scripts/mcore/players/.
Return type: | unicode |
---|---|
Returns: | A javascript string which will evaluate to an instance of a JS player class. For example: new mcore.Html5Player(). |
Bases: mediadrop.lib.players.AbstractFlashPlayer
FlowPlayer (Flash)
A unicode display name for the class, to be used in the settings UI.
Return a python dict of flashvars for this player.
A unicode string identifier for this class.
Return the flash player URL.
Bases: mediadrop.lib.players.AbstractFlashEmbedPlayer
Google Video Player
This simple player handles media with files that stored using mediadrop.lib.storage.GoogleVideoStorage.
A unicode display name for the class, to be used in the settings UI.
A unicode string identifier for this class.
The StorageURI.scheme which uniquely identifies this embed type.
Bases: mediadrop.lib.players.AbstractHTML5Player
HTML5 Player Implementation.
Seperated from AbstractHTML5Player to make it easier to subclass and provide a custom HTML5 player.
A unicode display name for the class, to be used in the settings UI.
A unicode string identifier for this class.
Bases: mediadrop.lib.players.AbstractHTML5Player
HTML5 Player with fallback to FlowPlayer.
An optional default data dictionary for user preferences.
A unicode display name for the class, to be used in the settings UI.
A unicode string identifier for this class.
Render the XHTML markup for this player instance.
Parameters: | error_text – Optional error text that should be included in the final markup if appropriate for the player. |
---|---|
Return type: | unicode or genshi.core.Markup |
Returns: | XHTML that will not be escaped by Genshi. |
An optional mediadrop.forms.admin.players.PlayerPrefsForm.
alias of HTML5OrFlashPrefsForm
Bases: mediadrop.lib.players.AbstractHTML5Player
JWPlayer (Flash)
A unicode display name for the class, to be used in the settings UI.
A unicode string identifier for this class.
Return a python dict of vars for this player.
Render the XHTML markup for this player instance.
Parameters: | error_text – Optional error text that should be included in the final markup if appropriate for the player. |
---|---|
Return type: | unicode or genshi.core.Markup |
Returns: | XHTML that will not be escaped by Genshi. |
Bases: mediadrop.lib.players.AbstractHTML5Player
Sublime Video Player with a builtin flash fallback
An optional default data dictionary for user preferences.
A unicode display name for the class, to be used in the settings UI.
A unicode string identifier for this class.
Render the XHTML markup for this player instance.
Parameters: | error_text – Optional error text that should be included in the final markup if appropriate for the player. |
---|---|
Return type: | unicode or genshi.core.Markup |
Returns: | XHTML that will not be escaped by Genshi. |
An optional mediadrop.forms.admin.players.PlayerPrefsForm.
alias of SublimePlayerPrefsForm
Sublime does not support AUDIO at this time.
A flag that allows us to mark the few players that can’t be resized.
Setting this to False ensures that the resize (expand/shrink) controls will not be shown in our player control bar.
Bases: mediadrop.lib.players.AbstractIframeEmbedPlayer
Vimeo Universal Player
This simple player handles media with files that stored using mediadrop.lib.storage.VimeoStorage.
This player has seamless HTML5 and Flash support.
A unicode display name for the class, to be used in the settings UI.
A unicode string identifier for this class.
Render the XHTML markup for this player instance.
Parameters: | error_text – Optional error text that should be included in the final markup if appropriate for the player. |
---|---|
Return type: | unicode or genshi.core.Markup |
Returns: | XHTML that will not be escaped by Genshi. |
The StorageURI.scheme which uniquely identifies this embed type.
Bases: mediadrop.lib.players.AbstractIframeEmbedPlayer
YouTube Player
This simple player handles media with files that stored using mediadrop.lib.storage.YoutubeStorage.
A unicode display name for the class, to be used in the settings UI.
A unicode string identifier for this class.
Render the XHTML markup for this player instance.
Parameters: | error_text – Optional error text that should be included in the final markup if appropriate for the player. |
---|---|
Return type: | unicode or genshi.core.Markup |
Returns: | XHTML that will not be escaped by Genshi. |
The StorageURI.scheme which uniquely identifies this embed type.
An optional mediadrop.forms.admin.players.PlayerPrefsForm.
alias of YoutubePlayerPrefsForm
Return an <iframe> tag that loads our universal player.
Parameters: | media (mediadrop.model.media.Media) – The media object that is being rendered, to be passed to all instantiated player objects. |
---|---|
Return type: | genshi.builder.Element |
Returns: | An iframe element stream. |
Return an <iframe> tag that loads our universal player.
Parameters: | media (mediadrop.model.media.Media) – The media object that is being rendered, to be passed to all instantiated player objects. |
---|---|
Return type: | genshi.builder.Element |
Returns: | An iframe element stream. |
Bases: mediadrop.lib.players.FileSupportMixin, mediadrop.lib.players.AbstractPlayer
A dummy iTunes Player that allows us to test if files can_play().
A unicode display name for the class, to be used in the settings UI.
A unicode string identifier for this class.
Instantiate and render the preferred player that can play this media.
We make no effort to pick the “best” player here, we simply return the first player that can play any of the URIs associated with the given media object. It’s up to the user to declare their own preferences wisely.
Player preferences are fetched from the database and the mediadrop.model.players.c.data dict is passed as kwargs to AbstractPlayer.__init__().
Parameters: |
|
---|---|
Return type: | str or None |
Returns: | A rendered player. |
Return a file playable in at least one of the configured players.
Parameters: | media – A Media instance. |
---|---|
Returns: | A MediaFile object or None |
Return a file playable in the most podcasting client: iTunes.
Parameters: | media – A Media instance. |
---|---|
Returns: | A MediaFile object or None |
Ensure that the encoding status of all media is up to date with the new set of enabled players.
The encoding status of Media objects is dependent on there being an enabled player that supports that format. Call this method after changing the set of enabled players, to ensure encoding statuses are up to date.
Bases: object
A state for FormEncode validate API with a smart _ hook.
This idea and explanation borrowed from Pylons, modified to work with our custom Translator object.
The FormEncode library used by validate() decorator has some provision for localizing error messages. In particular, it looks for attribute _ in the application-specific state object that gets passed to every .to_python() call. If it is found, the _ is assumed to be a gettext-like function and is called to localize error messages.
One complication is that FormEncode ships with localized error messages for standard validators so the user may want to re-use them instead of gathering and translating everything from scratch. To allow this, we pass as _ a function which looks up translation both in application and formencode message catalogs.
Handle database transactions for the decorated controller actions.
This decorator supports firing callbacks immediately after the transaction is committed or rolled back. This is useful when some external process needs to be called to process some new data, since it should only be called once that data is readable by new transactions.
Note
If your callback makes modifications to the database, you must manually handle the transaction, or apply the @autocommit decorator to the callback itself.
On the ingress, two attributes are added to the webob.Request:
- request.commit_callbacks
- A list of callback functions that should be called immediately after the DBSession has been committed by this decorator.
- request.rollback_callbacks
- A list of callback functions that should be called immediately after the DBSession has been rolled back by this decorator.
On the egress, we determine which callbacks should be called, remove the above attributes from the request, and then call the appropriate callbacks.
Cache decorator utilizing Beaker. Caches action or other function that returns a pickle-able object as a result.
Optional arguments:
Determines whether the response at the time beaker_cache is used should be cached or not, defaults to True.
Note
When cache_response is set to False, the cache_headers argument is ignored as none of the response is cached.
If cache_enabled is set to False in the .ini file, then cache is disabled globally.
Simple expose decorator for controller actions.
Transparently wraps a method in a function that will render the method’s return value with the given template.
Sets the ‘exposed’ and ‘template’ attributes of the wrapped method, marking it as safe to be accessed via HTTP request.
Example, using a genshi template:
class MyController(BaseController):
@expose('path/to/template.html')
def sample_action(self, *args):
# do something
return dict(message='Hello World!')
Parameters: |
|
---|
Expose different templates for normal vs XMLHttpRequest requests.
Example, using two genshi templates:
class MyController(BaseController):
@expose_xhr('items/main_list.html', 'items/ajax_list.html')
def sample_action(self, *args):
# do something
return dict(items=get_items_list())
Decorate this function so cached results are returned indefinitely.
Copied from docs for the decorator module by Michele Simionato: http://micheles.googlecode.com/hg/decorator/documentation.html#the-solution
Filter the result of the decorated action through the events observers.
Parameters: | event – An instance of mediadrop.plugin.events.Event whose observers are called. |
---|---|
Returns: | A decorator function. |
Paginate a given collection.
Duplicates and extends the functionality of tg.decorators.paginate() to:
- Copy the docstring of the exposed method to the decorator, allowing sphinx.ext.autodoc to read docstring.
- Support our CustomPage extension – used any time items_first_page is provided.
This decorator is mainly exposing the functionality of webhelpers.paginate().
You use this decorator as follows:
class MyController(object):
@expose()
@paginate("collection")
def sample(self, *args):
collection = get_a_collection()
return dict(collection=collection)
To render the actual pager, use:
${tmpl_context.paginators.<name>.pager()}
where c is the tmpl_context.
It is possible to have several paginate()-decorators for one controller action to paginate several collections independently from each other. If this is desired, don’t forget to set the use_prefix-parameter to True.
Parameters: |
|
---|
Bases: object
Registers which validators ought to be applied to the following action
Copies the functionality of TurboGears2.0, rather than that of Pylons1.0, except that we validate request.params, not kwargs. TurboGears has the unfortunate need to validate all kwargs because it uses object dispatch. We really only need to validate request.params: if we do need to validate the kw/routing args we can and should do that in our routes.
If you want to validate the contents of your form, you can use the @validate() decorator to register the validators that ought to be called.
Parameters: |
|
---|
The first positional parameter can either be a dictionary of validators, a FormEncode schema validator, or a callable which acts like a FormEncode validator.
Bases: mediadrop.lib.decorators.validate
Special validation that returns JSON dicts for Ajax requests.
Regular synchronous requests are handled normally.
Example Usage:
@expose_xhr()
@validate_xhr(my_form_instance, error_handler=edit)
def save(self, id, **kwargs):
something = make_something()
if request.is_xhr:
return dict(my_id=something.id)
else:
redirect(action='view', id=id)
On success, returns this in addition to whatever dict you provide:
{'success': True, 'values': {}, 'my_id': 123}
On validation error, returns:
{'success': False, 'values': {}, 'errors': {}}
Return the most likely container format based on the file extension.
This standardizes to an audio/video-agnostic form of the container, if applicable. For example m4v becomes mp4.
Parameters: | extension (string) – the file extension, without a preceding period. |
---|---|
Return type: | string |
Return the most likely media type based on the container or embed site.
Parameters: |
|
---|---|
Returns: | AUDIO, VIDEO, CAPTIONS, or None |
Return the best guess mimetype for the given container.
If the type (audio or video) is not provided, we make our best guess as to which is will probably be, using guess_container_type(). Note that this value is ignored for certain mimetypes: it’s useful only when a container can be both audio and video.
Parameters: |
|
---|---|
Returns: | A mime string or None. |
Create copies of the default thumbs for the given item.
This copies the default files (all named with an id of ‘new’) to use the given item’s id. This means there could be lots of duplicate copies of the default thumbs, but at least we can always use the same url when rendering.
Parameters: | item (tuple or mapped class instance) – A 2-tuple with a subdir name and an ID. If given a ORM mapped class with _thumb_dir and id attributes, the info can be extracted automatically. |
---|
Creates thumbnails in all sizes for a given Media or Podcast object.
Side effects: Closes the open file handle passed in as image_file.
Parameters: |
|
---|
Delete the thumbnails associated with the given item.
Parameters: | item (tuple or mapped class instance) – A 2-tuple with a subdir name and an ID. If given a ORM mapped class with _thumb_dir and id attributes, the info can be extracted automatically. |
---|
Return True if a thumb exists for this item.
Parameters: | item (tuple or mapped class instance) – A 2-tuple with a subdir name and an ID. If given a ORM mapped class with _thumb_dir and id attributes, the info can be extracted automatically. |
---|
Return True if the thumbs for the given item are the defaults.
Parameters: | item (tuple or mapped class instance) – A 2-tuple with a subdir name and an ID. If given a ORM mapped class with _thumb_dir and id attributes, the info can be extracted automatically. |
---|
Bases: dict
Dict wrapper with convenient attribute access
Get the thumbnail url & dimensions for the given item and size.
Parameters: |
|
---|---|
Returns: | The url, width (x) and height (y). |
Return type: | ThumbDict with keys url, x, y OR None |
Get the thumbnail path for the given item and size.
Parameters: |
|
---|---|
Returns: | The absolute system path or None. |
Return type: | str |
Return a list of paths to all sizes of thumbs for a given item.
Parameters: | item (tuple or mapped class instance) – A 2-tuple with a subdir name and an ID. If given a ORM mapped class with _thumb_dir and id attributes, the info can be extracted automatically. |
---|---|
Returns: | thumb sizes and their paths |
Return type: | dict |
Get the thumbnail url for the given item and size.
Parameters: |
|
---|---|
Returns: | The relative or absolute URL. |
Return type: | str |
Email Helpers
Todo
Clean this module up and use genshi text templates.
A simple method to send a simple email.
Parameters: |
---|
Send a creation notification email that a new Media object has been created.
Sends to the address configured in the ‘email_media_uploaded’ address, if one has been created.
Parameters: | media_obj (Media instance) – The media object to send a notification about. |
---|
Helper method to send a email notification that a comment has been posted.
Sends to the address configured in the ‘email_comment_posted’ setting, if it is configured.
Parameters: |
---|
Convert a string of comma separated email addresses to a list of separate strings.
Convert a string of comma separated email addresses to a list of separate strings.
A simple method to send a simple email.
Parameters: |
---|
Helper method to send a email notification that a comment has been posted.
Sends to the address configured in the ‘email_comment_posted’ setting, if it is configured.
Parameters: |
---|
Send a creation notification email that a new Media object has been created.
Sends to the address configured in the ‘email_media_uploaded’ address, if one has been created.
Parameters: | media_obj (Media instance) – The media object to send a notification about. |
---|
Helper method to send a Support Request email in response to a server error.
Sends to the address configured in the ‘email_support_requests’ setting, if it is configured.
Parameters: |
|
---|
Helper functions
Consists of functions to typically be used within templates, but also available to Controllers. This module is available to templates as ‘h’.
Return True if bool(x) is True for any x in the iterable. If the iterable is empty, return False.
Append to the class for any input that Genshi’s py:attrs understands.
This is useful when using XIncludes and you want to append a class to the body tag, while still allowing all other tags to remain unchanged.
For example:
<body py:match="body" py:attrs="h.append_class_attr(select('@*'), 'extra_special')">
Parameters: |
|
---|---|
Returns: | All attrs |
Return type: | dict |
Return the best translation given a preferred and a fallback string.
If we have a translation for our preferred string ‘a’ or if we are using English, return ‘a’. Otherwise, return a translation for the fallback string ‘b’.
Parameters: |
|
---|---|
Returns: | The best translation |
Return type: | string |
Return True if the logged in user has the “edit” permission.
For a default install this is true for all members of the “admins” group.
Parameters: | item (unimplemented) – unused parameter (deprecated) |
---|---|
Returns: | Whether or not the current user has “edit” permission. |
Return type: | bool |
Convert the given plain text or HTML into valid XHTML.
If there is no markup in the string, apply paragraph formatting.
Parameters: | |
---|---|
Returns: | XHTML |
Return type: | unicode |
This method returns the “current” (as in “url as request by the user”) url.
The default “url_for()” returns the current URL in most cases however when the error controller is triggered “url_for()” will return the url of the error document (‘<host>/error/document’) instead of the url requested by the user.
Converts HTML entities to unicode. For example ‘&’ becomes ‘&’.
FIXME: WARNING: There is a bug between sgmllib.SGMLParser.goahead() and BeautifulSoup.BeautifulStoneSoup.handle_entityref() where entity-like strings that don’t match known entities are guessed at (if they come in the middle of the text) or are omitted (if they come at the end of the text).
Further, unrecognized entities will have their leading ampersand escaped and trailing semicolon (if it exists) stripped. Examples:
Inputs ”...&bob;...”, ”...&bob&...”, ”...&bob;”, and ”...&bob” will give outputs ”...&bob...”, ”...&bob&...”, ”...&bob”, and ”...”, respectively.
Move the given files to the ‘deleted’ folder, or just delete them.
If the config contains a deleted_files_dir setting, then files are moved there. If that setting does not exist, or is empty, then the files will be deleted permanently instead.
Parameters: |
|
---|
Return a link (anchor element) to the documentation on the project site.
XXX: Target attribute is not XHTML compliant.
Return the HH:MM:SS duration for a given number of seconds.
Does not support durations longer than 24 hours.
Parameters: |
|
---|---|
Return type: | unicode |
Returns: | String HH:MM:SS, omitting the hours if less than one. |
Return the number of seconds in a given HH:MM:SS.
Does not support durations longer than 24 hours.
Parameters: | duration (unicode) – A HH:MM:SS or MM:SS formatted string |
---|---|
Return type: | int |
Returns: | seconds |
Raises ValueError: | |
If the input doesn’t matched the accepted formats |
Escapes only those entities that are required for XHTML compliance
Return an excerpt for the given string.
Truncate to the given size iff we are removing more than the buffer size.
Parameters: | |
---|---|
Returns: | XHTML |
Return a sanitized version of the given string.
Words are defined in the Comments settings and are replaced with *’s representing the length of the filtered word.
Parameters: | text (str) – The string to be filtered. |
---|---|
Returns: | The filtered string. |
Return type: | str |
Return a date formatted according to the given pattern.
This uses the locale of the current request’s pylons.translator.
Parameters: |
|
---|---|
Return type: | unicode |
Return a date formatted according to the given pattern.
This uses the locale of the current request’s pylons.translator.
Parameters: |
|
---|---|
Return type: | unicode |
Return a formatted number (using the correct decimal mark).
This uses the locale of the current request’s pylons.translator.
Parameters: | number – the int, float or decimal object |
---|---|
Return type: | unicode |
Convert text to HTML paragraphs.
Return a time formatted according to the given pattern.
This uses the locale of the current request’s pylons.translator.
Parameters: |
|
---|---|
Return type: | unicode |
Return the URL for a gravatar image matching the provided email address.
Parameters: |
|
---|
Return True if the logged in user has the “admin” permission.
For a default install a user has the “admin” permission if he is a member of the “admins” group.
Returns: | Whether or not the current user has “admin” permission. |
---|---|
Return type: | bool |
Add a linebreak after block-level tags are closed.
Return type: | unicode |
---|
Bases: unicode
Represents an HTML literal.
This subclass of unicode has a .__html__() method that is detected by the escape() function.
Also, if you add another string to this string, the other string will be quoted and you will get back another literal object. Also literal(...) % obj will quote any value(s) from obj. If you do something like literal(...) + literal(...), neither string will be changed because escape(literal(...)) doesn’t change the original literal.
Return a capitalized version of S, i.e. make the first character have upper case and the rest lower case.
Return S centered in a Unicode string of length width. Padding is done using the specified fill character (default is a space)
Return a copy of S where all tab characters are expanded using spaces. If tabsize is not given, a tab size of 8 characters is assumed.
Return S left-justified in a Unicode string of length width. Padding is done using the specified fill character (default is a space).
Return a copy of the string S converted to lowercase.
Return a copy of the string S with leading whitespace removed. If chars is given and not None, remove characters in chars instead. If chars is a str, it will be converted to unicode before stripping
Search for the separator sep in S, and return the part before it, the separator itself, and the part after it. If the separator is not found, return S and two empty strings.
Return a copy of S with all occurrences of substring old replaced by new. If the optional argument count is given, only the first count occurrences are replaced.
Return S right-justified in a Unicode string of length width. Padding is done using the specified fill character (default is a space).
Search for the separator sep in S, starting at the end of S, and return the part before it, the separator itself, and the part after it. If the separator is not found, return two empty strings and S.
Return a copy of the string S with trailing whitespace removed. If chars is given and not None, remove characters in chars instead. If chars is a str, it will be converted to unicode before stripping
Return a copy of the string S with leading and trailing whitespace removed. If chars is given and not None, remove characters in chars instead. If chars is a str, it will be converted to unicode before stripping
Return a copy of S with uppercase characters converted to lowercase and vice versa.
Return a titlecased version of S, i.e. words start with title case characters, all remaining cased characters have lower case.
Return a copy of the string S, where all characters have been mapped through the given translation table, which must be a mapping of Unicode ordinals to Unicode ordinals, Unicode strings or None. Unmapped characters are left untouched. Characters mapped to None are deleted.
Return a copy of S converted to uppercase.
Pad a numeric string S with zeros on the left, to fill a field of the specified width. The string S is never truncated.
Return a file playable in at least one of the configured players.
Parameters: | media – A Media instance. |
---|---|
Returns: | A MediaFile object or None |
Return a file playable in the most podcasting client: iTunes.
Parameters: | media – A Media instance. |
---|---|
Returns: | A MediaFile object or None |
Return the given file size in the largest possible unit of bytes.
Each part of a URL, e.g. the path info, the query, etc., has a different set of reserved characters that must be quoted.
RFC 2396 Uniform Resource Identifiers (URI): Generic Syntax lists the following reserved characters.
Each of these characters is reserved in some component of a URL, but not necessarily in all of them.
By default, the quote function is intended for quoting the path section of a URL. Thus, it will not encode ‘/’. This character is reserved, but in typical usage the quote function is being called on a path where the existing slash characters are used as reserved characters.
Compose a URL using url_for() and raise a redirect.
Raises: | webob.exc.HTTPFound |
---|
Store a JSON message dict in the named cookie.
The cookie will expire at the end of the session, but should be explicitly deleted by whoever reads it.
Parameters: |
|
---|---|
Returns: | The message python dict |
Return type: | dict |
Strip out xhtml and optionally convert HTML entities to unicode.
Return type: | unicode |
---|
Get the thumbnail url & dimensions for the given item and size.
Parameters: |
|
---|---|
Returns: | The url, width (x) and height (y). |
Return type: | ThumbDict with keys url, x, y OR None |
Get the thumbnail url for the given item and size.
Parameters: |
|
---|---|
Returns: | The relative or absolute URL. |
Return type: | str |
Truncate a plaintext string to roughly a given size (full words).
Parameters: |
|
---|---|
Return type: | unicode |
Truncate a XHTML string to roughly a given size (full words).
Parameters: |
|
---|---|
Return type: | unicode |
Compose a URL with pylons.url(), all arguments are passed.
Compose a URL pylons.url.current(), all arguments are passed.
Return the canonical URL for that media (‘/media/view’).
Encode a sequence of two-element tuples or dictionary into a URL query string.
If any values in the query arg are sequences and doseq is true, each sequence element is converted to a separate parameter.
If the query arg is a sequence of two-element tuples, the order of the parameters in the output will match the order of parameters in the input.
Parse a URL into 6 components: <scheme>://<netloc>/<path>;<params>?<query>#<fragment> Return a 6-tuple: (scheme, netloc, path, params, query, fragment). Note that we don’t break the components up in smaller bits (e.g. netloc is a single string) and we don’t expand % escapes.
Inject <wbr> periodically to let the browser wrap the string.
The <wbr /> tag is widely deployed and included in HTML5, but it isn’t XHTML-compliant. See this for more info: http://dev.w3.org/html5/spec/text-level-semantics.html#the-wbr-element
Return type: | literal |
---|