mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-01-29 00:38:11 -05:00
Use similar sr_props data structure across client and API.
This commit is contained in:
@@ -264,7 +264,7 @@ class LabeledMultiJsonTemplate(ThingJsonTemplate):
|
||||
|
||||
def thing_attr(self, thing, attr):
|
||||
if attr == "srs":
|
||||
return [{"name": sr.name} for sr in thing.srs]
|
||||
return thing.named_sr_props
|
||||
else:
|
||||
return ThingJsonTemplate.thing_attr(self, thing, attr)
|
||||
|
||||
|
||||
@@ -1375,6 +1375,11 @@ class LabeledMulti(tdb_cassandra.Thing, MultiReddit):
|
||||
def sr_props(self):
|
||||
return self.columns_to_sr_props(self.sr_columns)
|
||||
|
||||
@property
|
||||
def named_sr_props(self):
|
||||
sr_props = self.sr_props
|
||||
return {sr.name: sr_props[sr._id] for sr in self._srs}
|
||||
|
||||
@property
|
||||
def path(self):
|
||||
return self._id
|
||||
|
||||
@@ -36,10 +36,26 @@ r.multi.MultiRedditList = Backbone.Collection.extend({
|
||||
this.id = this.get('name').toLowerCase()
|
||||
}
|
||||
}),
|
||||
|
||||
comparator: function(model) {
|
||||
return model.id
|
||||
},
|
||||
|
||||
parse: function(response) {
|
||||
return _.map(response, function(srData, srName) {
|
||||
srData['name'] = srName
|
||||
return srData
|
||||
})
|
||||
},
|
||||
|
||||
toJSON: function() {
|
||||
srProps = {}
|
||||
this.each(function(sr) {
|
||||
srProps[sr.get('name')] = sr.omit('name')
|
||||
})
|
||||
return srProps
|
||||
},
|
||||
|
||||
getByName: function(name) {
|
||||
return this.get(name.toLowerCase())
|
||||
}
|
||||
@@ -52,10 +68,10 @@ r.multi.MultiReddit = Backbone.Model.extend({
|
||||
},
|
||||
|
||||
initialize: function() {
|
||||
this.subreddits = new r.multi.MultiRedditList(this.get('subreddits'))
|
||||
this.subreddits = new r.multi.MultiRedditList(this.get('subreddits'), {parse: true})
|
||||
this.subreddits.url = this.url() + '/r/'
|
||||
this.on('change:subreddits', function(model, value) {
|
||||
this.subreddits.reset(value)
|
||||
this.subreddits.reset(value, {parse: true})
|
||||
}, this)
|
||||
this.subreddits.on('request', function(model, xhr, options) {
|
||||
this.trigger('request', model, xhr, options)
|
||||
@@ -66,6 +82,12 @@ r.multi.MultiReddit = Backbone.Model.extend({
|
||||
return response.data
|
||||
},
|
||||
|
||||
toJSON: function() {
|
||||
data = Backbone.Model.prototype.toJSON.apply(this)
|
||||
data.subreddits = this.subreddits.toJSON()
|
||||
return data
|
||||
},
|
||||
|
||||
addSubreddit: function(name, options) {
|
||||
this.subreddits.create({name: name}, options)
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user