Ejemplo n.º 1
0
def search():
    """ Display the blueprint search page """
    blueprints = []
    has_corp_bp = False

    if current_user.is_authenticated:
        blueprints = Blueprint.query.join(User, Item).filter(
            ((Blueprint.character_id == current_user.character_id) |
             ((Blueprint.character_id == User.character_id) &
              (User.main_character_id == current_user.character_id))
             ), ).outerjoin(
                 ActivityProduct,
                 ((Blueprint.item_id == ActivityProduct.item_id) &
                  (ActivityProduct.activity == Activity.INVENTION))).options(
                      db.contains_eager(Blueprint.item).contains_eager(
                          Item.activity_products__eager)).order_by(
                              Blueprint.corporation.asc(),
                              Blueprint.original.asc(),
                              Item.name.asc(),
                          ).all()

        # take the latest blueprint (as corp bp are at the end)
        # and check if it's a corp bp.
        if blueprints:
            has_corp_bp = blueprints[-1].corporation

    return render_template(
        'blueprint/search.html', **{
            'blueprints': blueprints,
            'has_corp_bp': has_corp_bp,
        })
Ejemplo n.º 2
0
def blueprint_search(name):
    """
    Return JSON result for a specific search
    name is the request name.
    """
    if request.is_xhr:
        name_lower = name.lower()

        # prevent only % string, to avoid query the full database at once...
        if name_lower == '%' * len(name_lower):
            return jsonify(result=[])

        blueprints = Item.query.filter(
            Item.name.ilike('%' + name_lower + '%'),
            Item.max_production_limit.isnot(None)
        ).outerjoin(
            ActivityProduct,
            (
                (Item.id == ActivityProduct.item_id) & (
                    (ActivityProduct.activity == ActivityEnum.INVENTION.id) |
                    (ActivityProduct.activity == ActivityEnum.REACTIONS.id)
                )
            )
        ).options(
            db.contains_eager(Item.activity_products__eager)
        ).order_by(
            Item.name.asc()
        ).all()

        data = []
        for bp in blueprints:
            invention = False
            reaction = False

            # we can't have invention AND reaction
            # at the same time as product.
            if bp.activity_products__eager:
                invention = (
                    bp.activity_products__eager[0].activity ==
                    ActivityEnum.INVENTION.id
                )
                reaction = (
                    bp.activity_products__eager[0].activity ==
                    ActivityEnum.REACTIONS.id
                )

            data.append({
                'id': bp.id,
                'name': bp.name,
                'invention': invention,
                'reaction': reaction,
                'relic': bp.is_ancient_relic(),
            })

        return jsonify(result=data)
    else:
        return 'Cannot call this page directly', 403
Ejemplo n.º 3
0
def blueprint_search(name):
    """
    Return JSON result for a specific search
    name is the request name.
    """
    if request.is_xhr:
        name_lower = name.lower()

        # prevent only % string, to avoid query the full database at once...
        if name_lower == '%' * len(name_lower):
            return jsonify(result=[])

        blueprints = Item.query.filter(
            Item.name.ilike('%' + name_lower + '%'),
            Item.max_production_limit.isnot(None)).outerjoin(
                ActivityProduct,
                ((Item.id == ActivityProduct.item_id) &
                 ((ActivityProduct.activity == ActivityEnum.INVENTION.id) |
                  (ActivityProduct.activity == ActivityEnum.REACTIONS.id))
                 )).options(db.contains_eager(
                     Item.activity_products__eager)).order_by(
                         Item.name.asc()).all()

        data = []
        for bp in blueprints:
            invention = False
            reaction = False

            # we can't have invention AND reaction
            # at the same time as product.
            if bp.activity_products__eager:
                invention = (bp.activity_products__eager[0].activity ==
                             ActivityEnum.INVENTION.id)
                reaction = (bp.activity_products__eager[0].activity ==
                            ActivityEnum.REACTIONS.id)

            data.append({
                'id': bp.id,
                'name': bp.name,
                'invention': invention,
                'reaction': reaction,
                'relic': bp.is_ancient_relic(),
            })

        return jsonify(result=data)
    else:
        return 'Cannot call this page directly', 403
Ejemplo n.º 4
0
def search():
    """ Display the blueprint search page """
    blueprints = []
    has_corp_bp = False

    if current_user.is_authenticated:
        blueprints = Blueprint.query.join(User, Item).filter(
            (
                (Blueprint.character_id == current_user.character_id) |
                (
                    (Blueprint.character_id == User.character_id) &
                    (User.main_character_id == current_user.character_id)
                )
            ),
        ).outerjoin(
            ActivityProduct,
            (Blueprint.item_id == ActivityProduct.item_id) & (
                (ActivityProduct.activity == ActivityEnum.INVENTION.id) |
                (ActivityProduct.activity == ActivityEnum.REACTIONS.id)
            )
        ).options(
            db.contains_eager(Blueprint.item)
            .contains_eager(Item.activity_products__eager)
        ).order_by(
            Blueprint.corporation.asc(),
            Blueprint.original.asc(),
            Item.name.asc(),
        ).all()

        # take the latest blueprint (as corp bp are at the end)
        # and check if it's a corp bp.
        if blueprints:
            has_corp_bp = blueprints[-1].corporation

    return render_template('blueprint/search.html', ** {
        'blueprints': blueprints,
        'has_corp_bp': has_corp_bp,
    })
Ejemplo n.º 5
0
def blueprint_search(name):
    """
    Return JSON result for a specific search
    name is the request name.
    """
    if request.is_xhr:
        name_lower = name.lower()

        # prevent only % string, to avoid query the full database at once...
        if name_lower == '%' * len(name_lower):
            return jsonify(result=[])

        cache_key = 'blueprint:search:%s' % (name_lower.replace(" ", ""),)

        data = cache.get(cache_key)
        if data is None:
            blueprints = Item.query.filter(
                Item.name.ilike('%' + name_lower + '%'),
                Item.max_production_limit.isnot(None)
            ).outerjoin(
                ActivityProduct,
                (
                    (Item.id == ActivityProduct.item_id) & (
                        (ActivityProduct.activity == Activity.INVENTION) |
                        (ActivityProduct.activity == Activity.REACTIONS)
                    )
                )
            ).options(
                db.contains_eager(Item.activity_products__eager)
            ).order_by(
                Item.name.asc()
            ).all()

            data = []
            for bp in blueprints:
                invention = False
                reaction = False

                # we can't have invention AND reaction
                # at the same time as product.
                if bp.activity_products__eager:
                    invention = (
                        bp.activity_products__eager[0].activity ==
                        Activity.INVENTION
                    )
                    reaction = (
                        bp.activity_products__eager[0].activity ==
                        Activity.REACTIONS
                    )

                data.append({
                    'id': bp.id,
                    'name': bp.name,
                    'invention': invention,
                    'reaction': reaction
                })

            # cache for 7 day as it does not change that often
            cache.set(cache_key, json.dumps(data), 24 * 3600 * 7)

        else:
            data = json.loads(data)

        return jsonify(result=data)
    else:
        return 'Cannot call this page directly', 403