示例#1
0
 def test_update(self):
     db_users.update(self.user1.id,
                     user_new_info={
                         "email": '*****@*****.**',
                     })
     user1 = db_users.get_by_id(self.user1.id)
     self.assertEqual(user1['email'], '*****@*****.**')
示例#2
0
def edit():
    form = ProfileEditForm()
    if form.validate_on_submit():
        db_users.update(current_user.id, user_new_info={
            "display_name":form.display_name.data,
            "email":form.email.data,
            "show_gravatar":form.show_gravatar.data,
        })
        flash.success(gettext("Profile updated."))
        return redirect(url_for('user.reviews', user_id=current_user.id))
    else:
        form.display_name.data = current_user.display_name
        form.email.data = current_user.email
        form.show_gravatar.data = current_user.show_gravatar
    return render_template('profile/edit.html', form=form)
示例#3
0
def edit():
    form = ProfileEditForm()
    if form.validate_on_submit():
        db_users.update(current_user.id, user_new_info={
            "display_name": form.display_name.data,
            "email": form.email.data,
            "show_gravatar": form.show_gravatar.data,
            "license_choice": form.license_choice.data,
        })
        flash.success(gettext("Profile updated."))
        return redirect(url_for('user.reviews', user_id=current_user.id))

    form.display_name.data = current_user.display_name
    form.email.data = current_user.email
    form.show_gravatar.data = current_user.show_gravatar
    form.license_choice.data = current_user.license_choice
    return render_template('profile/edit.html', form=form)
示例#4
0
 def test_update(self):
     db_users.update(self.user1.id, user_new_info={
         "email": '*****@*****.**',
     })
     user1 = db_users.get_by_id(self.user1.id)
     self.assertEqual(user1['email'], '*****@*****.**')
示例#5
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
    reviews, count = db_review.list_reviews(user_id=current_user.id,
                                            entity_id=entity_id)
    review = reviews[0] if count is not 0 else None

    if review:
        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,
                            user_new_info={
                                "license_choice": form.license_choice.data,
                            })
        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)
示例#6
0
    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,
                            user_new_info={
                                "license_choice": form.license_choice.data,
                            })
        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']))

    try:
        entity = get_entity_by_id(entity_id, entity_type)
    except NoDataFoundException:
        raise NotFound(
            gettext("Sorry, we couldn't find a %s with that MusicBrainz ID." %
                    entity_type))

    if not entity: