Allow for saving specific attributes on resource models.

Review Request #6590 — Created Nov. 14, 2014 and submitted

Information

Review Board
release-2.0.x
b51b707...

Reviewers

Backbone's save() method accepts an 'attrs' option that contains a
dictionary of attribute names and new values. That's nice and all, but
there are times when you already have data set and want to just specify
which attributes to save.

Our version of save() now allows attrs to be an array of attribute
names. Those attributes will be fetched from the payload and saved,
without any of the other attributes on the model.

Care needs to be taken to only use this option when you know that the
save operation will only require those attributes. Creation of certain
resources may require additional attributes, as may an extension's
extra_data in certain cases. Rather than using this in every save()
call, we should only it where we know it'll make sense.

Some call sites have been updated to use this for simple cases and for
resources working with multiple rich text fields, in order to prevent
stomping over those fields' values server-side.

Unit tests passed.

Inspected the payloads for the saves I've updated. I only saw the values
I expected to see, and the saves performed fine in every case. That covers
both PUT and POST (where applicable, namely the review reply code).

Tested this with master, and saw that replies no longer resulted in text fields
containing "<p>" tags. The new review request dialog still needs to be updated
on master to take advantage of this to prevent reviews from having those tags.

reviewbot
  1. Tool: PEP8 Style Checker
    Ignored Files:
        reviewboard/static/rb/js/views/fileAttachmentThumbnailView.js
        reviewboard/static/rb/js/resources/models/reviewReplyModel.js
        reviewboard/static/rb/js/models/reviewReplyEditorModel.js
        reviewboard/static/rb/js/resources/models/baseResourceModel.js
    
    
    
    Tool: Pyflakes
    Ignored Files:
        reviewboard/static/rb/js/views/fileAttachmentThumbnailView.js
        reviewboard/static/rb/js/resources/models/reviewReplyModel.js
        reviewboard/static/rb/js/models/reviewReplyEditorModel.js
        reviewboard/static/rb/js/resources/models/baseResourceModel.js
    
    
  2. 
      
david
  1. Ship It!
  2. 
      
chipx86
Review request changed

Status: Closed (submitted)

Change Summary:

Pushed to release-2.0.x (5fe2138)
Loading...