Example #1
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(gettext("Please choose an entity to review."))
        return redirect(url_for('search.selector', next=url_for('.create')))

    if current_user.is_blocked:
        flash(gettext("You are not allowed to write new reviews because your "
                      "account has been blocked by a moderator."), 'error')
        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=current_user, entity_id=entity_id).first()
    if review:
        flash(gettext("You have already published a review for this entity!"), 'error')
        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(gettext("You have exceeded your limit of reviews per day."), 'error')
            return redirect(url_for('user.reviews', user_id=current_user.id))

        is_draft = form.state.data == 'draft'
        review = Review.create(user=current_user, 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(gettext("Review has been saved!"), 'success')
        else:
            flash(gettext("Review has been published!"), 'success')
        return redirect(url_for('.entity', id=review.id))

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

    if entity_type == 'release_group':
        spotify_mappings = mbspotify.mappings(entity_id)
        return render_template('review/write.html', form=form, entity_type=entity_type, entity=entity, spotify_mappings = spotify_mappings)
    return render_template('review/write.html', form=form, entity_type=entity_type, entity=entity)
Example #2
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(gettext("Please choose an entity to review."))
        return redirect(url_for('search.selector', next=url_for('.create')))

    if current_user.is_blocked:
        flash(gettext("You are not allowed to write new reviews because your "
                      "account has been blocked by a moderator."), 'error')
        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=current_user, entity_id=entity_id).first()
    if review:
        flash(gettext("You have already published a review for this entity!"), 'error')
        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(gettext("You have exceeded your limit of reviews per day."), 'error')
            return redirect(url_for('user.reviews', user_id=current_user.id))

        is_draft = form.state.data == 'draft'
        review = Review.create(user=current_user, 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(gettext("Review has been saved!"), 'success')
        else:
            flash(gettext("Review has been published!"), 'success')
        return redirect(url_for('.entity', id=review.id))

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

    if entity_type == 'release_group':
        spotify_mappings = mbspotify.mappings(entity_id)
        return render_template('review/modify/write.html', form=form, entity_type=entity_type, entity=entity, spotify_mappings = spotify_mappings)
    return render_template('review/modify/write.html', form=form, entity_type=entity_type, entity=entity)
Example #3
0
def create():
    entity_id, entity_type = None, None
    for entity_type in ENTITY_TYPES:
        entity_id = request.args.get(entity_type)
        if entity_id:
            entity_type = entity_type
            break

    if not (entity_id or entity_type):
        logging.warning("Unsupported entity type")
        raise BadRequest("Unsupported entity type")

    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 = db_review.list_reviews(user_id=current_user.id,
                                    entity_id=entity_id)[0]
    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'
        if form.text.data == '':
            form.text.data = None
        review = db_review.create(user_id=current_user.id,
                                  entity_id=entity_id,
                                  entity_type=entity_type,
                                  text=form.text.data,
                                  rating=form.rating.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 = 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)
        if not form.errors:
            flash.info(
                gettext(
                    "Please provide some text or a rating for this review."))
        return render_template('review/modify/write.html',
                               form=form,
                               entity_type=entity_type,
                               entity=entity,
                               spotify_mappings=spotify_mappings,
                               soundcloud_url=soundcloud_url)
    if not form.errors:
        flash.info(
            gettext("Please provide some text or a rating for this review."))
    return render_template('review/modify/write.html',
                           form=form,
                           entity_type=entity_type,
                           entity=entity)
Example #4
0
    if review:
        if review['is_draft']:
            return redirect(url_for('review.edit', id=review['id']))
        elif review['is_hidden']:
            return redirect(url_for('review.entity', id=review['id']))
        else:
            flash.error(
                gettext("You have already published a review for this entity"))
            return redirect(url_for('review.entity', id=review["id"]))

    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))

    form = ReviewCreateForm(default_license_id=current_user.license_choice,
                            default_language=get_locale())

    if form.validate_on_submit():
        is_draft = form.state.data == 'draft'
        if form.text.data == '':
            form.text.data = None
        review = db_review.create(user_id=current_user.id,
                                  entity_id=entity_id,
                                  entity_type=entity_type,
                                  text=form.text.data,
                                  rating=form.rating.data,
                                  license_id=form.license_choice.data,
                                  language=form.language.data,
                                  is_draft=is_draft)
        if form.remember_license.data:
            db_users.update(current_user.id,