当前位置: 首页>>代码示例>>Python>>正文


Python ChangeDescription.record_field_change方法代码示例

本文整理汇总了Python中reviewboard.changedescs.models.ChangeDescription.record_field_change方法的典型用法代码示例。如果您正苦于以下问题:Python ChangeDescription.record_field_change方法的具体用法?Python ChangeDescription.record_field_change怎么用?Python ChangeDescription.record_field_change使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在reviewboard.changedescs.models.ChangeDescription的用法示例。


在下文中一共展示了ChangeDescription.record_field_change方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: reopen

# 需要导入模块: from reviewboard.changedescs.models import ChangeDescription [as 别名]
# 或者: from reviewboard.changedescs.models.ChangeDescription import record_field_change [as 别名]
    def reopen(self, user=None):
        """Reopens the review request for review."""
        from reviewboard.reviews.models.review_request_draft import \
            ReviewRequestDraft

        if (user and not self.is_mutable_by(user) and
            not user.has_perm("reviews.can_change_status", self.local_site)):
            raise PermissionError

        if self.status != self.PENDING_REVIEW:
            changedesc = ChangeDescription()
            changedesc.record_field_change('status', self.status,
                                           self.PENDING_REVIEW)

            if self.status == self.DISCARDED:
                # A draft is needed if reopening a discarded review request.
                self.public = False
                changedesc.save()
                draft = ReviewRequestDraft.create(self)
                draft.changedesc = changedesc
                draft.save()
            else:
                changedesc.public = True
                changedesc.save()
                self.changedescs.add(changedesc)

            self.status = self.PENDING_REVIEW
            self.save(update_counts=True)

        review_request_reopened.send(sender=self.__class__, user=user,
                                     review_request=self)
开发者ID:karthikkn,项目名称:reviewboard,代码行数:33,代码来源:review_request.py

示例2: test_get_with_site

# 需要导入模块: from reviewboard.changedescs.models import ChangeDescription [as 别名]
# 或者: from reviewboard.changedescs.models.ChangeDescription import record_field_change [as 别名]
    def test_get_with_site(self):
        """Testing the GET review-requests/<id>/changes/ API
        with access to a local site
        """
        review_request = self.create_review_request(publish=True,
                                                    with_local_site=True)

        self._login_user(local_site=True)

        now = timezone.now()
        change1 = ChangeDescription(public=True,
                                    timestamp=now)
        change1.record_field_change('summary', 'foo', 'bar')
        change1.save()
        review_request.changedescs.add(change1)

        change2 = ChangeDescription(public=True,
                                    timestamp=now + timedelta(seconds=1))
        change2.record_field_change('description', 'foo', 'bar')
        change2.save()
        review_request.changedescs.add(change2)

        rsp = self.apiGet(
            get_change_list_url(review_request, self.local_site_name),
            expected_mimetype=change_list_mimetype)
        self.assertEqual(rsp['stat'], 'ok')
        self.assertEqual(len(rsp['changes']), 2)

        self.assertEqual(rsp['changes'][0]['id'], change2.pk)
        self.assertEqual(rsp['changes'][1]['id'], change1.pk)
开发者ID:CrystalLokKoo,项目名称:reviewboard,代码行数:32,代码来源:test_change.py

示例3: close

