Пример #1
0
    def _update_content_all(self, body, base_revision, comment, user, force_update, dont_create_rev, dont_defer):
        # do not update if the body is not changed
        if not force_update and self.body == body:
            return False

        # validate and prepare new contents
        new_data, new_md = self.validate_new_content(base_revision, body, user)
        new_body = self._merge_if_needed(base_revision, body)

        # get old data and metadata
        old_md = self.metadata.copy()
        old_data = self.data.copy()

        # delete caches
        caching.del_rendered_body(self.title)
        caching.del_hashbangs(self.title)
        caching.del_metadata(self.title)
        caching.del_data(self.title)

        # update model and save
        self.body = new_body
        self.modifier = user
        self.description = PageOperationMixin.make_description(new_body)
        self.acl_read = new_md.get('read', '')
        self.acl_write = new_md.get('write', '')
        self.comment = comment
        self.itemtype_path = schema.get_itemtype_path(new_md['schema'])
        self._update_pub_state(new_md, old_md)
        if not dont_create_rev:
            self.revision += 1
        if not force_update:
            self.updated_at = datetime.now()
        self.put()

        # create revision
        if not dont_create_rev:
            rev_key = self._rev_key()
            rev = WikiPageRevision(parent=rev_key, title=self.title, body=self.body,
                                   created_at=self.updated_at, revision=self.revision,
                                   comment=self.comment, modifier=self.modifier,
                                   acl_read=self.acl_read, acl_write=self.acl_write)
            rev.put()

        # update inlinks, outlinks and schema data index
        self.update_links_and_data(old_md.get('redirect'), new_md.get('redirect'), old_data, new_data, dont_defer)

        # delete config cache
        if self.title == '.config':
            caching.del_config()

        # delete title cache if it's a new page
        if self.revision == 1:
            caching.del_titles()

        return True
Пример #2
0
 def test_should_ignore_yaml_schema_block(self):
     self.assertEqual(u'Hello',
                      PageOperationMixin.make_description(u'.schema Book\n    #!yaml/schema\n    author: A\n\nHello', 20))
Пример #3
0
 def test_should_ignore_metadata(self):
     self.assertEqual(u'Hello',
                      PageOperationMixin.make_description(u'.pub\n\nHello', 20))
Пример #4
0
 def test_cut_off(self):
     self.assertEqual(u'Hi Hello World Se...',
                      PageOperationMixin.make_description(u'Hi Hello World Sentences.', 20))
Пример #5
0
 def test_try_period(self):
     self.assertEqual(u'Hi. Hello. World.',
                      PageOperationMixin.make_description(u'Hi. Hello. World. Sentences.', 20))
Пример #6
0
 def test_try_newline(self):
     self.assertEqual(u'Hello', PageOperationMixin.make_description(u'Hello\nWorld', 20))
Пример #7
0
    def _update_content_all(self, body, base_revision, comment, user,
                            force_update, dont_create_rev, dont_defer):
        # do not update if the body is not changed
        if not force_update and self.body == body:
            return False

        now = datetime.now()

        # validate and prepare new contents
        new_data, new_md = self.validate_new_content(base_revision, body, user)
        new_body = self._merge_if_needed(base_revision, body)

        # get old data and metadata
        try:
            old_md = self.metadata.copy()
        except ValueError:
            old_md = {}

        try:
            old_data = self.data.copy()
        except ValueError:
            old_data = {}

        # delete caches
        caching.del_rendered_body(self.title)
        caching.del_hashbangs(self.title)
        caching.del_metadata(self.title)
        caching.del_data(self.title)

        # update model and save
        self.body = new_body
        self.modifier = user
        self.description = PageOperationMixin.make_description(new_body)
        self.acl_read = new_md.get('read', '')
        self.acl_write = new_md.get('write', '')
        self.comment = comment
        self.itemtype_path = schema.get_itemtype_path(new_md['schema'])
        self._update_pub_state(new_md, old_md)
        if not dont_create_rev:
            self.revision += 1
        if not force_update:
            self.updated_at = now
        self.put()

        # create revision
        if not dont_create_rev:
            rev_key = self._rev_key()
            rev = WikiPageRevision(parent=rev_key,
                                   title=self.title,
                                   body=self.body,
                                   created_at=self.updated_at,
                                   revision=self.revision,
                                   comment=self.comment,
                                   modifier=self.modifier,
                                   acl_read=self.acl_read,
                                   acl_write=self.acl_write)
            rev.put()

        # update inlinks, outlinks and schema data index
        self.update_links_and_data(old_md.get('redirect'),
                                   new_md.get('redirect'), old_data, new_data,
                                   dont_defer)

        # delete config cache
        if self.title == '.config':
            caching.del_config()

        # delete title cache if it's a new page
        if self.revision == 1:
            caching.del_titles()

        return True
Пример #8
0
 def test_should_ignore_yaml_schema_block(self):
     self.assertEqual(
         u'Hello',
         PageOperationMixin.make_description(
             u'.schema Book\n    #!yaml/schema\n    author: A\n\nHello',
             20))
Пример #9
0
 def test_should_ignore_metadata(self):
     self.assertEqual(
         u'Hello',
         PageOperationMixin.make_description(u'.pub\n\nHello', 20))
Пример #10
0
 def test_cut_off(self):
     self.assertEqual(
         u'Hi Hello World Se...',
         PageOperationMixin.make_description(u'Hi Hello World Sentences.',
                                             20))
Пример #11
0
 def test_try_period(self):
     self.assertEqual(
         u'Hi. Hello. World.',
         PageOperationMixin.make_description(
             u'Hi. Hello. World. Sentences.', 20))
Пример #12
0
 def test_try_newline(self):
     self.assertEqual(
         u'Hello', PageOperationMixin.make_description(u'Hello\nWorld', 20))