def remove(self, a_id): db = openDB() cursor = db.cursor() cursor.execute("DELETE FROM annonce WHERE id='{0}'".format(a_id)) # Transmettre le SQL de type INSERT, UPDATE, DELETE db.commit() cursor.close() db.close() return '<h1>Annonce {0} effacée</h1><p><a href="/admin/annonces">Retour</a></p>'.format(a_id)
def check(): is_member = False db = openDB() c = db.cursor() # Vérifier dans la base de données si l'utilisateur appartient à groupname c.close() db.close() return True
def annonce(self, a_id): db = openDB() cursor = db.cursor() cursor.execute("SELECT * FROM annonce WHERE id='{0}'".format(a_id)) annonce = cursor.fetchone() # prendre une ligne. fetchall() égal à tous les lignes. cursor.close() db.close() if annonce: # Charger et compléter le template HTML return self.env.get_template('annoncesModerateur.html').render(a_id = annonce[0], prix = annonce[7], desc = annonce[6]) else: return '<h1>Erreur, annonce inexistante</h1>'
def modifier(self, a_id): db = openDB() cursor = db.cursor() cursor.execute("SELECT * FROM annonce WHERE id='{0}'".format(a_id)) if modifier: # Charger et compléter le template HTML return # Email utilisateurs et modérateur. Besoin de faire le lien avec la base de données Users. # db.commit() cursor.close() db.close()
def bloquer(self, a_id): db = openDB() cursor = db.cursor() cursor.execute("SELECT * FROM annonce WHERE id='{0}'".format(a_id)) annonce = cursor.fetchone() if annonce: print('bloquer...') #cursor = db.cursor() cursor.execute("UPDATE annonce SET state='blocked' WHERE id='{0}'".format(a_id)) db.commit(); if cursor.rowcount == 1: raise cherrypy.HTTPRedirect('/admin/annonce?a_id=' + a_id) else: return "Erreur"; else: cherrypy.HTTPRedirect('/')
def save(self, **kwargs): if 'type' in kwargs and 'publisher' in kwargs and 'category' in kwargs and 'title' in kwargs: db = openDB() cursor = db.cursor() cursor.execute("INSERT INTO annonce VALUES(NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", (kwargs['type'], kwargs['publisher'], kwargs['category'], '', kwargs['title'], '', 0, 'to_discuss', '', '', '', '', '', '', '', '')) # Enregistrer les insertions. db.commit() if cursor.rowcount == 1: return '<h1>Annonce enregistrée</h1><p><a href="/compte">Aller sur mon compte</a></p>' else: return '<h1>Erreur d\'enregistrement!</h1>' cursor.close() db.close() else: return '<h1>Il manque des paramètres!</h1>'
def annonce(self, a_id): db = openDB() cursor = db.cursor() cursor.execute("SELECT * FROM annonce WHERE id='{0}'".format(a_id)) annonce = cursor.fetchone() # prendre une ligne. fetchall() égal à tous les lignes. cursor.execute("SELECT * FROM picture WHERE a_id='{0}'".format(a_id)) picture = cursor.fetchone() cursor.close() db.close() if annonce: # Charger et compléter le template HTML return self.env.get_template('afficherAnnonce.html').render(image = picture[1], type = annonce[1], auteur = annonce[2], catego = annonce[3], faculty = annonce[4], titre = annonce[5], desc = annonce[6], prix = annonce[7], prixdesc = annonce[8], datepublic = annonce[9], etat = annonce[10]) else: return self.env.get_template('afficherAnnonceErreur.html').render(msg="Erreur, cette annonce n'existe pas")
def save(self, **kwargs): if 'type' in kwargs and 'category' in kwargs and 'title' in kwargs: db = openDB() cursor = db.cursor() cursor.execute("INSERT INTO annonce VALUES(NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?)", (kwargs['type'], kwargs['category'], kwargs['title'], '', '', '', '', '', '', '', '', '', '', '', '','')) # Enregistrer les insertions. db.commit() if cursor.rowcount == 1: return self.env.get_template('CreerAnnonce.html').render(msg = "Annonce enregistrée !") #TODO : bouton aller sur mon compte --> <a href="/compte">Aller sur mon compte</a></p>' else: #TODO : afficher le msg à la fin return self.env.get_template('CreerAnnonce.html').render(msg = "Erreur d'enregistrement !") cursor.close() db.close() else: return self.env.get_template('CreerAnnonce.html').render(msg = "Il manque des paramètres... Réessayez")
def login(self, user_name=None, password=None): # Charger et compléter le template HTML if user_name and password: print(cherrypy.url()) # verify login db = openDB() cursor = db.cursor() print("SELECT * FROM user WHERE username='******' AND password='******'".format(user_name, password)) cursor.execute("SELECT * FROM user WHERE username='******' AND password='******'".format(user_name, password)) user = cursor.fetchone() # prendre une ligne. fetchall() égal à tous les lignes. cursor.close() db.close() if user: # after login cherrypy.session[SESSION_KEY] = cherrypy.request.login = user_name raise cherrypy.HTTPRedirect("/compte") else: return self.env.get_template('login.html').render(msg = "login invalide!") else: return self.env.get_template('login.html').render(msg = "entrez votre ...")
def annoncesArchives(self, user=None): if user: db = openDB() cursor = db.cursor() # Annonces cursor.execute("SELECT * FROM annonce AS a INNER JOIN category AS c USING (id) WHERE publisher='{0}'AND a.state = 'archive'".format(user)) annonces_user = cursor.fetchall() # prendre tous les annonces # Pictures pictures = {} for a in annonces_user: cursor.execute("SELECT pict FROM picture WHERE a_id='{0}'".format(a[0])) pictures[a[0]] = cursor.fetchall() cursor.close() db.close() if annonces_user: # Charger et compléter le template HTML return self.env.get_template('mesAnnoncesArchives.html').render(annonces = annonces_user, pics = pictures) else: return "<h1>Erreur, utilisateur inexistant ou vous n'avez pas de droits.</h1>" else: return "<h1>Indiquez l'utilisateur ?user=username</h1>"