# 需要导入模块: from reviewboard.changedescs.models import ChangeDescription [as 别名]
# 或者: from reviewboard.changedescs.models.ChangeDescription import record_field_change [as 别名]
    def close(self, type, user=None, description=None, rich_text=False):
        """Closes the review request.

        The type must be one of SUBMITTED or DISCARDED.
        """
        if (user and not self.is_mutable_by(user) and
            not user.has_perm("reviews.can_change_status", self.local_site)):
            raise PermissionError

        if type not in [self.SUBMITTED, self.DISCARDED]:
            raise AttributeError("%s is not a valid close type" % type)

        if self.status != type:
            # TODO: Use the user's default for rich_text.
            changedesc = ChangeDescription(public=True,
                                           text=description or "",
                                           rich_text=rich_text or False)
            changedesc.record_field_change('status', self.status, type)
            changedesc.save()

            self.changedescs.add(changedesc)

            if type == self.SUBMITTED:
                self.public = True
            else:
                self.commit_id = None

            self.status = type
            self.save(update_counts=True)

            review_request_closed.send(sender=self.__class__, user=user,
                                       review_request=self,
                                       type=type)
        else:
            # Update submission description.
            changedesc = self.changedescs.filter(public=True).latest()
            changedesc.timestamp = timezone.now()
            changedesc.text = description or ""
            changedesc.rich_text = rich_text
            changedesc.save()

            # Needed to renew last-update.
            self.save()

        try:
            draft = self.draft.get()
        except ObjectDoesNotExist:
            pass
        else:
            draft.delete()
开发者ID:iapilgrim,项目名称:reviewboard,代码行数:52,代码来源:review_request.py

示例4: testRecordString

# 需要导入模块: from reviewboard.changedescs.models import ChangeDescription [as 别名]
# 或者: from reviewboard.changedescs.models.ChangeDescription import record_field_change [as 别名]
    def testRecordString(self):
        """Testing record_field_change with a string value"""
        old_value = "abc"
        new_value = "def"

        changedesc = ChangeDescription()
        changedesc.record_field_change("test", old_value, new_value)

        self.assert_("test" in changedesc.fields_changed)
        self.assert_("old" in changedesc.fields_changed["test"])
        self.assert_("new" in changedesc.fields_changed["test"])
        self.assert_("added" not in changedesc.fields_changed["test"])
        self.assert_("removed" not in changedesc.fields_changed["test"])
        self.assertEqual(changedesc.fields_changed["test"]["old"], (old_value,))
        self.assertEqual(changedesc.fields_changed["test"]["new"], (new_value,))
开发者ID:B-Rich,项目名称:reviewboard,代码行数:17,代码来源:tests.py

示例5: test_record_list

# 需要导入模块: from reviewboard.changedescs.models import ChangeDescription [as 别名]
# 或者: from reviewboard.changedescs.models.ChangeDescription import record_field_change [as 别名]
    def test_record_list(self):
        """Testing ChangeDescription.record_field_change with a list value"""
        old_value = [1, 2, 3]
        new_value = [2, 3, 4]

        changedesc = ChangeDescription()
        changedesc.record_field_change("test", old_value, new_value)

        self.assertIn("test", changedesc.fields_changed)
        self.assertIn("old", changedesc.fields_changed["test"])
        self.assertIn("new", changedesc.fields_changed["test"])
        self.assertIn("added", changedesc.fields_changed["test"])
        self.assertIn("removed", changedesc.fields_changed["test"])
        self.assertEqual(changedesc.fields_changed["test"]["old"], [(i,) for i in old_value])
        self.assertEqual(changedesc.fields_changed["test"]["new"], [(i,) for i in new_value])
        self.assertEqual(changedesc.fields_changed["test"]["added"], [(4,)])
        self.assertEqual(changedesc.fields_changed["test"]["removed"], [(1,)])
开发者ID:klpyang,项目名称:reviewboard,代码行数:19,代码来源:tests.py

示例6: test_get_with_site_no_access

# 需要导入模块: from reviewboard.changedescs.models import ChangeDescription [as 别名]
# 或者: from reviewboard.changedescs.models.ChangeDescription import record_field_change [as 别名]
    def test_get_with_site_no_access(self):
        """Testing the GET review-requests/<id>/changes/<id>/ API
        without access to a local site
        """
        review_request = self.create_review_request(publish=True,
                                                    with_local_site=True)

        now = timezone.now()
        change = ChangeDescription(public=True, timestamp=now)
        change.record_field_change('summary', 'foo', 'bar')
        change.save()
        review_request.changedescs.add(change)

        rsp = self.apiGet(
            get_change_item_url(change, self.local_site_name),
            expected_status=403)
        self.assertEqual(rsp['stat'], 'fail')
        self.assertEqual(rsp['err']['code'], PERMISSION_DENIED.code)
