From 9722944ee91856a3d9f1f8ec7f65892f369f057e Mon Sep 17 00:00:00 2001 From: Badri/Hippo Date: Wed, 5 Aug 2015 15:19:33 +0530 Subject: [PATCH] Add user_return function There are also some new generic templates, `shelf/accession_entry.htm` and `includes/form_errors.htm`, that can be reused in other places if required. --- growlinflask/growlin.py | 28 ++++++++++++++++++- .../templates/includes/form_errors.htm | 10 +++++++ .../templates/shelf/accession_entry.htm | 11 ++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 growlinflask/templates/includes/form_errors.htm create mode 100644 growlinflask/templates/shelf/accession_entry.htm diff --git a/growlinflask/growlin.py b/growlinflask/growlin.py index ca8defd..0938e9b 100644 --- a/growlinflask/growlin.py +++ b/growlinflask/growlin.py @@ -165,7 +165,33 @@ def user_borrow(): form=cform) else: return render_template('user/borrow.htm', form=form) - +@app.route('/shelf//return/', methods=['GET', 'POST'] ) +@login_required +def user_return(borrowid): + try: + b = Borrowing.get(Borrowing.id == borrowid) + except Borrowing.DoesNotExist: + flash('Please decide what you want to return') + return redirect(url_for('user_shelf')) + form = AccessionEntryForm() + if form.validate_on_submit(): + try: + current_user.unborrow(b, form.accession.data) + except BorrowError, e: + flash(e.message) + else: + if b.user.username == current_user.username: + msg = 'Please enter the accession number for "%(title)s"' % { + 'title': b.copy.item.display_title} + return render_template('shelf/accession_entry.htm', + message=msg, + form=form, + borrowing=b, + sumbit_button_text='Return') + else: + flash('That item was borrowed by %(name)s, not by you!' % { + 'name': b.user.name}) + return redirect(url_for('user_shelf')) # Admin interface class AdminRegistry(BaseView): @expose('/') diff --git a/growlinflask/templates/includes/form_errors.htm b/growlinflask/templates/includes/form_errors.htm new file mode 100644 index 0000000..b1fb949 --- /dev/null +++ b/growlinflask/templates/includes/form_errors.htm @@ -0,0 +1,10 @@ +{% if error or form.errors%} + +{% endif %} diff --git a/growlinflask/templates/shelf/accession_entry.htm b/growlinflask/templates/shelf/accession_entry.htm new file mode 100644 index 0000000..d010519 --- /dev/null +++ b/growlinflask/templates/shelf/accession_entry.htm @@ -0,0 +1,11 @@ +{% extends 'base.htm' %} +{% block content %} +
+{% include 'includes/form_errors.htm' %} +{{form.csrf_token}} +

{{message}}

+{{form.accession}} +Back + +
+{% endblock %}