def test_updating_agenda_item_will_update_modification_dates(
            self, browser):
        self.login(self.committee_responsible, browser)
        model = self.meeting.model

        creation_date = datetime(2017, 10, 16, 0, 0, tzinfo=pytz.utc)
        update_date = datetime(2018, 10, 16, 0, 0, tzinfo=pytz.utc)

        def generate_agendaitem_list(meeting):
            meeting_view = getMultiAdapter((self.meeting, self.request),
                                           name='view')
            browser.open(meeting_view.url_generate_agendaitem_list())

        # Generate first protocol
        with freeze(creation_date):
            generate_agendaitem_list(self.meeting)

        document = model.agendaitem_list_document.resolve_document()

        self.assertEqual(creation_date,
                         as_utc(document.modified().asdatetime()))
        self.assertEqual(creation_date, document.changed)

        # Update the protocol
        with freeze(update_date):
            generate_agendaitem_list(self.meeting)

        self.assertEqual(update_date, as_utc(document.modified().asdatetime()))
        self.assertEqual(update_date, document.changed)
Ejemplo n.º 2
0
    def test_updating_agenda_item_will_update_modification_dates(self, browser):
        self.login(self.committee_responsible, browser)
        model = self.meeting.model

        creation_date = datetime(2017, 10, 16, 0, 0, tzinfo=pytz.utc)
        update_date = datetime(2018, 10, 16, 0, 0, tzinfo=pytz.utc)

        def generate_agendaitem_list(meeting):
            meeting_view = getMultiAdapter(
                (self.meeting, self.request), name='view')
            browser.open(meeting_view.url_generate_agendaitem_list())

        # Generate first protocol
        with freeze(creation_date):
            generate_agendaitem_list(self.meeting)

        document = model.agendaitem_list_document.resolve_document()

        self.assertEqual(creation_date, as_utc(document.modified().asdatetime()))
        self.assertEqual(creation_date, document.changed)

        # Update the protocol
        with freeze(update_date):
            generate_agendaitem_list(self.meeting)

        self.assertEqual(update_date, as_utc(document.modified().asdatetime()))
        self.assertEqual(update_date, document.changed)
Ejemplo n.º 3
0
 def _get_changed(self):
     # XXX Can be deleted once the changed metadata has been filled on all deployments
     # https://github.com/4teamwork/opengever.core/issues/4988
     if self.context.changed is None:
         return as_utc(self.context.modified().asdatetime())
     if isinstance(self.context.changed, DateTime):
         return as_utc(self.context.changed.asdatetime())
     return self.context.changed
Ejemplo n.º 4
0
 def fill_changed_field(self):
     """Set the 'changed' field on the object if it hasn't been set already
     if it has been set already, make sure it is a python datetime"""
     for obj in self.objects(query, 'Initialize IChanged.changed field values'):
         if not obj.changed:
             IChanged(obj).changed = as_utc(obj.modified().asdatetime())
         elif isinstance(obj.changed, DateTime):
             IChanged(obj).changed = as_utc(obj.changed.asdatetime())
Ejemplo n.º 5
0
 def fill_changed_field(self):
     """Set the 'changed' field on the object if it hasn't been set already
     if it has been set already, make sure it is a python datetime"""
     for obj in self.objects(query,
                             'Initialize IChanged.changed field values'):
         if not obj.changed:
             IChanged(obj).changed = as_utc(obj.modified().asdatetime())
         elif isinstance(obj.changed, DateTime):
             IChanged(obj).changed = as_utc(obj.changed.asdatetime())
Ejemplo n.º 6
0
    def test_display_changed_property_as_last_modified_date(self, browser):
        self.login(self.committee_responsible, browser)
        model = self.meeting.model

        creation_date = datetime(2017, 10, 16, 0, 0, tzinfo=pytz.utc)
        update_date = datetime(2018, 10, 16, 0, 0, tzinfo=pytz.utc)

        # Generate first protocol
        with freeze(creation_date):
            model.update_protocol_document()

        document = model.protocol_document.resolve_document()

        document.changed = update_date
        document.reindexObject(idxs=["changed"])

        self.assertEqual(creation_date,
                         as_utc(document.modified().asdatetime()))
        self.assertEqual(update_date, document.changed)

        browser.open(self.meeting)

        self.assertEqual(
            'Modified at Oct 16, 2018 02:00 AM',
            browser.css('.protocol-doc .document-modified').first.text)
