fireblog package

Submodules

fireblog.comments module

Functionality for adding, viewing and deleting comments.

fireblog.comments.add_comment_section_below_posts(event) → None[source]

This function should be passed an instance of fireblog.events.RenderingPost. It adds a comment section onto the event parameter.

fireblog.comments.comment_add(request)[source]

Add a comment to a post.

We allow anyone to have access to this view. But we check whether a person is authenticated or not within this view. This is because we are allowing people to add comments anonymously ie not under an individual userid/username.

If a person is not authenticated, ie they are adding a comment anonymously, we run a Recaptcha test to try and avoid spam comments.

fireblog.comments.comment_delete(request)[source]

Delete a comment and redirect back to the post associated with the comment.

fireblog.comments.includeme(config)[source]

Add views for adding and deleting comments. Also, invalidate a cached post when we add or delete a comment on it.

fireblog.comments.render_comments_list_from_event(event) → list[source]

This function should be passed an instance of fireblog.events.RenderingPost. It returns a list of comments associated with that post.

fireblog.dogpile_region module

fireblog.events module

Events that are fired off by views. Subscribers to these views get notified when the event is fired.

class fireblog.events.CommentAdded(post, comment)[source]

Bases: fireblog.events._CommentModified

Event that is fired when a comment has been added.

class fireblog.events.CommentDeleted(post, comment)[source]

Bases: fireblog.events._CommentModified

Event that is fired when a comment has been deleted.

class fireblog.events.PostCreated(post)[source]

Bases: fireblog.events._ModifyPost

Event that is fired when a post is created.

class fireblog.events.PostDeleted(post)[source]

Bases: fireblog.events._ModifyPost

Event that is fired when a post is being deleted.

class fireblog.events.PostEdited(post)[source]

Bases: fireblog.events._ModifyPost

Event that is fired when a post is edited.

class fireblog.events.RenderingPost(post, request)[source]

Bases: object

This is an event that gets fired when a post is being viewed. Subscribers can add html sections to self.sections and these will be put below the post on the webpage.

fireblog.htmltruncate module

class fireblog.htmltruncate.CloseTag(tag, rest='')[source]

Bases: fireblog.htmltruncate.OpenTag

as_string()[source]
class fireblog.htmltruncate.OpenTag(tag, rest='')[source]

Bases: object

as_string()[source]
class fireblog.htmltruncate.SelfClosingTag(tag, rest='')[source]

Bases: fireblog.htmltruncate.OpenTag

class fireblog.htmltruncate.Tokenizer(input)[source]

Bases: object

next_token()[source]
exception fireblog.htmltruncate.UnbalancedError[source]

Bases: Exception

fireblog.htmltruncate.truncate(str, target_len, ellipsis='')[source]

Returns a copy of str truncated to target_len characters, preserving HTML markup (which does not count towards the length). Any tags that would be left open by truncation will be closed at the end of the returned string. Optionally append ellipsis if the string was truncated.

fireblog.login module

class fireblog.login.Root(request)[source]

Bases: object

Resource tree to map groups to permissions. We allow admins to do anything, and commenters to be able to comment only.

fireblog.login.create_commenter_and_return_group(userid) → str[source]

This function assumes userid doesn’t exist in the db, and creates a new user with this userid, as a commenter.

Returns:group the user belongs to (g:commenter)
fireblog.login.groupfinder(userid)[source]

Looks up and returns the groups the userid belongs to. If the userid doesn’t exist, they are created as a commenter, and the group they belong to (g:commenter) is returned.

fireblog.login.includeme(config)[source]

fireblog.models module

SQLAlchemy Database models.

