Exemplo n.º 1
0
def index():
    # Load press info from config
    press = ompdal.getPress(myconf.take('omp.press_id'))
    if not press:
        redirect(URL('home', 'index'))

    all_series = []
    for row in ompdal.getSeriesByPress(press.press_id):
        all_series.append(
            OMPItem(
                row, OMPSettings(ompdal.getSeriesSettings(row.series_id)), {
                    'series_editors': [
                        OMPItem(u,
                                OMPSettings(ompdal.getUserSettings(u.user_id)))
                        for u in ompdal.getSeriesEditors(
                            press.press_id, row.series_id)
                    ],
                    'series_categories': [
                        OMPItem(
                            u,
                            OMPSettings(
                                ompdal.getCategorySettings(u.category_id)))
                        for u in ompdal.getCategoriesBySeries(row.series_id)
                    ]
                }))
    # order by title
    # all_series.sort(key=lambda s: cur_locale.strxfrm(s.settings.getLocalizedValue('title', lang)))

    return locals()
Exemplo n.º 2
0
def index():
    if session.forced_language == "en":
        locale = "en_US"
    elif session.forced_language == "de":
        locale = "de_DE"
    else:
        locale = ""

    ompdal = OMPDAL(db, myconf)

    press = ompdal.getPress(myconf.take("omp.press_id"))
    if not press:
        redirect(URL("home", "index"))
    press_settings = OMPSettings(ompdal.getPressSettings(press.press_id))

    ignored_submission_id = myconf.take("omp.ignore_submissions") if myconf.take("omp.ignore_submissions") else -1

    submissions = []
    for submission_row in ompdal.getSubmissionsByPress(press.press_id, ignored_submission_id):
        authors = [
            OMPItem(author, OMPSettings(ompdal.getAuthorSettings(author.author_id)))
            for author in ompdal.getAuthorsBySubmission(submission_row.submission_id)
        ]
        editors = [
            OMPItem(editor, OMPSettings(ompdal.getAuthorSettings(editor.author_id)))
            for editor in ompdal.getEditorsBySubmission(submission_row.submission_id)
        ]
        publication_dates = [
            dateFromRow(pd)
            for pf in ompdal.getAllPublicationFormatsBySubmission(
                submission_row.submission_id, available=True, approved=True
            )
            for pd in ompdal.getPublicationDatesByPublicationFormat(pf.publication_format_id)
        ]
        submission = OMPItem(
            submission_row,
            OMPSettings(ompdal.getSubmissionSettings(submission_row.submission_id)),
            {"authors": authors, "editors": editors},
        )
        series_row = ompdal.getSeries(submission_row.series_id)
        if series_row:
            submission.associated_items["series"] = OMPItem(
                series_row, OMPSettings(ompdal.getSeriesSettings(series_row.series_id))
            )
        if publication_dates:
            submission.associated_items["publication_dates"] = publication_dates

        submissions.append(submission)

    submissions = sorted(
        submissions, key=lambda s: min(s.associated_items.get("publication_dates", [datetime(1, 1, 1)])), reverse=True
    )

    return locals()
Exemplo n.º 3
0
def series():
    if session.forced_language == "en":
        locale = "en_US"
    elif session.forced_language == "de":
        locale = "de_DE"
    else:
        locale = ""

    ignored_submission_id = myconf.take("omp.ignore_submissions") if myconf.take("omp.ignore_submissions") else -1

    if request.args == []:
        redirect(URL("home", "index"))
    series_path = request.args[0]

    ompdal = OMPDAL(db, myconf)

    press = ompdal.getPress(myconf.take("omp.press_id"))
    if not press:
        redirect(URL("home", "index"))

    series_row = ompdal.getSeriesByPathAndPress(series_path, press.press_id)

    # If series path is unknown
    if not series_row:
        redirect(URL("home", "index"))

    series = OMPItem(series_row, OMPSettings(ompdal.getSeriesSettings(series_row.series_id)))
    submission_rows = ompdal.getSubmissionsBySeries(
        series_row.series_id, ignored_submission_id=ignored_submission_id, status=3
    )

    submissions = []
    for submission_row in submission_rows:
        authors = [
            OMPItem(author, OMPSettings(ompdal.getAuthorSettings(author.author_id)))
            for author in ompdal.getAuthorsBySubmission(submission_row.submission_id)
        ]
        editors = [
            OMPItem(editor, OMPSettings(ompdal.getAuthorSettings(editor.author_id)))
            for editor in ompdal.getEditorsBySubmission(submission_row.submission_id)
        ]
        submission = OMPItem(
            submission_row,
            OMPSettings(ompdal.getSubmissionSettings(submission_row.submission_id)),
            {"authors": authors, "editors": editors},
        )

        submissions.append(submission)

    submissions = sorted(submissions, cmp=seriesPositionCompare, reverse=True)
    series.associated_items["submissions"] = submissions

    return locals()
