예제 #1
0
파일: schemas.py 프로젝트: sedrubal/bodhi
class SaveReleaseSchema(CSRFProtectedSchema, colander.MappingSchema):
    """An API schema for bodhi.server.services.releases.save_release()."""

    name = colander.SchemaNode(
        colander.String(),
    )
    long_name = colander.SchemaNode(
        colander.String(),
    )
    version = colander.SchemaNode(
        colander.String(),
        missing=None,
    )
    branch = colander.SchemaNode(
        colander.String(),
    )
    id_prefix = colander.SchemaNode(
        colander.String(),
    )
    dist_tag = colander.SchemaNode(
        colander.String(),
    )
    stable_tag = colander.SchemaNode(
        colander.String(),
    )
    testing_tag = colander.SchemaNode(
        colander.String(),
    )
    candidate_tag = colander.SchemaNode(
        colander.String(),
    )
    pending_signing_tag = colander.SchemaNode(
        colander.String(),
        missing="",
    )
    pending_testing_tag = colander.SchemaNode(
        colander.String(),
        missing="",
    )
    pending_stable_tag = colander.SchemaNode(
        colander.String(),
        missing="",
    )
    override_tag = colander.SchemaNode(
        colander.String(),
    )
    state = colander.SchemaNode(
        colander.String(),
        validator=colander.OneOf(list(ReleaseState.values())),
        missing="disabled",
    )
    edited = colander.SchemaNode(
        colander.String(),
        missing=None,
    )
    mail_template = colander.SchemaNode(
        colander.String(),
        missing="fedora_errata_template",
        validator=colander.OneOf(MAIL_TEMPLATES)
    )
예제 #2
0
class SaveReleaseSchema(CSRFProtectedSchema, colander.MappingSchema):
    """An API schema for bodhi.server.services.releases.save_release()."""

    name = colander.SchemaNode(colander.String(), )
    long_name = colander.SchemaNode(colander.String(), )
    version = colander.SchemaNode(
        colander.String(),
        missing=None,
    )
    branch = colander.SchemaNode(colander.String(), )
    id_prefix = colander.SchemaNode(colander.String(), )
    dist_tag = colander.SchemaNode(colander.String(), )
    stable_tag = colander.SchemaNode(colander.String(), )
    testing_tag = colander.SchemaNode(colander.String(), )
    candidate_tag = colander.SchemaNode(colander.String(), )
    pending_signing_tag = colander.SchemaNode(
        colander.String(),
        missing="",
    )
    pending_testing_tag = colander.SchemaNode(
        colander.String(),
        missing="",
    )
    pending_stable_tag = colander.SchemaNode(
        colander.String(),
        missing="",
    )
    override_tag = colander.SchemaNode(colander.String(), )
    state = colander.SchemaNode(
        colander.String(),
        validator=colander.OneOf(list(ReleaseState.values())),
        missing="disabled",
    )
    edited = colander.SchemaNode(
        colander.String(),
        missing=None,
    )
    mail_template = colander.SchemaNode(
        colander.String(),
        missing="fedora_errata_template",
        validator=colander.OneOf(MAIL_TEMPLATES))
    composed_by_bodhi = colander.SchemaNode(
        colander.Boolean(true_choices=('true', '1')),
        missing=True,
    )
    create_automatic_updates = colander.SchemaNode(
        colander.Boolean(true_choices=('true', '1')),
        missing=False,
    )
    package_manager = colander.SchemaNode(
        colander.String(),
        validator=colander.OneOf(list(PackageManager.values())),
        missing="unspecified",
    )
    testing_repository = colander.SchemaNode(
        colander.String(),
        missing=None,
    )
예제 #3
0
파일: schemas.py 프로젝트: sitedata/bodhi
class ListReleaseSchema(PaginatedSchema):
    """
    An API schema for listing releases.

    This schema is used by bodhi.server.services.releases.query_releases_html() and
    bodhi.server.services.releases.query_releases_json().
    """

    ids = ReleaseIds(
        colander.Sequence(accept_scalar=True),
        location="querystring",
        missing=None,
        preparer=[util.splitter],
    )

    name = colander.SchemaNode(
        colander.String(),
        location="querystring",
        missing=None,
    )

    updates = Updates(
        colander.Sequence(accept_scalar=True),
        location="querystring",
        missing=None,
        preparer=[util.splitter],
    )

    packages = Packages(
        colander.Sequence(accept_scalar=True),
        location="querystring",
        missing=None,
        preparer=[util.splitter],
    )

    state = colander.SchemaNode(
        colander.String(),
        validator=colander.OneOf(list(ReleaseState.values())),
        missing=None,
    )

    exclude_archived = colander.SchemaNode(
        colander.Boolean(true_choices=('true', '1')),
        location="querystring",
        missing=None,
    )
예제 #4
0
파일: releases.py 프로젝트: onosek/bodhi
def query_releases_json(request):
    """
    Search releases by given criteria, returning the results as JSON.

    Args:
        request (pyramid.request): The current request.
    Returns:
        dict: A dictionary with the following keys:
            releases: An iterable of the Releases that match the query.
            page: The current page.
            pages: The total number of pages.
            rows_per_page: The number of rows on a page.
            total: The number of matching results.
    """
    db = request.db
    data = request.validated
    query = db.query(Release)

    ids = data.get('ids')
    if ids is not None:
        query = query.filter(or_(*[Release.id == _id for _id in ids]))

    name = data.get('name')
    if name is not None:
        query = query.filter(Release.name.like(name))

    updates = data.get('updates')
    if updates is not None:
        query = query.join(Release.builds).join(Build.update)
        args = [Update.alias == update.alias for update in updates]
        query = query.filter(or_(*args))

    packages = data.get('packages')
    if packages is not None:
        query = query.join(Release.builds).join(Build.package)
        query = query.filter(or_(*[Package.id == p.id for p in packages]))

    exclude_archived = data.get('exclude_archived')
    if exclude_archived:
        query = query.filter(Release.state != ReleaseState.archived)

    state = data.get('state')
    if state is not None:
        query = query.filter(Release.state == ReleaseState.from_string(state))

    # We can't use ``query.count()`` here because it is naive with respect to
    # all the joins that we're doing above.
    count_query = query.with_labels().statement\
        .with_only_columns([func.count(distinct(Release.id))])\
        .order_by(None)
    total = db.execute(count_query).scalar()

    page = data.get('page')
    rows_per_page = data.get('rows_per_page')
    pages = int(math.ceil(total / float(rows_per_page)))
    query = query.offset(rows_per_page * (page - 1)).limit(rows_per_page)

    return dict(
        releases=query.all(),
        page=page,
        pages=pages,
        rows_per_page=rows_per_page,
        total=total,
    )