Exemplo n.º 1
0
def new_comment(tnote_id):
    tnote = db.session.query(TastingNote).get(tnote_id)
    new_comment_form = NewCommentForm()
    img_url = None
    filename = None

    if request.method == 'POST':
        if 'image' in request.files and request.files['image'].filename:
            filename = photos.save(request.files['image'])
            img = ProcessStandardImage(
                filename,  # path to temporary image location
                new_comment_form.rotate_image.data,  # desired rotation
                600  # maximum height or width
            )
            img.process_image()  # saves the modified image to the temp location
        if new_comment_form.validate_on_submit():
            img_url = upload_image(filename)
            comment = Comment(
                text=new_comment_form.text.data,
                tnote_id=tnote_id,
                author_id=current_user.id,
                image=img_url
            )

            db.session.add(comment)
            db.session.commit()
            message = 'You added a comment to the {} tasting note'.format(
                tnote.title)
            flash(message)
            return redirect(url_for('wines.wine_detail', wine_id=tnote.wine_id))

    return render_template('comments/comment-new.html',
                           form=new_comment_form,
                           tnote=tnote)
Exemplo n.º 2
0
def wine_edit(wine_id):
    is_admin = current_user.is_admin()
    cat_list = get_sorted_categories()
    reg_list = get_sorted_regions()
    wine = db.session.query(Wine).get(wine_id)
    prepopulated_data = Formatted_Data(wine, cat_list, reg_list)
    edit_wine_form = EditWineForm(obj=prepopulated_data)

    img_url = None
    filename = None

    if request.method == 'POST':
        if 'image' in request.files and request.files['image'].filename:
            filename = photos.save(request.files['image'])
            img = ProcessStandardImage(
                filename,  # path to temporary image location
                edit_wine_form.rotate_image.data,  # desired rotation
                600  # maximum height or width
            )
            img.process_image()  # saves the modified image to the temp location
            # img_url = edit_wine_form.image_url.data
            img_url = upload_image(filename)

        if edit_wine_form.validate_on_submit():
            categoryId = get_category_id(edit_wine_form.category.data, cat_list)
            regionId = get_region_id(edit_wine_form.region.data, reg_list)

            wine.name = edit_wine_form.name.data
            wine.maker = edit_wine_form.maker.data
            wine.vintage = edit_wine_form.vintage.data
            wine.price = edit_wine_form.price.data
            wine.description = edit_wine_form.description.data
            wine.region = regionId
            wine.category = categoryId
            wine.owner = edit_wine_form.owner.data
            if img_url:
                wine.image = img_url
            else:
                if edit_wine_form.delete_image.data == "true":
                    wine.image = DEFAULT_WINE_IMAGE

            db.session.add(wine)
            db.session.commit()
            message = 'You updated the {} wine'.format(wine.name)
            flash(message)
            return redirect(url_for('wines.list_wines'))

    return render_template('wines/wine-edit.html',
                           form=edit_wine_form,
                           cat_list=cat_list,
                           reg_list=reg_list,
                           wine=wine,
                           is_admin=is_admin)
Exemplo n.º 3
0
def region_edit(region_id):
    is_admin = current_user.is_admin()
    reg_list = get_sorted_regions()
    country_list = Countries.country_list(region_id)
    state_list = Countries.state_list(region_id)
    region = db.session.query(Region).filter_by(id=region_id).one()
    parent_id = region.parent_id
    prepopulated_data = Prepopulated_Data(region, reg_list)

    edit_region_form = EditRegionForm(obj=prepopulated_data)

    img_url = None
    filename = None

    if request.method == 'POST':
        if 'image' in request.files and request.files['image'].filename:
            filename = photos.save(request.files['image'])
            img = ProcessBannerImage(
                filename,  # path to temporary image location
                edit_region_form.rotate_image.data,  # desired rotation
                1140  # maximum height or width
            )
            img.process_image()  # saves the modified image to the temp location
        if edit_region_form.validate_on_submit():
            parentId = get_parent_id(edit_region_form, reg_list)

            img_url = upload_image(filename)

            region.name = edit_region_form.name.data
            region.description = edit_region_form.description.data
            region.parent_id = parentId
            region.country = edit_region_form.country.data
            region.state = edit_region_form.state.data
            if img_url:
                region.image = img_url
            else:
                if edit_region_form.delete_image.data == "true":
                    region.image = DEFAULT_REGION_IMAGE

            db.session.add(region)
            db.session.commit()
            message = 'You updated the {} region'.format(region.name)
            flash(message)
            return redirect(url_for('regions.list_regions'))

    return render_template('regions/region-edit.html',
                           form=edit_region_form,
                           reg_list=reg_list,
                           parent_id=parent_id,
                           region=region,
                           country_list=country_list,
                           state_list=state_list,
                           is_admin=is_admin)
