示例#1
0
    def test_get_localized_time_constraints(self):
        """Test the constraints for get_localized_time."""

        # When no parameters are given an error is raised
        from plone.api.exc import MissingParameterError
        with self.assertRaises(MissingParameterError):
            portal.get_localized_time()
示例#2
0
    def test_get_localized_time(self):
        """Test getting the localized time."""
        from plone.api.exc import InvalidParameterError

        # set the expected localized date format
        name_root = "Products.CMFPlone.i18nl10n.override_dateformat."
        try:
            portal.set_registry_record(name=name_root + "Enabled", value=True)
            portal.set_registry_record(name=name_root + "date_format_long", value="%b %d, %Y %I:%M %p")
            portal.set_registry_record(name=name_root + "time_format", value="%I:%M %p")
            portal.set_registry_record(name=name_root + "date_format_short", value="%b %d, %Y")
        except InvalidParameterError:
            # before Plone 4.3, date formats were stored in portal_properties
            properties = portal.get_tool("portal_properties")
            properties.localLongTimeFormat = "%b %d, %Y %I:%M %p"
            properties.localTimeOnlyFormat = "%I:%M %p"
            properties.localTimeFormat = "%b %d, %Y"

        # tests
        result = portal.get_localized_time(datetime=DateTime(1999, 12, 31, 23, 59), long_format=True)
        self.assertEqual(result, "Dec 31, 1999 11:59 PM")

        result = portal.get_localized_time(datetime=DateTime(1999, 12, 31, 23, 59), time_only=True)
        self.assertEqual(result, "11:59 PM")

        result = portal.get_localized_time(datetime=DateTime(1999, 12, 31, 23, 59))
        self.assertEqual(result, "Dec 31, 1999")
示例#3
0
    def test_document_report(self, browser):
        browser.login().open(view='document_report',
                             data={'paths:list': [
                                   '/'.join(self.document.getPhysicalPath()),
                                   ]})

        with NamedTemporaryFile(delete=False, suffix='.xlsx') as tmpfile:
            tmpfile.write(browser.contents)
            tmpfile.flush()
            workbook = load_workbook(tmpfile.name)

        self.assertSequenceEqual(
            [
             u'Client1 / 1 / 1',
             1L,
             u'Testdokum\xe4nt',
             u'Mustermann Max',
             get_localized_time(self.document_date),
             get_localized_time(self.receipt_date),
             get_localized_time(self.delivery_date),
             Actor.lookup(TEST_USER_ID).get_label(),
             u'unchecked',
             u'Dossier A',
             ],
            [cell.value for cell in workbook.active.rows[1]])
示例#4
0
    def test_get_localized_time_constraints(self):
        """Test the constraints for get_localized_time."""

        # When no parameters are given an error is raised
        from plone.api.exc import MissingParameterError
        with self.assertRaises(MissingParameterError):
            portal.get_localized_time()
示例#5
0
    def test_get_localized_time(self):
        result = portal.get_localized_time(
            datetime=DateTime(1999, 12, 31, 23, 59),
            long_format=True,
        )
        self.assertEqual(result, 'Dec 31, 1999 11:59 PM')

        result = portal.get_localized_time(
            datetime=DateTime(1999, 12, 31, 23, 59),
            time_only=True,
        )
        self.assertEqual(result, '11:59 PM')

        result = portal.get_localized_time(datetime=DateTime(
            1999, 12, 31, 23, 59), )
        self.assertEqual(result, 'Dec 31, 1999')
示例#6
0
    def test_get_localized_time(self):
        """Test getting the localized time."""
        from plone.api.exc import InvalidParameterError

        # set the expected localized date format
        name_root = 'Products.CMFPlone.i18nl10n.override_dateformat.'
        try:
            portal.set_registry_record(
                name=name_root + 'Enabled',
                value=True,
            )
            portal.set_registry_record(
                name=name_root + 'date_format_long',
                value='%b %d, %Y %I:%M %p',
            )
            portal.set_registry_record(
                name=name_root + 'time_format',
                value='%I:%M %p',
            )
            portal.set_registry_record(
                name=name_root + 'date_format_short',
                value='%b %d, %Y',
            )
        except InvalidParameterError:
            # before Plone 4.3, date formats were stored in portal_properties
            properties = portal.get_tool('portal_properties')
            properties.localLongTimeFormat = '%b %d, %Y %I:%M %p'
            properties.localTimeOnlyFormat = '%I:%M %p'
            properties.localTimeFormat = '%b %d, %Y'

        # tests
        result = portal.get_localized_time(
            datetime=DateTime(1999, 12, 31, 23, 59),
            long_format=True,
        )
        self.assertEqual(result, 'Dec 31, 1999 11:59 PM')

        result = portal.get_localized_time(
            datetime=DateTime(1999, 12, 31, 23, 59),
            time_only=True,
        )
        self.assertEqual(result, '11:59 PM')

        result = portal.get_localized_time(
            datetime=DateTime(1999, 12, 31, 23, 59),
        )
        self.assertEqual(result, 'Dec 31, 1999')
