Пример #1
0
def view(name):
    mpackage = MetaPackage.query.filter_by(name=name).first()
    if mpackage is None:
        abort(404)

    dependers = db.session.query(Package) \
     .select_from(MetaPackage) \
     .filter(MetaPackage.name==name) \
     .join(MetaPackage.dependencies) \
     .join(Dependency.depender) \
     .filter(Dependency.optional==False, Package.state==PackageState.APPROVED) \
     .all()

    optional_dependers = db.session.query(Package) \
     .select_from(MetaPackage) \
     .filter(MetaPackage.name==name) \
     .join(MetaPackage.dependencies) \
     .join(Dependency.depender) \
     .filter(Dependency.optional==True, Package.state==PackageState.APPROVED) \
     .all()

    similar_topics = None
    if mpackage.packages.filter_by(state=PackageState.APPROVED).count() == 0:
        similar_topics = ForumTopic.query \
          .filter_by(name=name) \
          .order_by(db.asc(ForumTopic.name), db.asc(ForumTopic.title)) \
          .all()

    return render_template("metapackages/view.html",
                           mpackage=mpackage,
                           dependers=dependers,
                           optional_dependers=optional_dependers,
                           similar_topics=similar_topics)
Пример #2
0
def get_sorted_article_query():
    """Get sorted query object of article. Judging by its sort_key [default: date] and order.
    
    Returns:
        object: Article.query (sorted)
    """
    sort_key = request.args.get('s', 'date')
    order = request.args.get('o', 'desc')
    article_query = None
    if sort_key:
        if order == 'asc':
            article_query = Article.query.order_by(db.asc(sort_key))
        else:
            article_query = Article.query.order_by(db.desc(sort_key))
    else:
        article_query = Article.query
    return article_query
Пример #3
0
def licenses():
    return jsonify([ { "name": license.name, "is_foss": license.is_foss } \
     for license in License.query.order_by(db.asc(License.name)).all() ])
Пример #4
0
def list_all():
    mpackages = db.session.query(MetaPackage, func.count(Package.id)) \
      .select_from(MetaPackage).outerjoin(MetaPackage.packages) \
      .order_by(db.asc(MetaPackage.name)) \
      .group_by(MetaPackage.id).all()
    return render_template("metapackages/list.html", mpackages=mpackages)