streetsign_server.logic¶
When the views start becoming overly complex, as much as possible the logic should be split out to sane sizes functions over here in logic.
streetsign_server.logic.feeds_and_posts¶
logic for feeds_and_posts views, separated out for clarity.
- streetsign_server.logic.feeds_and_posts.can_user_write_and_publish(user, post)¶
returns a tuple, expressing if ‘user’ has permission to write and publish a post.
- streetsign_server.logic.feeds_and_posts.clean_date(in_text)¶
take some input text, and return a datetime, if possible.
- streetsign_server.logic.feeds_and_posts.cleanup_orphaned_media_files()¶
Scan post_images/ and post_videos/ directories for files that have no corresponding Post record in the database, and remove them. Also removes orphaned thumbnails. Returns a dict with counts of removed files and thumbnails.
- streetsign_server.logic.feeds_and_posts.delete_post_and_run_callback(post, typemodule)¶
before a post is actually deleted, check if there is a ‘pre-delete’ callback on this post type, and run that first. This way, for uploaded images (for instance), the file can be deleted as well.
- streetsign_server.logic.feeds_and_posts.if_i_cant_write_then_i_quit(post, user)¶
checks if a post is editable by a user. If it isn’t, for whatever reason, then raise an appropriate ‘PleaseRedirect’ exception. (reasons could be that it’s in a feed we don’t have write access to, or it’s been published, and we don’t have publish permission to that feed, so the post is now ‘locked’ to us.)
- streetsign_server.logic.feeds_and_posts.post_form_intake(post, form, editor)¶
takes the values from ‘form’, passes the post contents to the editor ‘receive’ function, and adds all the values into the ‘post’ object.
NOTE: this actually modifies the post it is sent!
- streetsign_server.logic.feeds_and_posts.try_to_set_feed(post, new_feed_id, user)¶
Is this user actually allowed to set the feed of this post to what the form is saying they want to? If so, cool. Return that feed.