示例#1
0
def entity(id, rev=None):
    review = Review.query.get_or_404(str(id))
    # Not showing review if it isn't published yet and not viewed by author.
    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:
        if not current_user.is_admin():
            raise Forbidden(
                gettext("Review has been hidden. "
                        "You need to be an administrator to view it."))
        else:
            flash.warn(gettext("Review has been hidden."))

    spotify_mappings = None
    soundcloud_url = None
    if review.entity_type == 'release_group':
        spotify_mappings = mbspotify.mappings(review.entity_id)
        soundcloud_url = soundcloud.get_url(review.entity_id)
    count = db_revision.get_count(id)
    if not rev:
        rev = count
    if rev < count:
        flash.info(
            gettext(
                'You are viewing an old revision, the review has been updated since then.'
            ))
    elif rev > count:
        raise NotFound(
            gettext("The revision you are looking for does not exist."))

    revision = db_revision.get(id, offset=count - rev)[0]
    if not review.is_draft and current_user.is_authenticated:  # if user is logged in, get their vote for this review
        try:
            vote = db_vote.get(user_id=current_user.id,
                               revision_id=revision['id'])
        except db_exceptions.NoDataFoundException:
            vote = None
    else:  # otherwise set vote to None, its value will not be used
        vote = None
    review.text_html = markdown(revision['text'], safe_mode="escape")

    user_all_reviews, review_count = Review.list(user_id=review.user_id,
                                                 sort="random",
                                                 exclude=[review.id])
    other_reviews = user_all_reviews[:3]
    return render_template('review/entity/%s.html' % review.entity_type,
                           review=review,
                           spotify_mappings=spotify_mappings,
                           soundcloud_url=soundcloud_url,
                           vote=vote,
                           other_reviews=other_reviews)
示例#2
0
def reset_token():
    if request.method == "POST":
        token = request.form.get("token")
        if token != current_user.auth_token:
            raise BadRequest("Can only reset token of currently logged in user")
        reset = request.form.get("reset")
        if reset == "yes":
            try:
                db.user.update_token(current_user.id)
                flash.info("Access token reset")
            except DatabaseException as e:
                flash.error("Something went wrong! Unable to reset token right now.")
        return redirect(url_for("user.import_data"))
    else:
        token = current_user.auth_token
        return render_template(
            "user/resettoken.html",
            token = token,
        )
示例#3
0
def hide(id):
    review = Review.query.get_or_404(str(id))

    if review.is_hidden:
        flash.info(gettext("Review is already hidden."))
        return redirect(url_for('.entity', id=review.id))

    form = AdminActionForm()
    if form.validate_on_submit():
        review.hide()
        ModerationLog.create(admin_id=current_user.id,
                             action=ACTION_HIDE_REVIEW,
                             reason=form.reason.data,
                             review_id=review.id)
        for report in db_spam_report.list_reports(review_id=review.id):
            db_spam_report.archive(report["user_id"], report["revision_id"])
        flash.success(gettext("Review has been hidden."))
        return redirect(url_for('.entity', id=review.id))

    return render_template('log/action.html',
                           review=review,
                           form=form,
                           action=ACTION_HIDE_REVIEW)
示例#4
0
def create():
    for entity_type in ENTITY_TYPES:
        entity_id = request.args.get(entity_type)
        if entity_id:
            break

    if not entity_id:
        flash.info(gettext("Please choose an entity to review."))
        return redirect(url_for('search.selector', next=url_for('.create')))

    if current_user.is_blocked:
        flash.error(
            gettext("You are not allowed to write new reviews because your "
                    "account has been blocked by a moderator."))
        return redirect(url_for('user.reviews', user_id=current_user.id))

    # Checking if the user already wrote a review for this entity
    review = Review.query.filter_by(user_id=current_user.id,
                                    entity_id=entity_id).first()
    if review:
        flash.error(
            gettext("You have already published a review for this entity!"))
        return redirect(url_for('review.entity', id=review.id))

    form = ReviewCreateForm(default_language=get_locale())

    if form.validate_on_submit():
        if current_user.is_review_limit_exceeded:
            flash.error(
                gettext("You have exceeded your limit of reviews per day."))
            return redirect(url_for('user.reviews', user_id=current_user.id))

        is_draft = form.state.data == 'draft'
        review = Review.create(user_id=current_user.id,
                               entity_id=entity_id,
                               entity_type=entity_type,
                               text=form.text.data,
                               license_id=form.license_choice.data,
                               language=form.language.data,
                               is_draft=is_draft)
        if is_draft:
            flash.success(gettext("Review has been saved!"))
        else:
            flash.success(gettext("Review has been published!"))
        return redirect(url_for('.entity', id=review.id))

    entity = musicbrainz.get_entity_by_id(entity_id, entity_type)
    if not entity:
        flash.error(
            gettext(
                "You can only write a review for an entity that exists on MusicBrainz!"
            ))
        return redirect(url_for('search.selector', next=url_for('.create')))

    if entity_type == 'release_group':
        spotify_mappings = mbspotify.mappings(entity_id)
        soundcloud_url = soundcloud.get_url(entity_id)
        return render_template('review/modify/write.html',
                               form=form,
                               entity_type=entity_type,
                               entity=entity,
                               spotify_mappings=spotify_mappings,
                               soundcloud_url=soundcloud_url)
    return render_template('review/modify/write.html',
                           form=form,
                           entity_type=entity_type,
                           entity=entity)