Exemplo n.º 4
0
def info():
    if request.args == []:
        redirect(URL('home', 'index'))
    category_path = request.args[0]
    press = ompdal.getPress(myconf.take('omp.press_id'))

    content = []
    category = []

    if exists(request.folder + 'views/catalog/' + category_path + "_info.html"):
        content = "category/" + category_path + "_info.html"
        return locals()
    else:
        category_row = ompdal.getCategoryByPathAndPress(category_path, press.press_id)
        if not category_row:
            redirect(URL('home', 'index'))
        category = OMPItem(category_row,
                           OMPSettings(ompdal.getCategorySettings(category_row.category_id))
                           )

    submission_rows = ompdal.getSubmissionsByCategory(category_row.category_id, ignored_submission_id=-1, status=3)

    img_path = '{}{}{}{}-category.jpg'.format('static/files/presses/', press.press_id, '/categories/',
                                              category_row.category_id)

    category_thumbnail = IMG(_src="../../" + img_path) if exists(request.folder + img_path) else DIV()

    return locals()
Exemplo n.º 5
0
def series():
    if session.forced_language == 'en':
        locale = 'en_US'
    elif session.forced_language == 'de':
        locale = 'de_DE'
    else:
        locale = ''

    ignored_submission_id = myconf.take('omp.ignore_submissions') if myconf.take('omp.ignore_submissions') else -1
    
    if request.args == []:
        redirect( URL('home', 'index'))
    series_path = request.args[0]
    
    ompdal = OMPDAL(db, myconf)
    
    press = ompdal.getPress(myconf.take('omp.press_id'))
    if not press:
        redirect(URL('home', 'index'))
    
    series_row = ompdal.getSeriesByPathAndPress(series_path, press.press_id)
    
    # If series path is unknown
    if not series_row:
        redirect(URL('home', 'index'))
        
    series = OMPItem(series_row, OMPSettings(ompdal.getSeriesSettings(series_row.series_id)))
    submission_rows = ompdal.getSubmissionsBySeries(series_row.series_id, ignored_submission_id=ignored_submission_id, status=3)
    
    submissions = []
    for submission_row in submission_rows:
        authors = [OMPItem(author, OMPSettings(ompdal.getAuthorSettings(author.author_id))) for author in ompdal.getAuthorsBySubmission(submission_row.submission_id)]
        editors = [OMPItem(editor, OMPSettings(ompdal.getAuthorSettings(editor.author_id))) for editor in ompdal.getEditorsBySubmission(submission_row.submission_id)]
        submission = OMPItem(submission_row,
                             OMPSettings(ompdal.getSubmissionSettings(submission_row.submission_id)),
                             {'authors': authors, 'editors': editors}
        )
        
        submissions.append(submission)

    submissions = sorted(submissions, cmp=seriesPositionCompare, reverse=True)
    series.associated_items['submissions'] = submissions

    return locals()
Exemplo n.º 6
0
def index():
    if session.forced_language == 'en':
        locale = 'en_US'
    elif session.forced_language == 'de':
        locale = 'de_DE'
    else:
        locale = ''
    
    ompdal = OMPDAL(db, myconf)
    
    press = ompdal.getPress(myconf.take('omp.press_id'))
    if not press:
        redirect(URL('home', 'index'))            
    press_settings = OMPSettings(ompdal.getPressSettings(press.press_id))
    
    ignored_submission_id =  myconf.take('omp.ignore_submissions') if myconf.take('omp.ignore_submissions') else -1

    submissions = []
    for submission_row in ompdal.getSubmissionsByPress(press.press_id, ignored_submission_id):
        authors = [OMPItem(author, OMPSettings(ompdal.getAuthorSettings(author.author_id))) for author in ompdal.getAuthorsBySubmission(submission_row.submission_id)]
        editors = [OMPItem(editor, OMPSettings(ompdal.getAuthorSettings(editor.author_id))) for editor in ompdal.getEditorsBySubmission(submission_row.submission_id)]
        publication_dates = [dateFromRow(pd) for pf in ompdal.getAllPublicationFormatsBySubmission(submission_row.submission_id, available=True, approved=True) 
                                for pd in ompdal.getPublicationDatesByPublicationFormat(pf.publication_format_id)]
        submission = OMPItem(submission_row,
                             OMPSettings(ompdal.getSubmissionSettings(submission_row.submission_id)),
                             {'authors': authors, 'editors': editors}
        )
        series_row = ompdal.getSeries(submission_row.series_id)
        if series_row:
            submission.associated_items['series'] = OMPItem(series_row, OMPSettings(ompdal.getSeriesSettings(series_row.series_id)))
        if publication_dates:
            submission.associated_items['publication_dates'] = publication_dates
            
        submissions.append(submission)

    submissions = sorted(submissions, key=lambda s: min(s.associated_items.get('publication_dates', [datetime(1, 1, 1)])), reverse = True)
    
    return locals()
Exemplo n.º 7
0
def index():
    ompdal = OMPDAL(db, myconf)
    json_list = dict(xml_url='')
    if len(request.args) < 2:
        raise HTTP(404)
    submission_id = request.args[0]
    file_id = request.args[1]

    if str(file_id).endswith('.xml'):
        path = os.path.join(request.folder, 'static/files/presses',
                            myconf.take('omp.press_id'), 'monographs',
                            submission_id, 'submission/proof', file_id)
        if os.path.exists(path) is False:
            raise HTTP(404)

        submission_settings = ompdal.getSubmissionSettings(submission_id)
        series = ompdal.getSeriesBySubmissionId(submission_id)
        series_settings = ompdal.getSeriesSettings(
            series.get('series_id')) if series else []

        cssStyles = get_setting_value(series_settings, 'cssStyles')
        if not cssStyles:
            cssStyles = get_setting_value(submission_settings, 'cssStyles')

        cssStylesStr = cssStyles.replace("'",
                                         "\"") if len(cssStyles) > 0 else '{}'
        cssStylesDict = json.loads(cssStylesStr)
        font_family = cssStylesDict.get('font-face').get(
            'family') if cssStylesDict.get('font-face') else 'Source Sans Pro'

        authors = [
            OMPItem(author,
                    OMPSettings(ompdal.getAuthorSettings(author.author_id)))
            for author in ompdal.getAuthorsBySubmission(submission_id)
        ]
        authors_string = ', '.join(
            (ompformat.formatName(a.settings) for a in authors))

        return dict(json_list=XML(gluon.serializers.json(json_list)),
                    authors=authors_string,
                    font_family=font_family)
    else:
        path = os.path.join(request.folder, 'static/files/presses',
                            myconf.take('omp.press_id'), 'monographs',
                            submission_id, 'submission/', file_id)
        return response.stream(path, chunk_size=1048576)
