Beispiel #1
0
    def forwards(self, mongodb_collection, mongodb_database):
        vocabularies_service = get_resource_service("vocabularies")
        cursor = vocabularies_service.find({"field_type": "date"})
        if cursor.count() == 0:
            print('No field with "date" type, there is nothing to do')
        else:
            for resource in ["archive", "archive_autosave", "published"]:

                collection = mongodb_database[resource]

                for item in collection.find(
                    {"extra": {
                        "$exists": True,
                        "$ne": {}
                    }}):
                    transtype_metadata(item)
                    print(
                        collection.update(
                            {"_id": item["_id"]},
                            {
                                "$set": {
                                    "extra": item["extra"]
                                },
                            },
                        ))
Beispiel #2
0
    def test_if_metadata_are_transtyped(self):
        """Check that date metadata in extra are transtyped correctly"""
        content_type = {
            "_id": "type_1",
            "label": "test_type",
            "editor": {
                "test_date_field": {
                    "order": 1,
                    "section": "header"
                }
            },
            "schema": {
                "test_date_field": {
                    "type": "date",
                    "required": False,
                    "enabled": True,
                    "nullable": True,
                }
            },
        }
        self.app.data.insert('content_types', [content_type])
        doc = {
            "_id": "transtype_1",
            "profile": "type_1",
            "extra": {
                "test_date_field": "2019-11-06T00:00:00+0000"
            },
        }

        transtype_metadata(doc)
        self.assertIsInstance(doc['extra']['test_date_field'], datetime)
Beispiel #3
0
 def on_update(self, updates, original):
     self._refresh_associated_items(original)
     self._validate(original, updates)
     self._set_updates(original, updates,
                       updates.get(config.LAST_UPDATED, utcnow()))
     convert_task_attributes_to_objectId(updates)  # ???
     transtype_metadata(updates, original)
     self._process_publish_updates(original, updates)
     self._mark_media_item_as_used(updates, original)
Beispiel #4
0
 def on_update(self, updates, original):
     self._refresh_associated_items(original)
     self._validate(original, updates)
     self._set_updates(
         original,
         updates,
         updates.get(config.LAST_UPDATED, utcnow()),
         preserve_state=original.get("state") in (CONTENT_STATE.SCHEDULED,) and "pubstatus" not in updates,
     )
     convert_task_attributes_to_objectId(updates)  # ???
     transtype_metadata(updates, original)
     self._process_publish_updates(original, updates)
     self._mark_media_item_as_used(updates, original)
     update_refs(updates, original)
    def forwards(self, mongodb_collection, mongodb_database):
        vocabularies_service = get_resource_service('vocabularies')
        cursor = vocabularies_service.find({"field_type": "date"})
        if cursor.count() == 0:
            print('No field with "date" type, there is nothing to do')
        else:
            for resource in ['archive', 'archive_autosave', 'published']:

                collection = mongodb_database[resource]

                for item in collection.find(
                    {'extra': {
                        '$exists': True,
                        '$ne': {}
                    }}):
                    transtype_metadata(item)
                    print(
                        collection.update({'_id': item['_id']}, {
                            '$set': {
                                'extra': item['extra']
                            },
                        }))