Esempio n. 1
0
def collection(name=None):
    """Render the collection page.

    It renders it either with a collection specific template (aka
    collection_{collection_name}.html) or with the default collection
    template (collection.html)
    """
    if name is None:
        return redirect(url_for('.collection',
                                name=current_app.config['CFG_SITE_NAME']))
    collection = Collection.query.filter(Collection.name == name) \
                                 .first_or_404()

    @register_template_context_processor
    def index_context():
        breadcrumbs = current_breadcrumbs + collection.breadcrumbs(ln=g.ln)[1:]
        return dict(
            of=request.values.get('of', collection.formatoptions[0]['code']),
            format_record=format_record,
            easy_search_form=EasySearchForm(csrf_enabled=False),
            breadcrumbs=breadcrumbs)

    return render_template([
        'search/collection_{0}.html'.format(collection.id),
        'search/collection_{0}.html'.format(slugify(name, '_')),
        'search/collection.html'], collection=collection)
Esempio n. 2
0
def collection(name=None):
    """Render the collection page.

    It renders it either with a collection specific template (aka
    collection_{collection_name}.html) or with the default collection
    template (collection.html)
    """
    if name is None:
        return redirect(
            url_for('.collection', name=current_app.config['CFG_SITE_NAME']))
    collection = Collection.query.filter(Collection.name == name) \
                                 .first_or_404()

    @register_template_context_processor
    def index_context():
        breadcrumbs = current_breadcrumbs + collection.breadcrumbs(ln=g.ln)[1:]
        return dict(of=request.values.get('of',
                                          collection.formatoptions[0]['code']),
                    format_record=format_record,
                    easy_search_form=EasySearchForm(csrf_enabled=False),
                    breadcrumbs=breadcrumbs)

    return render_template([
        'search/collection_{0}.html'.format(
            collection.id), 'search/collection_{0}.html'.format(
                slugify(name, '_')), 'search/collection.html'
    ],
                           collection=collection)
Esempio n. 3
0
def collection(name):
    """
    Render the collection page.

    It renders it either with a collection specific template (aka
    collection_{collection_name}.html) or with the default collection
    template (collection.html)
    """
    from invenio.utils.text import slugify
    from invenio.modules.formatter import format_record
    from invenio.modules.search.forms import EasySearchForm
    from invenio.ext.template.context_processor import \
    register_template_context_processor

    from flask.ext.breadcrumbs import current_breadcrumbs
    collection = Collection.query.filter(Collection.name == name).first()

    if collection == None:
        return render_template('404.html')

    parent_collection = collection.most_specific_dad \
                        if (collection.most_specific_dad and \
                            collection.most_specific_dad.id != 1) else None

    coll_reclist = collection.reclist
    coll_records = []
    for rec in coll_reclist:
        coll_records.append(get_record(rec))
    def splitting(value, delimiter='/'):
        return value.split(delimiter)

    current_app.jinja_env.filters['splitthem'] = splitting

    @register_template_context_processor
    def index_context():
        breadcrumbs = current_breadcrumbs + collection.breadcrumbs(ln=g.ln)[1:]
        return dict(
            of=request.values.get('of', collection.formatoptions[0]['code']),
            format_record=format_record,
            easy_search_form=EasySearchForm(csrf_enabled=False),
            breadcrumbs=breadcrumbs)

    breadcrumbs = [{}]
    if parent_collection:
        breadcrumbs.append({ "url":".collection", "text": parent_collection.name_ln, "param":"name", "value": parent_collection.name })
        exp = parent_collection.name_ln
    else:
        exp = collection.name_ln

    breadcrumbs.append({ "url":".collection", "text": collection.name_ln, "param":"name", "value": collection.name })

    return render_template(['search/collection_{0}.html'.format(collection.id),
                            'search/collection_{0}.html'.format(slugify(name,
                                                                        '_')),
                            'search/collection.html'],
                           collection=collection, coll_records=coll_records, breadcrumbs = breadcrumbs, exp = exp)
