refacto: rename variables
This commit is contained in:
parent
917b67484c
commit
d368b59cba
2 changed files with 39 additions and 37 deletions
|
@ -67,7 +67,7 @@ class FilmInterface():
|
|||
conn.close()
|
||||
|
||||
def selectFilm(self):
|
||||
f.printAll()
|
||||
f.list_all()
|
||||
rep = input("Entrez le code identifiant du film\n")
|
||||
try:
|
||||
self.filmCharge = f(rep)
|
||||
|
@ -77,7 +77,7 @@ class FilmInterface():
|
|||
self.menu()
|
||||
|
||||
def newFilm(self):
|
||||
self.filmCharge = f.newFilm()
|
||||
self.filmCharge = f.new_film()
|
||||
|
||||
def afficherFilm(self):
|
||||
if self.filmCharge:
|
||||
|
@ -124,9 +124,9 @@ class FilmInterface():
|
|||
print(
|
||||
"La valeur actuelle du champ %s est %s.\nVeuillez entrer la nouvelle valeur pour ce champ (et -1 si vous ne souhaitez finalement pas modifier le champ)\n" % (
|
||||
nomAttr, self.filmCharge.__getattr__(nomAttr)))
|
||||
newValue = f.makeListActors()
|
||||
elif nomAttr == "durée":
|
||||
self.filmCharge.__setattr__(nomAttr, f.input_duree())
|
||||
newValue = f.make_actors_list()
|
||||
elif nomAttr == "duree":
|
||||
newValue = f.input_duration()
|
||||
elif nomAttr == "couleur":
|
||||
newValue = f.input_color()
|
||||
elif nomAttr == "date":
|
||||
|
|
|
@ -17,12 +17,14 @@ import sqlite3
|
|||
from config import db_path
|
||||
from datetime import date
|
||||
import locale
|
||||
|
||||
locale.setlocale(locale.LC_ALL, 'fr_FR.utf8')
|
||||
|
||||
#def adapt_datetime(ts):
|
||||
|
||||
# def adapt_datetime(ts):
|
||||
# return time.mktime(ts.timetuple())
|
||||
|
||||
#sqlite3.register_adapter(datetime.date, adapt_datetime)
|
||||
# sqlite3.register_adapter(datetime.date, adapt_datetime)
|
||||
|
||||
class filmSQ():
|
||||
|
||||
|
@ -36,7 +38,7 @@ class filmSQ():
|
|||
c = conn.cursor()
|
||||
|
||||
try:
|
||||
c.execute("""SELECT i FROM films WHERE idN = ?""",(dic,))
|
||||
c.execute("""SELECT i FROM films WHERE idN = ?""", (dic,))
|
||||
r = c.fetchone()
|
||||
self.i = r[0]
|
||||
|
||||
|
@ -57,7 +59,7 @@ class filmSQ():
|
|||
c = conn.cursor()
|
||||
|
||||
try:
|
||||
c.execute("""SELECT idN FROM films WHERE i = ?""",(dic,))
|
||||
c.execute("""SELECT idN FROM films WHERE i = ?""", (dic,))
|
||||
r = c.fetchone()
|
||||
self.idN = r[0]
|
||||
|
||||
|
@ -75,9 +77,11 @@ class filmSQ():
|
|||
c = conn.cursor()
|
||||
|
||||
try:
|
||||
c.execute('INSERT INTO films VALUES (:i, :idN, :date, :nom, :realisateur, :duree, :synopsis, :pays, :annee, :youtube, :couleur, :image, :formatCopie, :langST)', dic)
|
||||
c.execute(
|
||||
'INSERT INTO films VALUES (:i, :idN, :date, :nom, :realisateur, :duree, :synopsis, :pays, :annee, :youtube, :couleur, :image, :formatCopie, :langST)',
|
||||
dic)
|
||||
|
||||
acteursToSq = [{'idFilm' : dic['i'], 'acteur' : a} for a in dic['acteurs']]
|
||||
acteursToSq = [{'idFilm': dic['i'], 'acteur': a} for a in dic['acteurs']]
|
||||
c.executemany('INSERT INTO acteurs VALUES (NULL, :idFilm, :acteur)', acteursToSq)
|
||||
|
||||
conn.commit()
|
||||
|
@ -86,25 +90,25 @@ class filmSQ():
|
|||
raise e
|
||||
finally:
|
||||
conn.close()
|
||||
#id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT [PRIMARY KEY]
|
||||
# id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT [PRIMARY KEY]
|
||||
|
||||
self.__setattr__('idN', dic['idN'])
|
||||
|
||||
def __setattr__(self, nom_attr, val_attr):
|
||||
if nom_attr == 'idN':
|
||||
object.__setattr__(self, 'idN', val_attr)
|
||||
def __setattr__(self, attr_name, attr_value):
|
||||
if attr_name == 'idN':
|
||||
object.__setattr__(self, 'idN', attr_value)
|
||||
else:
|
||||
try:
|
||||
conn = sqlite3.connect(db_path)
|
||||
conn.row_factory = sqlite3.Row
|
||||
c = conn.cursor()
|
||||
|
||||
if nom_attr == 'acteurs':
|
||||
if attr_name == 'acteurs':
|
||||
c.execute("""DELETE FROM acteurs WHERE iFilm =?""", (self.i,))
|
||||
acteursToSq = [{'iFilm' : self.i, 'acteur' : a} for a in val_attr]
|
||||
acteursToSq = [{'iFilm': self.i, 'acteur': a} for a in attr_value]
|
||||
c.executemany('INSERT INTO acteurs VALUES (NULL, :iFilm, :acteur)', acteursToSq)
|
||||
else:
|
||||
c.execute('UPDATE films SET %s = ? WHERE idN = ?' % nom_attr, (val_attr, self.idN))
|
||||
c.execute('UPDATE films SET %s = ? WHERE idN = ?' % attr_name, (attr_value, self.idN))
|
||||
conn.commit()
|
||||
except Exception as e:
|
||||
conn.rollback()
|
||||
|
@ -112,17 +116,17 @@ class filmSQ():
|
|||
finally:
|
||||
conn.close()
|
||||
|
||||
def __getattr__(self, nom):
|
||||
def __getattr__(self, attr_name):
|
||||
conn = sqlite3.connect(db_path, detect_types=sqlite3.PARSE_DECLTYPES)
|
||||
conn.row_factory = sqlite3.Row
|
||||
c = conn.cursor()
|
||||
try:
|
||||
if nom == 'acteurs':
|
||||
if attr_name == 'acteurs':
|
||||
c.execute("""SELECT name FROM acteurs WHERE iFilm=?""", (self.i,))
|
||||
r = c.fetchall()
|
||||
res = [a[0] for a in r]
|
||||
else:
|
||||
c.execute("""SELECT %s FROM films WHERE idN=:idN""" % nom, {"idN":self.idN})
|
||||
c.execute("""SELECT %s FROM films WHERE idN=:idN""" % attr_name, {"idN": self.idN})
|
||||
r = c.fetchone()
|
||||
res = r[0]
|
||||
conn.commit()
|
||||
|
@ -138,7 +142,7 @@ class filmSQ():
|
|||
def __str__(self):
|
||||
try:
|
||||
conn = sqlite3.connect(db_path)
|
||||
#conn.row_factory = sqlite3.Row
|
||||
# conn.row_factory = sqlite3.Row
|
||||
c = conn.cursor()
|
||||
c.execute('SELECT idN, nom, date FROM films WHERE idN = ?', (self.idN))
|
||||
r = c.fetchone()
|
||||
|
@ -152,7 +156,7 @@ class filmSQ():
|
|||
|
||||
return s
|
||||
|
||||
def maxId():
|
||||
def max_id():
|
||||
try:
|
||||
conn = sqlite3.connect(db_path)
|
||||
|
||||
|
@ -168,7 +172,7 @@ class filmSQ():
|
|||
|
||||
return r[0]
|
||||
|
||||
def printAll():
|
||||
def list_all():
|
||||
try:
|
||||
conn = sqlite3.connect(db_path)
|
||||
|
||||
|
@ -185,12 +189,13 @@ class filmSQ():
|
|||
conn.close()
|
||||
pass
|
||||
|
||||
def makeListActors():
|
||||
def make_actors_list():
|
||||
l = []
|
||||
new = input("Entrez le nom des acteurs en appuyant sur Entrée entre chaque. Pour terminer, appuyer sur Entrée avec une ligne vide.\n")
|
||||
new = input(
|
||||
"Entrez le nom des acteurs en appuyant sur Entrée entre chaque. Pour terminer, appuyer sur Entrée avec une ligne vide.\n")
|
||||
if (new == -1):
|
||||
return -1
|
||||
while(new != ""):
|
||||
while (new != ""):
|
||||
l += [new]
|
||||
new = input()
|
||||
pass
|
||||
|
@ -208,7 +213,7 @@ class filmSQ():
|
|||
print("Veuillez entrer la date au format JJ/MM/AAA")
|
||||
return res
|
||||
|
||||
def input_duree():
|
||||
def input_duration():
|
||||
ok = False
|
||||
while not ok:
|
||||
try:
|
||||
|
@ -232,29 +237,27 @@ class filmSQ():
|
|||
ok = True
|
||||
return res
|
||||
|
||||
|
||||
def newFilm():
|
||||
def new_film():
|
||||
"""Interface d'ajout d'un nouveau film"""
|
||||
dic = {}
|
||||
i = filmSQ.maxId()
|
||||
i = filmSQ.max_id()
|
||||
ok = False
|
||||
dic['i'] = i+1
|
||||
dic['i'] = i + 1
|
||||
dic['idN'] = input("identifiant du film ? ")
|
||||
dic['date'] = filmSQ.input_date()
|
||||
dic['nom'] = input("titre ? ")
|
||||
dic['realisateur'] = input("realisateur ? ")
|
||||
dic['acteurs'] = filmSQ.makeListActors()
|
||||
dic['acteurs'] = filmSQ.make_actors_list()
|
||||
dic['synopsis'] = input("Donnez ici un synopsis rapide du film ")
|
||||
dic['pays'] = input("pays de diffusion du film ? ")
|
||||
dic['annee'] = input("année de sortie du film (format AAAA) ? ")
|
||||
dic['duree'] = filmSQ.input_duree();
|
||||
dic['duree'] = filmSQ.input_duration();
|
||||
dic['youtube'] = input("adresse youtube de la bande-annonce ? ")
|
||||
dic['image'] = input("url d'une affiche du film ? ")
|
||||
dic['couleur'] = filmSQ.input_color();
|
||||
dic['formatCopie'] = input("format de la copie ? ")
|
||||
dic['langST'] = input("langue et sous-titre : VF/VOSTFR ? ")
|
||||
|
||||
|
||||
seance = filmSQ(dic)
|
||||
return seance
|
||||
|
||||
|
@ -262,8 +265,7 @@ class filmSQ():
|
|||
def strListe(liste):
|
||||
res = ""
|
||||
for l in liste[:-1]:
|
||||
res += l +', '
|
||||
res += l + ', '
|
||||
if liste != []:
|
||||
res += liste[-1]
|
||||
return res
|
||||
|
||||
|
|
Loading…
Reference in a new issue