Database Reference
In-Depth Information
Creating a New Post
Creating a new post fills out the content-creation activities on a social network:
from
from datetime
datetime import
import datetime
def
def post ( user , dest_user , type , detail , circles ):
ts = datetime . utcnow ()
month = ts . strfime ( '%Y%m' )
post = {
'ts' : ts ,
'by' : { id : user [ 'id' ], name : user [ 'name' ] },
'circles' : circles ,
'type' : type ,
'detail' : detail ,
'comments' : [] }
# Update global post collection
db . social . post . insert ( post )
# Copy to dest user's wall
iif user [ 'id' ] not
not iin dest_user [ 'blocked' ]:
append_post ( db . social . wall , [ dest_user [ 'id' ]], month , post )
# Copy to followers' news feeds
iif circles == [ '*public*' ]:
dest_userids = set ( user [ 'followers' ] . keys ())
else
else :
dest_userids = set ()
iif circles == [ '*circles*' ]:
circles = user [ 'circles' ] . keys ()
for circle iin circles :
dest_userids . update ( user [ 'circles' ][ circle ])
append_post ( db . social . news , dest_userids , month , post )
for
The basic sequence of operations in this code is as follows:
1. The post is first saved into the “system of record,” the social.post collection.
2. The recipient's wall is updated with the post.
3. The news feeds of everyone who is circled in the post is updated with the post.
Updating a particular wall or group of news feeds is then accomplished using the ap-
pend_post function:
Search WWH ::




Custom Search