Skip to content

Commit

Permalink
Add user_return function
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
badrihippo committed Aug 5, 2015
1 parent e6683c6 commit 9722944
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
28 changes: 27 additions & 1 deletion growlinflask/growlin.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,33 @@ def user_borrow():
form=cform)
else:
return render_template('user/borrow.htm', form=form)

@app.route('/shelf/<borrowid>/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('/')
Expand Down
10 changes: 10 additions & 0 deletions growlinflask/templates/includes/form_errors.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{% if error or form.errors%}
<ul style="color: red">
<li>{{error}}</li>
{% for field_name, field_errors in form.errors|dictsort if field_errors %}
{% for error in field_errors %}
<li>{{error}}</li>
{% endfor %}
{% endfor %}
</ul>
{% endif %}
11 changes: 11 additions & 0 deletions growlinflask/templates/shelf/accession_entry.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% extends 'base.htm' %}
{% block content %}
<form action="{{url_for('user_return', borrowid=borrowing.id)}}" method="POST">
{% include 'includes/form_errors.htm' %}
{{form.csrf_token}}
<p>{{message}}</p>
{{form.accession}}
<a href="{{ return_url if return_url else url_for('user_shelf') }}">Back</a>
<input type="submit" value="{{ submit_button_text if submit_button_text else 'OK' }}" />
</form>
{% endblock %}

0 comments on commit 9722944

Please sign in to comment.