コード例 #1
0
    def test_workspace_tile(self):
        ''' This will test the existence of the workspaces.tile
        and its functionality
        '''
        tile = api.content.get_view('workspaces.tile', self.portal,
                                    self.request)
        su = StatusUpdate('Proposal draft V1.0 # This is a mock!!!', **{
            'microblog_context': self.workspace,
        })
        su.id = 123456789L
        su.creator = 'charlotte_holzer'
        su.date = DateTime('2008/02/14 18:43')
        mb = queryUtility(IMicroblogTool)
        mb.add(su)
        workspaces = tile.workspaces(include_activities=True)
        self.assertEqual(len(workspaces), 1)

        demo_ws = workspaces[0]

        activities = demo_ws['activities']
        self.assertEqual(len(activities), 1)
        self.assertDictEqual(
            activities[0], {
                'object': 'Proposal draft V1.0 # This is a mock!!!',
                'subject': 'charlotte_holzer',
                'time': {
                    'datetime': '2008-02-14',
                    'title': '14 February 2008, 18:43'
                },
                'verb': 'posted'
            })
コード例 #2
0
def create(
    text,
    context=None,
    thread_id=None,
    mention_ids=None,
    tags=None,
    user=None,
    userid=None,
    time=None,
):
    """Create a status update (post).

    :param text: [required] text of the post
    :type text: Unicode object

    :param context: Container of the post
    :type context: Content object

    :param user: User who should post. By default the current user posts.
    :type user: user object

    :param userid: userid of the user who should post.
    :type userid: string

    :param time: time when the post should happen. By default the current time.
    :type time: datetime object

    :returns: Newly created statusupdate
    :rtype: StatusUpdate object
    """
    status_obj = StatusUpdate(
        text=text,
        context=context,
        thread_id=thread_id,
        mention_ids=mention_ids,
        tags=tags
    )
    # By default the post is done by the current user
    # Passing a userid or user allows to post as a different user
    if user is None and userid is not None:
        user = api.user.get(userid=userid)
    if user is not None:
        status_obj.userid = user.getId()
        status_obj.creator = user.getUserName()

    # By default the post happens now
    # Passing a time (as a datetime-object) the id and the date can be set
    if time is not None:
        assert(isinstance(time, datetime))
        delta = time - datetime.utcfromtimestamp(0)
        status_obj.id = long(delta.total_seconds() * 1e6)
        status_obj.date = DateTime(time)

    status_id = status_obj.id
    microblog = queryUtility(IMicroblogTool)
    microblog.add(status_obj)
    return microblog.get(status_id)
コード例 #3
0
def create(
    text,
    microblog_context=None,
    thread_id=None,
    mention_ids=None,
    tags=None,
    user=None,
    userid=None,
    time=None,
):
    """Create a status update (post).

    :param text: [required] text of the post
    :type text: Unicode object

    :param microblog_context: Container of the post
    :type microblog_context: Content object

    :param user: User who should post. By default the current user posts.
    :type user: user object

    :param userid: userid of the user who should post.
    :type userid: string

    :param time: time when the post should happen. By default the current time.
    :type time: datetime object

    :returns: Newly created statusupdate
    :rtype: StatusUpdate object
    """
    status_obj = StatusUpdate(
        text=text,
        microblog_context=microblog_context,
        thread_id=thread_id,
        mention_ids=mention_ids,
        tags=tags
    )
    # By default the post is done by the current user
    # Passing a userid or user allows to post as a different user
    if user is None and userid is not None:
        user = api.user.get(userid=userid)
    if user is not None:
        status_obj.userid = user.getId()
        status_obj.creator = user.getUserName()

    # By default the post happens now
    # Passing a time (as a datetime-object) the id and the date can be set
    if time is not None:
        assert(isinstance(time, datetime))
        delta = time - datetime.utcfromtimestamp(0)
        status_obj.id = long(delta.total_seconds() * 1e6)
        status_obj.date = DateTime(time)

    status_id = status_obj.id
    microblog = queryUtility(IMicroblogTool)
    microblog.add(status_obj)
    return microblog.get(status_id)