示例#7
0
    def test_get_localized_time(self):
        """Test getting the localized time."""
        from plone.api.exc import InvalidParameterError

        # set the expected localized date format
        name_root = 'Products.CMFPlone.i18nl10n.override_dateformat.'
        try:
            portal.set_registry_record(
                name=name_root + 'Enabled',
                value=True,
            )
            portal.set_registry_record(
                name=name_root + 'date_format_long',
                value='%b %d, %Y %I:%M %p',
            )
            portal.set_registry_record(
                name=name_root + 'time_format',
                value='%I:%M %p',
            )
            portal.set_registry_record(
                name=name_root + 'date_format_short',
                value='%b %d, %Y',
            )
        except InvalidParameterError:
            # before Plone 4.3, date formats were stored in portal_properties
            properties = portal.get_tool('portal_properties')
            properties.localLongTimeFormat = '%b %d, %Y %I:%M %p'
            properties.localTimeOnlyFormat = '%I:%M %p'
            properties.localTimeFormat = '%b %d, %Y'

        # tests
        result = portal.get_localized_time(
            datetime=DateTime(1999, 12, 31, 23, 59),
            long_format=True,
        )
        self.assertEqual(result, 'Dec 31, 1999 11:59 PM')

        result = portal.get_localized_time(
            datetime=DateTime(1999, 12, 31, 23, 59),
            time_only=True,
        )
        self.assertEqual(result, '11:59 PM')

        result = portal.get_localized_time(
            datetime=DateTime(1999, 12, 31, 23, 59),
        )
        self.assertEqual(result, 'Dec 31, 1999')
示例#8
0
 def getAccomadationDates(self): 
     start = self.accomadation_start
     end = self.accomadation_end
     options = []
     dates = daterange(start,  end + timedelta(days=1) ) 
     for single_date in dates:
         options.append(get_localized_time(single_date))
     return options
示例#9
0
    def test_get_localized_time(self):
        result = portal.get_localized_time(
            datetime=DateTime(1999, 12, 31, 23, 59),
            long_format=True,
        )
        self.assertEqual(result, 'Dec 31, 1999 11:59 PM')

        result = portal.get_localized_time(
            datetime=DateTime(1999, 12, 31, 23, 59),
            time_only=True,
        )
        self.assertEqual(result, '11:59 PM')

        result = portal.get_localized_time(
            datetime=DateTime(1999, 12, 31, 23, 59),
        )
        self.assertEqual(result, 'Dec 31, 1999')
示例#10
0
    def get_publication_date(self, brain):
        date = brain.effective

        if date.year() == 1969:
            return ''
        # date = obj.effective_date

        return portal.get_localized_time(datetime=date).encode('utf-8')
示例#11
0
    def test_get_localized_time_python_date(self):
        """Test getting the localized time using Python datetime.date."""

        # set the expected localized date format
        self._set_localization_date_format()

        # tests
        result = portal.get_localized_time(
            datetime=date(1999, 12, 31),
            long_format=True,
        )
        self.assertEqual(result, 'Dec 31, 1999')

        result = portal.get_localized_time(
            datetime=date(1999, 12, 31),
            time_only=True,
        )
        self.assertEqual(result, '')

        result = portal.get_localized_time(datetime=date(1999, 12, 31), )
        self.assertEqual(result, 'Dec 31, 1999')
示例#12
0
    def test_get_localized_time(self):
        """Test getting the localized time."""

        # set the expected localized date format
        self._set_localization_date_format()

        # tests
        result = portal.get_localized_time(
            datetime=DateTime(1999, 12, 31, 23, 59),
            long_format=True,
        )
        self.assertEqual(result, 'Dec 31, 1999 11:59 PM')

        result = portal.get_localized_time(
            datetime=DateTime(1999, 12, 31, 23, 59),
            time_only=True,
        )
        self.assertEqual(result, '11:59 PM')

        result = portal.get_localized_time(datetime=DateTime(
            1999, 12, 31, 23, 59), )
        self.assertEqual(result, 'Dec 31, 1999')
