@@ -145,7 +145,7 @@ def _from_row(cls, env, row):
145
145
return None
146
146
147
147
@classmethod
148
- def _from_dict (cls , env , dict_ , create = True ):
148
+ def from_dict (cls , env , dict_ , create = True ):
149
149
"""
150
150
Retrieves or (optionally) creates a subscription from a dict.
151
151
"""
@@ -174,11 +174,12 @@ def _from_dict(cls, env, dict_, create=True):
174
174
subscription .id , subscription )
175
175
176
176
# (Optionally) create a new subscription if we didn't find one
177
- if subscription is None and create :
177
+ if subscription is None :
178
178
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 )
182
183
183
184
return subscription
184
185
@@ -199,7 +200,7 @@ def from_attachment(cls, env, attachment, user=None, notify=True):
199
200
'rev' : '' ,
200
201
'notify' : notify ,
201
202
}
202
- return cls ._from_dict (env , sub )
203
+ return cls .from_dict (env , sub )
203
204
204
205
@classmethod
205
206
def from_changeset (cls , env , changeset , user = None , notify = True ):
@@ -214,7 +215,7 @@ def from_changeset(cls, env, changeset, user=None, notify=True):
214
215
'rev' : changeset .rev ,
215
216
'notify' : notify ,
216
217
}
217
- return cls ._from_dict (env , sub )
218
+ return cls .from_dict (env , sub )
218
219
219
220
@classmethod
220
221
def from_comment (cls , env , comment , user = None , notify = True ):
@@ -250,7 +251,7 @@ def from_comment(cls, env, comment, user=None, notify=True):
250
251
else :
251
252
sub ['rev' ] = _cs .rev
252
253
253
- return cls ._from_dict (env , sub )
254
+ return cls .from_dict (env , sub )
254
255
255
256
@classmethod
256
257
def for_attachment (cls , env , attachment , path = None , notify = None ):
@@ -334,7 +335,7 @@ def for_request(cls, env, req, create=False):
334
335
dict_ ['rev' ] = req .args .get ('rev' ) or ''
335
336
dict_ ['repos' ] = reponame
336
337
337
- return cls ._from_dict (env , dict_ , create = create )
338
+ return cls .from_dict (env , dict_ , create = create )
338
339
339
340
340
341
class SubscriptionJSONEncoder (json .JSONEncoder ):
@@ -479,20 +480,18 @@ def _do_GET(self, req):
479
480
'application/json' )
480
481
481
482
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 )
483
486
status = 201
484
487
req .send (json .dumps (subscription , cls = SubscriptionJSONEncoder ),
485
488
'application/json' , status )
486
489
487
490
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 )
493
491
content = req .read ()
494
492
if len (content ) > 0 :
495
493
data = json .loads (content )
494
+ subscription = Subscription .from_dict (self .env , data , create = True )
496
495
subscription .notify = data ['notify' ]
497
496
subscription .update ()
498
497
req .send (json .dumps (subscription , cls = SubscriptionJSONEncoder ),
0 commit comments