streetsign_server.models¶
All Peewee ORM database models, organised into submodules:
base.py, users.py, auth.py, feeds.py, screens.py,
config.py. Everything is re-exported from the __init__.py package root.
Utility functions¶
- streetsign_server.models.safe_json_load(text, default)¶
either parse a string from JSON into python or else return default.
- streetsign_server.models.eval_datetime_formula(string)¶
evaluate a simple date/time formula, returning a unix datetime stamp
- streetsign_server.models.by_id(model, ids)¶
returns a list of objects, selected by id (list)
Database initialisation¶
- streetsign_server.models.init(dbfile=False)¶
- streetsign_server.models.create_all(dbfile=False)¶
- streetsign_server.models.migrations(dbfile=False)¶
Users and Groups¶
- class streetsign_server.models.User(*args, **kwargs)¶
Back-end user.
- DoesNotExist¶
alias of
UserDoesNotExist
- confirm_password(password)¶
Check that password does verify against the stored hash
- displayname = <CharField: User.displayname>¶
how the user would like to be displayed
- emailaddress = <CharField: User.emailaddress>¶
how to contact the user:
- failed_logins = <IntegerField: User.failed_logins>¶
how many times has the user failed to log in?
- groups()¶
Returns all the Groups that this user is part of.
- is_admin = <BooleanField: User.is_admin>¶
is the user an admin?
- is_locked_out = <BooleanField: User.is_locked_out>¶
you can lock out users, so they cannot log in for a while.
- last_login_attempt = <DateTimeField: User.last_login_attempt>¶
when was the last attempt to log in?
- loginname = <CharField: User.loginname>¶
the unique name user to log in
- passwordhash = <CharField: User.passwordhash>¶
bcrypt’d, salted, etc password hash
- publishable_feeds()¶
Returns all the Feeds that this user can publish to.
- set_groups(groupidlist)¶
Set the grouplist for this user (and remove old groups)
- set_password(password)¶
Encrypts password, and sets the password hash. Not stored until you save!
- writeable_feeds()¶
Returns a list of all Feeds this user can write to.
Login Stuff¶
Most of the time, these shouldn’t be used directly, but instead use the functions from streetsign_server.user_session
- class streetsign_server.models.UserSession(*args, **kwargs)¶
Track user logged in sessions in the database.
- DoesNotExist¶
alias of
UserSessionDoesNotExist
- id = <CharField: UserSession.id>¶
unique id
- login_time = <DateTimeField: UserSession.login_time>¶
when did they log in?
- user = <ForeignKeyField: UserSession.user>¶
the user
- username = <CharField: UserSession.username>¶
which username?
- streetsign_server.models.user_login(name, password)¶
preferred way to get a user object, which checks the password, and either returns a User object, or raises an exception
- streetsign_server.models.get_logged_in_user(name, session_uuid)¶
either returns a logged in user, or raises an error
- streetsign_server.models.user_logout(name, session_uuid)¶
removes a session
And the Invalid Password Exception:
- class streetsign_server.models.InvalidPassword(value)¶
Oh no! Invalid password!
Posts and Feeds¶
- class streetsign_server.models.Feed(*args, **kwargs)¶
A Feed is kind of like a collection, or category of posts. Different ‘zones’ on screen outputs will subscribe to these Feeds.
- DoesNotExist¶
alias of
FeedDoesNotExist
- author_groups()¶
return all groups with write permission
- authors()¶
return all users with write permission
- grant(permission, user=None, group=None)¶
Give either a user or group permission (either ‘Read’,’Write’ or ‘Publish’) on this Feed.
Granting one permission does not revoke any others the user/group already holds on this feed - the flags accumulate on a single FeedPermission row.
- name = <CharField: Feed.name>¶
the name of the feed.
- post_count(published=True, expired=False)¶
how many posts in this feed?
- post_types = <CharField: Feed.post_types>¶
which types of posts are allowed in this feed (comma,separated)?
- post_types_as_list()¶
return a list of post types, from the single field
- publisher_groups()¶
return all groups with publishing permission
- publishers()¶
return all users with publishing permission
- set_author_groups(authorlist)¶
set the complete author_groups list. deletes previous set
- set_authors(authorlist)¶
set the complete authorlist. deletes previous set
- set_publisher_groups(publisherlist)¶
set the complete publisher_groups list. deletes previous set
- set_publishers(publisherlist)¶
set the complete publisherlist. deletes previous set
- user_can_publish(user)¶
Checks publish permission. (Admins get automatically)
- user_can_read(user)¶
Checks read permission for a feed. Not really used, as yet.
- user_can_write(user)¶
Checks write permission. (Admins get automatically)
- class streetsign_server.models.FeedPermission(*args, **kwargs)¶
Essentially a cross-reference table, but with specified permissions.
- DoesNotExist¶
alias of
FeedPermissionDoesNotExist
- class streetsign_server.models.Post(*args, **kwargs)¶
The actual main point of this whole thing. The contents that get displayed. This object/row/thing hands off all the actual editing of, displaying of, and validating of the contents to a post type module. It’s stored in the database as JSON. This means new types of post can be added quite easily later, without changing the schema.
- DoesNotExist¶
alias of
PostDoesNotExist
- active_end = <DateTimeField: Post.active_end>¶
end
- active_start = <DateTimeField: Post.active_start>¶
lifetime start
- active_status()¶
is this post active now, in the future, or the past? (returns a string ‘now’/’future’/’past’)
- author = <ForeignKeyField: Post.author>¶
who wrote it?
- content = <TextField: Post.content>¶
JSON data sent to the content-type module
- dict_repr()¶
must give all info, for use on screens, etc.
- display_time = <IntegerField: Post.display_time>¶
For how long should it be displayed?
- feed = <ForeignKeyField: Post.feed>¶
which feed
- publish(user, state=True)¶
set the published status, published & date of this post. use state=False to unpublish
- publish_date = <DateTimeField: Post.publish_date>¶
when was it published?
- published = <BooleanField: Post.published>¶
is this post published?
- publisher = <ForeignKeyField: Post.publisher>¶
who published it?
- repr()¶
This is actually used by the back-end to display different ‘thumbnails’ of posts. If you want to show HTML (careful!!!!!!!!) then wrap it in Markup(), so jinja2 doesn’t escape it.
- save(*vargs, **kwargs)¶
Save the state of the object to the database, updating the ‘write_date’ time along the way.
- status = <IntegerField: Post.status>¶
can be 0:active/1:finished/2:archived.
- time_restrictions = <TextField: Post.time_restrictions>¶
and the actual restrictions:
- time_restrictions_show = <BooleanField: Post.time_restrictions_show>¶
Time restrictions don’t need to be cross queried, and honestly are easier just left in javascript/JSON land: are these restrictions “Only show during these times” or “Do not show during these times” ?
- title = <TextField: Post.title>¶
used to easily identify the post
- type = <TextField: Post.type>¶
used to load the content-type module for this post
- write_date = <DateTimeField: Post.write_date>¶
when was it written?
- class streetsign_server.models.ExternalSource(*args, **kwargs)¶
How do we pull data in from external sources?
- DoesNotExist¶
alias of
ExternalSourceDoesNotExist
- current_lifetime_end()¶
given the equation in the lifetime_end field, what time should the end of a new post lifetime be?
- current_lifetime_start()¶
given the equation in the lifetime_start field, what should the time be of a new post start time?
- display_time = <IntegerField: ExternalSource.display_time>¶
how long should each post be displayed for?
- feed = <ForeignKeyField: ExternalSource.feed>¶
Which feed should posts from this source show up in?
- frequency = <IntegerField: ExternalSource.frequency>¶
how often to check for new data at the source…
- last_checked = <DateTimeField: ExternalSource.last_checked>¶
when was it last checked?
- lifetime_end = <CharField: ExternalSource.lifetime_end>¶
Lifetime end of new posts (formula)
- lifetime_start = <CharField: ExternalSource.lifetime_start>¶
Lifetime start of new posts (formula)
- name = <CharField: ExternalSource.name>¶
name, displayed in the interface
- post_as_user = <ForeignKeyField: ExternalSource.post_as_user>¶
Which user should be set as the owner / author of these?
- post_template = <CharField: ExternalSource.post_template>¶
initial post settings. (TODO)
- publish = <BooleanField: ExternalSource.publish>¶
Should new posts from this source start off published?
- settings = <CharField: ExternalSource.settings>¶
Where the actual per-type-specific settings are saved:
- type = <CharField: ExternalSource.type>¶
source types are loaded in later, the same as post types.
Screens and Output¶
- class streetsign_server.models.Screen(*args, **kwargs)¶
Each URL for output is known as a screen. (You can point a web-browser with a physical screen at it.) This stores the info needed to display them.
Since most of the settings here are made with a JS interface, and sent as json packets to another JS interface for display, and don’t need to be queried against, just leave ‘em as JSON.
- DoesNotExist¶
alias of
ScreenDoesNotExist
- background = <CharField: Screen.background>¶
the background image
- css = <TextField: Screen.css>¶
general CSS settings for the whole page. Can contain selectors, etc.
- defaults = <TextField: Screen.defaults>¶
default post settings (JSON)
- md5()¶
return MD5 digest of this screen’s JSON representation.
- settings = <TextField: Screen.settings>¶
screen settings (JSON)
- to_dict()¶
returns a dict, ready for transmission as JSON
- urlname = <CharField: Screen.urlname>¶
the url where this will be available
/screens/<urlname
- zones = <TextField: Screen.zones>¶
spec all the zones (JSON)