Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,8 @@ pip-log.txt
# sass
static/css
sass/.sass-cache

# virtualenv
biciklo-env/

config.yml
20 changes: 15 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ Système d'inventaire pour l'atelier **Biciklo**.

dépendances
-----------
* Python 2 ou 3
* Python 3
* Paquet `virtualenv` recommandé (`pip install virtualenv`)
* MongoDB
* Ruby
* Paquet `compass`, seulement nécessaire pour regénérer les fichiers css
* [Recherche Babac2](https://github.com/normcyr/recherche_babac2) pour la recherche dans le catalogue de Babac

installation pour le développement
----------------------------------
Expand All @@ -28,7 +29,16 @@ installation pour le développement
$ cd biciklo
$ pip install -e .

4. Lancer l'inventaire:
4. Pour pouvoir utiliser le module de recherche sur le site de Cycle Babac,
entrer ses informations de connexion au site de Babac dans le fichier
`.env.example` et en renommant le fichier pour `.env`, puis en éditant le
fichier `.env` pour refléter les informations de connexion au site de Babac:

$ cd biciklo-env/lib/python3.5/site-packages/recherche_babac2
$ cp .env.example .env
Comment thread
normcyr marked this conversation as resolved.
$ nano .env

5. Lancer l'inventaire:

$ BICIKLO_DEBUG=1 biciklo-inventaire

Expand All @@ -49,16 +59,16 @@ Exemples d'utilisation de cURL pour déboguer l'API HTTP.
### Liste de factures

$ curl -X GET http://0.0.0.0:8888/api/factures

### Liste de membres


$ curl -X GET http://0.0.0.0:8888/api/membres

### Ajout d'un membre

$ curl -X POST --data "prenom=bob&nom=leponge" http://0.0.0.0:8888/api/membres

### Suppression d'un membre

$ curl -X DELETE http://0.0.0.0:8888/api/membres/6
56 changes: 50 additions & 6 deletions biciklo/biciklo.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,29 @@
import json
import os
import time
import re

if python_major == 2:
import httplib
elif python_major == 3:
import http.client as httplib

import http.client as httplib
import pymongo
from bson import json_util

from flask import Flask
from flask import request
from flask import render_template
from flask import url_for
from flask import flash

from wtforms import Form
from wtforms import StringField
from wtforms import validators

from biciklo import db, settings
from recherche_babac2 import recherche_babac2 as rb2

from biciklo import db

app = Flask(__name__)
app.config.from_object(__name__)
app.config['SECRET_KEY'] = os.urandom(24)

# numéro de pièce des abonnements et durées
abonnements = {
Expand Down Expand Up @@ -1048,6 +1054,44 @@ def ObtenirProchainNumeroDeFacture():
else:
return d.factures.find().sort('numero', pymongo.DESCENDING).limit(1)[0]['numero'] + 1

# api recherche_babac
class FormulaireRechercherBabac(Form):
search_text = StringField('Indiquer le nom d\'une pièce pour obtenir son prix chez Cycle Babac: ',
validators=[validators.DataRequired(message='Veuillez entrer un mot'),
validators.Regexp('^[\w0-9 -]+$', message='Veuillez ne pas utiliser de caractères spéciaux.')
])

@app.route("/recherche_babac", methods=['GET', 'POST'])
def RechercheBabac():
"""Effectue une recherche sur le site de Cycle Babac."""
form = FormulaireRechercherBabac(request.form)

if request.method == 'GET':
return render_template('recherche_babac.html', form=form)

if request.method == 'POST':
search_text = request.form['search_text']

if form.validate():
utilisateur_babac, motdepasse_babac = settings.lire_config()

if utilisateur_babac != None or motdepasse_babac != None:
recherche = rb2.BabacSearch(utilisateur_babac, motdepasse_babac)
list_products, loggedin = recherche.do_the_search(search_text)

if loggedin:
return render_template('recherche_babac.html', form=form, list_products=list_products, search_text=search_text)
else:
flash('Le nom d\'utilisateur et/ou le mot de passe pour le site de Cycle Babac est incorrect. Veuillez vérifier vos information de connexion dans le fichier de configuration de l\'application.')
return render_template('recherche_babac.html', form=form)

else:
flash('Veuillez spécifier le nom d\'utilisateur et le mot de passe pour le site de Cycle Babac dans le fichier de configuration de l\'application.')
return render_template('recherche_babac.html', form=form)
else:
flash(form.errors['search_text'][0])
return render_template('recherche_babac.html', form=form)


def main():
if 'BICIKLO_DEBUG' in os.environ:
Expand Down
28 changes: 28 additions & 0 deletions biciklo/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from pathlib import Path
import yaml


def lire_config():

fichier_config = Path.home() / '.config' / 'biciklo' / 'config.yml'

if fichier_config.is_file():

with fichier_config.open(mode='r') as fichier:
info_config = yaml.safe_load(fichier)

utilisateur_babac = info_config['Cycle Babac']['nom utilisateur']
motdepasse_babac = info_config['Cycle Babac']['mot de passe']


else:
with fichier_config.open(mode='w') as fichier:
yaml.dump({'Cycle Babac': {'nom utilisateur': 'BoblEponge', 'mot de passe': 'BasdeBikini'}}, fichier)

utilisateur_babac = None
motdepasse_babac = None

return utilisateur_babac, motdepasse_babac
1 change: 1 addition & 0 deletions biciklo/templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<li><a href="/membres" style="color:white; font-weight:900;">Membres</a></li>
<li><a href="/pieces" style="color:white; font-weight:900;">Pièces</a></li>
<li><a href="/factures" style="color:white; font-weight:900;">Factures</a></li>
<li><a href="/recherche_babac" style="color:white; font-weight:900;">Recherche Babac</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" style="color:white; font-weight:900;">
Admin
Expand Down
61 changes: 61 additions & 0 deletions biciklo/templates/recherche_babac.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{% extends "layout.html" %}

{% block head_extra %}
<style>
p.error_message {
color: red;
font-weight: bold;
}
</style>
{% endblock %}

{% block content %}
<h1>Recherche Babac</h1>

<form action="" method="post">
{{ form.csrf }}
<div class="input text">
{{ form.search_text.label }} {{ form.search_text }}</div>
<div class="input submit">
<input type="submit" value="Submit"></div>
</form>

{% with messages = get_flashed_messages() %}
{% if messages %}
{% for message in messages %}
<p class="error_message">{{ message }}</p>
{% endfor %}
{% endif %}
{% endwith %}

<div>
{% if search_text %}
{% if list_products|length >= 1 %}
<p>{{ list_products|length }} résultats trouvés pour <strong>{{ search_text }}</strong> sur Cycle Babac.</p>
<p>Vous pouvez cliquer sur le numéro de produit pour accéder à la page du produit sur le site de Cycle Babac.</p>
<table id="resultats" class="dataTable" style="display: table;">
<thead>
<tr>
<th data-column="numerobabac" class="sorting" role="columnheader" tabindex="0" aria-controls="pieces" rowspan="1" colspan="1" style="width: 0px;" aria-label="# babac: activate to sort column ascending"># Babac</th>
<th data-column="nom" class="sorting" role="columnheader" tabindex="0" aria-controls="pieces" rowspan="1" colspan="1" style="width: 0px;" aria-label="Nom: activate to sort column ascending">Nom</th>
<th data-column="prix" data-transform="NombreVersPrix" class="sorting" role="columnheader" tabindex="0" aria-controls="pieces" rowspan="1" colspan="1" style="width: 0px;" aria-label="Prix: activate to sort column ascending">Prix</th>
<th data-column="piece-en-stock" class="sorting" role="columnheader" tabindex="0" aria-controls="pieces" rowspan="1" colspan="1" style="width: 0px;" aria-label="En stock: activate to sort column ascending">En stock?</th>
</tr>
</thead>
<tbody>
{% for product in list_products %}
<tr class="odd", style="text-align: center;">
<td style="font-weight: bold;"><a href={{ product['page url']}} target="_blank">{{ product['sku'] }}</a></td>
<td>{{ product['name'] }}</td>
<td>{{ product['price'] }} $</td>
<td>{{ product['stock'] }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
<p class="error_message">Aucun produit trouvé.</p>
{% endif %}
{% endif %}
</div>
{% endblock %}
5 changes: 5 additions & 0 deletions config.yml.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# copier ce fichier vers $HOME/.config/biciklo/
# modifier le nom d'utilisateur et le mot de passe
Cycle Babac:
nom utilisateur: BoblEponge
mot de passe: BasdeBikini
8 changes: 7 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@

setup(
name='Biciklo',
version='1.0',
python_requires='>=3',
version='1.1',
packages=['biciklo'],
entry_points={
'console_scripts': ['biciklo-inventaire=biciklo.biciklo:main'],
},
install_requires=[
'pymongo',
'flask',
'wtforms',
'recherche_babac2',
],
data_files=[
('.', ['config.yml.example'])
],
zip_safe=False,
include_package_data=True,
Expand Down