Пример #1
0
 def loads(self, serialized_activity):
     serialized_activity.pop('activity_id')
     serialized_activity.pop('feed_id')
     serialized_activity['verb'] = get_verb_by_id(int(serialized_activity['verb']))
     serialized_activity['extra_context'] = pickle.loads(
         serialized_activity['extra_context']
     )
     return self.activity_class(**serialized_activity)
Пример #2
0
def create_activity(request):
    """
    Creates an Activity Item to be sent to user stream
    ---
    #YAML
    type:
        author:
            required: true
            type: string
        object_type:
            required: true
            type: string
        object_id:
            required: true
            type: string
        verb:
            required: true
            type: integer
        target_id:
            required: false
            type: string
        target_type:
            required: false
            type: string

    parameters:
        - in: body
          name: "ActivityObject"
          pytype: ActivityRequestSerializer
          paramType: body
          description: JSON representation of the activity item
    """
    if request.method == 'POST':
        serializer = ActivityRequestSerializer(data=request.data)
        if serializer.is_valid():
            act = serializer.data
            if act['verb_id'] != '12':
                from stream_framework.activity import Activity
                activity = Activity(
                    actor       = act['author'],
                    object      = act['object_id'],
                    object_type = act['object_type'],
                    verb        = get_verb_by_id(int(act['verb_id'])),
                    target      = act['target_id'],
                    target_type = act['target_type'],
                )
                actor = act['author']
                print act["created_at"]
                print actor, activity
                manager.addactivity_rest(actor=actor, activity=activity)
            else:
                return Response("Not adding views as activities", status=status.HTTP_400_BAD_REQUEST)

            return Response(act, status=status.HTTP_201_CREATED)
        else:
            print serializer.errors
            return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
 def loads(self, serialized_activity):
     # TODO: convert cqlengine model to stream_framework Activity using public API
     activity_kwargs = {k: getattr(serialized_activity, k)
                        for k in serialized_activity.__dict__['_values'].keys()}
     activity_kwargs.pop('activity_id')
     activity_kwargs.pop('feed_id')
     activity_kwargs['verb'] = get_verb_by_id(int(serialized_activity.verb))
     activity_kwargs['extra_context'] = pickle.loads(
         activity_kwargs['extra_context']
     )
     return self.activity_class(**activity_kwargs)
 def loads(self, serialized_activity):
     # TODO: convert cqlengine model to stream_framework Activity using public API
     activity_kwargs = {
         k: getattr(serialized_activity, k)
         for k in serialized_activity.__dict__['_values'].keys()
     }
     activity_kwargs.pop('activity_id')
     activity_kwargs.pop('feed_id')
     activity_kwargs['verb'] = get_verb_by_id(int(serialized_activity.verb))
     activity_kwargs['extra_context'] = pickle.loads(
         activity_kwargs['extra_context'])
     return self.activity_class(**activity_kwargs)
Пример #5
0
    def loads(self, serialized_activity):
        parts = serialized_activity.split(',')
        # convert these to ids
        actor_id, verb_id, object_id, target_id = map(
            int, parts[:4])
        activity_datetime = epoch_to_datetime(float(parts[4]))
        pickle_string = str(parts[5])
        if not target_id:
            target_id = None
        verb = get_verb_by_id(verb_id)
        extra_context = {}
        if pickle_string:
            extra_context = pickle.loads(pickle_string)
        activity = self.activity_class(actor_id, verb, object_id, target_id,
                                       time=activity_datetime, extra_context=extra_context)

        return activity
    def loads(self, serialized_activity):
        parts = serialized_activity.split(',')
        # convert these to ids
        actor_id, verb_id, object_id, target_id = map(int, parts[:4])
        activity_datetime = epoch_to_datetime(float(parts[4]))
        pickle_string = str(parts[5])
        if not target_id:
            target_id = None
        verb = get_verb_by_id(verb_id)
        extra_context = {}
        if pickle_string:
            extra_context = pickle.loads(pickle_string)
        activity = self.activity_class(actor_id,
                                       verb,
                                       object_id,
                                       target_id,
                                       time=activity_datetime,
                                       extra_context=extra_context)

        return activity