示例#13
0
    def test_get_localized_time(self):
        """Test getting the localized time."""

        # set the expected localized date format
        self._set_localization_date_format()

        # tests
        result = portal.get_localized_time(
            datetime=DateTime(1999, 12, 31, 23, 59),
            long_format=True,
        )
        self.assertEqual(result, 'Dec 31, 1999 11:59 PM')

        result = portal.get_localized_time(
            datetime=DateTime(1999, 12, 31, 23, 59),
            time_only=True,
        )
        self.assertEqual(result, '11:59 PM')

        result = portal.get_localized_time(
            datetime=DateTime(1999, 12, 31, 23, 59),
        )
        self.assertEqual(result, 'Dec 31, 1999')
示例#14
0
    def test_get_localized_time_python_date(self):
        """Test getting the localized time using Python datetime.date."""

        # set the expected localized date format
        self._set_localization_date_format()

        # tests
        result = portal.get_localized_time(
            datetime=date(1999, 12, 31),
            long_format=True,
        )
        self.assertEqual(result, 'Dec 31, 1999')

        result = portal.get_localized_time(
            datetime=date(1999, 12, 31),
            time_only=True,
        )
        self.assertEqual(result, '')

        result = portal.get_localized_time(
            datetime=date(1999, 12, 31),
        )
        self.assertEqual(result, 'Dec 31, 1999')
示例#15
0
    def test_document_report(self, browser):
        browser.login().open(
            view='document_report',
            data={'paths:list': [
                '/'.join(self.document.getPhysicalPath()),
            ]})

        with NamedTemporaryFile(delete=False, suffix='.xlsx') as tmpfile:
            tmpfile.write(browser.contents)
            tmpfile.flush()
            workbook = load_workbook(tmpfile.name)

        self.assertSequenceEqual([
            u'Client1 / 1 / 1',
            1L,
            u'Testdokum\xe4nt',
            u'Mustermann Max',
            get_localized_time(self.document_date),
            get_localized_time(self.receipt_date),
            get_localized_time(self.delivery_date),
            Actor.lookup(TEST_USER_ID).get_label(),
            u'unchecked',
            u'Dossier A',
        ], [cell.value for cell in list(workbook.active.rows)[1]])
示例#16
0
    def get_event_date(self, obj):
        start = obj.startDate
        end = obj.endDate
        if start.year() == end.year():
            if start.month() == end.month():
                if start.day() == end.day():
                    return get_localized_time(start)
                else:
                    return u"{0} - {1}".format(
                        get_localized_time(start).split()[0],
                        get_localized_time(end))
            else:
                front_date = re.sub(str(start.year()), '',
                                    get_localized_time(start))
                return u"{0} - {1}".format(front_date, get_localized_time(end))

        return u'{0} - {1}'.format(get_localized_time(start),
                                  get_localized_time(end))
示例#17
0
    def get_event_date(self, obj):
        start = obj.startDate
        end = obj.endDate
        if start.year() == end.year():
            if start.month() == end.month():
                if start.day() == end.day():
                    return get_localized_time(start)
                else:
                    return u"{0} - {1}".format(
                        get_localized_time(start).split()[0],
                        get_localized_time(end))
            else:
                front_date = re.sub(str(start.year()), '',
                                    get_localized_time(start))
                return u"{0} - {1}".format(front_date, get_localized_time(end))

        return u'{0} - {1}'.format(get_localized_time(start),
                                   get_localized_time(end))
示例#18
0
 def city_modified(self):
     return portal.get_localized_time(self.context.modified())
示例#19
0
 def formated_date(self, modifiedTime):
     modif_date = portal.get_localized_time(datetime=modifiedTime)
     return modif_date
示例#20
0
 def city_modified(self):
     return portal.get_localized_time(self.context.modified())
示例#21
0
 def _get_text(self, value):
     return portal.get_localized_time(datetime=value)
示例#22
0
def readable_date(date):
    """Helper method to return a localized date"""
    return get_localized_time(date) if date else None
示例#23
0
def readable_date(date):
    """Helper method to return a localized date"""
    return get_localized_time(date) if date else None
示例#24
0
    def formated_date(self, modifiedTime):
        modif_date = portal.get_localized_time(datetime=modifiedTime)

        return modif_date