Bases: philo.models.base.SlugTreeEntity
Nodes are the basic building blocks of a website using Philo. They define the URL hierarchy and connect each URL to a View subclass instance which is used to generate an HttpResponse.
A property shortcut for self.view.accepts_subpath
This is a shortcut method for View.render_to_response()
This is essentially a shortcut for calling construct_url() without a subpath.
Returns: | The absolute url of the node on the current site. |
---|
This method will do its best to construct a URL based on the Node’s location. If with_domain is True, that URL will include a domain and a protocol; if secure is True as well, the protocol will be https. The request will be used to construct a domain in cases where a call to Site.objects.get_current() fails.
Node urls will not contain a trailing slash unless a subpath is provided which ends with a trailing slash. Subpaths are expected to begin with a slash, as if returned by django.core.urlresolvers.reverse().
Because this method will be called frequently and will always try to reverse philo-root, the results of that reversal will be cached by default. This can be disabled by setting PHILO_CACHE_PHILO_ROOT to False.
construct_url() may raise the following exceptions:
Parameters: |
|
---|---|
Returns: | A constructed url for accessing the given subpath of the current node instance. |
Bases: philo.models.base.Entity
View is an abstract model that represents an item which can be “rendered”, generally in response to an HttpRequest.
An attribute on the class which defines whether this View can handle subpaths. Default: False
Returns True if the View handles the given subpath, and False otherwise.
If accepts_subpath is True, try to reverse a URL using the given parameters using self as the urlconf.
If obj is provided, get_reverse_params() will be called and the results will be combined with any view_name, args, and kwargs that may have been passed in.
Parameters: |
|
---|---|
Returns: | A subpath beyond the node that reverses the view, or an absolute url that reverses the view if a node was passed in. |
Raises: |
|
This method is not implemented on the base class. It should return a (view_name, args, kwargs) tuple suitable for reversing a url for the given obj using self as the urlconf. If a reversal will not be possible, this method should raise ViewCanNotProvideSubpath.
Returns a LazyPassthroughAttributeMapper which can be used to directly retrieve the values of Attributes related to the View, falling back on the Attributes of the passed-in Node and its ancestors.
Renders the View as an HttpResponse. This will raise MIDDLEWARE_NOT_CONFIGURED if the request doesn’t have an attached Node. This can happen if the RequestNodeMiddleware is not in settings.MIDDLEWARE_CLASSES or if it is not functioning correctly.
render_to_response() will send the view_about_to_render signal, then call actually_render_to_response(), and finally send the view_finished_rendering signal before returning the response.
Concrete subclasses must override this method to provide the business logic for turning a request and extra_context into an HttpResponse.
Bases: philo.models.nodes.View
MultiView is an abstract model which represents a section of related pages - for example, a BlogView might have a foreign key to Pages for an index, an entry detail, an entry archive by day, and so on. MultiView subclasses View, and defines the following additional methods and attributes:
Same as View.accepts_subpath. Default: True
Returns urlpatterns that point to views (generally methods on the class). MultiViews can be thought of as “managing” these subpaths.
Resolves the remaining subpath left after finding this View‘s node using self.urlpatterns and renders the view function (or method) found with the appropriate args and kwargs.
Hook for providing instance-specific context - such as the value of a Field - to any view methods on the instance.
Given the name of a field on the class, accesses the value of that field and treats it as a View instance. Creates a basic context based on self.get_context() and any extra_context that was passed in, then calls the View instance’s render_to_response() method. This method is meant to be called to return a view function appropriate for urlpatterns.
Parameters: | field_name – The name of a field on the instance which contains a View subclass instance. |
---|---|
Returns: | A simple view function. |
Example:
class Foo(Multiview):
page = models.ForeignKey(Page)
@property
def urlpatterns(self):
urlpatterns = patterns('',
url(r'^$', self.basic_view('page'))
)
return urlpatterns
Bases: philo.models.nodes.TargetURLModel, philo.models.nodes.View
Represents a 301 or 302 redirect to a different url on an absolute or relative path.
A choices tuple of redirect status codes (temporary or permanent).
An IntegerField which uses STATUS_CODES as its choices. Determines whether the redirect is considered temporary or permanent.
Returns an HttpResponseRedirect to self.target_url.
Bases: philo.models.nodes.View
Stores an arbitrary file.
The name of the uploaded file. This is meant for finding the file again later, not for display.
Defines the mimetype of the uploaded file. This will not be validated. If no mimetype is provided, it will be automatically generated based on the filename.
Contains the uploaded file. Files are uploaded to philo/files/%Y/%m/%d.
Pages are the most frequently used View subclass. They define a basic HTML page and its associated content. Each Page renders itself according to a Template. The Template may contain container tags, which define related Contentlets and ContentReferences for any page using that Template.
Bases: philo.models.nodes.View
Represents a page - something which is rendered according to a Template. The page will have a number of related Contentlets and ContentReferences depending on the template selected - but these will appear only after the page has been saved with that template.
The name of this page. Chances are this will be used for organization - i.e. finding the page in a list of pages - rather than for display.
Returns the results containers for the related template. This is a tuple containing the specs of all containers in the Template‘s code. The value will be cached on the instance so that multiple accesses will be less expensive.
Returns the results containers for the related template. This is a tuple containing the specs of all containers in the Template‘s code. The value will be cached on the instance so that multiple accesses will be less expensive.
In addition to rendering as an HttpResponse, a Page can also render as a string. This means, for example, that Pages can be used to render emails or other non-HTML content with the same container-based functionality as is used for HTML.
The Page will add itself to the context as page and its attributes as attributes. If a request is provided, then request.node will also be added to the context as node and attributes will be set to the result of calling attributes_with_node() with that Node.
Returns an HttpResponse with the content of the render_to_string() method and the mimetype set to the mimetype of the related Template.
This is an override of the default model clean_fields method. Essentially, in addition to validating the fields, this method validates the Template instance that is used to render this Page. This is useful for catching template errors before they show up as 500 errors on a live site.
Bases: philo.models.base.SlugTreeEntity
Represents a database-driven django template.
See also
The name of the template. Used for organization and debugging.
Can be used to let users know what the template is meant to be used for.
Defines the mimetype of the template. This is not validated. Default: text/html.
An insecure TemplateField containing the django template code for this template.
Returns a tuple where the first item is a list of names of contentlets referenced by containers, and the second item is a list of tuples of names and contenttypes of contentreferences referenced by containers. This will break if there is a recursive extends or includes in the template code. Due to the use of an empty Context, any extends or include tags with dynamic arguments probably won’t work.
Returns a tuple where the first item is a list of names of contentlets referenced by containers, and the second item is a list of tuples of names and contenttypes of contentreferences referenced by containers. This will break if there is a recursive extends or includes in the template code. Due to the use of an empty Context, any extends or include tags with dynamic arguments probably won’t work.
Represents a piece of content on a page. This content is treated as a secure TemplateField.
The page which this Contentlet is related to.
This represents the name of the container as defined by a container tag.
A secure TemplateField holding the content for this Contentlet. Note that actually using this field as a template requires use of the include_string template tag.
Represents a model instance related to a page.
The page which this ContentReference is related to.
This represents the name of the container as defined by a container tag.
A GenericForeignKey to a model instance. The content type of this instance is defined by the container tag which defines this ContentReference.