Exemplo n.º 8
0
def book():
    if session.forced_language == 'en':
        locale = 'en_US'
    elif session.forced_language == 'de':
        locale = 'de_DE'
    else:
        locale = ''

    submission_id = request.args[0] if request.args else redirect(
        URL('home', 'index'))
    
    dal = OMPDAL(db, myconf)
    
    press = dal.getPress(myconf.take('omp.press_id'))
    if not press:
        redirect(URL('home', 'index'))
    press_settings = OMPSettings(dal.getPressSettings(press.press_id))
    
    # Get basic submission info (check, if submission is associated with the actual press and if the submission has been published)
    submission = dal.getPublishedSubmission(submission_id, press_id=myconf.take('omp.press_id'))
    if not submission:
        redirect(URL('home', 'index'))

    submission_settings = OMPSettings(dal.getSubmissionSettings(submission_id))
    
    # Get contributors and contributor settings
    editor_rows = dal.getEditorsBySubmission(submission_id)
    editors = [OMPItem(e, OMPSettings(dal.getAuthorSettings(e.author_id))) for e in editor_rows]

    # Do not load authors if the submission has editors
    authors = [] if editors else [OMPItem(a, OMPSettings(dal.getAuthorSettings(a.author_id))) for a in
                                  dal.getActualAuthorsBySubmission(submission_id, filter_browse=True)]
    
    # Get chapters and chapter authors
    chapters = []
    for chapter in dal.getChaptersBySubmission(submission_id):
        chapters.append(OMPItem(chapter,
                             OMPSettings(dal.getChapterSettings(chapter.chapter_id)),
                             {'authors': [OMPItem(a, OMPSettings(dal.getAuthorSettings(a.author_id))) for a in dal.getAuthorsByChapter(chapter.chapter_id)]})
        )
        
    # Get digital publication formats, settings, files, and identification codes
    digital_publication_formats = []
    for pf in dal.getDigitalPublicationFormats(submission_id, available=True, approved=True):
        publication_format = OMPItem(pf, 
            OMPSettings(dal.getPublicationFormatSettings(pf.publication_format_id)),
            {'identification_codes': dal.getIdentificationCodesByPublicationFormat(pf.publication_format_id),
             'publication_dates': dal.getPublicationDatesByPublicationFormat(pf.publication_format_id)}
        )
        full_file = dal.getLatestRevisionOfFullBookFileByPublicationFormat(submission_id, pf.publication_format_id)
        if full_file:
            publication_format.associated_items['full_file'] = OMPItem(full_file, OMPSettings(dal.getSubmissionFileSettings(full_file.file_id)))
        digital_publication_formats.append(publication_format)
        
        for chapter in chapters:
            chapter_file = dal.getLatestRevisionOfChapterFileByPublicationFormat(chapter.attributes.chapter_id, pf.publication_format_id)
            if chapter_file:
                chapter.associated_items.setdefault('files', {})[pf.publication_format_id] = OMPItem(chapter_file, OMPSettings(dal.getSubmissionFileSettings(chapter_file.file_id)))
            
    # Get physical publication formats, settings, and identification codes
    physical_publication_formats = []
    for pf in dal.getPhysicalPublicationFormats(submission_id, available=True, approved=True):
        physical_publication_formats.append(OMPItem(pf, 
            OMPSettings(dal.getPublicationFormatSettings(pf.publication_format_id)),
            {'identification_codes': dal.getIdentificationCodesByPublicationFormat(pf.publication_format_id),
             'publication_dates': dal.getPublicationDatesByPublicationFormat(pf.publication_format_id)})
        )
    
    pdf = dal.getPublicationFormatByName(submission_id, myconf.take('omp.doi_format_name')).first()
    # Get DOI from the format marked as DOI carrier
    if pdf:
        doi = OMPSettings(dal.getPublicationFormatSettings(pdf.publication_format_id)).getLocalizedValue("pub-id::doi", "")    # DOI always has empty locale
    else:
        doi = ""
        
    def get_first(l):
        if l:
            return l[0]
        else:
            return None
    
    date_published = None
    # Get the OMP publication date (column publication_date contains latest catalog entry edit date.) Try:
    # 1. Custom publication date entered for a publication format calles "PDF"
    if pdf:
        date_published = get_first([dateFromRow(pd) for pd in dal.getPublicationDatesByPublicationFormat(pdf.publication_format_id) if pd.role=="01"])
    # 2. Date on which the catalog entry was first published
    if not date_published:
        date_published = get_first([pd.date_logged for pd in dal.getMetaDataPublishedDates(submission_id)])
    # 3. Date on which the submission status was last modified (always set)
    if not date_published:
        date_published = submission.date_status_modified
        
    series = dal.getSeriesBySubmissionId(submission_id)
    if series:
        series = OMPItem(series, OMPSettings(dal.getSeriesSettings(series.series_id)))
    
    # Get purchase info
    representatives = dal.getRepresentativesBySubmission(submission_id, myconf.take('omp.representative_id_type'))
    
    #stats = OMPStats(myconf, db, locale)

    return locals()