Esempio n. 4
0
def collection(name):
    """
    Render the collection page.

    It renders it either with a collection specific template (aka
    collection_{collection_name}.html) or with the default collection
    template (collection.html)
    """
    from invenio.utils.text import slugify
    from invenio.modules.formatter import format_record
    from invenio.modules.search.forms import EasySearchForm
    from invenio.ext.template.context_processor import \
    register_template_context_processor

    from flask.ext.breadcrumbs import current_breadcrumbs
    collection = Collection.query.filter(Collection.name == name).first()

    if collection == None:
        return render_template('404.html')

    parent_collection = collection.most_specific_dad \
                        if (collection.most_specific_dad and \
                            collection.most_specific_dad.id != 1) else None

    coll_reclist = collection.reclist
    coll_records = []
    for rec in coll_reclist:
        coll_records.append(get_record(rec))
    def splitting(value, delimiter='/'):
        return value.split(delimiter)

    current_app.jinja_env.filters['splitthem'] = splitting

    @register_template_context_processor
    def index_context():
        breadcrumbs = current_breadcrumbs + collection.breadcrumbs(ln=g.ln)[1:]
        return dict(
            of=request.values.get('of', collection.formatoptions[0]['code']),
            format_record=format_record,
            easy_search_form=EasySearchForm(csrf_enabled=False),
            breadcrumbs=breadcrumbs)

    breadcrumbs = [{}]
    if parent_collection:
        breadcrumbs.append({ "url":".collection", "text": parent_collection.name_ln, "param":"name", "value": parent_collection.name })
        exp = parent_collection.name_ln
    else:
        exp = collection.name_ln

    breadcrumbs.append({ "url":".collection", "text": collection.name_ln, "param":"name", "value": collection.name })

    return render_template(['search/collection_{0}.html'.format(collection.id),
                            'search/collection_{0}.html'.format(slugify(name,
                                                                        '_')),
                            'search/collection.html'],
                           collection=collection, coll_records=coll_records, breadcrumbs = breadcrumbs, exp = exp)
def generate_slug(name):
    """Generate a slug for the knowledge.

    :param name: text to slugify
    :return: slugified text
    """
    slug = slugify(unicode(name))

    i = run_sql("SELECT count(*) FROM knwKB "
                "WHERE knwKB.slug LIKE %s OR knwKB.slug LIKE %s",
                (slug, slug + '-%'))[0][0]

    return slug + ('-{0}'.format(i) if i > 0 else '')
Esempio n. 6
0
    def generate_slug(name):
        """Generate a slug for the knowledge.

        :param name: text to slugify
        :return: slugified text
        """
        slug = slugify(name)

        i = KnwKB.query.filter(db.or_(
            KnwKB.slug.like(slug),
            KnwKB.slug.like(slug + '-%'),
        )).count()

        return slug + ('-{0}'.format(i) if i > 0 else '')
Esempio n. 7
0
def generate_slug(name):
    """Generate a slug for the knowledge.

    :param name: text to slugify
    :return: slugified text
    """
    slug = slugify(unicode(name))

    i = run_sql(
        "SELECT count(*) FROM knwKB "
        "WHERE knwKB.slug LIKE %s OR knwKB.slug LIKE %s",
        (slug, slug + '-%'))[0][0]

    return slug + ('-{0}'.format(i) if i > 0 else '')
Esempio n. 8
0
    def generate_slug(name):
        """Generate a slug for the knowledge.

        :param name: text to slugify
        :return: slugified text
        """
        slug = slugify(name)

        i = KnwKB.query.filter(
            db.or_(
                KnwKB.slug.like(slug),
                KnwKB.slug.like(slug + '-%'),
            )).count()

        return slug + ('-{0}'.format(i) if i > 0 else '')
Esempio n. 9
0
def collection(name):
    """
    Renders the collection page either with a collection specific template
    (aka collection_{collection_name}.html) or with the default collection
    template (collection.html)
    """
    collection = Collection.query.filter(Collection.name == name).first_or_404()

    @register_template_context_processor
    def index_context():
        return dict(
            of=request.values.get('of', collection.formatoptions[0]['code']),
            format_record=format_record,
            easy_search_form=EasySearchForm(csrf_enabled=False),
            breadcrumbs=current_breadcrumbs + collection.breadcrumbs(ln=g.ln)[1:])

    return render_template(['search/collection_{0}.html'.format(collection.id),
                            'search/collection_{0}.html'.format(slugify(name,
                                                                        '_')),
                            'search/collection.html'],
                           collection=collection)
Esempio n. 10
0
def collection(name):
    """
    Render the collection page.

    It renders it either with a collection specific template (aka
    collection_{collection_name}.html) or with the default collection
    template (collection.html)
    """
    from invenio.utils.text import slugify
    from invenio.modules.formatter import format_record
    from invenio.modules.search.forms import EasySearchForm
    from invenio.ext.template.context_processor import \
    register_template_context_processor
    from flask.ext.breadcrumbs import current_breadcrumbs

    collection = Collection.query.filter(Collection.name == name) \
                                 .first_or_404()
    coll_reclist = collection.reclist
    coll_records = []
    for rec in coll_reclist:
        coll_records.append(get_record(rec))
    def splitting(value, delimiter='/'):
        return value.split(delimiter)

    current_app.jinja_env.filters['splitthem'] = splitting
    
    @register_template_context_processor
    def index_context():
        breadcrumbs = current_breadcrumbs + collection.breadcrumbs(ln=g.ln)[1:]
        return dict(
            of=request.values.get('of', collection.formatoptions[0]['code']),
            format_record=format_record,
            easy_search_form=EasySearchForm(csrf_enabled=False),
            breadcrumbs=breadcrumbs)

    return render_template(['search/collection_{0}.html'.format(collection.id),
                            'search/collection_{0}.html'.format(slugify(name,
                                                                        '_')),
                            'search/collection.html'],
                           collection=collection, coll_records=coll_records)