Skip to content

Commit bde5260

Browse files
committed
Fix revision not stored in subscription from browser view
1 parent ffd97bb commit bde5260

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

code_comments/htdocs/code-comments.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ var underscore = _.noConflict();
363363
button.prop('title', title);
364364
},
365365

366-
doToggle: function( event ){
366+
doToggle: function( event ) {
367367
this.model.save({'notify': !this.model.get('notify')}, {wait: true});
368368
if (this.model.isNew()) {
369369
this.model.fetch();

code_comments/subscription.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def _from_row(cls, env, row):
145145
return None
146146

147147
@classmethod
148-
def _from_dict(cls, env, dict_, create=True):
148+
def from_dict(cls, env, dict_, create=True):
149149
"""
150150
Retrieves or (optionally) creates a subscription from a dict.
151151
"""
@@ -174,11 +174,12 @@ def _from_dict(cls, env, dict_, create=True):
174174
subscription.id, subscription)
175175

176176
# (Optionally) create a new subscription if we didn't find one
177-
if subscription is None and create:
177+
if subscription is None:
178178
subscription = cls(env, dict_)
179-
subscription.insert()
180-
env.log.info('Subscription created: [%d] %s',
181-
subscription.id, subscription)
179+
if create:
180+
subscription.insert()
181+
env.log.info('Subscription created: [%d] %s',
182+
subscription.id, subscription)
182183

183184
return subscription
184185

@@ -199,7 +200,7 @@ def from_attachment(cls, env, attachment, user=None, notify=True):
199200
'rev': '',
200201
'notify': notify,
201202
}
202-
return cls._from_dict(env, sub)
203+
return cls.from_dict(env, sub)
203204

204205
@classmethod
205206
def from_changeset(cls, env, changeset, user=None, notify=True):
@@ -214,7 +215,7 @@ def from_changeset(cls, env, changeset, user=None, notify=True):
214215
'rev': changeset.rev,
215216
'notify': notify,
216217
}
217-
return cls._from_dict(env, sub)
218+
return cls.from_dict(env, sub)
218219

219220
@classmethod
220221
def from_comment(cls, env, comment, user=None, notify=True):
@@ -250,7 +251,7 @@ def from_comment(cls, env, comment, user=None, notify=True):
250251
else:
251252
sub['rev'] = _cs.rev
252253

253-
return cls._from_dict(env, sub)
254+
return cls.from_dict(env, sub)
254255

255256
@classmethod
256257
def for_attachment(cls, env, attachment, path=None, notify=None):
@@ -334,7 +335,7 @@ def for_request(cls, env, req, create=False):
334335
dict_['rev'] = req.args.get('rev') or ''
335336
dict_['repos'] = reponame
336337

337-
return cls._from_dict(env, dict_, create=create)
338+
return cls.from_dict(env, dict_, create=create)
338339

339340

340341
class SubscriptionJSONEncoder(json.JSONEncoder):
@@ -479,20 +480,18 @@ def _do_GET(self, req):
479480
'application/json')
480481

481482
def _do_POST(self, req):
482-
subscription = Subscription.for_request(self.env, req, create=True)
483+
content = req.read()
484+
data = json.loads(content)
485+
subscription = Subscription.from_dict(self.env, data, create=True)
483486
status = 201
484487
req.send(json.dumps(subscription, cls=SubscriptionJSONEncoder),
485488
'application/json', status)
486489

487490
def _do_PUT(self, req):
488-
subscription = Subscription.for_request(self.env, req)
489-
if subscription is None:
490-
raise HTTPNotFound('Subscription to /%s%s for %s not found',
491-
req.args.get('realm'), req.args.get('path'),
492-
req.authname)
493491
content = req.read()
494492
if len(content) > 0:
495493
data = json.loads(content)
494+
subscription = Subscription.from_dict(self.env, data, create=True)
496495
subscription.notify = data['notify']
497496
subscription.update()
498497
req.send(json.dumps(subscription, cls=SubscriptionJSONEncoder),

0 commit comments

Comments
 (0)