Skip to content
This repository has been archived by the owner on May 11, 2020. It is now read-only.

Commit

Permalink
feat: add request_datetime to request data
Browse files Browse the repository at this point in the history
Signed-off-by: Aly Badr <aly.badr@rero.ch>
  • Loading branch information
Aly Badr committed Jun 6, 2018
1 parent 65f551e commit 5cb7773
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 11 deletions.
12 changes: 7 additions & 5 deletions reroils_data/items/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@

from __future__ import absolute_import, print_function

from datetime import datetime

import pytz
from flask import Blueprint, flash, jsonify, redirect, render_template, \
request, url_for
from flask_babelex import gettext as _
Expand Down Expand Up @@ -133,16 +136,15 @@ def request_item(pid_value, member):
patron = Patron.get_patron_by_email(current_user.email)
patron_barcode = patron['barcode']
start_date, end_date = request_start_end_date()
item_resolver = Resolver(pid_type='item',
object_type='rec',
getter=Item.get_record)
pid, item = item_resolver.resolve(pid_value)
item = Item.get_record_by_pid(pid_value)
doc = DocumentsWithItems.get_document_by_itemid(item.id)
request_datetime = pytz.utc.localize(datetime.now()).isoformat()
item.request_item(
patron_barcode=patron_barcode,
pickup_member_pid=member,
start_date=start_date,
end_date=end_date
end_date=end_date,
request_datetime=request_datetime
)
commit_item(item)
flash(_('The item %s has been requested.' % pid_value), 'success')
Expand Down
7 changes: 5 additions & 2 deletions reroils_data/jinja2.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@
import json

import babel
import dateparser


def format_date_filter(date_str, format='medium', locale='en'):
"""Format the date."""
date = datetime.datetime.strptime(date_str, "%Y-%m-%d").date()
form_date = dateparser.parse(str(date_str))
if format == 'full':
format = "EEEE, d. MMMM y"
elif format == 'medium':
Expand All @@ -42,7 +43,9 @@ def format_date_filter(date_str, format='medium', locale='en'):
format = "dd MMMM y"
elif format == 'short_date':
format = "dd.MM.y"
return babel.dates.format_datetime(date, format, locale=locale)
elif format == 'timestamp':
format = "dd.MM.y HH:mm"
return babel.dates.format_datetime(form_date, format, locale=locale)


def to_pretty_json(value):
Expand Down
15 changes: 11 additions & 4 deletions reroils_data/patrons/templates/reroils_data/patron_profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,17 @@
{% endif %}
</td>
<td>
{{ document.item.holding.start_date|format_date(
format='short_date',
locale=current_i18n.locale.language
) }}
{% if 'loan' == type %}
{{ document.item.holding.start_date|format_date(
format='short_date',
locale=current_i18n.locale.language
) }}
{% else %}
{{ document.item.holding.request_datetime|format_date(
format='timestamp',
locale=current_i18n.locale.language
)}}
{% endif %}
</td>
<td>
{% if 'loan' == type %}
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def run(self):
install_requires = [
'Flask-BabelEx>=0.9.2',
'dojson>=1.3.2',
'dateparser>=0.7.0',
'invenio-pidstore>=1.0.0b2',
'jsonschema>=2.5.1',
'invenio-db>=1.0.0b6',
Expand Down
29 changes: 29 additions & 0 deletions tests/items/test_items_views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# -*- coding: utf-8 -*-
#
# This file is part of Invenio.
# Copyright (C) 2017 RERO.
#
# Invenio is free software; you can redistribute it
# and/or modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# Invenio is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Invenio; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307, USA.
#
# In applying this license, RERO does not
# waive the privileges and immunities granted to it by virtue of its status
# as an Intergovernmental Organization or submit itself to any jurisdiction.

"""Utils tests."""

from __future__ import absolute_import, print_function

# create tests for items.views
7 changes: 7 additions & 0 deletions tests/test_jinja2_format_date_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@
from reroils_data.jinja2 import format_date_filter


def test_date_filter_format_timestamp_en():
"""Test timestamp english date filter"""
datestring = format_date_filter('2018-06-06T09:29:55.947149+00:00',
'timestamp')
assert '06.06.2018 09:29' in datestring


def test_date_filter_format_default_en():
"""Test medium english date filter"""
datestring = format_date_filter('1950-01-01')
Expand Down

0 comments on commit 5cb7773

Please sign in to comment.