开发者ID:CrystalLokKoo,项目名称:reviewboard,代码行数:20,代码来源:test_change.py

示例7: test_record_object_list_name_field

# 需要导入模块: from reviewboard.changedescs.models import ChangeDescription [as 别名]
# 或者: from reviewboard.changedescs.models.ChangeDescription import record_field_change [as 别名]
    def test_record_object_list_name_field(self):
        """Testing ChangeDescription.record_field_change with an object list
        (using name_field)
        """

        class DummyObject(object):
            def __init__(self, id):
                self.id = id
                self.text = "Object %s" % id

            def get_absolute_url(self):
                return "http://localhost/%s" % self.id

        objs = [DummyObject(i) for i in range(4)]
        old_value = [objs[0], objs[1], objs[2]]
        new_value = [objs[1], objs[2], objs[3]]

        changedesc = ChangeDescription()
        changedesc.record_field_change("test", old_value, new_value, "text")

        self.assertIn("test", changedesc.fields_changed)
        self.assertIn("old", changedesc.fields_changed["test"])
        self.assertIn("new", changedesc.fields_changed["test"])
        self.assertIn("added", changedesc.fields_changed["test"])
        self.assertIn("removed", changedesc.fields_changed["test"])
        self.assertEqual(
            set(changedesc.fields_changed["test"]["old"]),
            set([(obj.text, obj.get_absolute_url(), obj.id) for obj in old_value]),
        )
        self.assertEqual(
            set(changedesc.fields_changed["test"]["new"]),
            set([(obj.text, obj.get_absolute_url(), obj.id) for obj in new_value]),
        )
        self.assertEqual(
            set(changedesc.fields_changed["test"]["added"]),
            set([(new_value[2].text, new_value[2].get_absolute_url(), new_value[2].id)]),
        )
        self.assertEqual(
            set(changedesc.fields_changed["test"]["removed"]),
            set([(old_value[0].text, old_value[0].get_absolute_url(), old_value[0].id)]),
        )
开发者ID:klpyang,项目名称:reviewboard,代码行数:43,代码来源:tests.py

示例8: test_get_changes

# 需要导入模块: from reviewboard.changedescs.models import ChangeDescription [as 别名]
# 或者: from reviewboard.changedescs.models.ChangeDescription import record_field_change [as 别名]
    def test_get_changes(self):
        """Testing the GET review-requests/<id>/changes/ API"""
        review_request = self.create_review_request(publish=True)

        now = timezone.now()
        change1 = ChangeDescription(public=True, timestamp=now)
        change1.record_field_change("summary", "foo", "bar")
        change1.save()
        review_request.changedescs.add(change1)

        change2 = ChangeDescription(public=True, timestamp=now + timedelta(seconds=1))
        change2.record_field_change("description", "foo", "bar")
        change2.save()
        review_request.changedescs.add(change2)

        rsp = self.apiGet(get_change_list_url(review_request), expected_mimetype=change_list_mimetype)
        self.assertEqual(rsp["stat"], "ok")
        self.assertEqual(len(rsp["changes"]), 2)

        self.assertEqual(rsp["changes"][0]["id"], change2.pk)
        self.assertEqual(rsp["changes"][1]["id"], change1.pk)
开发者ID:harrifeng,项目名称:reviewboard,代码行数:23,代码来源:test_change.py

示例9: save_autolandrequest_id