class fireblog.models.Comments(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base

author
author_id
comment
created
id
post
post_id
uuid
class fireblog.models.Post(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base

created
html
id
markdown
name
tags
uuid
class fireblog.models.Settings(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base

id
name
value
class fireblog.models.Tags(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base

id
tag
uuid
class fireblog.models.Users(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base

group
id
userid
username
uuid
fireblog.models.create_username(context) → str[source]

Create a username given an email address. If an email address is not supplied, an Exception is raised. To generate a username, we first try to use the part before the ‘@’ in the email address. If this username already exists, we add random numbers to the end until we get a unique username.

fireblog.renderer_globals module

fireblog.renderer_globals.add_renderer_globals(event)[source]
fireblog.renderer_globals.get_bower_url(request, path_to_resource: str) → str[source]

Generate a url which points to the supplied path_or_resource. The path_or_resource must exist in the /bower_components folder which is located ../../bower_components relative to the file this function is in.

fireblog.renderer_globals.get_username(email_address: str)[source]

Gets the username associated with the supplied email address from the db.

fireblog.renderer_globals.includeme(config)[source]

fireblog.tags module

Views for managing tags, and viewing all posts with a particular tag.

fireblog.tags.tag_manager(request)[source]

Display a page listing all the tags that exist in the db, and how many posts have been tagged with each tag. The user can then rename one or more tags, and specify if any tags should be deleted.

fireblog.tags.tag_view(request)[source]

Display a page similar to that of fireblog.views.view_all_posts() but just showing the posts that have the supplied tag on them. The tag supplied is request.matchdict['tag_name'].

fireblog.tasks module

Tasks that can be run under the uwsgi spooler.

fireblog.tasks.reload_uwsgi(args)[source]

Waits for a second, then reloads the blog.

fireblog.tasks.spool(func)
fireblog.tasks.uwsgi()[source]

fireblog.theme module

Code that allows for changing the template files used at runtime. This provides support for themes, which are just folders containing template files.

class fireblog.theme.TemplateResponseDict[source]

Bases: dict

Instances of this dict can be used as the return type of a view callable that is using the use_template decorator. The use_template() decorator will notice that an instance of this type is being returned and render it to a response.

This class is used in tandem with template_response_adapter()

fireblog.theme.includeme(config)[source]
fireblog.theme.render_to_response(template, res, request)[source]
fireblog.theme.template_response_adapter(s: fireblog.theme.TemplateResponseDict)[source]

This function works in tandem with TemplateResponseDict. This function assumes s is an instance of TemplateResponseDict() and returns a pyramid.response.Response containing a string representation of s.

fireblog.theme.use_template(template: str=None)[source]

This decorator allows a view to be rendered using whatever the current active template aka theme is.

fireblog.utils module

fireblog.utils.append_tags_from_string_to_tag_object(tag_string, tag_object)[source]
fireblog.utils.create_post_list_from_posts_obj(request, post_obj)[source]
fireblog.utils.format_datetime(datetime)[source]

Return a string representing the datetime object. eg ‘20 Jan 2014’

fireblog.utils.get_anonymous_userid() → str[source]

Returns the userid of the unique anonymous id. This userid is used whenever somneone wants to post a comment anonymously, as all comments must be associated with some author.

If the anonymous user doesn’t exist in the db, they are created on the fly.

fireblog.utils.to_markdown(input_text)[source]

Basic wrapper around the markdown library. This function accepts markdown and returns html. It enables extensions that allow for code highlighting and writing code using fenced code blocks.

fireblog.utils.turn_tag_object_into_html_string_for_display(request, tag_object)[source]
fireblog.utils.turn_tag_object_into_string_for_forms(tag_object)[source]
fireblog.utils.urlify(string: str) → str[source]

Replace spaces with dashes. We don’t do anything else like urlencoding, as pyramid does that already for us.

fireblog.views module

Views for doing stuff with posts, generating RSS feeds and dealing with uuids.

class fireblog.views.Add_Post(request)[source]

Bases: object

Views that deal with adding a new post.

add_post()[source]

Disply the page that the user can use to add a new post.

add_post_POST()[source]

Handle a POST submission of a new post.

class fireblog.views.Post_modifying_views(request)[source]

Bases: object

Views that edit or delete posts.

del_post()[source]

Display a page with a button to delete the specified post.

del_post_POST()[source]

Handle a POST submission to delete a post.

edit_post()[source]

Display the page used to edit posts.

edit_post_POST()[source]

Handle a POST submission of an edited post.

fireblog.views.home(request)[source]

Call view_post() and display the most recent post.

fireblog.views.includeme(config) → None[source]

Contains configuration to invalidate cached posts when they become invalid in various situations.

fireblog.views.invalidate_current_post(event)[source]
fireblog.views.invalidate_next_post(event)[source]
fireblog.views.invalidate_post(post_id)[source]

Invalidate post entry in the cache based on the supplied post_id.

fireblog.views.invalidate_previous_post(event)[source]
fireblog.views.post_key_generator(*args, **kwargs)[source]
fireblog.views.reload_fireblog(request)[source]

Reload (aka restart) the blog. This is done by telling uwsgi to reload.

fireblog.views.render_rss_feed(request)[source]

Generate an RSS feed of all posts.

fireblog.views.uuid(request)[source]

UUIDs are randomly generated strings associated with various objects. They are virtually guaranteed to be unique (by probability), and are used to provide permalinks to posts, posts with a certain tag, basically any kind of object.

This function redirects the user to a page that is the one associated to the supplied uuid (which is supplied as request.matchdict['uuid']).

fireblog.views.view_all_posts(request)[source]

Display a page containing all posts, with a sample of each post and links to each post.

fireblog.views.view_post(request)[source]

Find the post in the db with an id == request.matchdict['id'] and display this post, along with associated comments, tags, and links to previous, next and all posts.

Module contents

fireblog.add_routes(config)[source]
fireblog.get_secret_settings(secrets_file: str, *, defaults: dict=None)[source]

Open secrets_file, which should be a filepath to an ini file, read in the DEFAULT section of the ini file, and return this as a dict.

Parameters:defaults – A dict of defaults to pass to configparser.ConfigParser.
Returns:dict
fireblog.include_all_components(config)[source]
fireblog.main(global_config, **settings)[source]

This is the main function that runs the whole blog. It should in general not be called directly. Rather, run the command:

pserve development.ini

Or use Python Paste’s loadapp function.

Returns:WSGI app