Пример #1
0
    def test_future_days(self):
        def make_expected():
            # Uses the hourfmt instead of the hourminfmt from pretty_datetime
            if test.strftime('%p'):
                expected = test.strftime('%I%p')
            else:
                expected = test.strftime('%Hh')
            expected = expected.decode('utf-8')
            return expected

        test = self.now + datetime.timedelta(days=1)
        actual = helper.pretty_datetime(test)
        expected = test.strftime('%a ') + make_expected()
        self.assertEqual(actual, expected)
Пример #2
0
    def test_future_days(self):
        def make_expected():
            # Uses the hourfmt instead of the hourminfmt from pretty_datetime
            if test.strftime('%p'):
                expected = test.strftime('%I%p')
            else:
                expected = test.strftime('%Hh')
            expected = expected.decode('utf-8')
            return expected

        test = self.now + datetime.timedelta(days=1)
        actual = helper.pretty_datetime(test)
        expected = test.strftime('%a ') + make_expected()
        self.assertEqual(actual, expected)
Пример #3
0
    def get_datestring(self):
        """
        returns reformated datestring for this messages.

        It uses the format spacified by `timestamp_format` in
        the general section of the config.
        """
        if self._datetime == None:
            return None
        formatstring = settings.get('timestamp_format')
        if formatstring == None:
            res = helper.pretty_datetime(self._datetime)
        else:
            res = self._datetime.strftime(formatstring)
        return res
Пример #4
0
    def represent_datetime(self, d):
        """
        turns a given datetime obj into a unicode string representation.
        This will:

        1) look if a fixed 'timestamp_format' is given in the config
        2) check if a 'timestamp_format' hook is defined
        3) use :func:`~alot.helper.pretty_datetime` as fallback
        """

        fixed_format = self.get('timestamp_format')
        if fixed_format:
            rep = string_decode(d.strftime(fixed_format), 'UTF-8')
        else:
            format_hook = self.get_hook('timestamp_format')
            if format_hook:
                rep = string_decode(format_hook(d), 'UTF-8')
            else:
                rep = pretty_datetime(d)
        return rep
Пример #5
0
    def represent_datetime(self, d):
        """
        turns a given datetime obj into a unicode string representation.
        This will:

        1) look if a fixed 'timestamp_format' is given in the config
        2) check if a 'timestamp_format' hook is defined
        3) use :func:`~alot.helper.pretty_datetime` as fallback
        """

        fixed_format = self.get('timestamp_format')
        if fixed_format:
            rep = string_decode(d.strftime(fixed_format), 'UTF-8')
        else:
            format_hook = self.get_hook('timestamp_format')
            if format_hook:
                rep = string_decode(format_hook(d), 'UTF-8')
            else:
                rep = pretty_datetime(d)
        return rep
Пример #6
0
 def test_future_hours(self):
     test = self.now + datetime.timedelta(hours=1)
     actual = helper.pretty_datetime(test)
     expected = test.strftime('%a ') + self._future_expected(test)
     self.assertEqual(actual, expected)
Пример #7
0
 def test_future_seconds(self):
     test = self.now + datetime.timedelta(seconds=30)
     actual = helper.pretty_datetime(test)
     expected = self._future_expected(test)
     self.assertEqual(actual, expected)
