Exemple #1
0
def artists(user_name):
    """ Show the top artists for the user. These users must have been already
        calculated using Google BigQuery. If the stats are not present, we
        redirect to the user page with a message.
    """

    try:
        user = _get_user(user_name)
        data = db_stats.get_user_artists(user.id)
    except DatabaseException as e:
        current_app.logger.error(
            'Error while getting top artist page for user %s: %s',
            user.musicbrainz_id, str(e))
        raise

    # if no data, flash a message and return to profile page
    if data is None:
        msg = (
            'No data calculated for user %s yet. ListenBrainz only calculates statistics for'
            ' recently active users. If %s has logged in recently, they\'ve already been added to'
            ' the stats calculation queue. Please wait until the next statistics calculation batch is finished'
            ' or request stats calculation from your info page.') % (user_name,
                                                                     user_name)

        flash.error(msg)
        return redirect(url_for('user.profile', user_name=user_name))

    top_artists = data['artist']['all_time']
    return render_template("user/artists.html",
                           user=user,
                           data=ujson.dumps(top_artists),
                           section='artists')
def artists(user_name):
    """ Show the top artists for the user. These users must have been already
        calculated using Google BigQuery. If the stats are not present, we
        redirect to the user page with a message.
    """

    try:
        user = _get_user(user_name)
        data = db_stats.get_user_artists(user.id)
    except DatabaseException as e:
        current_app.logger.error('Error while getting top artist page for user %s: %s', user.musicbrainz_id, str(e))
        raise

    # if no data, flash a message and return to profile page
    if data is None:
        msg = ('No data calculated for user %s yet. ListenBrainz only calculates statistics for'
        ' recently active users. If %s has logged in recently, they\'ve already been added to'
        ' the stats calculation queue. Please wait until the next statistics calculation batch is finished'
        ' or request stats calculation from your info page.') % (user_name, user_name)

        flash.error(msg)
        return redirect(url_for('user.profile', user_name=user_name))

    top_artists = data['artist']['all_time']
    return render_template(
        "user/artists.html",
        user=user,
        data=ujson.dumps(top_artists),
        section='artists'
    )
Exemple #3
0
def musicbrainz_post():
    """Callback endpoint."""
    if mb_auth.validate_post_login():
        login_user(mb_auth.get_user())
        next = session.get('next')
        if next:
            return redirect(next)
    else:
        flash.error(gettext("Login failed."))
    return redirect(url_for('frontend.index'))
Exemple #4
0
def vote_delete(id):
    review = Review.query.get_or_404(str(id))
    if review.is_hidden and not current_user.is_admin():
        raise NotFound(gettext("Review has been hidden."))
    try:
        vote = db_vote.get(user_id=current_user.id,
                           revision_id=review.last_revision.id)
        flash.success(gettext("You have deleted your vote for this review!"))
        db_vote.delete(user_id=vote["user_id"],
                       revision_id=vote["revision_id"])
    except db_exceptions.NoDataFoundException:
        flash.error(gettext("This review is not rated yet."))
    return redirect(url_for('.entity', id=id))
Exemple #5
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,
        )
Exemple #6
0
def report(id):
    review = Review.query.get_or_404(str(id))
    if review.is_hidden and not current_user.is_admin():
        raise NotFound(gettext("Review has been hidden."))
    if review.user == current_user:
        flash.error(gettext("You cannot report your own review."))
        return redirect(url_for('.entity', id=id))

    if current_user.is_blocked:
        flash.error(
            gettext("You are not allowed to report this review because "
                    "your account has been blocked by a moderator."))
        return redirect(url_for('.entity', id=id))

    last_revision_id = review.last_revision.id
    report = db_spam_report.get(current_user.id, last_revision_id)
    if report:
        flash.error(gettext("You have already reported this review."))
        return redirect(url_for('.entity', id=id))

    form = ReviewReportForm()
    if form.validate_on_submit():
        db_spam_report.create(last_revision_id, current_user.id,
                              form.reason.data)
        flash.success(gettext("Review has been reported."))
        return redirect(url_for('.entity', id=id))

    return render_template('review/report.html', review=review, form=form)
Exemple #7
0
def vote_submit(review_id):
    review_id = str(review_id)
    if 'yes' in request.form:
        vote = True
    elif 'no' in request.form:
        vote = False
    else:
        vote = None

    review = Review.query.get_or_404(review_id)
    if review.is_hidden and not current_user.is_admin():
        raise NotFound(gettext("Review has been hidden."))
    if review.user == current_user:
        flash.error(gettext("You cannot rate your own review."))
        return redirect(url_for('.entity', id=review_id))
    if current_user.is_vote_limit_exceeded is True and current_user.has_voted(
            review) is False:
        flash.error(gettext("You have exceeded your limit of votes per day."))
        return redirect(url_for('.entity', id=review_id))
    if current_user.is_blocked:
        flash.error(
            gettext("You are not allowed to rate this review because "
                    "your account has been blocked by a moderator."))
        return redirect(url_for('.entity', id=review_id))

    db_vote.submit(
        user_id=current_user.id,
        revision_id=review.last_revision.id,
        vote=vote,  # overwrites an existing vote, if needed
    )

    flash.success(gettext("You have rated this review!"))
    return redirect(url_for('.entity', id=review_id))
Exemple #8
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)
Exemple #9
0
 def handle_csrf_error(e):
     flash.error("Session timed out", "error")
     return redirect(url_for('user.login'))