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,8 +17,10 @@ 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):
|
||||
# return time.mktime(ts.timetuple())
|
||||
|
||||
|
@ -75,7 +77,9 @@ 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']]
|
||||
c.executemany('INSERT INTO acteurs VALUES (NULL, :idFilm, :acteur)', acteursToSq)
|
||||
|
@ -90,21 +94,21 @@ class filmSQ():
|
|||
|
||||
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()
|
||||
|
@ -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,9 +189,10 @@ 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 != ""):
|
||||
|
@ -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['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
|
||||
|
||||
|
@ -266,4 +269,3 @@ def strListe(liste):
|
|||
if liste != []:
|
||||
res += liste[-1]
|
||||
return res
|
||||
|
||||
|
|
Loading…
Reference in a new issue