Exemplo n.º 9
0
def category():
    ignored_submission_id = myconf.take(
        'omp.ignore_submissions') if myconf.take(
            'omp.ignore_submissions') else -1

    if request.args == []:
        redirect(URL('home', 'index'))
    category_path = request.args[0]

    ompdal = OMPDAL(db, myconf)

    press = ompdal.getPress(myconf.take('omp.press_id'))
    if not press:
        redirect(URL('home', 'index'))

    category_row = ompdal.getCategoryByPathAndPress(category_path,
                                                    press.press_id)

    if not category_row:
        redirect(URL('home', 'index'))

    category = OMPItem(
        category_row,
        OMPSettings(ompdal.getCategorySettings(category_row.category_id)))
    submission_rows = ompdal.getSubmissionsByCategory(
        category_row.category_id,
        ignored_submission_id=ignored_submission_id,
        status=3)
    submissions = []
    for submission_row in submission_rows:
        contributors_by_group = defaultdict(list)
        for contrib in ompdal.getAuthorsBySubmission(
                submission_row.submission_id, filter_browse=True):
            contrib_item = OMPItem(
                contrib,
                OMPSettings(ompdal.getAuthorSettings(contrib.author_id)))
            contributors_by_group[contrib.user_group_id].append(contrib_item)

        editors = contributors_by_group[myconf.take('omp.editor_id', cast=int)]
        authors = contributors_by_group[myconf.take('omp.author_id', cast=int)]
        chapter_authors = contributors_by_group[myconf.take(
            'omp.chapter_author_id', cast=int)]
        translators = []
        if myconf.get('omp.translator_id'):
            translators = contributors_by_group[int(
                myconf.take('omp.translator_id'))]
        submission = OMPItem(
            submission_row,
            OMPSettings(
                ompdal.getSubmissionSettings(submission_row.submission_id)), {
                    'authors': authors,
                    'editors': editors,
                    'chapter_authors': chapter_authors
                })
        if authors:
            attribution = ompformat.formatContributors(authors,
                                                       max_contributors=4,
                                                       with_and=True)
            additional_attribution = ompformat.formatAttribution(
                editors, [], translators, [])
        else:
            attribution = ompformat.formatAttribution(editors, [], [],
                                                      chapter_authors)
            additional_attribution = ""
        submission.attribution = attribution
        submission.additional_attribution = additional_attribution

        series_row = ompdal.getSeries(submission_row.series_id)
        if series_row:
            submission.associated_items['series'] = OMPItem(
                series_row,
                OMPSettings(ompdal.getSeriesSettings(series_row.series_id)))

        category_row = ompdal.getCategoryBySubmissionId(
            submission_row.submission_id)
        if category_row:
            submission.associated_items['category'] = OMPItem(
                category_row,
                OMPSettings(
                    ompdal.getCategorySettings(category_row.category_id)))

        publication_dates = [
            ompformat.dateFromRow(pd)
            for pf in ompdal.getAllPublicationFormatsBySubmission(
                submission_row.submission_id)
            for pd in ompdal.getPublicationDatesByPublicationFormat(
                pf.publication_format_id)
        ]
        if publication_dates:
            submission.associated_items[
                'publication_dates'] = publication_dates
        submissions.append(submission)

    sortby = ompdal.getCategorySettings(category_row.category_id).find(
        lambda row: row.setting_name == 'sortOption').first()
    if sortby:
        b = Browser(submissions, 0, locale, 100, sortby.get('setting_value'),
                    [])
        submissions = b.process_submissions(submissions)

    return locals()
