Merge lp://staging/~aaronp/rnr-server/modify-only into lp://staging/rnr-server
Status: | Superseded | ||||
---|---|---|---|---|---|
Proposed branch: | lp://staging/~aaronp/rnr-server/modify-only | ||||
Merge into: | lp://staging/rnr-server | ||||
Diff against target: |
411 lines (+199/-15) 9 files modified
django_project/config_dev/config/main.cfg (+1/-0) django_project/config_dev/schema.py (+1/-0) src/reviewsapp/api/handlers.py (+32/-7) src/reviewsapp/api/urls.py (+9/-1) src/reviewsapp/forms.py (+16/-1) src/reviewsapp/models/reviews.py (+8/-0) src/reviewsapp/tests/test_handlers.py (+83/-1) src/reviewsapp/tests/test_models.py (+10/-0) src/reviewsapp/tests/test_rnrclient.py (+39/-5) |
||||
To merge this branch: | bzr merge lp://staging/~aaronp/rnr-server/modify-only | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Aaron Peachey (community) | Needs Resubmitting | ||
Ratings and Reviews Developers | Pending | ||
Review via email: mp+62115@code.staging.launchpad.net |
This proposal has been superseded by a proposal from 2011-05-28.
Description of the change
adds functionality for user to modify their existing review within 120 minutes (config option) of submission.
Diff of associated rnrclient changes:
=== modified file 'rnrclient.py'
--- rnrclient.py 2011-05-06 06:35:36 +0000
+++ rnrclient.py 2011-05-24 12:07:16 +0000
@@ -174,3 +174,14 @@
"""Delete a review"""
return self._post(
+
+ @validate(
+ @validate('rating', int)
+ @validate_
+ @validate_
+ @returns_json
+ def modify_review(self, review_id, rating, summary, review_text):
+ """Modify an existing review"""
+ data = {'rating':rating, 'summary':summary, 'review_
+ return self._put(
+ scheme=
Excellent work Aaron - as far as I can see, you've tested everything very well. I've only got a few small simplifications, formatting points or wording suggestions below. See what you think.
> === modified file 'src/reviewsapp /api/handlers. py' api/handlers. py 2011-05-05 14:32:04 +0000 api/handlers. py 2011-05-24 12:31:07 +0000 dler(BaseHandle r): or_404( Review, id=review_id, reviewer= request. user) minutes= settings. MODIFY_ WINDOW_ MINUTES) bidden( "Time to modify review has expired")
> --- src/reviewsapp/
> +++ src/reviewsapp/
> @@ -239,6 +240,32 @@
>
> return review
>
> +class ModifyReviewHan
> + allowed_methods = ('PUT',)
> +
> + def update(self, request, review_id):
> + """Uses PUT verb to modify an existing review"""
> + review = get_object_
> +
> + # check review modify window has not closed before allowing update
> + time_diff = datetime.utcnow() - review.date_created
> + time_limit = timedelta(
> + if time_diff > time_limit:
> + return HttpResponseFor
Hrm - I wonder if we can get a balance of simple language with the actual reason
in parenthesis? Maybe:
"This review can not be edited (edit window expired)."
> + elif review. is_awaiting_ moderation( ): bidden( "Can't modify review with pending moderation")
> + return HttpResponseFor
"This review can not be edited (pending moderation)."
> + else: request. POST, instance=review) items() ) dumps({ 'errors' : errors}) Request( response)
> + form = ReviewEditForm(
> + if not form.is_valid():
> + errors = dict((key, [unicode(v) for v in values])
> + for (key, values) in form.errors.
> + response = simplejson.
> + return HttpResponseBad
I noticed that we're already doing this for the SubmitReviewHandler - it'd be
nice to DRY it up. Feel free to leave it, but if you're keen, we could add an
'errors_json' to our forms. We'd only need to define it once if we use a mixin
like:
class JSONErrorMixin( object) :
def errors_json():
...
and then the forms that use this would simply do:
class ReviewEditForm( forms.ModelForm , JSONErrorMixin):
...
Then the above handler could be simplified to:
if not form.is_valid(): form.errors_ json())
return HttpResponse(
Again, feel free to leave this - and tackle it only if it interests you.
> === modified file 'src/reviewsapp /models/ reviews. py' models/ reviews. py 2011-05-06 01:17:56 +0000 models/ reviews. py 2011-05-24 12:31:07 +0000 displayname( self): get_full_ name() moderation( self): n.objects. filter( ReviewModeratio n.PENDING_ STATUS) .count( )
> --- src/reviewsapp/
> +++ src/reviewsapp/
> @@ -342,6 +342,15 @@
> def reviewer_
> return self.reviewer.
>
> + def is_awaiting_
> + """Return true if the review has any pending moderations"""
> + moderations = ReviewModeratio
> + review=self,
> + status=
Just a simplification, you should be able to do:
moderations = self.reviewmode ration_ set.filter( status= ...).count( )
> + if moderations == 0:
> + return False
> + return True
> +
> def delete(self):
> """...