Ejemplo n.º 1
0
def recipes():
    ''' gets all user's recipes from database'''
    form = SearchName()
    recipes = mongo.db.recipes
    all_recipes = recipes.find({'owner': current_user.email})
    tags = get_tags(all_recipes)
    return render_template('pages/recipes.html',
                           recipes=all_recipes,
                           tags=tags,
                           form=form,
                           title="recipes")
Ejemplo n.º 2
0
def informacao(message, user_data):
    response = ''
    tags = h.get_tags(message)

    prods = tags['products']

    for prod in prods:
        p = config.products[prod]
        nome = p['nome']
        desc = p['descricao']
        response += 'Informacoes sobre o %s: \n\n*%s*\n' % (nome, desc)

    return response
Ejemplo n.º 3
0
def entrega(message, user_data):
    # Processa tags
    tags = h.get_tags(message)
    shipping = tags['shipping']

    # Seta tipo de entrega
    user_data['shipping_method'] = shipping

    if shipping == 'self':
        return "Pedido para retirada!"
    elif shipping == 'direct':
        return 'Pedido para entrega!'
    else:
        user_data['shipping_method'] = None
        return "Deseja que seu pedido seja retirado ou entregue?"
Ejemplo n.º 4
0
def search_name():
    ''' performs a case insensitive search for user's recipe documents including searched string '''
    form = SearchName()
    recipes = mongo.db.recipes
    all_recipes = recipes.find({'owner': current_user.email})
    tags = get_tags(all_recipes)
    if form.validate_on_submit():
        recipe_name = request.form.get('name').strip()
        searched = 'name'
        if recipes.count_documents({
                "name": {
                    '$regex': recipe_name,
                    '$options': 'i'
                },
                'owner': current_user.email
        }) > 0:
            search_results = recipes.find({
                "name": {
                    '$regex': recipe_name,
                    '$options': 'i'
                },
                'owner': current_user.email
            })
            return render_template('pages/recipes.html',
                                   recipes=search_results,
                                   tags=tags,
                                   searched=searched,
                                   recipe_name=recipe_name,
                                   form=form,
                                   title="recipes")
        else:
            flash('No results found', "errors")
            return render_template('pages/recipes.html',
                                   recipes=[],
                                   tags=tags,
                                   searched=searched,
                                   recipe_name=recipe_name,
                                   form=form,
                                   title="recipes")
    return render_template('pages/recipes.html',
                           recipes=all_recipes,
                           tags=tags,
                           form=form,
                           title="recipes")
Ejemplo n.º 5
0
def search_tag():
    ''' retrievs all user's recipes with selected tag '''
    form = SearchName()
    recipes = mongo.db.recipes
    all_recipes = recipes.find({'owner': current_user.email})
    tags = get_tags(all_recipes)
    selected_tag = request.args.get('tag')
    searched = 'tag'
    search_results = recipes.find({
        "tags": selected_tag,
        'owner': current_user.email
    })
    return render_template('pages/recipes.html',
                           recipes=search_results,
                           tags=tags,
                           searched=searched,
                           tag=selected_tag,
                           form=form,
                           title="recipes")
Ejemplo n.º 6
0
def text_message(update, context):
    message = update.message.text
    print('Received message: %s' % message)
    intention = predict_action(message)

    actions = {
        'cardapio': cardapio,
        'conta': conta,
        'entrega': entrega,
        'tempo': tempo,
        'bebidas': bebidas,
        'informacao': informacao,
        'pagamento': pagamento,
        'pedido': pedido,
    }

    if intention in actions:
        call = actions[intention]
    else:
        call = nao_entendi

    print('Itention: %s' % intention)
    print(h.get_tags(message))

    user_data = context.user_data

    if 'order' not in user_data:
        user_data['order'] = {}
    if 'payment_method' not in user_data:
        user_data['payment_method'] = ''
    if 'shipping_method' not in user_data:
        user_data['shipping_method'] = ''

    print('Calling intention')
    response = call(message, user_data)
    print('Response: %s' % response)
    update.message.reply_text(response, parse_mode=telegram.ParseMode.MARKDOWN)

    if done(user_data):
        response = finish(user_data)
        update.message.reply_text(response,
                                  parse_mode=telegram.ParseMode.MARKDOWN)
Ejemplo n.º 7
0
def pedido(message, user_data):
    order = user_data['order']
    response = ''
    tags = h.get_tags(message)

    if len(tags['nums']) != len(tags['products']):
        return 'Por favor mencione a quantidade e o produto em seguida!'

    for i in range(len(tags['nums'])):
        quant = tags['nums'][i]
        cod = tags['products'][i]
        nome = config.products[cod]['nome']

        if cod not in order:
            order[cod] = 0

        order[cod] += quant

        response += "*%d* `%s` %s ao seu pedido!\n" % (quant, nome, (
            'adicionado', 'adicionados')[quant > 1])
    response += '\n✅ Deseja mais algo?'
    return response
Ejemplo n.º 8
0
def pagamento(message, user_data):
    response = ''

    # Processa tags da mensagem (e cria "atalho" para tags de pagamento)
    tags = h.get_tags(message)
    pay = tags['payment']

    # Seta tipo de pagamento do pedido
    user_data['payment_method'] = pay

    # Monta resposta dependente do tipo de pagamento
    if pay == 'credit':
        response += 'Enviaremos uma máquina para pagamento com cartão de crédito.'
    elif pay == 'debit':
        response += 'Enviaremos uma máquina para pagamento com cartão de débito.'
    elif pay == 'cash':
        response += 'Seu pedido foi registrado para pagamento em dinheiro.'
    else:
        # Reseta tipo de pagamento
        user_data['payment_method'] = None
        return 'Como voce deseja pagar seu pedido?'

    response += '\n\nDeseja que seu pedido seja entregue ou para retirada?'
    return response
Ejemplo n.º 9
0
def archives(request, tag=None):
    return render_to_response(request, 'ladypenh/archives.html',
                              dict(theme_name=helpers.get_theme(helpers.today()),
                                   articles=helpers.get_articles(helpers.today(), tag),
                                   tags=helpers.get_tags()))