Пример #7
0

        

manager = NewManager()
manager.follow_user(1,2)

# some activity in Redis (e.g. keys *)
# - create celery list (e.g. LRANGE celery 0 100)
# - create _kombu.bindings.celery set (e.g. SSCAN _kombu.binding.celery 0)
#from stream_framework.verbs import register
#from stream_framework.verbs.base import Verb

from stream_framework.verbs import get_verb_by_id    
for x in range(1,5):
    verb = get_verb_by_id(x)
    print verb

# 1: Follow
# 2: Comment
# 3: Love
# 4: Add
feed1 = RedisFeed(1) 

User = namedtuple('User', ['id'])
a1 = Activity(
    #actor=User("54blablabla"), # some type of mongo user id
    actor=1, # some type of mongo user id
    verb=Follow, # The id associated with the  verb
    object=2, # The id of something/someone
    #target=1, # The id of the Surf Girls board
Пример #8
0
def enrich_custom_activities(activities):
    # We need to get the enriched activities for each activity...
    # following the activity stream specs, I believe
    start_time = datetime.datetime.now()
    list = []
    for a in activities:
        # Build the activity stream object...
        print a
        activity_item = ActivityItemModel()
        # Should be empty
        print content_by_author_stmt, a.actor, a.object
        object = session.execute(content_by_author_stmt, [a.actor, a.object])
        print type(object)

        if len(object) > 0:

            activity_item.published = object[0].created_at

            actor_object = session.execute("Select * from users where username = '******'")

            profile_object = session.execute("Select * from userprofile where username = '******'")

            #raise Exception(actor_object)

            # Actor element
            activity_item.actor['id'] = unicode(actor_object[0].username)
            activity_item.actor['displayname'] = actor_object[0].firstname + " " + actor_object[0].lastname
            activity_item.actor['objecttype'] = 'yookos:person'
            activity_item.actor['creationdate'] = actor_object[0].creationdate
            activity_item.actor['lastprofileupdate'] = actor_object[0].lastprofileupdate
            #activity_item.actor['url'] = settings.BASE_URL + "users/" + actor_object[0].username

            # Patrick - providing link to user profile and profile picture
            activity_item.actor['url'] = "auth/profile/" + actor_object[0].username
            # providing a link to the profile picture
            if len (profile_object)>0 and profile_object[0].imageurl:
                activity_item.actor['imageurl'] = profile_object[0].imageurl
            else:
                activity_item.actor['imageurl'] = ''

            # END - providing link to user profile and profile picture

            #verb element
            activity_item.verb = (get_verb_by_id(a.verb)).past_tense

            content_object = session.execute(
                "Select * from content where author = '" + a.actor + "' and  id = " + str(a.object))
            #raise Exception(content_object)

            #object element
            activity_item.object['id'] = content_object[0].id
            activity_item.object['type'] = content_object[0].content_type
            if content_object[0].title:
                activity_item.object['title'] = content_object[0].title
            else:
                activity_item.object['title'] = ''
            if content_object[0].body:
                activity_item.object['text'] = content_object[0].body
            else:
                activity_item.object['text'] = ''
            activity_item.object['publishdate'] = content_object[0].created_at
            activity_item.object['likes'] = content_object[0].like_count
            activity_item.object['views'] = content_object[0].view_count
            activity_item.object['commentcount'] = content_object[0].comment_count
            # Patrick - adding images to the feed
            if content_object[0].uri_image:
                activity_item.object['img'] ='http://192.168.10.123:8000/api/images/'+ str(content_object[0].uri_image[0])+'/'
            else:
                activity_item.object['img'] =''
            if content_object[0].content_type == 'photo' and content_object[0].data:
                activity_item.object['img'] ='http://192.168.10.123:8000/api/images/'+ str(content_object[0].id)+'/'
            if content_object[0].url_original:
                activity_item.object['url_original'] = str(content_object[0].url_original)
            else:
                activity_item.object['url_original'] = ''
            if content_object[0].image_url:
                activity_item.object['image_url'] = str(content_object[0].image_url)
            else:
                activity_item.object['image_url'] = ''
            # END - adding images to the feed

            # Emile - audio feature additions
            if content_object[0].content_type == "audioblog" or content_object[0].content_type == "audio":
                activity_item.object['filename'] = str(content_object[0].filename)
                activity_item.object['caption'] = str(content_object[0].caption)
            elif content_object[0].content_type == "photo":
                activity_item.object['filename'] = str(content_object[0].filename)
                activity_item.object['caption'] = str(content_object[0].caption)
            else:
                activity_item.object['filename'] = ''
                activity_item.object['caption'] = ''

            # END - audio feature additions

            # has this object been like by this author before?
            query = "select * from like where author='"+ content_object[0].author+"' "
            query += " and object_id="+str(content_object[0].id)+" allow filtering"
            like_object = session.execute(query)
            if len(like_object)>0:
                activity_item.object['liked'] = True
            else:
                activity_item.object['liked'] = False

            '''activity_item.object['url'] = settings.BASE_URL + "api/content/" + actor_object[0].username + "/" + str(
                content_object[0].id)'''
            activity_item.object['url'] = "api/content/" + str(content_object[0].id) + '/'
            # if content_object[0].content_type == 'statusupdate':
            #     activity_item.object['comments'] = settings.CONTENT_URL + "status_updates/" + str(
            #         content_object[0].id) + "/comments"
            # if content_object[0].content_type == 'blogpost':
            #     activity_item.object['comments'] = settings.CONTENT_URL + "blogposts/" + str(
            #         content_object[0].id) + "/comments"
            activity_item.object['comments'] = settings.CONTENT_URL + "content/" + str(
                    content_object[0].id) + "/comments/"
            #Updated element
            if content_object[0].updated_at:
                activity_item.updated = content_object[0].updated_at
            else:
                activity_item.updated = content_object[0].created_at

            #This block of code will get the latest comment, if any.

            lc = Comment.filter(object_id=str(content_object[0].id))[:1]

            if len(lc) > 0:
                commenter_object = session.execute("Select * from users where username = '******'")

                commenter_profile_object = session.execute("Select * from userprofile where username = '******'")


                if len(commenter_object) > 0:
                    #for now we assume the author always exists

                    fullname = commenter_object[0].firstname + " " + commenter_object[0].lastname
                    """
                    if commenter_object[0].profile is not None:
                        profile_pic_url = commenter_object.profile.profilepicture
                        activity_item.object['latestcomment'] = dict(author=settings.BASE_URL + "users/" + lc[0].author,
                                                                     authorname=fullname, body=lc[0].body,
                                                                     creationdate=lc[0].created_at,
                                                                     imageurl=profile_pic_url)
                    else:
                    """
                    # if the profile of the commenter exists
                    if len(commenter_profile_object) >0 and commenter_profile_object[0].imageurl:
                        profile_pic_url = commenter_profile_object[0].imageurl
                        activity_item.object['latestcomment'] = dict(author=settings.BASE_URL + "users/" + lc[0].author,
                                                                     username= lc[0].author,
                                                                     authorname=fullname, body=lc[0].body,
                                                                     creationdate=lc[0].created_at,
                                                                     imageurl=profile_pic_url)
                    else:
                        activity_item.object['latestcomment'] = dict(author=settings.BASE_URL + "users/" + lc[0].author,
                                                                     username= lc[0].author,
                                                                     authorname=fullname, body=lc[0].body,
                                                                     creationdate=lc[0].created_at,
                        )

                    # activity_item.object.latestcomment['body'] = lc[0].body
                    # activity_item.object.latestcomment['created_at'] = lc[0].created_at
                    #Build the comment object.

                    print "Last comment: ", lc[0]
                else:
                    activity_item.object['latestcomment'] = {}
            else:
                activity_item.object['latestcomment'] = {}
                print "No comments"

            #Target element coming soon


            serializer = ActivityModelSerializer(activity_item)
            list.append(serializer.data)
    end_time = datetime.datetime.now()
    elapsed_time = end_time - start_time
    print "Elapsed time: ", elapsed_time

    return list