def compare(id): review = Review.query.get_or_404(str(id)) if review.is_draft and not (current_user.is_authenticated and current_user == review.user): raise NotFound(gettext("Can't find a review with the specified ID.")) if review.is_hidden and not current_user.is_admin(): raise NotFound(gettext("Review has been hidden.")) revisions = Revision.query.filter_by(review=review).order_by( desc(Revision.timestamp)) count = revisions.count() old, new = int(request.args.get('old') or count - 1), int(request.args.get('new') or count) if old > count or new > count: raise NotFound( gettext("The revision(s) you are looking for does not exist.")) if old > new: return redirect(url_for('.compare', id=id, old=new, new=old)) left = revisions.offset(count - old).first() right = revisions.offset(count - new).first() left.number, right.number = old, new left.text, right.text = side_by_side_diff(left.text, right.text) return render_template('review/compare.html', review=review, left=left, right=right)
def compare(id): review = get_review_or_404(id) if review["is_draft"] and not (current_user.is_authenticated and current_user == review["user"]): raise NotFound(gettext("Can't find a review with the specified ID.")) if review["is_hidden"] and not current_user.is_admin(): raise NotFound(gettext("Review has been hidden.")) count = db_revision.get_count(id) old, new = int(request.args.get('old') or count - 1), int(request.args.get('new') or count) if old > count or new > count: raise NotFound(gettext("The revision(s) you are looking for does not exist.")) if old > new: return redirect(url_for('.compare', id=id, old=new, new=old)) left = db_revision.get(id, offset=count - old)[0] right = db_revision.get(id, offset=count - new)[0] left['number'], right['number'] = old, new left['text'], right['text'] = side_by_side_diff(left['text'], right['text']) return render_template('review/compare.html', review=review, left=left, right=right)
def compare(id): review = Review.query.get_or_404(str(id)) if review.is_draft and not (current_user.is_authenticated() and current_user == review.user): raise NotFound(gettext("Can't find a review with the specified ID.")) if review.is_hidden and not current_user.is_admin(): raise NotFound(gettext("Review has been hidden.")) revisions = Revision.query.filter_by(review=review).order_by(desc(Revision.timestamp)) count = revisions.count() old, new = int(request.args.get('old') or count - 1), int(request.args.get('new') or count) if old > count or new > count: raise NotFound(gettext("The revision(s) you are looking for does not exist.")) if old > new: return redirect(url_for('.compare', id=id, old=new, new=old)) left = revisions.offset(count-old).first() right = revisions.offset(count-new).first() left.number, right.number = old, new left.text, right.text = side_by_side_diff(left.text, right.text) return render_template('review/compare.html', review=review, left=left, right=right)