-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrecreate_dynamic.py
More file actions
185 lines (167 loc) · 5.35 KB
/
recreate_dynamic.py
File metadata and controls
185 lines (167 loc) · 5.35 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# We need to import the DB object
from api.models import *
import os, sys
import importlib
# Don't forget to import your own models!
from api.config import load_config
from api.models import *
# The path is relative to the top of the project.
conf = load_config('api/config.yaml')
# Get the names of the databases we want to work with
sqlite_dbs = [
conf['databases']['dynamic'],
# conf['databases']['static']
]
# Remove them, then create them.
for fname in sqlite_dbs:
try:
print ("Removing {0}.".format(fname))
os.remove(fname)
except OSError:
pass
for fname in sqlite_dbs:
if os.path.isfile(fname):
print ("Database {0} should not exist at this point!".format(fname))
print ("Creating empty SQLite file: {0}.".format(fname))
open(fname, 'a').close()
def class_from_name (module_name, class_name):
# load the module, will raise ImportError if module cannot be loaded
# m = __import__(module_name, globals(), locals(), class_name)
# get the class, will raise AttributeError if class cannot be found
c = getattr(module_name, class_name)
return c
def get_classes (db):
classes = []
for str in conf['models'][db]:
print ("\tCreating model for '{0}'".format(str))
c = class_from_name(sys.modules[__name__], str)
classes.append(c)
return classes
# staticDB.create_tables(get_classes('static'))
dynamicDB.create_tables(get_classes('dynamic'))
# Add some dummy data.
# budget = Budget (
# facultyStipend = 12,
# facultyStipendDesc ="Awesome!",
# miles = 12,
# milesDesc ="Awesome!",
# otherTravel = 12,
# otherTravelDesc ="Awesome!",
# equipment = 12,
# equipmentDesc ="Awesome!",
# materials = 12,
# materialsDesc ="Awesome!",
# other = 12,
# otherDesc ="Awesome!",
# )
# budget.save()
# budget = Budget (
# facultyStipend = 13,
# facultyStipendDesc ="Awesome!",
# miles = 13,
# milesDesc ="Awesome!",
# otherTravel = 13,
# otherTravelDesc ="Awesome!",
# equipment = 13,
# equipmentDesc ="Awesome!",
# materials = 13,
# materialsDesc ="Awesome!",
# other = 13,
# otherDesc ="Awesome!",
# )
# budget.save()
# budget = Budget (
# facultyStipend = 14,
# facultyStipendDesc ="Awesome!",
# miles = 14,
# milesDesc ="Awesome!",
# otherTravel = 14,
# otherTravelDesc ="Awesome!",
# equipment = 14,
# equipmentDesc ="Awesome!",
# materials = 14,
# materialsDesc ="Awesome!",
# other = 14,
# otherDesc ="Awesome!",
# )
# budget.save()
# proj = Projects (
# title = "Super Dooper Robots",
# budgetID = 1,
# duration = 8,
# startDate = "2015-12-15",
# endDate = "2016-02-09",
# year = 2016,
# hasCommunityPartner = True,
# isServiceToCommunity = True,
# humanSubjects = True,
# numberStudents = 3
# )
# proj.save()
# fac = URCPPFaculty (
# pID = proj.pID,
# username = "heggens",
# # Possible values: oneyr, twoyr, threeToFiveyr, sixToTenyr, elevenPlus
# yearsFunded = "{oneyr:1,twoyr:1,threeToFiveyr:1,sixToTenyr:1,elevenPlus:1}",
# relatedFunding = "I got big bucks and I cannot tell untruths.",
# programID = 1,
# )
# fac.save()
# proj = Projects (
# title = "Super Dooper Robots version2",
# budgetID = 1,
# duration = 8,
# startDate = "2016-12-15",
# endDate = "2017-02-09",
# year = 2017,
# hasCommunityPartner = True,
# isServiceToCommunity = True,
# humanSubjects = True,
# numberStudents = 3
# )
# proj.save()
# fac = URCPPFaculty (
# pID = proj.pID,
# username = "nakazawam",
# # Possible values: oneyr, twoyr, threeToFiveyr, sixToTenyr, elevenPlus
# yearsFunded = "{oneyr:1,twoyr:1,threeToFiveyr:1,sixToTenyr:1,elevenPlus:1}",
# relatedFunding = "I got big bucks and I cannot deceive.",
# programID = 1,
# )
# fac.save()
# proj = Projects (
# title = "Super Dooper Robots version 3",
# budgetID = 1,
# duration = 8,
# startDate = "2017-12-15",
# endDate = "2018-02-09",
# year = 2018,
# hasCommunityPartner = True,
# isServiceToCommunity = True,
# humanSubjects = True,
# numberStudents = 3
# )
# proj.save()
# collab = Collaborators (
# pID = proj.pID,
# username = "heggens"
# )
# collab.save()
# fac = URCPPFaculty (
# pID = proj.pID,
# username = "jadudm",
# # Possible values: oneyr, twoyr, threeToFiveyr, sixToTenyr, elevenPlus
# yearsFunded = "{oneyr:1,twoyr:1,threeToFiveyr:1,sixToTenyr:1,elevenPlus:1}",
# relatedFunding = "I got big bucks and I cannot lie.",
# programID = 1,
# )
# fac.save()
params = Parameters(
year = 2016,
appOpenDate = "2015-12-15",
appCloseDate = "2016-01-31",
mileageRate = 0.52,
laborRate = 8.00,
isCurrentParameter = True
)
params.save()