Exemplo n.º 10
0
def book():
    ompdal = OMPDAL(db, myconf)

    submission_id = request.args[
        0] if request.args and request.args[0].isdigit() else raise400()
    press_id = myconf.take('omp.press_id')
    editor_group_id = myconf.take('omp.editor_id', cast=int)
    author_group_id = myconf.take('omp.author_id', cast=int)
    chapter_author_group_id = myconf.take('omp.chapter_author_id', cast=int)
    translator_group_id = int(myconf.get('omp.translator_id')) if myconf.get(
        'omp.translator_id') else None

    press = ompdal.getPress(press_id)
    submission = ompdal.getPublishedSubmission(submission_id,
                                               press_id=press_id)
    if not submission or not press:
        raise HTTP(400)
    if len(request.args) > 1 and request.args[1][0] == 'c' and request.args[1][
            1:].isdigit():
        chapter_id = int(request.args[1][1:])
    elif len(request.args) > 1:
        redirect(URL(r=request, args=request.args[0:1]))
    else:
        chapter_id = 0

    submission_settings = OMPSettings(
        ompdal.getSubmissionSettings(submission_id))
    press_settings = OMPSettings(ompdal.getPressSettings(press.press_id))

    # Get chapters and chapter authors
    chapters = []
    chapter = {}
    for i in ompdal.getChaptersBySubmission(submission_id):
        item = OMPItem(
            i, OMPSettings(ompdal.getChapterSettings(i.chapter_id)), {
                'authors': [
                    OMPItem(a,
                            OMPSettings(ompdal.getAuthorSettings(a.author_id)))
                    for a in ompdal.getAuthorsByChapter(i.chapter_id)
                ]
            })
        chapters.append(item)

    contributors_by_group = defaultdict(list)
    contributors_by_id = {}
    for contrib in ompdal.getAuthorsBySubmission(submission_id,
                                                 filter_browse=True):
        contrib_item = OMPItem(
            contrib, OMPSettings(ompdal.getAuthorSettings(contrib.author_id)))
        contributors_by_group[contrib.user_group_id].append(contrib_item)
        contributors_by_id[contrib.author_id] = contrib_item

    editors = contributors_by_group[editor_group_id]
    authors = contributors_by_group[author_group_id]
    chapter_authors = contributors_by_group[chapter_author_group_id]
    # if no editors or authors are saved for this submission, treat chapter authors as authors
    if not editors and not authors:
        authors = chapter_authors
    translators = []
    if translator_group_id:
        translators = contributors_by_group[translator_group_id]
    # Get digital publication formats, settings, files, and identification codes
    c = None
    chapter_doi = None
    digital_publication_formats = []
    for pf in ompdal.getDigitalPublicationFormats(submission_id,
                                                  available=True,
                                                  approved=True):
        publication_format = OMPItem(
            pf,
            OMPSettings(
                ompdal.getPublicationFormatSettings(pf.publication_format_id)),
            {
                'identification_codes':
                ompdal.getIdentificationCodesByPublicationFormat(
                    pf.publication_format_id),
                'publication_dates':
                ompdal.getPublicationDatesByPublicationFormat(
                    pf.publication_format_id)
            })
        full_file = ompdal.getLatestRevisionOfFullBookFileByPublicationFormat(
            submission_id, pf.publication_format_id)
        full_epub_file = ompdal.getLatestRevisionOfEBook(
            submission_id, pf.publication_format_id)
        if full_epub_file:
            publication_format.associated_items['full_file'] = OMPItem(
                full_epub_file,
                OMPSettings(
                    ompdal.getSubmissionFileSettings(full_epub_file.file_id)))

        if full_file:
            publication_format.associated_items['full_file'] = OMPItem(
                full_file,
                OMPSettings(ompdal.getSubmissionFileSettings(
                    full_file.file_id)))

        digital_publication_formats.append(publication_format)

        for i in chapters:
            chapter_file = ompdal.getLatestRevisionOfChapterFileByPublicationFormat(
                i.attributes.chapter_id, pf.publication_format_id)
            if chapter_file:
                i.associated_items.setdefault(
                    'files', {})[pf.publication_format_id] = OMPItem(
                        chapter_file,
                        OMPSettings(
                            ompdal.getSubmissionFileSettings(
                                chapter_file.file_id)))
            if chapter_id > 0 and chapter_id == i.attributes.chapter_id:
                c = i
    if c:
        c_title = c.settings.getLocalizedValue('title', locale)
        c_subtitle = c.settings.getLocalizedValue('subtitle', locale)
        c_abstract = c.settings.getLocalizedValue('abstract', locale)
        c_authors = c.associated_items.get('authors', [])
        c_files = c.associated_items.get('files', {})
        chapter_doi = c.settings.getLocalizedValue(DOI_SETTING_NAME, '')

    # Get physical publication formats, settings, and identification codes
    physical_publication_formats = []
    for pf in ompdal.getPhysicalPublicationFormats(submission_id,
                                                   available=True,
                                                   approved=True):
        physical_publication_formats.append(
            OMPItem(
                pf,
                OMPSettings(
                    ompdal.getPublicationFormatSettings(
                        pf.publication_format_id)), {
                            'identification_codes':
                            ompdal.getIdentificationCodesByPublicationFormat(
                                pf.publication_format_id),
                            'publication_dates':
                            ompdal.getPublicationDatesByPublicationFormat(
                                pf.publication_format_id)
                        }))

    pdf = ompdal.getPublicationFormatByName(
        submission_id, myconf.take('omp.doi_format_name')).first()

    doi = ""
    submission_doi = submission_settings.getLocalizedValue(
        DOI_SETTING_NAME, '')
    if submission_doi:
        doi = submission_doi
    elif pdf:
        # DOI always has empty locale
        doi = OMPSettings(
            ompdal.getPublicationFormatSettings(
                pdf.publication_format_id)).getLocalizedValue(
                    DOI_SETTING_NAME, "")

    date_published = None
    date_first_published = None
    # Get the OMP publication date (column publication_date contains latest catalog entry edit date.) Try:
    # 1. Custom publication date entered for a publication format calles "PDF"
    if pdf:
        date_published = ompformat.dateFromRow(
            ompdal.getPublicationDatesByPublicationFormat(
                pdf.publication_format_id, "01").first())
        date_first_published = ompformat.dateFromRow(
            ompdal.getPublicationDatesByPublicationFormat(
                pdf.publication_format_id, "11").first())
    # 2. Date on which the catalog entry was first published
    if not date_published:
        metadatapublished_date = ompdal.getMetaDataPublishedDates(
            submission_id).first()
        date_published = metadatapublished_date.date_logged if metadatapublished_date else None
    # 3. Date on which the submission status was last modified (always set)
    if not date_published:
        date_published = submission.date_status_modified

    series = ompdal.getSeriesBySubmissionId(submission_id)
    if series:
        series = OMPItem(
            series, OMPSettings(ompdal.getSeriesSettings(series.series_id)))

    # Get purchase info
    representatives = ompdal.getRepresentativesBySubmission(
        submission_id, myconf.take('omp.representative_id_type'))

    # stats = OMPStats(myconf, db, locale)
    onix_types = ONIX_PRODUCT_IDENTIFIER_TYPE_CODES
    # submissions = sorted(submissions, key=lambda s: s.attributes['series_id'], reverse=True)
    pfs = digital_publication_formats + physical_publication_formats
    idntfrs = {}

    for p in pfs:
        for i in p.associated_items['identification_codes'].as_list():
            idntfrs['{}.{}'.format(
                i['code'], p.settings.getLocalizedValue(
                    'name',
                    locale))] = (i['value'], i['code'],
                                 p.settings.getLocalizedValue('name', locale))

    idntfrs = sorted(idntfrs.items(),
                     key=lambda i: IDENTIFIER_ORDER.index(
                         (i[0]) if i in IDENTIFIER_ORDER else '15.PDF'))

    category_row = ompdal.getCategoryBySubmissionId(submission_id)
    category = OMPItem(
        category_row,
        OMPSettings(ompdal.getCategorySettings(
            category_row.category_id))) if category_row else None

    cleanTitle = " ".join([
        submission_settings.getLocalizedValue('prefix', locale),
        submission_settings.getLocalizedValue('title', locale)
    ])
    subtitle = submission_settings.getLocalizedValue('subtitle', locale)
    abstract = submission_settings.getLocalizedValue('abstract', locale)
    series_name = ""

    if series:
        series_title = " ".join([
            series.settings.getLocalizedValue('prefix', locale),
            series.settings.getLocalizedValue('title', locale)
        ])
        series_subtitle = series.settings.getLocalizedValue('subtitle', locale)
        series_name = " – ".join(
            [t for t in [series_title.strip(), series_subtitle] if t])

    citation = ompformat.formatCitation(
        cleanTitle,
        subtitle,
        authors,
        editors,
        translators,
        date_published,
        press_settings.getLocalizedValue('location', ''),
        press_settings.getLocalizedValue('publisher', ''),
        locale=locale,
        series_name=series_name,
        series_pos=submission.series_position,
        max_contrib=3,
        date_first_published=date_first_published)
    if authors:
        attribution = ompformat.formatContributors(authors,
                                                   max_contributors=4,
                                                   with_and=True)
        additional_attribution = ompformat.formatAttribution(
            editors, [], translators, [])
        title_attribution = ompformat.formatName(authors[0].settings)
    elif editors:
        suffix = T("(Eds.)") if len(editors) > 1 else T("(Ed.)")
        title_attribution = "{} {}".format(
            ompformat.formatContributors(editors,
                                         max_contributors=4,
                                         with_and=True), suffix)
        attribution = "{} {}".format(
            ompformat.formatContributors(editors,
                                         max_contributors=100,
                                         with_and=True), suffix)
        additional_attribution = ""
    else:
        title_attribution = ompformat.formatName(chapter_authors[0].settings)
        attribution = ompformat.formatAttribution([], [], [], chapter_authors)
        additional_attribution = ""

    response.title = "{}: {} - {}".format(
        title_attribution, cleanTitle,
        settings.short_title if settings.short_title else settings.title)

    if c:
        # Select different template for chapters
        citation = ompformat.formatChapterCitation(citation, c, locale)
        response.view = 'catalog/book/chapter/index.html'
    return locals()
