Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored set year #61

Merged
merged 8 commits into from
Mar 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ name = "pypi"

[packages]

Django = "*"
django = "*"
dj-database-url = "*"
django-dirtyfields = "*"
django-filter = "*"
Expand All @@ -16,7 +16,7 @@ django-tequila = {git = "https://github.com/epfl-idevelop/django-tequila.git", e
"django-bootstrap4" = "*"
gevent = "*"
gunicorn = "*"
Markdown = "*"
markdown = "*"
"psycopg2-binary" = "*"
pymarc = "*"
pytz = "*"
Expand All @@ -31,9 +31,9 @@ codecov = "*"
django-debug-toolbar = "*"
django-extensions = "*"
django-nose = "*"
"Fabric3" = "*"
factory_boy = "*"
Faker = "*"
"fabric3" = "*"
factory-boy = "*"
faker = "*"
"flake8" = "*"
graypy = "*"
ipdb = "*"
Expand All @@ -44,6 +44,7 @@ nose-progressive = "*"
selenium = "*"
requests = "*"
rope = "*"
pytest = "*"


[requires]
Expand Down
52 changes: 48 additions & 4 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docker-compose-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ selenium:
image: selenium/standalone-chrome-debug:3.11
ports:
- "4444:4444" # Selenium
- "5900:5900" # VNC server, pass is "secret"
- "${VNC_PORT}:5900" # VNC server, pass is "secret"
1 change: 1 addition & 0 deletions env/django.env
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ SERVER_HOST=${ALLOWED_HOSTS}
# -> 80 in production
# -> 8000 or 8080 in dev
DEV_PORT=8000
VNC_PORT=5900

# `SITE_PATH` is the root path of the application (it not hosted on a bare domain)
SITE_PATH=/publications-exports
Expand Down
56 changes: 29 additions & 27 deletions infoscience_exports/exports/marc21xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""
Parse a marc-21-xml file
"""

from logging import getLogger
from django.utils.translation import gettext as _
from django.conf import settings
from os.path import dirname, splitext
Expand All @@ -12,27 +12,22 @@
from pymarc import marcxml
import unicodedata

logger = getLogger(__name__)

def get_attributes(subfields):
res_value = {}
for element1 in subfields:
for key1, value1 in element1.items():
res_value[key1] = value1
return res_value

class Author:

# Authors is a list of a dictionary of author: full name, initial name, url in infoscience
def set_authors(authors):
result = []
for author in authors:
author_record = {}
author_record['fullname'] = author
author_record['search_url'] = "{}/search?p={}".format(
def __init__(self, author):
self.fullname = author
self.search_url = "{}/search?p={}".format(
settings.SITE_DOMAIN, author.replace(",", "+").replace(" ", "+"))
self.initname = self.compute_name()

names = author.split(',')
def compute_name(self):
names = self.fullname.split(',')
family = names[0].strip() if len(names) > 0 else ''
fnames = names[1].split(' ') if len(names) > 1 else ''

initname = ""
for fname in fnames:
if not fname:
Expand All @@ -53,23 +48,22 @@ def set_authors(authors):
if family:
initname += family

author_record['initname'] = initname
result.append(author_record)
return initname

return result

# Authors is a list of Author instance: full name, initial name, url in infoscience
def set_authors(authors):
return [Author(author) for author in authors]


# get only the year in a date-string
def set_year(date):
if len(date) == 4:
return date
dates = date.split("-")
year = date
for val in dates:
if len(val) == 4:
year = val
break
return year
dates = [val for val in date.split("-") if len(val) == 4]
if len(dates) == 1:
return dates[0]
else:
logger.warning("Year not found in %s, decomposed as %s", date, dates)
return ''


# get fulltext: link to pdf or link to repository if several links
Expand Down Expand Up @@ -110,6 +104,14 @@ def set_fulltext(fulltexts):
return result


def get_attributes(subfields):
res_value = {}
for element1 in subfields:
for key1, value1 in element1.items():
res_value[key1] = value1
return res_value


# get dictionary (icon, fulltexts) of ELA
def get_ELA_fields(field):
ela_fulltexts = []
Expand Down
14 changes: 7 additions & 7 deletions infoscience_exports/exports/options_notices.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


DOC_TYPE_ORDERED = {
#('ARTICLE', _("Journal Articles")),
# ('ARTICLE', _("Journal Articles")),
'ARTICLE': _("Articles & Reviews"),
'CONF': _("Conference Papers"),
'REVIEW': _("Reviews"),
Expand Down Expand Up @@ -75,17 +75,17 @@ def get_sorted_by_doc_types(notices):
# add doc_types not listed in DOC_TYPE_ORDERED
for index, head in enumerate(groups_head):
if head not in doc_type_keys:
groups_list_ordered.extend(groups_list[index])
groups_list_ordered.extend(groups_list[index])
return groups_list_ordered


def get_sorted_by_year(notices, url):
queries = parse_qs(urlsplit(url).query)
is_ascending = queries.get('so', ['d'])[0] == "a"
if is_ascending:
notices = sorted(notices, key=lambda k: k['Publication_Year'])
else:
notices = sorted(notices, key=lambda k: k['Publication_Year'], reverse=True)
is_ascending = queries.get('so', ['d'])[0] == "a"
if is_ascending:
notices = sorted(notices, key=lambda k: k['Publication_Year'])
else:
notices = sorted(notices, key=lambda k: k['Publication_Year'], reverse=True)
return notices


Expand Down
26 changes: 26 additions & 0 deletions infoscience_exports/exports/test/test_authors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from django.conf import settings

from exports.marc21xml import Author


def expected_url(name):
return "{}/search?p={}".format(settings.SITE_DOMAIN, name)


def test_standard_case():
author = Author("Emmanuel Bréton")
assert author.fullname == "Emmanuel Bréton"
assert author.search_url == expected_url("Emmanuel+Bréton")
assert author.initname == "Emmanuel Bréton"


def test_search_url():
assert Author("Jean-Marc Marco").search_url == expected_url("Jean-Marc+Marco")
assert Author("Jean, Marc Marco").search_url == expected_url("Jean++Marc+Marco")


def test_initial_names():
assert Author("Marco Jean Marc").initname == "Marco Jean Marc"
assert Author("Marco, Jean").initname == "J. Marco"
assert Author("Marco, Jean Marc").initname == "J. M. Marco"
assert Author("Marco, Jean-Marc").initname == "J.-M. Marco"
14 changes: 14 additions & 0 deletions infoscience_exports/exports/test/test_dates.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from exports.marc21xml import set_year


def test_year_only():
assert set_year('2018') == '2018'


def test_full_date():
assert set_year('2018-01-01') == '2018'
assert set_year('01-01-2018') == '2018'


def test_error():
assert set_year('2018.01.01') == ''
5 changes: 2 additions & 3 deletions infoscience_exports/exports/versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# the release comes from git and should not be modified
# => read-only
_release = '0.3.7-3-g3a4e66e'
_release = '0.3.7-16-g5e0cae8'

# you can set the next version number manually
# if you do not, the system will make sure that version > release
Expand All @@ -13,5 +13,4 @@
# the build number will generate conflicts on each PR merge
# just keep yours every time
# => read-only

_build = '086e59f5d9fdf7c643968137b2f1fe3936657d3d'
_build = '5e0cae8b46c21d3448ab566f21295f59d76bbf8f'
8 changes: 7 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
-r requirements.txt
appnope==0.1.0; sys_platform == 'darwin'
asn1crypto==0.24.0
attrs==17.4.0
autopep8==1.3.4
bcrypt==3.1.4
blessings==1.6.1
Expand All @@ -9,19 +10,21 @@ cffi==1.11.5
chardet==3.0.4
click==6.7
codecov==2.0.15
colorama==0.3.9; sys_platform == 'win32'
coverage==4.5.1
coveralls==1.3.0
cryptography==2.1.4
decorator==4.2.1
django-debug-toolbar==1.9.1
django-extensions==2.0.5
django-extensions==2.0.6
django-nose==1.4.5
django==2.0.3
docopt==0.6.2
fabric3==1.14.post1
factory-boy==2.10.0
faker==0.8.12
flake8==3.5.0
funcsigs==1.0.2; python_version < '3.0'
graypy==0.2.14
idna==2.6
ipdb==0.11
Expand All @@ -42,14 +45,17 @@ parso==0.1.1
pbr==3.1.1
pexpect==4.4.0; sys_platform != 'win32'
pickleshare==0.7.4
pluggy==0.6.0
prompt-toolkit==1.0.15
ptyprocess==0.5.2
py==1.5.2
pyasn1==0.4.2
pycodestyle==2.3.1
pycparser==2.18
pyflakes==1.6.0
pygments==2.2.0
pynacl==1.2.1
pytest==3.4.2
python-dateutil==2.7.0
pytz==2018.3
pyyaml==3.12
Expand Down