forked from cesar-david-quiros-sierra/ISIS1225-SampleMVC
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontroller.py
More file actions
89 lines (77 loc) · 2.43 KB
/
controller.py
File metadata and controls
89 lines (77 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
"""
* Copyright 2020, Departamento de sistemas y Computación,
* Universidad de Los Andes
*
*
* Desarrolado para el curso ISIS1225 - Estructuras de Datos y Algoritmos
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along withthis program. If not, see <http://www.gnu.org/licenses/>.
*
* Contribuciones:
*
* Dario Correal - Version inicial
* Santiago Arteaga - Otras versiones
"""
import config as cf
import model
import csv
import os
"""
El controlador se encarga de mediar entre la vista y el modelo.
"""
def newController():
"""
Crea una instancia del modelo
"""
control = {
"model": None
}
control["model"] = model.newCatalog()
return control
# Funciones para la carga de datos
def loadBooks(control, filename):
"""
Carga los libros del archivo. Por cada libro se toman sus autores y por
cada uno de ellos, se crea en la lista de autores, a dicho autor y una
referencia al libro que se esta procesando.
"""
catalog = control.get("model")
booksfile = os.path.join(cf.data_dir, filename)
catalog = model.addBooks(catalog, booksfile)
if model.emptyBooks(catalog):
return None
else:
return model.bookSize(catalog)
def loadTags(control, filename):
"""
Carga todos los tags del archivo y los agrega a la lista de tags
"""
catalog = control.get("model")
tagsfile = os.path.join(cf.data_dir, filename)
input_file = csv.DictReader(open(tagsfile, encoding="utf-8"))
catalog = model.createTagList(catalog)
for tag in input_file:
model.addTag(catalog, tag)
if model.emptyTags(catalog):
return None
else:
return model.tagSize(catalog)
def loadBooksTags(control, filename):
"""
Carga los tags de los libros del archivo y los agrega a la lista
de tags. Siga el mismo procedimiento que en la carga de libros.
"""
# TODO: Mods Lab 1, integrar vista y modelo
pass