Exemplo n.º 11
0
def index():
    ompdal = OMPDAL(db, myconf)
    press = ompdal.getPress(myconf.take('omp.press_id'))
    editor_group_id = myconf.take('omp.editor_id', cast=int)
    author_group_id = myconf.take('omp.author_id', cast=int)
    chapter_author_group_id = myconf.take('omp.chapter_author_id', cast=int)
    translator_group_id = int(myconf.get('omp.translator_id')) if myconf.get(
        'omp.translator_id') else None

    if not press:
        redirect(URL('home', 'index'))
    press_settings = OMPSettings(ompdal.getPressSettings(press.press_id))

    ignored_submission_id = myconf.take(
        'omp.ignore_submissions') if myconf.take(
            'omp.ignore_submissions') else -1

    submissions = []
    submission_rows = ompdal.getSubmissionsByPress(press.press_id,
                                                   ignored_submission_id)

    for submission_row in submission_rows:
        # Get contributors and contributor settings
        contributors_by_group = defaultdict(list)
        for contrib in ompdal.getAuthorsBySubmission(
                submission_row.submission_id, filter_browse=True):
            contrib_item = OMPItem(
                contrib,
                OMPSettings(ompdal.getAuthorSettings(contrib.author_id)))
            contributors_by_group[contrib.user_group_id].append(contrib_item)

        editors = contributors_by_group[editor_group_id]
        authors = contributors_by_group[author_group_id]
        chapter_authors = contributors_by_group[chapter_author_group_id]
        translators = []

        if translator_group_id:
            translators = contributors_by_group[translator_group_id]
        publication_dates = [
            ompformat.dateFromRow(pd)
            for pf in ompdal.getAllPublicationFormatsBySubmission(
                submission_row.submission_id, available=True, approved=True)
            for pd in ompdal.getPublicationDatesByPublicationFormat(
                pf.publication_format_id)
        ]
        for s in ompdal.getDigitalPublicationFormats(
                submission_row.submission_id, available=True, approved=True):
            if s['remote_url']:
                frontpage_url = s['remote_url']
                break
        else:
            frontpage_url = URL('book', args=[submission_row.submission_id])
        submission = OMPItem(
            submission_row,
            OMPSettings(
                ompdal.getSubmissionSettings(submission_row.submission_id)), {
                    'authors': authors,
                    'editors': editors,
                    'translators': translators,
                    'chapter_authors': chapter_authors,
                    'frontpage_url': frontpage_url
                })
        if authors:
            attribution = ompformat.formatContributors(authors,
                                                       max_contributors=4,
                                                       with_and=True)
            additional_attribution = ompformat.formatAttribution(
                editors, [], translators, [])
        else:
            attribution = ompformat.formatAttribution(editors, [], [],
                                                      chapter_authors)
            additional_attribution = ""
        submission.attribution = attribution
        submission.additional_attribution = additional_attribution
        category_row = ompdal.getCategoryBySubmissionId(
            submission_row.submission_id)
        if category_row:
            submission.associated_items['category'] = OMPItem(
                category_row,
                OMPSettings(
                    ompdal.getCategorySettings(category_row.category_id)))

        series_row = ompdal.getSeries(submission_row.series_id)
        if series_row:
            submission.associated_items['series'] = OMPItem(
                series_row,
                OMPSettings(ompdal.getSeriesSettings(series_row.series_id)))
        if publication_dates:
            submission.associated_items[
                'publication_dates'] = publication_dates

        submissions.append(submission)

    session.filters = request.vars.get('filter_by').strip('[').strip(
        ']') if request.vars.get('filter_by') else session.get('filters', '')
    session.per_page = int(
        request.vars.get('per_page')) if request.vars.get('per_page') else int(
            session.get('per_page', 20))
    if request.vars.get('sort_by'):
        session.sort_by = request.vars.get('sort_by')
    elif session.get('sort_by'):
        session.sort_by = session.get('sort_by')
    else:
        session.sort_by = 'datePublished-2'

    current = int(request.vars.get('page_nr', 1)) - 1

    b = Browser(submissions, current, locale, session.get('per_page'),
                session.get('sort_by'), session.get('filters'))
    submissions = b.process_submissions(submissions)

    return locals()