Exemplo n.º 4
0
def category_edit(category_id):
    is_admin = current_user.is_admin()
    is_owner = get_is_owner(category_id)
    cat_list = get_sorted_categories()
    category = db.session.query(Category).filter_by(id=category_id).one()
    parent_id = category.parent_id
    prepopulated_data = Prepopulated_Data(category, cat_list)

    edit_category_form = EditCategoryForm(obj=prepopulated_data)

    img_url = None
    filename = None

    if request.method == 'POST':
        if 'image' in request.files and request.files['image'].filename:
            filename = photos.save(request.files['image'])
            img = ProcessBannerImage(
                filename,  # path to temporary image location
                edit_category_form.rotate_image.data,  # desired rotation
                1140  # maximum height or width
            )
            img.process_image()  # saves the modified image to the temp location
        if edit_category_form.validate_on_submit():
            parentId = get_parent_id(edit_category_form, cat_list)

            img_url = upload_image(filename)

            category.name = edit_category_form.name.data
            category.description = edit_category_form.description.data
            category.parent_id = parentId
            if img_url:
                category.image = img_url
            else:
                if edit_category_form.delete_image.data == "true":
                    print('delete')
                    category.image = DEFAULT_CATEGORY_IMAGE

            db.session.add(category)
            db.session.commit()
            message = 'You updated the {} category'.format(category.name)
            flash(message)
            return redirect(url_for('categories.list_categories'))

    return render_template('categories/category-edit.html',
                           form=edit_category_form,
                           cat_list=cat_list,
                           parent_id=parent_id,
                           category=category,
                           is_admin=is_admin,
                           is_owner=is_owner)
Exemplo n.º 5
0
def new_region():
    reg_list = get_sorted_regions()
    country_list = Countries.country_list('')
    state_list = Countries.state_list('')
    new_region_form = NewRegionForm()
    img_url = None
    filename = None

    if request.method == 'POST':
        if 'image' in request.files and request.files['image'].filename:
            filename = photos.save(request.files['image'])
            img = ProcessBannerImage(
                filename,  # path to temporary image location
                new_region_form.rotate_image.data,  # desired rotation
                1140  # maximum height or width
            )
            img.process_image()  # saves the modified image to the temp location
        if new_region_form.validate_on_submit():
            parentId = 0
            if new_region_form.parent.data:
                for id, name in reg_list.items():
                    if name == new_region_form.parent.data:
                        parentId = int(id)

            img_url = upload_image(filename)
            if img_url == None:
                img_url = DEFAULT_REGION_IMAGE
            region = Region(
                name=new_region_form.name.data,
                description=new_region_form.description.data,
                parent_id=parentId,
                country=new_region_form.country.data,
                state=new_region_form.state.data,
                owner=current_user.id,
                image=img_url
            )

            db.session.add(region)
            db.session.commit()
            message = 'You added the {} region'.format(region.name)
            flash(message)
            return redirect(url_for('regions.list_regions'))

    return render_template('regions/region-new.html',
                           form=new_region_form,
                           reg_list=reg_list,
                           country_list=country_list,
                           state_list=state_list)
Exemplo n.º 6
0
def new_wine():
    cat_list = get_sorted_categories()
    reg_list = get_sorted_regions()
    new_wine_form = NewWineForm()
    img_url = None
    filename = None

    if request.method == 'POST':
        if 'image' in request.files and request.files['image'].filename:
            filename = photos.save(request.files['image'])
            img = ProcessStandardImage(
                filename,  # path to temporary image location
                new_wine_form.rotate_image.data,  # desired rotation
                600  # maximum height or width
            )
            img.process_image()  # saves the modified image to the temp location
        if new_wine_form.validate_on_submit():
            categoryId = get_category_id(new_wine_form.category.data, cat_list)
            regionId = get_region_id(new_wine_form.region.data, reg_list)
            img_url = upload_image(filename)
            if img_url == None:
                img_url = DEFAULT_WINE_IMAGE

            wine = Wine(
                name=new_wine_form.name.data,
                maker=new_wine_form.maker.data,
                vintage=new_wine_form.vintage.data,
                price=new_wine_form.price.data,
                description=new_wine_form.description.data,
                category=categoryId,
                region=regionId,
                owner=current_user.id,
                image=img_url
            )

            db.session.add(wine)
            db.session.commit()
            message = 'You added {} to the journal'.format(wine.name)
            flash(message)
            return redirect(url_for('wines.list_wines'))

    return render_template('wines/wine-new.html',
                           form=new_wine_form,
                           cat_list=cat_list,
                           reg_list=reg_list,
                           img_url=img_url)