# 需要导入模块: from reviewboard.changedescs.models import ChangeDescription [as 别名]
# 或者: from reviewboard.changedescs.models.ChangeDescription import record_field_change [as 别名]
    def save_autolandrequest_id(self, fieldname, rr, autoland_request_id):
        # TODO: this method is only required while we are using change
        #       descriptions to render autoland results. Once Bug 1176330 is
        #       fixed this code can be removed.

        # There's possibly a race condition here with multiple web-heads. If
        # two requests come in at the same time to this endpoint, the request
        # that saves their value first here will get overwritten by the second
        # but the first request will have their changedescription come below
        # the second. In that case you'd have the "most recent" try build stats
        # appearing at the top be for a changedescription that has a different
        # try build below it (Super rare, not a big deal really).
        old_request_id = rr.extra_data.get(fieldname, None)
        rr.extra_data[fieldname] = autoland_request_id
        rr.save()

        # In order to display the fact that a build was kicked off in the UI,
        # we construct a change description that our TryField can render.
        changedesc = ChangeDescription(public=True, text="", rich_text=False)
        changedesc.record_field_change(fieldname, old_request_id, autoland_request_id)
        changedesc.save()
        rr.changedescs.add(changedesc)
开发者ID:pkdevboxy,项目名称:version-control-tools,代码行数:24,代码来源:resources.py

示例10: test_determine_user_for_review_request

# 需要导入模块: from reviewboard.changedescs.models import ChangeDescription [as 别名]
# 或者: from reviewboard.changedescs.models.ChangeDescription import record_field_change [as 别名]
    def test_determine_user_for_review_request(self):
        """Testing ChangeDescription.get_user for change descriptions for
        review requests
        """
        review_request = self.create_review_request(publish=True)
        doc = review_request.submitter
        grumpy = User.objects.get(username='grumpy')

        change1 = ChangeDescription()
        change1.record_field_change('foo', ['bar'], ['baz'])
        change1.save()
        review_request.changedescs.add(change1)

        change2 = ChangeDescription()
        change2.record_field_change('submitter', doc, grumpy, 'username')
        change2.save()
        review_request.changedescs.add(change2)

        change3 = ChangeDescription()
        change3.record_field_change('foo', ['bar'], ['baz'])
        change3.save()
        review_request.changedescs.add(change3)

        change4 = ChangeDescription()
        change4.record_field_change('submitter', grumpy, doc, 'username')
        change4.save()
        review_request.changedescs.add(change4)

        self.assertIsNone(change1.user)
        self.assertIsNone(change2.user)
        self.assertIsNone(change3.user)
        self.assertIsNone(change4.user)

        self.assertEqual(change1.get_user(review_request), doc)
        self.assertEqual(change2.get_user(review_request), doc)
        self.assertEqual(change3.get_user(review_request), grumpy)
        self.assertEqual(change4.get_user(review_request), grumpy)

        self.assertEqual(change1.user, doc)
        self.assertEqual(change2.user, doc)
        self.assertEqual(change3.user, grumpy)
        self.assertEqual(change4.user, grumpy)
开发者ID:davidt,项目名称:reviewboard,代码行数:44,代码来源:test_review_request.py

示例11: ReviewRequestDraft

# 需要导入模块: from reviewboard.changedescs.models import ChangeDescription [as 别名]
# 或者: from reviewboard.changedescs.models.ChangeDescription import record_field_change [as 别名]

