Пример #1
0
 def _renderLastUpdateDate(self, template):
     """Render a template's "last updated" column."""
     formatter = DateTimeFormatterAPI(template.date_last_updated)
     full_time = formatter.datetime()
     date = formatter.approximatedate()
     return ''.join([
         '<span class="sortkey">%s</span>' % full_time,
         '<span class="lastupdate_column" title="%s">%s</span>' %
         (full_time, date),
     ])
Пример #2
0
 def _renderLastUpdateDate(self, template):
     """Render a template's "last updated" column."""
     formatter = DateTimeFormatterAPI(template.date_last_updated)
     full_time = formatter.datetime()
     date = formatter.approximatedate()
     return ''.join([
         '<span class="sortkey">%s</span>' % full_time,
         '<span class="lastupdate_column" title="%s">%s</span>' % (
             full_time, date),
         ])
    def status_change_date(self):
        """Show date of last status change.

        Says nothing at all if the entry's status has not changed since
        upload.
        """
        change_date = self.context.date_status_changed
        if change_date == self.context.dateimported:
            return ""
        else:
            formatter = DateTimeFormatterAPI(change_date)
            return "Last changed %s." % formatter.displaydate()
    def status_change_date(self):
        """Show date of last status change.

        Says nothing at all if the entry's status has not changed since
        upload.
        """
        change_date = self.context.date_status_changed
        if change_date == self.context.dateimported:
            return ""
        else:
            formatter = DateTimeFormatterAPI(change_date)
            return "Last changed %s." % formatter.displaydate()
Пример #5
0
    def getPickerEntries(self, term_values, context_object, **kwarg):
        """See `IPickerEntrySource`"""
        picker_entries = (super(PersonPickerEntrySourceAdapter,
                                self).getPickerEntries(term_values,
                                                       context_object))

        affiliated_context = IHasAffiliation(context_object, None)
        if affiliated_context is not None:
            # If a person is affiliated with the associated_object then we
            # can display a badge.
            badges = affiliated_context.getAffiliationBadges(term_values)
            for picker_entry, badges in izip(picker_entries, badges):
                picker_entry.badges = []
                for badge_info in badges:
                    picker_entry.badges.append(
                        dict(url=badge_info.url,
                             label=badge_info.label,
                             role=badge_info.role))

        for person, picker_entry in izip(term_values, picker_entries):
            picker_entry.details = []

            if person.preferredemail is not None:
                if person.hide_email_addresses:
                    picker_entry.description = '<email address hidden>'
                else:
                    try:
                        picker_entry.description = person.preferredemail.email
                    except Unauthorized:
                        picker_entry.description = '<email address hidden>'

            picker_entry.metadata = get_person_picker_entry_metadata(person)
            # We will display the person's name (launchpad id) after their
            # displayname.
            picker_entry.alt_title = person.name
            # We will linkify the person's name so it can be clicked to
            # open the page for that person.
            picker_entry.alt_title_link = canonical_url(person,
                                                        rootsite='mainsite')
            # We will display the person's irc nick(s) after their email
            # address in the description text.
            irc_nicks = None
            if person.ircnicknames:
                irc_nicks = ", ".join([
                    IRCNicknameFormatterAPI(ircid).displayname()
                    for ircid in person.ircnicknames
                ])
            if irc_nicks:
                picker_entry.details.append(irc_nicks)
            if person.is_team:
                picker_entry.details.append('Team members: %s' %
                                            person.all_member_count)
            else:
                picker_entry.details.append(
                    'Member since %s' %
                    DateTimeFormatterAPI(person.datecreated).date())
        return picker_entries
 def test_submitted_after_quota(self):
     # The view explains when a message was not sent because the quota
     # was exceeded.
     user = self.factory.makePerson()
     sender = self.makeThrottledSender()
     form = self.makeForm('*****@*****.**')
     with person_logged_in(sender):
         view = create_initialized_view(user, '+contactuser', form=form)
     notification = [
         'Your message was not sent because you have exceeded your daily '
         'quota of 3 messages to contact users. Try again %s.' %
         DateTimeFormatterAPI(view.next_try).approximatedate()
     ]
     notes = [n.message for n in view.request.response.notifications]
     self.assertContentEqual(notification, notes)
 def _renderTime(self, time):
     """Represent `time` as HTML."""
     formatter = DateTimeFormatterAPI(time)
     return """<span title="%s">%s</span>""" % (formatter.datetime(),
                                                formatter.approximatedate())
Пример #8
0
 def getDurationsince(self, delta):
     """Return the durationsince for a given delta."""
     creation = datetime(2000, 1, 1, tzinfo=utc)
     formatter = DateTimeFormatterAPI(creation)
     formatter._now = lambda: creation + delta
     return formatter.durationsince()
Пример #9
0
 def assert_delta(expected, old, new):
     old = datetime(*old, tzinfo=utc)
     new = datetime(*new, tzinfo=utc)
     delta = DateTimeFormatterAPI._yearDelta(old, new)
     self.assertEqual(expected, delta)