blog package

Provides simple blog functionality. Article data is stored in blog.models.Article and can be rendered as django template.

Submodules

blog.admin module

class blog.admin.ArticleAdmin(model, admin_site)[source]

Bases: django.contrib.admin.options.ModelAdmin

Article admin class. New articles are created by moderators via this page

form

alias of ArticleAdminForm

save_model(request, obj, form, change)[source]

Sets object author as request.user

blog.forms module

Forms for article app

class blog.forms.ArticleAdminForm(data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=<class 'django.forms.utils.ErrorList'>, label_suffix=None, empty_permitted=False, instance=None, use_required_attribute=None)[source]

Bases: django.forms.models.ModelForm

Basic form for article change_view. Replaces text input with WYSISYG editor

blog.models module

This module defines models for blog app

class blog.models.Article(*args, **kwargs)[source]

Bases: django.db.models.base.Model

Describes model for storing articles. Can render it’s content as Django template.

author

Article author, relates to profiles.models.UserProfile

content

Article content. Can store html (including Django templates). Behaviour is defined by is_django_template.

get_absolute_url()[source]

Get URL of this article

Returns:URL
hidden

True if article is hidden from regular users. See is_visible().

is_django_template

True if article should be rendered as Django template. See rendered_content()

is_visible(user: django.contrib.auth.models.User)[source]

Checks if specified user van ciew this post. E.g. post is published, of user is staff & so on

Parameters:user (User) – User to be checked
Returns:True if User can view this post, else False
Return type:bool
publish_dttm

Publication Date and time. Auto populated at article creation.

rendered_content

Renders self.content as Django template.

Parameters:context (Context) – Additional context to be passed to template
Returns:Rendered template
show_in_feed

True if article should appear in feeds such as blog.views.ArticleList

slug

models.SlugField storing user-friendly article URL

title

Article title.

Don’t insert HTML tags like <h3> - it’s rendered in templates. But, you may apply some text formatting like <b>.

blog.tests module

blog.urls module

URL dispatcher for blog app

Used urls: * Empty url redirects to news feed. See blog.views.ArticleList * post/<slug> and <slug> show detailed view of article (blog.views.ArticleDetail). The first one is kept to keep old urls valid

blog.views module

class blog.views.ArticleDetail(**kwargs)[source]

Bases: django.views.generic.detail.DetailView

Detailed view of article.

Base template is blog/article_detail.html.

get_context_data(**kwargs)[source]

Raises 403 error if user can’t view this article. See Article.is_visible()

model

alias of Article

class blog.views.ArticleList(**kwargs)[source]

Bases: django.views.generic.list.ListView

Blog’s newsfeed. Shows all visible articles with show_in_feed == True

Base temlate is blog/article_list.html.

get_context_data(**kwargs)[source]

Returns list of articles to be shown in feed. See blog.models.Article params for details

model

alias of Article

Module contents