Skip to content

Commit

Permalink
added book submission in literature suggest
Browse files Browse the repository at this point in the history
  • Loading branch information
Glignos committed Mar 17, 2017
1 parent 058dcf1 commit 1334778
Show file tree
Hide file tree
Showing 7 changed files with 419 additions and 15 deletions.
78 changes: 75 additions & 3 deletions inspirehep/bat/pages/create_literature.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,35 @@ def _submit_thesis():
return ArsenicResponse(_submit_thesis)


def submit_book(input_data):
def _submit_book():
return (
'The INSPIRE staff will review it and your changes will be added '
'to INSPIRE.'
) in WebDriverWait(Arsenic(), 10).until(
EC.visibility_of_element_located(
(
By.XPATH,
'(//div[@class="alert alert-success alert-form-success"])',
)
)
).text

_skip_import_data()
Arsenic().hide_title_bar()
_select_book()
_links_population(input_data)
_basic_info_population(input_data)
_book_info_population(input_data)
_references_comment_population(input_data)
Arsenic().find_element_by_xpath(
'//div[@id="webdeposit_form_accordion"]/div[4]/span/button'
).click()
Arsenic().show_title_bar()

return ArsenicResponse(_submit_book)


def submit_journal_article_with_proceeding(input_data):
def _submit_journal_article_with_proceeding():
return (
Expand Down Expand Up @@ -148,6 +177,36 @@ def _thesis_info_population(input_data):
)


def _book_info_population(input_data):
WebDriverWait(Arsenic(), 10).until(
EC.visibility_of_element_located((By.ID, 'publisher_name'))
)
Arsenic().find_element_by_id('publisher_name').send_keys(
input_data['publisher-name']
)
Arsenic().find_element_by_id('publication_date').send_keys(
input_data['publication-date']
)
Arsenic().find_element_by_id('publication_place').send_keys(
input_data['publication-place']
)
Arsenic().find_element_by_id('book_edition').send_keys(
input_data['book-edition']
)
Arsenic().find_element_by_id('series_title').send_keys(
input_data['book-title']
)
Arsenic().find_element_by_id('series_volume').send_keys(
input_data['book-volume']
)
Arsenic().find_element_by_id('isbn-0-code').send_keys(
input_data['isbn']
)
Select(Arsenic().find_element_by_id('isbn-0-type_of_isbn')).select_by_value(
input_data['isbn_type']
)


def _links_population(input_data):
Arsenic().find_element_by_id('url').send_keys(input_data['pdf-1'])
Arsenic().find_element_by_id('additional_url').send_keys(
Expand Down Expand Up @@ -235,9 +294,7 @@ def _references_comment_population(input_data):
).send_keys(input_data['references'])

WebDriverWait(Arsenic(), 10).until(
EC.visibility_of_element_located(
(By.ID, 'extra_comments')
)
EC.visibility_of_element_located((By.ID, 'extra_comments'))
).send_keys(input_data['extra-comments'])