コード例 #4
0
ファイル: test_tiles.py プロジェクト: sudhan77/ploneintranet
    def test_workspace_tile(self):
        ''' This will test the existence of the workspaces.tile
        and its functionality
        '''
        tile = api.content.get_view(
            'workspaces.tile',
            self.portal,
            self.request
        )
        su = StatusUpdate(
            'Proposal draft V1.0 # This is a mock!!!',
            **{
                'microblog_context': self.workspace,
            }
        )
        su.id = 123456789L
        su.creator = 'charlotte_holzer'
        su.date = DateTime('2008/02/14 18:43')
        mb = queryUtility(IMicroblogTool)
        mb.add(su)
        workspaces = tile.workspaces()
        self.assertEqual(len(workspaces), 1)

        demo_ws = workspaces[0]
        activities = demo_ws['activities']
        self.assertEqual(len(activities), 1)
        self.assertDictEqual(
            activities[0],
            {
                'object': 'Proposal draft V1.0 # This is a mock!!!',
                'subject': 'charlotte_holzer',
                'time': {
                    'datetime': '2008-02-14',
                    'title': '14 February 2008, 18:43'
                },
                'verb': 'posted'
            }
        )
コード例 #5
0
def create(
    text=u'',
    microblog_context=None,
    thread_id=None,
    mention_ids=None,
    tags=None,
    user=None,
    userid=None,
    time=None,
    content_context=None,
    action_verb=None,
):
    """Create a status update (post).

    :param text: text of the post
    :type text: Unicode object

    :param microblog_context: Container of the post
    :type microblog_context: Content object

    :param user: User who should post. By default the current user posts.
    :type user: user object

    :param userid: userid of the user who should post.
    :type userid: string

    :param time: time when the post should happen. By default the current time.
    :type time: timezone aware datetime object

    :param content_context: a content referenced we are talking about
    :type content_context: content object

    :param action_verb: indicate event source (posted, created, published)
    :type action_verb: string

    :returns: Newly created statusupdate
    :rtype: StatusUpdate object

    Note that you can add attachments to statusupdates by calling
    .add_attachment(filename, data)
    on the returned StatusUpdate.
    """
    if IPloneSiteRoot.providedBy(microblog_context):
        microblog_context = None
    if IPloneSiteRoot.providedBy(content_context):
        content_context = None

    # Avoid circulat dependencies
    from ploneintranet.microblog.statusupdate import StatusUpdate
    status_obj = StatusUpdate(
        text=text,
        microblog_context=microblog_context,
        thread_id=thread_id,
        mention_ids=mention_ids,
        tags=tags,
        content_context=content_context,
        action_verb=action_verb,
    )
    # By default the post is done by the current user
    # Passing a userid or user allows to post as a different user
    if user is None and userid is not None:
        user = api.user.get(userid=userid)
    if user is not None:
        status_obj.userid = user.getId()
        status_obj.creator = user.getId()

    # By default the post happens now
    # Passing a time (as a datetime-object) the id and the date can be set
    if time is not None:
        assert (isinstance(time, datetime))
        if not time.tzinfo or time.tzinfo.utcoffset(time) is None:
            raise ValueError("Naive datetime not supported")
        UTC = pytz.timezone('UTC')
        epoch = UTC.localize(datetime.utcfromtimestamp(0))
        delta = time - epoch
        status_obj.id = long(delta.total_seconds() * 1e6)
        status_obj.date = DateTime(time)
        if time > datetime.now(UTC):
            raise ValueError("Future statusupdates are an abomination")

    microblog = queryUtility(IMicroblogTool)
    microblog.add(status_obj)
    # take care - statusupdate may still be queued for storage
    # and not actually written into the container yet
    # this may change the status_obj.id
    return status_obj