This module defines the configurations of the Flask application.
pytwask.config.
Config
¶Bases: object
The base configuration which defines the common parameters which will be inherited by the child configurations.
Note
If ‘REDIS_DB_SOCKET’ is specified and non-empty, it will override hostname and port.
DEBUG
= False¶REDIS_DB_HOSTNAME
= '127.0.0.1'¶REDIS_DB_INDEX
= 0¶REDIS_DB_PASSWORD
= ''¶REDIS_DB_PORT
= 6379¶REDIS_DB_SOCKET
= ''¶REMEMBER_COOKIE_DURATION
= datetime.timedelta(7)¶SECRET_KEY
= b'c\x04\x14\x00;\xe44 \xf4\xf3-_9B\x1d\x15u\x02g\x1a\xcc\xd8\x04~'¶pytwask.config.
DevelopmentConfig
¶Bases: pytwask.config.Config
The configuration for development.
DEBUG
= True¶REDIS_DB_INDEX
= 1¶pytwask.config.
ProductionConfig
¶Bases: pytwask.config.Config
The production configuration.
This module defines the two data models ‘Tweet’ and ‘User’ which are used by views and templates.
pytwask.models.
Tweet
(username, post_unix_time, body)¶Bases: object
This ‘Tweet’ class encapsulates all the information related to one tweet.
Note that it will convert the posted UNIX timestamp into a datetime.
get_general_timeline
()¶Get the general timeline. Since the general timeline doesn’t belong to any user, it is defined as a static method of the ‘Tweet’ class.
Returns: | |
---|---|
Return type: | A list of ‘Tweet’ instances. |
pytwask.models.
User
(username, auth_secret, session_token)¶Bases: flask_login.mixins.UserMixin
This ‘User’ class is mainly used by flask-login to manage the user authentication. It can also be used to retrieve and modify user-specific data, e.g., getting user timeline, changing user password.
change_password
(old_password, new_password)¶Change the user password.
Parameters: |
|
---|---|
Raises: |
|
create_new_user
(password)¶Create a new user with the given username and password.
Parameters: |
|
---|---|
Raises: |
|
follow
(followee_username)¶Follow another user by his/her username.
Parameters: | followee_username (str) – |
---|---|
Raises: | ValueError – If failed to follow the user |
get
()¶Get a ‘User’ instance from the session token.
Parameters: | session_token (str) – |
---|---|
Returns: | |
Return type: | A ‘User’ instance if session_token exists; otherwise None. |
get_by_username_and_password
(password)¶Get a ‘User’ instance from the username and the password.
Parameters: |
|
---|---|
Returns: | |
Return type: | A ‘User’ instance if username and password are correct; otherwise None. |
get_followers
()¶Get the follower list.
Returns: | |
---|---|
Return type: | A set of the usernames of the followers. |
get_followings
()¶Get the following list.
Returns: | |
---|---|
Return type: | A set of the usernames of the followings. |
get_id
()¶Get the user ID which is the session token in our case.
get_user_timeline
()¶Get the user timeline.
Returns: | |
---|---|
Return type: | A list of ‘Tweet’ instances. |
get_user_tweets
(username)¶Get the tweets posted by a given user.
Parameters: | username (str) – |
---|---|
Returns: | |
Return type: | A list of ‘Tweet’ instances. |
post_tweet
(body)¶Post a tweet.
Parameters: | body (str) – The tweet body that will be posted. |
---|---|
Raises: | ValueError – If failed to post the tweet. |
unfollow
(followee_username)¶Unfollow another user by his/her username.
Parameters: | followee_username (str) – |
---|---|
Raises: | ValueError – If failed to unfollow the user. |