Example #1
0
def book_edit(book_id):
    book = controller.get_book_by_id(current_user.get_vendor_code(), book_id)
    people = controller.get_people()
    people_selected = controller.get_selected_people(book_id)
    form = book_edit_form(territory=book.territory,
                          currency=book.currency,
                          series=book.series,
                          **people_selected)
    form.series.choices = [(series.id, series.title)
                           for series in controller.get_all_series()]
    people_list = [(person.id, (person.last_name + ", " + person.first_name))
                   for person in people]
    form.authors.choices = people_list
    form.illustrators.choices = people_list
    form.editors.choices = people_list
    form.contributors.choices = people_list
    form.translators.choices = people_list
    if form.validate_on_submit():
        for k, v in form.data.items():
            if v is not None:
                controller.update_book(book_id, k, v)
        flash('Successfully updated')
        return redirect(url_for('book_mgr'))
    return render_template('book_edit.html',
                           page_title='Edit a book',
                           book=book,
                           form=form)
Example #2
0
def book_mgr():
    books = controller.get_books_for_vendor(current_user.get_vendor_code(), 20, 0)
    book_ids = [b.id for b in books.all()]
    for_sale_status = dict()
    for book_id in book_ids:
        status = controller.for_sale_status(book_id)
        for_sale_status[book_id] = {'us': status.sell_in_us, 'uk': status.sell_in_uk}
    return render_template('book_mgr.html', page_title='Book Manager', books=books, for_sale_status=for_sale_status)
Example #3
0
def book_mgr():
    books = controller.get_books_for_vendor(current_user.get_vendor_code(), 20,
                                            0)
    book_ids = [b.id for b in books.all()]
    for_sale_status = dict()
    for book_id in book_ids:
        status = controller.for_sale_status(book_id)
        for_sale_status[book_id] = {
            'us': status.sell_in_us,
            'uk': status.sell_in_uk
        }
    return render_template('book_mgr.html',
                           page_title='Book Manager',
                           books=books,
                           for_sale_status=for_sale_status)
Example #4
0
def on_identity_loaded(sender, identity):
    # Set the identity user object
    identity.user = current_user

    # Add the UserNeed to the identity
    if hasattr(current_user, 'id'):
        identity.provides.add(UserNeed(current_user.id))

    identity.provides.add(UserNeed(current_user.get_vendor_code()))

    # Assuming the User model has a list of roles, update the
    # identity with the roles that the user provides
    if hasattr(current_user, 'roles'):
        for role in current_user.roles:
            identity.provides.add(RoleNeed(role.name))
Example #5
0
def on_identity_loaded(sender, identity):
    # Set the identity user object
    identity.user = current_user

    # Add the UserNeed to the identity
    if hasattr(current_user, 'id'):
        identity.provides.add(UserNeed(current_user.id))

    identity.provides.add(UserNeed(current_user.get_vendor_code()))

    # Assuming the User model has a list of roles, update the
    # identity with the roles that the user provides
    if hasattr(current_user, 'roles'):
        for role in current_user.roles:
            identity.provides.add(RoleNeed(role.name))
Example #6
0
def book_add():
    people = controller.get_people()
    people_selected = controller.get_selected_people()
    form = book_edit_form(**people_selected)
    form.series.choices = [(series.id, series.title) for series in controller.get_all_series()]
    people_list = [(person.id, (person.last_name + ", " + person.first_name)) for person in people]
    form.authors.choices = people_list
    form.illustrators.choices = people_list
    form.editors.choices = people_list
    form.contributors.choices = people_list
    form.translators.choices = people_list
    if form.validate_on_submit():
        controller.new_book(current_user.get_vendor_code(), form.data)
        flash("Successfully created a new book")
        return redirect(url_for('book_mgr'))
    return render_template('book_edit.html', page_title='Add a new book', book = controller.new_book(), form = form)
Example #7
0
def book_edit(book_id):
    book = controller.get_book_by_id(current_user.get_vendor_code(), book_id)
    people = controller.get_people()
    people_selected = controller.get_selected_people(book_id)
    form = book_edit_form(territory = book.territory, currency = book.currency, series = book.series, **people_selected)
    form.series.choices = [(series.id, series.title) for series in controller.get_all_series()]
    people_list = [(person.id, (person.last_name + ", " + person.first_name)) for person in people]
    form.authors.choices = people_list
    form.illustrators.choices = people_list
    form.editors.choices = people_list
    form.contributors.choices = people_list
    form.translators.choices = people_list
    if form.validate_on_submit():
        for k,v in form.data.items():
            if v is not None:
                controller.update_book(book_id, k, v)
        flash('Successfully updated')
        return redirect(url_for('book_mgr'))
    return render_template('book_edit.html', page_title='Edit a book', book=book, form=form)
Example #8
0
def book_add():
    people = controller.get_people()
    people_selected = controller.get_selected_people()
    form = book_edit_form(**people_selected)
    form.series.choices = [(series.id, series.title)
                           for series in controller.get_all_series()]
    people_list = [(person.id, (person.last_name + ", " + person.first_name))
                   for person in people]
    form.authors.choices = people_list
    form.illustrators.choices = people_list
    form.editors.choices = people_list
    form.contributors.choices = people_list
    form.translators.choices = people_list
    if form.validate_on_submit():
        controller.new_book(current_user.get_vendor_code(), form.data)
        flash("Successfully created a new book")
        return redirect(url_for('book_mgr'))
    return render_template('book_edit.html',
                           page_title='Add a new book',
                           book=controller.new_book(),
                           form=form)