Ejemplo n.º 7
0
    def test_display_changed_property_as_last_modified_date(self, browser):
        self.login(self.committee_responsible, browser)
        model = self.meeting.model

        creation_date = datetime(2017, 10, 16, 0, 0, tzinfo=pytz.utc)
        update_date = datetime(2018, 10, 16, 0, 0, tzinfo=pytz.utc)

        def generate_agendaitem_list(meeting):
            meeting_view = getMultiAdapter(
                (self.meeting, self.request), name='view')
            browser.open(meeting_view.url_generate_agendaitem_list())

        # Generate first protocol
        with freeze(creation_date):
            generate_agendaitem_list(self.meeting)

        document = model.agendaitem_list_document.resolve_document()
        document.changed = update_date
        document.reindexObject(idxs=["changed"])

        self.assertEqual(creation_date, as_utc(document.modified().asdatetime()))
        self.assertEqual(update_date, document.changed)

        browser.open(self.meeting)

        self.assertEqual(
            'Modified at Oct 16, 2018 02:00 AM',
            browser.css('.agenda-item-list-doc .document-modified').first.text)
    def test_display_changed_property_as_last_modified_date(self, browser):
        self.login(self.committee_responsible, browser)
        model = self.meeting.model

        creation_date = datetime(2017, 10, 16, 0, 0, tzinfo=pytz.utc)
        update_date = datetime(2018, 10, 16, 0, 0, tzinfo=pytz.utc)

        def generate_agendaitem_list(meeting):
            meeting_view = getMultiAdapter((self.meeting, self.request),
                                           name='view')
            browser.open(meeting_view.url_generate_agendaitem_list())

        # Generate first protocol
        with freeze(creation_date):
            generate_agendaitem_list(self.meeting)

        document = model.agendaitem_list_document.resolve_document()
        document.changed = update_date
        document.reindexObject(idxs=["changed"])

        self.assertEqual(creation_date,
                         as_utc(document.modified().asdatetime()))
        self.assertEqual(update_date, document.changed)

        browser.open(self.meeting)

        self.assertEqual(
            'Modified at Oct 16, 2018 02:00 AM',
            browser.css('.agenda-item-list-doc .document-modified').first.text)
Ejemplo n.º 9
0
    def toFieldValue(self, value):
        value = super(UTCDatetimeDataConverter, self).toFieldValue(value)

        try:
            local_dt = get_localzone().localize(value)
            return as_utc(local_dt)
        except ValueError:
            raise DatetimeValidationError
Ejemplo n.º 10
0
    def toFieldValue(self, value):
        value = super(UTCDatetimeDataConverter, self).toFieldValue(value)
        if value is None:
            return value

        try:
            local_dt = get_localzone().localize(value)
            return as_utc(local_dt)
        except ValueError:
            raise DatetimeValidationError
Ejemplo n.º 11
0
def localized_datetime(*args, **kwargs):
    """Localize timezone naive datetime to default timezone and return as utc.

    """
    if args or kwargs:
        dt = datetime(*args, **kwargs)
    else:
        dt = datetime.now()

    return as_utc(DEFAULT_TZ.localize(dt))
Ejemplo n.º 12
0
def localized_datetime(*args, **kwargs):
    """Localize timezone naive datetime to default timezone and return as utc.

    """
    if args or kwargs:
        dt = datetime(*args, **kwargs)
    else:
        dt = datetime.now()

    return as_utc(DEFAULT_TZ.localize(dt))
Ejemplo n.º 13
0
    def _convert_to_date(self, datetime_obj):
        if isinstance(datetime_obj, datetime):
            return datetime_obj.date()

        # XXX Can be deleted once the changed metadata has been filled on all deployments
        # https://github.com/4teamwork/opengever.core/issues/4988
        elif isinstance(datetime_obj, DateTime):
            return as_utc(datetime_obj.asdatetime()).date()

        # It is already a date-object
        return datetime_obj
Ejemplo n.º 14
0
    def _convert_to_date(self, datetime_obj):
        if isinstance(datetime_obj, datetime):
            return datetime_obj.date()

        # XXX Can be deleted once the changed metadata has been filled on all deployments
        # https://github.com/4teamwork/opengever.core/issues/4988
        elif isinstance(datetime_obj, DateTime):
            return as_utc(datetime_obj.asdatetime()).date()

        # It is already a date-object
        return datetime_obj
Ejemplo n.º 15
0
    def _set_changed(self, value):
        # Make sure we have a python datetime
        if isinstance(value, DateTime):
            value = value.asdatetime()
        assert isinstance(value, datetime), "changed should be a python datetime"
        # Make sure we have a timezone aware datetime
        assert value.tzinfo is not None, "changed should be timezone aware"

        # Make sure we save the datetime as utc. This is especially important
        # to avoid the unpickling issues when unpickling a datetime obtained
        # from DateTime.asdatetime()
        self.context.changed = as_utc(value)
Ejemplo n.º 16
0
    def test_updating_word_protocol_will_update_modification_dates(self):
        self.login(self.committee_responsible)
        model = self.meeting.model

        creation_date = datetime(2017, 10, 16, 0, 0, tzinfo=pytz.utc)
        update_date = datetime(2018, 10, 16, 0, 0, tzinfo=pytz.utc)

        # Generate first protocol
        with freeze(creation_date):
            model.update_protocol_document()

        document = model.protocol_document.resolve_document()

        self.assertEqual(creation_date, as_utc(document.modified().asdatetime()))
        self.assertEqual(creation_date, document.changed)

        # Update the protocol
        with freeze(update_date):
            model.update_protocol_document()

        self.assertEqual(update_date, as_utc(document.modified().asdatetime()))
        self.assertEqual(update_date, document.changed)