Пример #8
0
 def test_x_hours_ago(self):
     for i in (self.random.randint(3600, 3600 * 6) for _ in range(10)):
         test = self.now - datetime.timedelta(seconds=i)
         actual = helper.pretty_datetime(test)
         self.assertEqual(
             actual, u'{}h ago'.format((self.now - test).seconds // 3600))
Пример #9
0
 def test_just_now(self):
     for i in (self.random.randint(0, 60) for _ in range(5)):
         test = self.now - datetime.timedelta(seconds=i)
         actual = helper.pretty_datetime(test)
         self.assertEqual(actual, u'just now')
Пример #10
0
 def test_future_year(self):
     test = self.now + datetime.timedelta(days=365)
     actual = helper.pretty_datetime(test)
     expected = test.strftime('%b %Y')
     self.assertEqual(actual, expected)
Пример #11
0
 def test_future_hours(self):
     test = self.now + datetime.timedelta(hours=1)
     actual = helper.pretty_datetime(test)
     expected = test.strftime('%a ') + self._future_expected(test)
     self.assertEqual(actual, expected)
Пример #12
0
 def test_future_seconds(self):
     test = self.now + datetime.timedelta(seconds=30)
     actual = helper.pretty_datetime(test)
     expected = self._future_expected(test)
     self.assertEqual(actual, expected)
Пример #13
0
 def test_x_hours_ago(self):
     for i in (self.random.randint(3600, 3600 * 6) for _ in range(10)):
         test = self.now - datetime.timedelta(seconds=i)
         actual = helper.pretty_datetime(test)
         self.assertEqual(
             actual, u'{}h ago'.format((self.now - test).seconds // 3600))
Пример #14
0
 def test_just_now(self):
     for i in (self.random.randint(0, 60) for _ in range(5)):
         test = self.now - datetime.timedelta(seconds=i)
         actual = helper.pretty_datetime(test)
         self.assertEqual(actual, u'just now')
Пример #15
0
 def test_x_minutes_ago(self):
     for i in (self.random.randint(60, 3600) for _ in xrange(10)):
         test = self.now - datetime.timedelta(seconds=i)
         actual = helper.pretty_datetime(test)
         self.assertEquals(
             actual, u'{}min ago'.format((self.now - test).seconds // 60))
Пример #16
0
 def test_future_year(self):
     test = self.now + datetime.timedelta(days=365)
     actual = helper.pretty_datetime(test)
     expected = test.strftime('%b %Y')
     self.assertEqual(actual, expected)
Пример #17
0
 def test_x_minutes_ago(self):
     for i in (self.random.randint(60, 3600) for _ in range(10)):
         test = self.now - datetime.timedelta(seconds=i)
         actual = helper.pretty_datetime(test)
         self.assertEquals(
             actual, u'{}min ago'.format((self.now - test).seconds // 60))
Пример #18
0
    def rebuild(self):
        cols = []
        if self.thread:
            newest = self.thread.get_newest_date()
        else:
            newest = None
        if newest == None:
            datestring = ''
        else:
            formatstring = settings.get('timestamp_format')
            if formatstring is None:
                datestring = pretty_datetime(newest)
            else:
                datestring = newest.strftime(formatstring)
        datestring = datestring.rjust(self.pretty_datetime_len)
        self.date_w = urwid.AttrMap(urwid.Text(datestring),
                                    self._get_theme('date'))
        cols.append(('fixed', len(datestring), self.date_w))

        if self.thread:
            mailcountstring = "(%d)" % self.thread.get_total_messages()
        else:
            mailcountstring = "(?)"
        self.mailcount_w = urwid.AttrMap(urwid.Text(mailcountstring),
                                         self._get_theme('mailcount'))
        cols.append(('fixed', len(mailcountstring), self.mailcount_w))

        if self.thread:
            self.tag_widgets = [TagWidget(t)
                                for t in self.thread.get_tags()]
        else:
            self.tag_widgets = []
        self.tag_widgets.sort(tag_cmp,
                              lambda tag_widget: tag_widget.translated)
        for tag_widget in self.tag_widgets:
            if not tag_widget.hidden:
                cols.append(('fixed', tag_widget.width(), tag_widget))

        if self.thread:
            authors = self.thread.get_authors_string() or '(None)'
        else:
            authors = '(None)'
        maxlength = settings.get('authors_maxlength')
        authorsstring = shorten_author_string(authors, maxlength)
        self.authors_w = urwid.AttrMap(urwid.Text(authorsstring),
                                       self._get_theme('authors'))
        cols.append(('fixed', len(authorsstring), self.authors_w))

        if self.thread:
            subjectstring = self.thread.get_subject() or ''
        else:
            subjectstring = ''
        # sanitize subject string:
        subjectstring = subjectstring.replace('\n', ' ')
        subjectstring = subjectstring.replace('\r', '')
        subjectstring = subjectstring.strip()

        self.subject_w = urwid.AttrMap(urwid.Text(subjectstring, wrap='clip'),
                                       self._get_theme('subject'))
        if subjectstring:
            cols.append(('weight', 2, self.subject_w))

        if self.display_content:
            if self.thread:
                msgs = self.thread.get_messages().keys()
            else:
                msgs = []
            msgs.sort()
            lastcontent = ' '.join([m.get_text_content() for m in msgs])
            contentstring = lastcontent.replace('\n', ' ').strip()
            self.content_w = urwid.AttrMap(urwid.Text(
                                                   contentstring,
                                                   wrap='clip'),
                                                   self._get_theme('content'))
            cols.append(self.content_w)

        self.columns = urwid.Columns(cols, dividechars=1)
        self.original_widget = self.columns