<s> """<STR_LIT>""" <EOL> __author__ = '<STR_LIT>' <EOL> import json <EOL> from tornado import gen <EOL> from viewfinder . backend . db import vf_schema <EOL> from viewfinder . backend . db . asset_id import IdPrefix , ConstructTimestampAssetId , DeconstructTimestampAssetId , VerifyAssetId <EOL> from viewfinder . backend . db . base import DBObject <EOL> from viewfinder . backend . db . operation import Operation <EOL> from viewfinder . backend . db . range_base import DBRangeObject <EOL> @ DBObject . map_table_attributes <EOL> class Activity ( DBRangeObject ) : <EOL> """<STR_LIT>""" <EOL> __slots__ = [ ] <EOL> _table = DBObject . _schema . GetTable ( vf_schema . ACTIVITY ) <EOL> def MakeMetadataDict ( self ) : <EOL> """<STR_LIT>""" <EOL> activity_dict = self . _asdict ( ) <EOL> activity_dict [ activity_dict . pop ( '<STR_LIT:name>' ) ] = json . loads ( activity_dict . pop ( '<STR_LIT>' ) ) <EOL> return activity_dict <EOL> @ classmethod <EOL> def ConstructActivityId ( cls , timestamp , device_id , uniquifier ) : <EOL> """<STR_LIT>""" <EOL> return ConstructTimestampAssetId ( IdPrefix . Activity , timestamp , device_id , uniquifier ) <EOL> @ classmethod <EOL> def ConstructActivityIdFromOperationId ( cls , timestamp , operation_id ) : <EOL> """<STR_LIT>""" <EOL> device_id , uniquifier = Operation . DeconstructOperationId ( operation_id ) <EOL> return Activity . ConstructActivityId ( timestamp , device_id , uniquifier ) <EOL> @ classmethod <EOL> def DeconstructActivityId ( cls , activity_id ) : <EOL> """<STR_LIT>""" <EOL> return DeconstructTimestampAssetId ( IdPrefix . Activity , activity_id ) <EOL> @ classmethod <EOL> @ gen . coroutine <EOL> def VerifyActivityId ( cls , client , user_id , device_id , activity_id ) : <EOL> """<STR_LIT>""" <EOL> yield VerifyAssetId ( client , user_id , device_id , IdPrefix . Activity , activity_id , has_timestamp = True ) <EOL> @ classmethod <EOL> @ gen . coroutine <EOL> def CreateAddFollowers ( cls , client , user_id , viewpoint_id , activity_id , timestamp , <EOL> update_seq , follower_ids ) : <EOL> """<STR_LIT>""" <EOL> args_dict = { '<STR_LIT>' : follower_ids } <EOL> activity = yield Activity . _CreateActivity ( client , <EOL> user_id , <EOL> viewpoint_id , <EOL> activity_id , <EOL> timestamp , <EOL> update_seq , <EOL> '<STR_LIT>' , <EOL> args_dict ) <EOL> raise gen . Return ( activity ) <EOL> @ classmethod <EOL> @ gen . coroutine <EOL> def CreateMergeAccounts ( cls , client , user_id , viewpoint_id , activity_id , timestamp , <EOL> update_seq , target_user_id , source_user_id ) : <EOL> """<STR_LIT>""" <EOL> args_dict = { '<STR_LIT>' : target_user_id , <EOL> '<STR_LIT>' : source_user_id } <EOL> activity = yield Activity . _CreateActivity ( client , <EOL> user_id , <EOL> viewpoint_id , <EOL> activity_id , <EOL> timestamp , <EOL> update_seq , <EOL> '<STR_LIT>' , <EOL> args_dict ) <EOL> raise gen . Return ( activity ) <EOL> @ classmethod <EOL> @ gen . coroutine <EOL> def CreatePostComment ( cls , client , user_id , viewpoint_id , activity_id , timestamp , <EOL> update_seq , cm_dict ) : <EOL> """<STR_LIT>""" <EOL> args_dict = { '<STR_LIT>' : cm_dict [ '<STR_LIT>' ] } <EOL> activity = yield Activity . _CreateActivity ( client , <EOL> user_id , <EOL> viewpoint_id , <EOL> activity_id , <EOL> timestamp , <EOL> update_seq , <EOL> '<STR_LIT>' , <EOL> args_dict ) <EOL> raise gen . Return ( activity ) <EOL> @ classmethod <EOL> @ gen . coroutine <EOL> def CreateRemoveFollowers ( cls , client , user_id , viewpoint_id , activity_id , timestamp , <EOL> update_seq , follower_ids ) : <EOL> """<STR_LIT>""" <EOL> args_dict = { '<STR_LIT>' : follower_ids } <EOL> activity = yield Activity . _CreateActivity ( client , <EOL> user_id , <EOL> viewpoint_id , <EOL> activity_id , <EOL> timestamp , <EOL> update_seq , <EOL> '<STR_LIT>' , <EOL> args_dict ) <EOL> raise gen . Return ( activity ) <EOL> @ classmethod <EOL> @ gen . coroutine <EOL> def CreateRemovePhotos ( cls , client , user_id , viewpoint_id , activity_id , timestamp , <EOL> update_seq , ep_dicts ) : <EOL> """<STR_LIT>""" <EOL> args_dict = { '<STR_LIT>' : [ { '<STR_LIT>' : ep_dict [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : ep_dict [ '<STR_LIT>' ] } <EOL> for ep_dict in ep_dicts ] } <EOL> activity = yield Activity . _CreateActivity ( client , <EOL> user_id , <EOL> viewpoint_id , <EOL> activity_id , <EOL> timestamp , <EOL> update_seq , <EOL> '<STR_LIT>' , <EOL> args_dict ) <EOL> raise gen . Return ( activity ) <EOL> @ classmethod <EOL> @ gen . coroutine <EOL> def CreateSavePhotos ( cls , client , user_id , viewpoint_id , activity_id , timestamp , <EOL> update_seq , ep_dicts ) : <EOL> """<STR_LIT>""" <EOL> args_dict = { '<STR_LIT>' : [ { '<STR_LIT>' : ep_dict [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : ep_dict [ '<STR_LIT>' ] } <EOL> for ep_dict in ep_dicts ] } <EOL> activity = yield Activity . _CreateActivity ( client , <EOL> user_id , <EOL> viewpoint_id , <EOL> activity_id , <EOL> timestamp , <EOL> update_seq , <EOL> '<STR_LIT>' , <EOL> args_dict ) <EOL> raise gen . Return ( activity ) <EOL> @ classmethod <EOL> @ gen . coroutine <EOL> def CreateShareExisting ( cls , client , user_id , viewpoint_id , activity_id , timestamp , <EOL> update_seq , ep_dicts ) : <EOL> """<STR_LIT>""" <EOL> args_dict = { '<STR_LIT>' : [ { '<STR_LIT>' : ep_dict [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : ep_dict [ '<STR_LIT>' ] } <EOL> for ep_dict in ep_dicts ] } <EOL> activity = yield Activity . _CreateActivity ( client , <EOL> user_id , <EOL> viewpoint_id , <EOL> activity_id , <EOL> timestamp , <EOL> update_seq , <EOL> '<STR_LIT>' , <EOL> args_dict ) <EOL> raise gen . Return ( activity ) <EOL> @ classmethod <EOL> @ gen . coroutine <EOL> def CreateShareNew ( cls , client , user_id , viewpoint_id , activity_id , timestamp , <EOL> update_seq , ep_dicts , follower_ids ) : <EOL> """<STR_LIT>""" <EOL> args_dict = { '<STR_LIT>' : [ { '<STR_LIT>' : ep_dict [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : ep_dict [ '<STR_LIT>' ] } <EOL> for ep_dict in ep_dicts ] , <EOL> '<STR_LIT>' : follower_ids } <EOL> activity = yield Activity . _CreateActivity ( client , <EOL> user_id , <EOL> viewpoint_id , <EOL> activity_id , <EOL> timestamp , <EOL> update_seq , <EOL> '<STR_LIT>' , <EOL> args_dict ) <EOL> raise gen . Return ( activity ) <EOL> @ classmethod <EOL> @ gen . coroutine <EOL> def CreateUnshare ( cls , client , user_id , viewpoint_id , activity_id , timestamp , <EOL> update_seq , ep_dicts ) : <EOL> """<STR_LIT>""" <EOL> args_dict = { '<STR_LIT>' : [ { '<STR_LIT>' : ep_dict [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : ep_dict [ '<STR_LIT>' ] } <EOL> for ep_dict in ep_dicts ] } <EOL> activity = yield Activity . _CreateActivity ( client , <EOL> user_id , <EOL> viewpoint_id , <EOL> activity_id , <EOL> timestamp , <EOL> update_seq , <EOL> '<STR_LIT>' , <EOL> args_dict ) <EOL> raise gen . Return ( activity ) <EOL> @ classmethod <EOL> @ gen . coroutine <EOL> def CreateUpdateEpisode ( cls , client , user_id , viewpoint_id , activity_id , timestamp , <EOL> update_seq , ep_dict ) : <EOL> """<STR_LIT>""" <EOL> args_dict = { '<STR_LIT>' : ep_dict [ '<STR_LIT>' ] } <EOL> activity = yield Activity . _CreateActivity ( client , <EOL> user_id , <EOL> viewpoint_id , <EOL> activity_id , <EOL> timestamp , <EOL> update_seq , <EOL> '<STR_LIT>' , <EOL> args_dict ) <EOL> raise gen . Return ( activity ) <EOL> @ classmethod <EOL> @ gen . coroutine <EOL> def CreateUpdateViewpoint ( cls , client , user_id , viewpoint_id , activity_id , timestamp , <EOL> update_seq , prev_values ) : <EOL> """<STR_LIT>""" <EOL> args_dict = { '<STR_LIT>' : viewpoint_id } <EOL> args_dict . update ( prev_values ) <EOL> activity = yield Activity . _CreateActivity ( client , <EOL> user_id , <EOL> viewpoint_id , <EOL> activity_id , <EOL> timestamp , <EOL> update_seq , <EOL> '<STR_LIT>' , <EOL> args_dict ) <EOL> raise gen . Return ( activity ) <EOL> @ classmethod <EOL> @ gen . coroutine <EOL> def CreateUploadEpisode ( cls , client , user_id , viewpoint_id , activity_id , timestamp , <EOL> update_seq , ep_dict , ph_dicts ) : <EOL> """<STR_LIT>""" <EOL> args_dict = { '<STR_LIT>' : ep_dict [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : [ ph_dict [ '<STR_LIT>' ] for ph_dict in ph_dicts ] } <EOL> activity = yield Activity . _CreateActivity ( client , <EOL> user_id , <EOL> viewpoint_id , <EOL> activity_id , <EOL> timestamp , <EOL> update_seq , <EOL> '<STR_LIT>' , <EOL> args_dict ) <EOL> raise gen . Return ( activity ) <EOL> @ classmethod <EOL> @ gen . coroutine <EOL> def _CreateActivity ( cls , client , user_id , viewpoint_id , activity_id , timestamp , <EOL> update_seq , name , args_dict ) : <EOL> """<STR_LIT>""" <EOL> activity = yield gen . Task ( Activity . Query , client , viewpoint_id , activity_id , None , must_exist = False ) <EOL> if activity is None : <EOL> from viewfinder . backend . base import message <EOL> args_dict [ '<STR_LIT>' ] = dict ( version = message . MAX_MESSAGE_VERSION ) <EOL> activity = Activity . CreateFromKeywords ( viewpoint_id = viewpoint_id , activity_id = activity_id , <EOL> user_id = user_id , timestamp = timestamp , update_seq = update_seq , <EOL> name = name , json = json . dumps ( args_dict ) ) <EOL> yield gen . Task ( activity . Update , client ) <EOL> else : <EOL> assert activity . user_id == user_id , ( activity , user_id ) <EOL> raise gen . Return ( activity ) </s>