Expand Down Expand Up @@ -500,10 +557,25 @@ def _skip_import_data():
null
).singleNodeValue.click()"""
)
Arsenic().execute_script(
"""document.evaluate(
"//div[@id='webdeposit_form_accordion']/div[3]/div[10]/div[1]",
document,
null,
XPathResult.FIRST_ORDERED_NODE_TYPE,
null
).singleNodeValue.click()"""
)
Arsenic().show_title_bar()


def _select_thesis():
Select(Arsenic().find_element_by_id('type_of_doc')).select_by_value(
'thesis'
)


def _select_book():
Select(Arsenic().find_element_by_id('type_of_doc')).select_by_value(
'book'
)
110 changes: 99 additions & 11 deletions inspirehep/modules/literaturesuggest/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,18 @@ def defensedate_widget(field, **kwargs):
return HTMLString(u''.join(html))


def bookdate_widget(field, **kwargs):
"""Date widget fot thesis."""
field_id = kwargs.pop('id', field.id)
html = [u'<div class="row %s"><div class="col-xs-12">\
<input class="datepicker form-control" %s type="text">\
</div></div>'
% (BOOK_CLASS, html_params(id=field_id,
name=field_id,
value=field.data or ''))]
return HTMLString(u''.join(html))


class CheckboxButton(object):

"""Checkbox button."""
Expand Down Expand Up @@ -195,6 +207,29 @@ class AuthorInlineForm(INSPIREForm):
)


types_of_isbn = [("hardcover", _("Hardcover")),
("online", _("Online")),
("print", _("Print")),
('softcover', _('Softcover')),
('unknown', _('Unknown'))]


class BookInlineForm(INSPIREForm):

code = fields.TextField(
widget_classes='form-control',
widget=ColumnInput(class_="col-xs-6", description="ISBN code"),

export_key='full_name',
)

type_of_isbn = fields.SelectField(
label='type',
choices=types_of_isbn,
description=_('type'),
)


class UrlInlineForm(INSPIREForm):

"""Url inline form."""
Expand Down Expand Up @@ -254,22 +289,14 @@ class LiteratureForm(INSPIREForm):
export_key='categories',
)

# isbn = ISBNField(
# label=_('ISBN'),
# widget_classes='form-control',
# )

import_buttons = fields.SubmitField(
label=_(' '),
widget=import_buttons_widget
)

types_of_doc = [("article", _("Article/Conference paper")),
("thesis", _("Thesis"))]

# ("chapter", _("Book Chapter")),
# ("book", _("Book")),
# ("proceedings", _("Proceedings"))]
("thesis", _("Thesis")),
('book', _('Book'))]

type_of_doc = fields.SelectField(
label='Type of Document',
Expand Down Expand Up @@ -414,7 +441,6 @@ def _is_other_language(language):
widget_classes='',
widget=UnsortedDynamicListWidget(),
)

# ==============
# Thesis related
# ==============
Expand Down Expand Up @@ -457,6 +483,63 @@ def _is_other_language(language):
# default='',
# widget_classes="form-control" + THESIS_CLASS,
# )
# ============
# Book Info
# ============

publisher_name = fields.TextField(
label=_('Publisher Name'),
export_key='publisher_name',
widget_classes="form-control" + BOOK_CLASS,
)

publication_place = fields.TextField(
label=_('Place of Publication'),
export_key='publication_place',
widget_classes="form-control" + BOOK_CLASS,
)

book_edition = fields.TextField(
label=_('Book edition'),
export_key='book_edition',
widget_classes="form-control" + BOOK_CLASS,
)

series_title = fields.TextField(
label=_('Book series title'),
export_key='series_title',
widget_classes="form-control" + BOOK_CLASS,
)

series_volume = fields.TextField(
label=_('Book series volume'),
export_key='series_volume',
widget_classes="form-control" + BOOK_CLASS,
)

publication_date = fields.TextField(
label=_('Publication Date'),
description='Format: YYYY-MM-DD, YYYY-MM or YYYY.',
validators=[date_validator],
widget=bookdate_widget,
export_key='publication_date',
widget_classes="" + BOOK_CLASS,
)

isbn = fields.DynamicFieldList(
fields.FormField(
BookInlineForm,
widget=ExtendedListWidget(
item_widget=ItemWidget(),
html_tag='div',
),
),
label='ISBN',
add_label='Add another ISBN',
min_entries=1,
widget_classes="" + BOOK_CLASS,
export_key='isbn',
)

# ============
# Journal Info
Expand Down Expand Up @@ -603,6 +686,9 @@ def _is_other_language(language):
('Thesis Information',
['degree_type', 'thesis_date', 'institution',
'supervisors', 'license_url']),
('Book Information',
['publisher_name', 'publication_date', 'publication_place',
'book_edition', 'series_title', 'series_volume', 'isbn']),
# ('Licenses and copyright',
# ['license', 'license_url'], {'classes': 'collapse'}),
('Journal Information',
Expand All @@ -623,6 +709,8 @@ def _is_other_language(language):
field_sizes = {
'type_of_doc': 'col-xs-12 col-md-3',
'wrap_nonpublic_note': 'col-md-9',
'publisher_name': 'col-xs-12 col-md-9',
'publication_date': 'col-xs-12 col-md-4',
'thesis_date': 'col-xs-12 col-md-4',
'degree_type': 'col-xs-12 col-md-3',
}
Expand Down
13 changes: 12 additions & 1 deletion inspirehep/modules/literaturesuggest/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def _is_arxiv_url(url):

form_fields = copy.deepcopy(formdata)
filter_empty_elements(
form_fields, ['authors', 'supervisors', 'report_numbers']
form_fields, ['authors', 'supervisors', 'report_numbers', 'isbn']
)

builder = LiteratureBuilder(source='submitter')
Expand Down Expand Up @@ -153,6 +153,17 @@ def _is_arxiv_url(url):
date=form_fields.get('thesis_date')
)

if form_fields.get('type_of_doc') == 'book':
builder.add_book(
publisher=form_fields.get('publisher_name'),
place=form_fields.get('publication_place'),
date=form_fields.get('publication_date'))
builder.add_book_edition(edition=form_fields.get('book_edition'))
builder.add_book_series(title=form_fields.get('series_title'),
volume=form_fields.get('series_volume'))
for isbn_single in form_fields.get('isbn', []):
builder.add_isbns(isbn_single)

builder.add_accelerator_experiments_legacy_name(
legacy_name=form_fields.get('experiment')
)
Expand Down
32 changes: 32 additions & 0 deletions tests/acceptance/test_literature_suggestion_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,38 @@
holding_panel_literature_list,
)

def test_literature_create_book_manually(login):
input_data = {
'pdf-1': 'pdf_url_correct',
'pdf-2': 'pdf_another_url_correct',
'title': 'My Title For Test',
'language': 'ru',
'title_translation': 'My Title was in Russian',
'subject': 'Computing',
'author-0': 'Mister White',
'author-0-affiliation': 'Wisconsin U., Madison',
'author-1': 'Mister Brown',
'author-1-affiliation': 'CERN',
'collaboration': 'This is a collaboration',
'experiment': 'This is an experiment',
'abstract': 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr.',
'report-number-0': '100',
'report-number-1': '101',
'publisher-name': 'Oxford University',
'publication-date': '2001-01-01',
'publication-place': 'Oxford',
'book-edition': 'No 2',
'book-title': 'Astrowars',
'book-volume': 'Andromeda',
'isbn': '152865466211',
'isbn_type': 'online',
'references': 'references',
'extra-comments': 'comments about the document'
}

create_literature.go_to()
assert create_literature.submit_book(input_data).has_error()
_check_back_office(input_data)

def test_literature_create_thesis_manually(login):
input_data = {
Expand Down
Loading

0 comments on commit 1334778

Please sign in to comment.