streetsign_server.post_types¶
Post types are the different kinds of posts. So plain text posts, rich html posts, image posts, etc. Each type is defined in its own module here, so it’s easy to add your own.
As well as the .py module, there’s also usually a .screen.js javascript
file which contains the output screen javascript for rendering it again at the
other end, and a .form.html file, which is the template used by the
individual module to render the form for editing that type of post.
Any other bits and pieces you need for this specific post type should be kept here with the module.
Post Type Generic Module Overview¶
As each type of post is different, and has different data storage requirements in the database, and doesn’t have to be queried against, there is no point in having some complex database schema to cope with all possibilities.
Instead, there are columns in the database for storing things common to all posts, and which are queried against, such as lifetime, etc. There is also a CharField textual field which stores post-type-specific data in it as JSON.
Each post-type module doesn’t need to do the json dumping and loading, that’s
done further up the chain. Instead, the module functions are handed standard
python dicts ({"thing": "value"}), to work with. When they return those
dicts, they get bundled back into JSON and stuffed in the database.
So you will need to be careful not to try and store things which aren’t JSONable.
Inside each module,¶
You need the following functions:
- form(data)¶
return the html for the form for editing this kind of post.
datais, of course, the data last saved and to be displayed in the form.
- receive(data)¶
when the form is submitted, this function will be send the request.form data, which you should now extract the relevant info from, sanitize!!, and then this function should return the data you want to store in the database about this post.
- display(data)¶
if you need to do anything to the data before it gets sent on to the screen (as json) to be displayed, this is the place to do it.
- screen_js()¶
return the javascript object used to render this item on the screen client side.
Rendering Screen Zones¶
streetsign_server.post_types¶
Main methods for working with multiple post_types.
- streetsign_server.post_types.load(type_name)¶
load a module, and return it. (caches in this module)
- streetsign_server.post_types.module_dict(name)¶
turns a name (string) into a dict ready for use in importing,
- streetsign_server.post_types.modules()¶
a list of all post types modules which can be used/imported
- streetsign_server.post_types.my(filename, level=1)¶
given a filename, returns the contents of that file in the same directory as the file which has the ‘my’ call in it.
- streetsign_server.post_types.path_to_module(path)¶
given a path (/var/blah/x.py) return the name of x.py for importing (just x)
- streetsign_server.post_types.receive(posttype, form)¶
hand a form object from a request on to the appropriate handler
- streetsign_server.post_types.renderer_js(posttype)¶
return the javascript for rendering a module’s data
- streetsign_server.post_types.renderers()¶
return the javascript for ALL post_types to be rendered. (as a list - you still need to combine it as you like…
- streetsign_server.post_types.types()¶
return a list of dicts of all post types.
streetsign_server.post_types.html¶
HTML / rich text post type.
- streetsign_server.post_types.html.display(data)¶
return the data ready for the display js to do stuff with.
- streetsign_server.post_types.html.form(data)¶
the form for editing this type of post
- streetsign_server.post_types.html.receive(data)¶
turn the contents posted back to us from the form into a dict which can be JSON’d by the system, and dumped as text into the database.
- streetsign_server.post_types.html.safecolor(text, default='#fff')¶
check that a color string is actually a html hex-type color…
- streetsign_server.post_types.html.safehtml(text)¶
used by ‘receive’ to clean html, and not allow scripts and other nasties.
- streetsign_server.post_types.html.screen_js()¶
return the js needed to display this content.
streetsign_server.post_types.text¶
plain text post type.
- streetsign_server.post_types.text.display(data)¶
return the data to send to the display system (screen)
- streetsign_server.post_types.text.form(data)¶
return the html for editing a text post
- streetsign_server.post_types.text.receive(data)¶
recieve the data from the form, and return the dict to save in the db
- streetsign_server.post_types.text.screen_js()¶
the js needed to display a post correctly.
streetsign_server.post_types.image¶
uploaded image post type.
- streetsign_server.post_types.image.allow_filetype(filename)¶
what kinds of files are allowed?
- streetsign_server.post_types.image.delete(data)¶
when a post is deleted, this is called first, so we can clean up.
- streetsign_server.post_types.image.display(data)¶
display the html to display the posted image.
- streetsign_server.post_types.image.form(data)¶
return the html form for editing an image post
- streetsign_server.post_types.image.image_path()¶
return the path to save images to, creating the folder if it doesn’t exist.
- streetsign_server.post_types.image.receive(data)¶
revieve the form data, including the uploaded file, and put it where it should be, and return all the image data we need.
- streetsign_server.post_types.image.resize_image(filename)¶
try to resize an image in place on the system. if fail, just flash a message, don’t actually freak out
- streetsign_server.post_types.image.run_local_script(scriptname, *vargs)¶
run an local (“my”) <scriptname> script, with <*vargs>
- streetsign_server.post_types.image.screen_js()¶
return the javascript for displaying these images correctly
streetsign_server.post_types.video¶
HTML5 video post type. Upload a video file to be displayed on screen.
- streetsign_server.post_types.video.allow_filetype(filename)¶
What video file types do we allow?
- streetsign_server.post_types.video.delete(data)¶
Clean up the video file when the post is deleted.
- streetsign_server.post_types.video.display(data)¶
Return HTML for backend preview of the video.
- streetsign_server.post_types.video.receive(data)¶
Receive the form data, save the uploaded video, return saved info.
- streetsign_server.post_types.video.screen_js()¶
Return the JavaScript for rendering this post on screen.
- streetsign_server.post_types.video.video_path()¶
Return the path to save videos to, creating the folder if needed.
streetsign_server.post_types.html¶
Display an External Web Page embedded in a screen.
- streetsign_server.post_types.external_webpage.display(data)¶
return the data ready for the display js to do stuff with.
- streetsign_server.post_types.external_webpage.form(data)¶
the form for editing this type of post
- streetsign_server.post_types.external_webpage.receive(data)¶
turn the contents posted back to us from the form into a dict which can be JSON’d by the system, and dumped as text into the database.
- streetsign_server.post_types.external_webpage.screen_js()¶
return the js needed to display this content.
streetsign_server.post_types.raw_html¶
Full HTML page with no sanitization. Scripts and arbitrary HTML are allowed.
Test module. This post type, when shown, doesn’t display any data, but instead sends an ajax POST request to a specified URL, thus allowing the presentation to actually control other machines or processes.
- streetsign_server.post_types.web_hook.display(data)¶
don’t actually display anything.
- streetsign_server.post_types.web_hook.form(data)¶
the form for editing this type of post
- streetsign_server.post_types.web_hook.receive(data)¶
When the data comes in from the form, what parts do we actually want to save?
- streetsign_server.post_types.web_hook.screen_js()¶
return the javascript for doing the dirty work.