#.........这里部分代码省略.........
        Each field in 'fields_changed' represents a changed field. This will
        save fields in the standard formats as defined by the
        'ChangeDescription' documentation, with the exception of the
        'screenshot_captions' and 'diff' fields.

        For the 'screenshot_captions' field, the value will be a dictionary
        of screenshot ID/dict pairs with the following fields:

           * 'old': The old value of the field
           * 'new': The new value of the field

        For the 'diff' field, there is only ever an 'added' field, containing
        the ID of the new diffset.

        The 'send_notification' parameter is intended for internal use only,
        and is there to prevent duplicate notifications when being called by
        ReviewRequest.publish.
        """
        if not review_request:
            review_request = self.review_request

        if not user:
            user = review_request.submitter

        if not self.changedesc and review_request.public:
            self.changedesc = ChangeDescription()

        def update_list(a, b, name, record_changes=True, name_field=None):
            aset = set([x.id for x in a.all()])
            bset = set([x.id for x in b.all()])

            if aset.symmetric_difference(bset):
                if record_changes and self.changedesc:
                    self.changedesc.record_field_change(name, a.all(), b.all(),
                                                        name_field)

                a.clear()
                for item in b.all():
                    a.add(item)

        for field_cls in get_review_request_fields():
            field = field_cls(review_request)

            if field.can_record_change_entry:
                old_value = field.load_value(review_request)
                new_value = field.load_value(self)

                if field.has_value_changed(old_value, new_value):
                    field.save_value(new_value)

                    if self.changedesc:
                        field.record_change_entry(self.changedesc,
                                                  old_value, new_value)

        # Screenshots are a bit special.  The list of associated screenshots
        # can change, but so can captions within each screenshot.
        screenshots = list(self.screenshots.all())
        caption_changes = {}

        for s in review_request.screenshots.all():
            if s in screenshots and s.caption != s.draft_caption:
                caption_changes[s.id] = {
                    'old': (s.caption,),
                    'new': (s.draft_caption,),
                }
开发者ID:down-networks,项目名称:reviewboard,代码行数:69,代码来源:review_request_draft.py

示例12: ReviewRequestDraft

# 需要导入模块: from reviewboard.changedescs.models import ChangeDescription [as 别名]
# 或者: from reviewboard.changedescs.models.ChangeDescription import record_field_change [as 别名]

#.........这里部分代码省略.........
        'ChangeDescription' documentation, with the exception of the
        'screenshot_captions' and 'diff' fields.

        For the 'screenshot_captions' field, the value will be a dictionary
        of screenshot ID/dict pairs with the following fields:

           * 'old': The old value of the field
           * 'new': The new value of the field

        For the 'diff' field, there is only ever an 'added' field, containing
        the ID of the new diffset.

        The 'send_notification' parameter is intended for internal use only,
        and is there to prevent duplicate notifications when being called by
        ReviewRequest.publish.
        """
        if not review_request:
            review_request = self.review_request

        if not user:
            user = review_request.submitter

        if not self.changedesc and review_request.public:
            self.changedesc = ChangeDescription()

        def update_field(a, b, name, record_changes=True):
            # Apparently django models don't have __getattr__ or __setattr__,
            # so we have to update __dict__ directly.  Sigh.
            value = b.__dict__[name]
            old_value = a.__dict__[name]

            if old_value != value:
                if record_changes and self.changedesc:
                    self.changedesc.record_field_change(name, old_value, value)

                a.__dict__[name] = value

        def update_list(a, b, name, record_changes=True, name_field=None):
            aset = set([x.id for x in a.all()])
            bset = set([x.id for x in b.all()])

            if aset.symmetric_difference(bset):
                if record_changes and self.changedesc:
                    self.changedesc.record_field_change(name, a.all(), b.all(),
                                                        name_field)

                a.clear()
                map(a.add, b.all())


        update_field(review_request, self, 'summary')
        update_field(review_request, self, 'description')
        update_field(review_request, self, 'testing_done')
        update_field(review_request, self, 'branch')

        update_list(review_request.target_groups, self.target_groups,
                    'target_groups', name_field="name")
        update_list(review_request.target_people, self.target_people,
                    'target_people', name_field="username")

        # Specifically handle bug numbers
        old_bugs = set(review_request.get_bug_list())
        new_bugs = set(self.get_bug_list())

        if old_bugs != new_bugs:
            update_field(review_request, self, 'bugs_closed',
开发者ID:cortextual,项目名称:reviewboard,代码行数:70,代码来源:models.py

示例13: ReviewRequestDraft

# 需要导入模块: from reviewboard.changedescs.models import ChangeDescription [as 别名]
# 或者: from reviewboard.changedescs.models.ChangeDescription import record_field_change [as 别名]

#.........这里部分代码省略.........
            diff_file_name='diff',
            diff_file_contents=commit.diff,
            parent_diff_file_name=None,
            parent_diff_file_contents=None,
            diffset_history=None,
            basedir='/',
            request=None,
            base_commit_id=commit.parent,
            check_existence=False)

        # Compute a suitable revision for the diffset.
        self.diffset.update_revision_from_history(
            self.review_request.diffset_history)
        self.diffset.save(update_fields=('revision',))

        return [
            'commit_id',
            'description',
            'description_rich_text',
            'diffset',
            'summary',
        ]

    def copy_fields_to_request(self, review_request):
        """Copies the draft information to the review request and updates the
        draft's change description.
        """
        def update_list(a, b, name, record_changes=True, name_field=None):
            aset = set([x.id for x in a.all()])
            bset = set([x.id for x in b.all()])

            if aset.symmetric_difference(bset):
                if record_changes and self.changedesc:
                    self.changedesc.record_field_change(name, a.all(), b.all(),
                                                        name_field)

                a.clear()
                for item in b.all():
                    a.add(item)

        for field_cls in get_review_request_fields():
            field = field_cls(review_request)

            if field.can_record_change_entry:
                old_value = field.load_value(review_request)
                new_value = field.load_value(self)

                if field.has_value_changed(old_value, new_value):
                    field.propagate_data(self)

                    if self.changedesc:
                        field.record_change_entry(self.changedesc,
                                                  old_value, new_value)

        # Screenshots are a bit special.  The list of associated screenshots
        # can change, but so can captions within each screenshot.
        if (review_request.screenshots_count > 0 or
            self.screenshots_count > 0):
            screenshots = list(self.screenshots.all())
            caption_changes = {}

            for s in review_request.screenshots.all():
                if s in screenshots and s.caption != s.draft_caption:
                    caption_changes[s.id] = {
                        'old': (s.caption,),
                        'new': (s.draft_caption,),
开发者ID:chipx86,项目名称:reviewboard,代码行数:70,代码来源:review_request_draft.py

示例14: ReviewRequestDraft

# 需要导入模块: from reviewboard.changedescs.models import ChangeDescription [as 别名]
# 或者: from reviewboard.changedescs.models.ChangeDescription import record_field_change [as 别名]

#.........这里部分代码省略.........
        self.commit = commit_id
        self.summary = summary.strip()

        self.description = message
        self.description_rich_text = False

        self.diffset = DiffSet.objects.create_from_data(
            repository=self.repository,
            diff_file_name='diff',
            diff_file_contents=commit.diff,
            parent_diff_file_name=None,
            parent_diff_file_contents=None,
            diffset_history=None,
            basedir='/',
            request=None,
            base_commit_id=commit.parent,
            check_existence=False)

        # Compute a suitable revision for the diffset.
        self.diffset.update_revision_from_history(
            self.review_request.diffset_history)
        self.diffset.save(update_fields=('revision',))

    def copy_fields_to_request(self, review_request):
        """Copies the draft information to the review request and updates the
        draft's change description.
        """
        def update_list(a, b, name, record_changes=True, name_field=None):
            aset = set([x.id for x in a.all()])
            bset = set([x.id for x in b.all()])

            if aset.symmetric_difference(bset):
                if record_changes and self.changedesc:
                    self.changedesc.record_field_change(name, a.all(), b.all(),
                                                        name_field)

                a.clear()
                for item in b.all():
                    a.add(item)

        for field_cls in get_review_request_fields():
            field = field_cls(review_request)

            if field.can_record_change_entry:
                old_value = field.load_value(review_request)
                new_value = field.load_value(self)

                if field.has_value_changed(old_value, new_value):
                    field.propagate_data(self)

                    if self.changedesc:
                        field.record_change_entry(self.changedesc,
                                                  old_value, new_value)

        # Screenshots are a bit special.  The list of associated screenshots
        # can change, but so can captions within each screenshot.
        if (review_request.screenshots_count > 0 or
            self.screenshots_count > 0):
            screenshots = list(self.screenshots.all())
            caption_changes = {}

            for s in review_request.screenshots.all():
                if s in screenshots and s.caption != s.draft_caption:
                    caption_changes[s.id] = {
                        'old': (s.caption,),
                        'new': (s.draft_caption,),
开发者ID:darmhoo,项目名称:reviewboard,代码行数:70,代码来源:review_request_draft.py


注:本文中的reviewboard.changedescs.models.ChangeDescription.record_field_change方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。