Ejemplo n.º 17
0
    def toFieldValue(self, value):
        for val in value:
            if not val:
                return self.field.missing_value

        try:
            value = map(int, value)
        except ValueError:
            raise DatetimeValidationError
        try:
            local_dt = get_localzone().localize(datetime(*value))
            return as_utc(local_dt)
        except ValueError:
            raise DatetimeValidationError
Ejemplo n.º 18
0
    def test_updating_word_protocol_will_update_modification_dates(self):
        self.login(self.committee_responsible)
        model = self.meeting.model

        creation_date = datetime(2017, 10, 16, 0, 0, tzinfo=pytz.utc)
        update_date = datetime(2018, 10, 16, 0, 0, tzinfo=pytz.utc)

        # Generate first protocol
        with freeze(creation_date):
            model.update_protocol_document()

        document = model.protocol_document.resolve_document()

        self.assertEqual(creation_date,
                         as_utc(document.modified().asdatetime()))
        self.assertEqual(creation_date, document.changed)

        # Update the protocol
        with freeze(update_date):
            model.update_protocol_document()

        self.assertEqual(update_date, as_utc(document.modified().asdatetime()))
        self.assertEqual(update_date, document.changed)
Ejemplo n.º 19
0
    def _dict_to_object(self, obj):
        if TYPE_KEY not in obj:
            return obj

        decode_as = obj[TYPE_KEY]
        value = obj[VALUE_KEY]
        if decode_as == u'datetime':
            dt = parser.parse(value)
            if dt.tzinfo:
                dt = as_utc(dt)
            return dt
        elif decode_as == u'UUID':
            return UUID(value)
        elif decode_as == u'set':
            return set(value)
        elif decode_as == u'PersistentMapping':
            return PersistentMapping(value)

        raise CannotDecodeJsonType(decode_as, value)
Ejemplo n.º 20
0
    def _dict_to_object(self, obj):
        if TYPE_KEY not in obj:
            return obj

        decode_as = obj[TYPE_KEY]
        value = obj[VALUE_KEY]
        if decode_as == u'datetime':
            dt = parser.parse(value)
            if dt.tzinfo:
                dt = as_utc(dt)
            return dt
        elif decode_as == u'UUID':
            return UUID(value)
        elif decode_as == u'set':
            return set(value)
        elif decode_as == u'PersistentMapping':
            return PersistentMapping(value)

        raise CannotDecodeJsonType(decode_as, value)
Ejemplo n.º 21
0
    def test_display_changed_property_as_last_modified_date(self, browser):
        self.login(self.committee_responsible, browser)
        model = self.meeting.model

        creation_date = datetime(2017, 10, 16, 0, 0, tzinfo=pytz.utc)
        update_date = datetime(2018, 10, 16, 0, 0, tzinfo=pytz.utc)

        # Generate first protocol
        with freeze(creation_date):
            model.update_protocol_document()

        document = model.protocol_document.resolve_document()

        document.changed = update_date
        document.reindexObject(idxs=["changed"])

        self.assertEqual(creation_date, as_utc(document.modified().asdatetime()))
        self.assertEqual(update_date, document.changed)

        browser.open(self.meeting)

        self.assertEqual(
            'Modified at Oct 16, 2018 02:00 AM',
            browser.css('.protocol-doc .document-modified').first.text)
Ejemplo n.º 22
0
 def test_as_utc_converts_to_utc_summer(self):
     zurich = pytz.timezone('Europe/Zurich')
     zurich_dt_summer = zurich.localize(datetime(2011, 6, 17, 11, 30))
     self.assertEqual(
         pytz.UTC.localize(datetime(2011, 6, 17, 9, 30)),
         as_utc(zurich_dt_summer))
Ejemplo n.º 23
0
 def test_as_utc_fails_for_naive_datetime(self):
     with self.assertRaises(ValueError):
         as_utc(datetime(2010, 1, 1))
Ejemplo n.º 24
0
 def test_as_utc_converts_to_utc_summer(self):
     zurich = pytz.timezone('Europe/Zurich')
     zurich_dt_summer = zurich.localize(datetime(2011, 6, 17, 11, 30))
     self.assertEqual(pytz.UTC.localize(datetime(2011, 6, 17, 9, 30)),
                      as_utc(zurich_dt_summer))
Ejemplo n.º 25
0
 def get_timestamp(self):
     return as_utc(self.row.created)
Ejemplo n.º 26
0
 def test_as_utc_fails_for_naive_datetime(self):
     with self.assertRaises(ValueError):
         as_utc(datetime(2010, 1, 1))
Ejemplo n.º 27
0
    def server_timestamp(self):
        """Return the modified timestamp as seconds since the epoch."""

        return timegm(as_utc(self.model.modified).timetuple())
Ejemplo n.º 28
0
    def server_timestamp(self):
        """Return the modified timestamp as seconds since the epoch."""

        return timegm(as_utc(self.model.modified).timetuple())
Ejemplo n.º 29
0
 def get_timestamp(self):
     return as_utc(self.row.created)