Ejemplo n.º 1
0
    def context(self, data, check, mutator):
        assert access_checker.isSet(data.conversation)
        assert access_checker.isSet(data.user)

        # Marks the conversation as "read" for the user
        gciconversation_logic.markAllReadForConversationAndUser(
            data.conversation.key, ndb.Key.from_old_key(data.user.key())
        )

        num_users = gciconversation_logic.queryConversationUserForConversation(data.conversation.key).count()

        messages = gcimessage_logic.queryForConversation(data.conversation.key).order(
            gcimessage_model.GCIMessage.sent_on
        )

        for message in messages:
            message.author_name = db.get(ndb.Key.to_old_key(message.author)).name
            message.sent_on_relative = timeformat_helper.relativeTime(message.sent_on)
            message.sent_on_ctime = message.sent_on.ctime()

        return {
            "page_name": data.conversation.subject,
            "conversation": data.conversation,
            "num_users": num_users,
            "messages": messages,
            "user_list": UserList(data),
            "user_actions": UserActions(data),
            "reply_action": urlresolvers.reverse(url_names.GCI_CONVERSATION_REPLY, kwargs=data.kwargs),
        }
Ejemplo n.º 2
0
    def context(self):
        """See soc.views.template.Template.context for full specification."""

        conv_model = self.conversation.get()

        context = {
            'subject':
            conv_model.subject,
            'num_messages':
            gcimessage_logic.numMessagesInConversation(conv_model.key),
            'num_new_messages':
            gciconversation_logic.numUnreadMessagesForConversationAndUser(
                conv_model.key, ndb.Key.from_old_key(self.data.user.key())),
        }

        last_message = gcimessage_logic.getLastMessageForConversation(
            conv_model.key)

        if last_message is not None:
            last_message_author = db.get(
                ndb.Key.to_old_key(last_message.author))
            context['last_message_author'] = last_message_author.name
            context['last_message_content'] = (html.strip_tags(
                last_message.content).replace('\r', '').replace('\n',
                                                                ' ').strip())
            context['last_message_time'] = timeformat_helper.relativeTime(
                last_message.sent_on)
            context['last_message_ctime'] = last_message.sent_on.ctime()

        return context
Ejemplo n.º 3
0
    def testRelativeTime(self):
        """Tests that relativeTime() correctly returns a relative time string for
    various datetimes.
    """
        now = datetime.utcnow()

        expected = 'just now'
        actual = timeformat.relativeTime(now - timedelta(seconds=0.5))
        self.assertEqual(expected, actual)

        expected = '5 seconds ago'
        actual = timeformat.relativeTime(now - timedelta(seconds=5.4))
        self.assertEqual(expected, actual)

        expected = '1 minute ago'
        actual = timeformat.relativeTime(now -
                                         timedelta(minutes=1, seconds=20))
        self.assertEqual(expected, actual)

        expected = '13 minutes ago'
        actual = timeformat.relativeTime(now -
                                         timedelta(minutes=13, seconds=20))
        self.assertEqual(expected, actual)

        expected = '1 hour ago'
        actual = timeformat.relativeTime(now - timedelta(hours=1, minutes=20))
        self.assertEqual(expected, actual)

        expected = '19 hours ago'
        actual = timeformat.relativeTime(now - timedelta(hours=19, minutes=20))
        self.assertEqual(expected, actual)

        expected = '1 day ago'
        actual = timeformat.relativeTime(now - timedelta(days=1, hours=8))
        self.assertEqual(expected, actual)

        expected = '6 days ago'
        actual = timeformat.relativeTime(now - timedelta(days=6, hours=8))
        self.assertEqual(expected, actual)

        date = now - timedelta(days=8)
        expected = date.ctime()
        actual = timeformat.relativeTime(date)
        self.assertEqual(expected, actual)
Ejemplo n.º 4
0
  def testRelativeTime(self):
    """Tests that relativeTime() correctly returns a relative time string for
    various datetimes.
    """
    now = datetime.utcnow()

    expected = 'just now'
    actual = timeformat.relativeTime(now - timedelta(seconds=0.5))
    self.assertEqual(expected, actual)

    expected = '5 seconds ago'
    actual = timeformat.relativeTime(now - timedelta(seconds=5.4))
    self.assertEqual(expected, actual)

    expected = '1 minute ago'
    actual = timeformat.relativeTime(now - timedelta(minutes=1, seconds=20))
    self.assertEqual(expected, actual)

    expected = '13 minutes ago'
    actual = timeformat.relativeTime(now - timedelta(minutes=13, seconds=20))
    self.assertEqual(expected, actual)

    expected = '1 hour ago'
    actual = timeformat.relativeTime(now - timedelta(hours=1, minutes=20))
    self.assertEqual(expected, actual)

    expected = '19 hours ago'
    actual = timeformat.relativeTime(now - timedelta(hours=19, minutes=20))
    self.assertEqual(expected, actual)

    expected = '1 day ago'
    actual = timeformat.relativeTime(now - timedelta(days=1, hours=8))
    self.assertEqual(expected, actual)

    expected = '6 days ago'
    actual = timeformat.relativeTime(now - timedelta(days=6, hours=8))
    self.assertEqual(expected, actual)

    date = now - timedelta(days=8)
    expected = date.ctime()
    actual = timeformat.relativeTime(date)
    self.assertEqual(expected, actual)
Ejemplo n.º 5
0
    def context(self, data, check, mutator):
        assert access_checker.isSet(data.conversation)
        assert access_checker.isSet(data.user)

        # Marks the conversation as "read" for the user
        gciconversation_logic.markAllReadForConversationAndUser(
            data.conversation.key, ndb.Key.from_old_key(data.user.key()))

        num_users = (
            gciconversation_logic.queryConversationUserForConversation(
                data.conversation.key).count())

        messages = gcimessage_logic.queryForConversation(
            data.conversation.key).order(gcimessage_model.GCIMessage.sent_on)

        for message in messages:
            message.author_name = db.get(ndb.Key.to_old_key(
                message.author)).name
            message.sent_on_relative = timeformat_helper.relativeTime(
                message.sent_on)
            message.sent_on_ctime = message.sent_on.ctime()

        return {
            'page_name':
            data.conversation.subject,
            'conversation':
            data.conversation,
            'num_users':
            num_users,
            'messages':
            messages,
            'user_list':
            UserList(data),
            'user_actions':
            UserActions(data),
            'reply_action':
            urlresolvers.reverse(url_names.GCI_CONVERSATION_REPLY,
                                 kwargs=data.kwargs)
        }