예제 #1
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())
예제 #2
0
    def test_earliest_possible_is_latest_of_dossiers_end_dates_and_document_modificiation_dates(self):
        self.login(self.dossier_responsible)

        IChanged(self.document).changed = datetime(2020, 1, 1, tzinfo=pytz.utc)
        self.document.reindexObject(idxs=['changed'])
        IDossier(self.subdossier).end = date(2020, 2, 2)
        self.subdossier.reindexObject(idxs=['end'])
        self.assertEquals(date(2020, 2, 2), self.dossier.earliest_possible_end_date())

        IChanged(self.document).changed = datetime(2020, 3, 3, tzinfo=pytz.utc)
        self.document.reindexObject(idxs=['changed'])
        self.assertEquals(date(2020, 3, 3), self.dossier.earliest_possible_end_date())
예제 #3
0
 def test_changed_is_not_updated_when_subdossier_is_changed(self, browser):
     self.login(self.regular_user, browser)
     self.dossier_initial_changed = IChanged(self.dossier).changed
     with freeze(FREEZING_TIME):
         browser.open(self.subdossier, view='transition-deactivate', send_authenticator=True)
     self.assert_changed_value(self.subdossier, FREEZING_TIME)
     self.assert_changed_value(self.dossier, self.dossier_initial_changed)
예제 #4
0
    def test_earliest_possible_can_handle_datetime_objs(self):
        self.login(self.dossier_responsible)

        IChanged(self.document).changed = datetime(2020, 1, 1, 10, 10, tzinfo=pytz.utc)
        self.document.reindexObject(idxs=['changed'])
        IDossier(self.subdossier).end = datetime(2020, 2, 2, 10, 10)
        self.subdossier.reindexObject(idxs=['end'])
        self.assertEquals(date(2020, 2, 2), self.dossier.earliest_possible_end_date())
예제 #5
0
 def test_changed_is_not_updated_when_containing_dossier_is_changed(self, browser):
     self.login(self.regular_user, browser)
     initial_changed = IChanged(self.document).changed
     with freeze(FREEZING_TIME):
         browser.open(self.dossier, view='edit')
         browser.fill({'Title': 'foo'})
         browser.find('Save').click()
     self.assert_changed_value(self.document, initial_changed)
예제 #6
0
 def test_enddate_may_be_latest_dossier_end_date(self, browser):
     """When a dossiers end date is greater than the document's modification
     date, use the dossier end date.
     """
     self.login(self.dossier_responsible, browser)
     IDossier(self.dossier).end = date(2021, 2, 2)
     self.dossier.reindexObject(idxs=['end'])
     IChanged(self.subdocument).changed = datetime(2021,
                                                   1,
                                                   2,
                                                   tzinfo=pytz.utc)
     self.subdocument.reindexObject(idxs=['changed'])
     browser.open(self.dossier, view='transition-archive')
     self.assertEqual(date(2021, 2, 2),
                      self._get_form_date(browser, 'dossier_enddate'))
예제 #7
0
    def test_earliest_possible_ignores_automatically_generated_documents(self):
        self.login(self.dossier_responsible)
        IDossier(self.dossier).end = date(2021, 1, 21)
        self.dossier.reindexObject(idxs=['end'])
        IChanged(self.document).changed = datetime(2021, 1, 22, tzinfo=pytz.utc)
        self.document.reindexObject(idxs=['changed'])

        self.assertEquals(date(2021, 1, 22),
                          self.dossier.earliest_possible_end_date())

        alsoProvides(self.document, IDossierJournalPDFMarker)
        self.document.reindexObject(idxs=['object_provides'])

        self.assertEquals(date(2021, 1, 21),
                          self.dossier.earliest_possible_end_date())
예제 #8
0
 def test_document_changed_is_not_modified_on_checkout(self):
     self.login(self.regular_user)
     initial_changed = IChanged(self.document).changed
     with freeze(FREEZING_TIME):
         self.checkout_document(self.document)
     self.assert_changed_value(self.document, initial_changed)
예제 #9
0
 def assert_changed_value(self, obj, value):
     self.assertEqual(value, IChanged(obj).changed)
     self.assert_index_and_metadata(value, "changed")
예제 #10
0
 def test_setter_normalizes_timezone_to_utc(self):
     self.login(self.manager)
     IChanged(self.document).changed = DateTime()
     self.assertEqual(IChanged(self.document).changed.tzinfo,
                      pytz.UTC)
예제 #11
0
 def test_setter_requires_timezone_aware_datetime(self):
     self.login(self.manager)
     with self.assertRaises(AssertionError):
         IChanged(self.document).changed = datetime.now()
예제 #12
0
 def test_setter_transforms_zope_datetime_to_python_datetime(self):
     self.login(self.manager)
     IChanged(self.document).changed = DateTime()
     self.assertIsInstance(IChanged(self.document).changed, datetime)
예제 #13
0
 def test_earliest_possible_is_last_modified_document_modification_date(self):
     self.login(self.dossier_responsible)
     IChanged(self.document).changed = datetime(2021, 1, 22, tzinfo=pytz.utc)
     self.document.reindexObject(idxs=['changed'])
     self.assertEquals(date(2021, 1, 22),
                       self.dossier.earliest_possible_end_date())
예제 #14
0
def changed_indexer(obj):
    if IChangedMarker.providedBy(obj):
        # The indexer transforms this to UTC and then represents it as a integer
        return IChanged(obj).changed
    return None
예제 #15
0
 def test_dossier_end_cannot_be_earlier_to_document_modification_date(self):
     self.login(self.dossier_responsible)
     IDossier(self.dossier).end = date(2020, 1, 1)
     IChanged(self.document).changed = datetime(2020, 2, 2, tzinfo=pytz.utc)
     self.document.reindexObject(idxs=['changed'])
     self.assertFalse(self.dossier.has_valid_enddate())
예제 #16
0
 def test_reindexing_does_not_update_changed(self):
     self.login(self.regular_user)
     initial_changed = IChanged(self.document).changed
     self.document.reindexObject()
     self.assert_changed_value(self.document, initial_changed)
예제 #17
0
 def get_modification_date(self):
     return self.context.toLocalizedTime(IChanged(self.context).changed,
                                         long_format=True)
예제 #18
0
def update_changed_date(context, event):
    IChanged(context).changed = utcnow_tz_aware()
    context.reindexObject(idxs=["changed"])