Exemplo n.º 7
0
def tasting_notes_edit(tnote_id):
    is_admin = current_user.is_admin()
    note = db.session.query(TastingNote).filter_by(id=tnote_id).one()
    wine = db.session.query(Wine).get(note.wine_id)
    img_url = None
    filename = None

    edit_tasting_note_form = EditNoteForm(obj=note)

    if request.method == 'POST':
        if 'image' in request.files and request.files['image'].filename:
            filename = photos.save(request.files['image'])
            img = ProcessStandardImage(
                filename,  # path to temporary image location
                edit_tasting_note_form.rotate_image.data,  # desired rotation
                600  # maximum height or width
            )
            img.process_image(
            )  # saves the modified image to the temp location
        if edit_tasting_note_form.validate_on_submit():
            img_url = upload_image(filename)  # moves image from temp to S3

            note.title = edit_tasting_note_form.title.data
            note.text = edit_tasting_note_form.text.data
            note.vintage = edit_tasting_note_form.vintage.data
            note.rating = edit_tasting_note_form.rating.data
            note.price = edit_tasting_note_form.price.data
            if img_url:
                note.image = img_url
            else:
                if edit_tasting_note_form.delete_image.data == "true":
                    note.image = ''

            db.session.add(note)
            db.session.commit()
            message = 'You updated the {} tasting note'.format(wine.name)
            flash(message)
            return redirect(url_for('wines.wine_detail', wine_id=wine.id))

    return render_template('tasting_notes/tasting-note-edit.html',
                           form=edit_tasting_note_form,
                           note=note,
                           wine=wine,
                           is_admin=is_admin)
Exemplo n.º 8
0
def new_category():
    cat_list = get_sorted_categories()
    new_category_form = NewCategoryForm()
    img_url = None
    filename = None

    if request.method == 'POST':
        if 'image' in request.files and request.files['image'].filename:
            filename = photos.save(request.files['image'])
            img = ProcessBannerImage(
                filename,  # path to temporary image location
                new_category_form.rotate_image.data,  # desired rotation
                1140  # maximum height or width
            )
            img.process_image()  # saves the modified image to the temp location
        if new_category_form.validate_on_submit():
            parentId = 0
            if new_category_form.parent.data:
                for id, name in cat_list.items():
                    if name == new_category_form.parent.data:
                        parentId = int(id)

            img_url = upload_image(filename)
            if img_url == None:
                img_url = DEFAULT_CATEGORY_IMAGE
            category = Category(
                name=new_category_form.name.data,
                description=new_category_form.description.data,
                parent_id=parentId,
                owner=current_user.id,
                image=img_url
            )

            db.session.add(category)
            db.session.commit()
            message = 'You added the {} category'.format(category.name)
            flash(message)
            return redirect(url_for('categories.list_categories'))
    print(request.method)
    return render_template('categories/category-new.html',
                           form=new_category_form,
                           cat_list=cat_list,
                           img_url=img_url)
Exemplo n.º 9
0
def comment_edit(comment_id):
    is_admin = current_user.is_admin()
    comment = db.session.query(Comment).get(comment_id)
    img_url = None
    filename = None

    edit_tasting_note_form = EditCommentorm(obj=comment)

    if request.method == 'POST':
        if 'image' in request.files and request.files['image'].filename:
            filename = photos.save(request.files['image'])
            img = ProcessStandardImage(
                filename,  # path to temporary image location
                edit_tasting_note_form.rotate_image.data,  # desired rotation
                600  # maximum height or width
            )
            img.process_image()  # saves the modified image to the temp location
        if edit_tasting_note_form.validate_on_submit():
            img_url = upload_image(filename)  # moves image from temp to S3
            comment.text = edit_tasting_note_form.text.data
            comment.author_id = edit_tasting_note_form.author_id.data
            comment.tnote_id = edit_tasting_note_form.tnote_id.data
            if img_url:
                comment.image = img_url
            else:
                if edit_tasting_note_form.delete_image.data == "true":
                    comment.image = ''

            db.session.add(comment)
            db.session.commit()
            message = 'You updated your comment about the {} tasting note'\
                .format(comment.tasting_note.title)
            flash(message)
            return redirect(url_for('wines.wine_detail',
                                    wine_id=comment.tasting_note.wine_id))

    return render_template('comments/comment-edit.html',
                           form=edit_tasting_note_form,
                           is_admin=is_admin,
                           comment=comment)
Exemplo n.º 10
0
def new_tasting_note(wine_id):
    wine = db.session.query(Wine).get(wine_id)
    new_tasting_note_form = NewNoteForm()
    img_url = None
    filename = None

    if request.method == 'POST':
        if 'image' in request.files and request.files['image'].filename:
            filename = photos.save(request.files['image'])
            img = ProcessStandardImage(
                filename,  # path to temporary image location
                new_tasting_note_form.rotate_image.data,  # desired rotation
                600  # maximum height or width
            )
            img.process_image(
            )  # saves the modified image to the temp location
        if new_tasting_note_form.validate_on_submit():
            img_url = upload_image(filename)
            note = TastingNote(title=new_tasting_note_form.title.data,
                               text=new_tasting_note_form.text.data,
                               vintage=new_tasting_note_form.vintage.data,
                               rating=new_tasting_note_form.rating.data,
                               price=new_tasting_note_form.price.data,
                               wine_id=wine_id,
                               author_id=current_user.id,
                               image=img_url)

            db.session.add(note)
            db.session.commit()
            message = 'You added the {} tasting note'.format(note.title)
            flash(message)
            return redirect(url_for('wines.wine_detail', wine_id=wine_id))

    return render_template('tasting_notes/tasting-note-new.html',
                           form=new_tasting_note_form,
                           wine=wine)