-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpopulation_script.py
332 lines (296 loc) · 12.7 KB
/
population_script.py
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE',
'Team7DWebApp.settings')
import django
django.setup()
from designmytee.models import Designer, Submission, Competition, Support_Request, ItemVideo
from django.contrib.auth.models import User
# Below populate function is used to generate a series of database entries that can be used to populate the database of the web app.
# It creates entries for all fields, including: Designer, Submission, Competition, SupportRequest and ItemVideo models
# Note that the populate function is also used for generating entries for tests in tests.py
def populate():
# Below dictionaries store the information that will be passed into functions to generate sample data for the database
python_Designers = [
{'first_name': 'John',
'last_name': 'Thomas',
'username': 'John212',
'password':'badPassword123',
'email':'[email protected]',
'participations':52,
'picture': 'profile_images/profile_1.jpg',
'wins': 22},
{'first_name': 'Simon',
'last_name': 'Peterson',
'username': 'Simon1212',
'password':'goodPassword-12345',
'email':'[email protected]',
'participations':9,
'wins': 2},
{'first_name': 'Malinda',
'last_name': 'Robberts',
'username': 'boom673',
'password':'password',
'participations': 321,
'picture': 'profile_images/profile_3.jpg',
'email':'[email protected]'},
{'first_name': 'Sven',
'last_name': 'Robberts',
'username': 'Ö7',
'password':'WhereAmI',
'email':'Ö@fakemail.com',
'participations':812,
'wins': 111},
{'first_name': 'Paul',
'last_name': 'Byron',
'username': 'PaulJog',
'password':'Test1234',
'email':'[email protected]',
'participations':221,
'wins': 32},
{'first_name': 'Tim',
'last_name': 'Thomas',
'username': 'timtom',
'password':'GoodPassword_99',
'email':'[email protected]',
'participations':88,},
{'first_name': 'Userson',
'last_name': 'Samson',
'username': 'user444',
'password':'testpassword',
'email':'[email protected]',
'participations':3,
'wins': 2},
{'first_name': 'Phil',
'last_name': 'Pjyotr',
'username': 'designer234',
'password':'pleaseDontSteal',
'email':'[email protected]',
'participations':2212,
'wins': 1111},
]
python_Hosts = [
{'first_name': 'bob',
'last_name': 'Wilbur',
'username': 'bob1',
'password': 'WindowCleaner',
'email': '[email protected]'},
{'first_name': 'Scott',
'last_name': 'Thomas',
'username': 'hostUser',
'password': 'grapeSoda',
'email': '[email protected]',}
]
python_Competitions = [
{
'competitionDescription': 'Submit your favourite animal picture design!',
'competitionImage': 'competition_images/competition_1.jpg',
'title': "Animals",
'startDate': '2021-04-02',
'endDate': '2021-07-22',
'expiryDate': '2021-08-22'
},
{
'competitionDescription': 'Submit your favourite TV show design!',
'competitionImage': 'competition_images/competition_2.jpg',
'title': "TV shows",
'startDate': '2020-12-23',
'endDate': '2021-01-22',
'expiryDate': '2021-03-30'
},
{
'competitionDescription': 'Submit your favourite video game design!',
'competitionImage': 'competition_images/competition_3.jpg',
'title': "video games",
'startDate': '2021-02-27',
'endDate': '2021-04-3',
'expiryDate': '2021-06-14'
},
{
'competitionDescription': 'Submit your favourite city picture design!',
'competitionImage': 'competition_images/competition_4.jpg',
'title': "Cities",
'startDate': '2021-01-13',
'endDate': '2021-04-01',
'expiryDate': '2021-05-01'
},
{
'competitionDescription': 'Submit your favourite space themed design!',
'competitionImage': 'competition_images/competition_5.jpg',
'title': "Space",
'startDate': '2020-11-03',
'endDate': '2021-02-28',
'expiryDate': '2021-04-02'
},
{
'competitionDescription': 'Submit your favourite country themed design!',
'competitionImage': 'competition_images/competition_6.jpg',
'title': "Countries",
'startDate': '2021-08-23',
'endDate': '2021-09-22',
'expiryDate': '2021-10-22'
}
]
python_Submissions = [
{'votes': 12,
'participant': 'Ö7',
'submissionDescription': 'Its a tiger, imagine a cat but like REALLY big',
'designImage': "submission_images/submission_1_4.jpg",
'competition': 1
},
{'votes': 22,
'participant': 'Simon1212',
'submissionDescription': 'puppy!',
'designImage': "submission_images/submission_1_2.jpg",
'competition': 1
},
{'votes': 1,
'participant': 'boom673',
'submissionDescription': 'Is this google',
'designImage': "submission_images/submission_1_3.jpg",
'competition': 1
},
{'votes': 72,
'participant': 'John212',
'submissionDescription': 'Idk its sitting funny what else do you want',
'designImage': "submission_images/submission_1_1.png",
'competition': 1
},
{'votes': 32,
'participant': 'PaulJog',
'submissionDescription': 'My favourite TV show! made the design myself....',
'designImage': "submission_images/submission_2_5.jpg",
'competition': 2,
'winner': True
},
{'votes': 22,
'participant': 'timtom',
'submissionDescription': 'The best Netflix series! cant wait for the next season!',
'designImage': "submission_images/submission_2_6.png",
'competition': 2,
},
{'votes': 321,
'participant': 'user444',
'submissionDescription': 'Greatest video game character of all time!',
'designImage': "submission_images/submission_3_7.jpg",
'competition': 3
},
{'votes': 222,
'participant': 'designer234',
'submissionDescription': 'The most popular video game of all time! I made this using photoshop',
'designImage': "submission_images/submission_3_8.jpeg",
'competition': 3
},
{'votes': 22,
'participant': 'PaulJog',
'submissionDescription': 'This is my home city! I love it very much',
'designImage': "submission_images/submission_4_5.jpg",
'competition': 4
},
{'votes': 262,
'participant': 'boom673',
'submissionDescription': 'I visited here last year... it was amazing!',
'designImage': "submission_images/submission_4_3.jpg",
'competition': 4,
},
{'votes': 421,
'participant': 'John212',
'submissionDescription': 'I love space! I have always dreamed of visiting the moon!',
'designImage': "submission_images/submission_5_1.jpg",
'competition': 5,
'winner': True
},
{'votes': 174,
'participant': 'timtom',
'submissionDescription': 'FOOD IN SPACE!!!!!!',
'designImage': "submission_images/submission_5_6.jpg",
'competition': 5
},
{'votes': 7,
'participant': 'Simon1212',
'submissionDescription': 'I visited here last year, I would love to go again! it looks lovely on the map!',
'designImage': "submission_images/submission_6_2.jpg",
'competition': 6
},
{'votes': 22,
'participant': 'Ö7',
'submissionDescription': 'Austrailia is great, what a massive country!',
'designImage': "submission_images/submission_6_4.jpg",
'competition': 6
},
]
Feedback_Submissions = [
{'firstName': 'Tim',
'lastName': 'Higgins',
'contactNumber': '07919421023',
'contactEmail': '[email protected]',
'suggestionsOrFeedback' : 'I enjoy using this site, but the site needs better moderation, somebody stole my work!'},
{'firstName': 'Sam',
'lastName': 'Chandler',
'contactNumber': '07911921023',
'contactEmail': '[email protected]',
'suggestionsOrFeedback' : 'It would be nice to have a community spotlight section, maybe with a submission of the week by highest votes?'},
{'firstName': 'Sam',
'lastName': 'John',
'contactNumber': '07817261023',
'contactEmail': '[email protected]',
'suggestionsOrFeedback' : 'I would like to recieve more clarity on whats happening to my data'},
]
Videos = [
{"video": "https://youtu.be/Jds59BJBuw0"}
]
# Below for loops iterate through each entry in the above dictionaries and use the various functions below to generate database entries for each
# item in dictionaries. The database
for Des in python_Designers:
add_Designer( Des.get('username'), Des.get('first_name'), Des.get('last_name'), Des.get('password'), Des.get('email'), Des.get('picture'), Des.get('participations'), Des.get('wins'))
for Hos in python_Hosts:
add_Host(Hos.get('username'), Hos.get('first_name'), Hos.get('last_name'), Hos.get('password'), Hos.get('email'))
for Comp in python_Competitions:
add_Competition(Comp.get('competitionDescription'), Comp.get('competitionImage'), Comp.get('title'), Comp.get('startDate'), Comp.get('endDate'), Comp.get('expiryDate'))
for Sub in python_Submissions:
add_Submission(Sub.get('participant'), Sub.get('submissionDescription'), Sub.get('designImage'), Sub.get('competition'), Sub.get('votes'),Sub.get('winner'))
for Fed in Feedback_Submissions:
add_Feedback(Fed.get('firstName'), Fed.get('lastName'), Fed.get('contactNumber'), Fed.get('contactEmail'), Fed.get('suggestionsOrFeedback'))
for Vid in Videos:
add_videos(Vid.get('video'))
def add_Designer(name, firstName, lastName, password, email, picture=None, participations=0, wins=0):
if wins == None:
wins = 0
if participations == None:
wins = 0
if picture == None:
picture = 'profile_images/base.jpeg'
u = User.objects.create(username=name, email=email, first_name=firstName, last_name=lastName)
u.set_password(password)
u.save()
d = Designer.objects.get_or_create(user=u, picture=picture, participations=participations, wins=wins)[0]
return d
def add_Host(name, firstName, lastName, password, email):
u = User.objects.create(username=name, email=email, first_name=firstName, last_name=lastName, is_superuser=True, is_staff=True)
u.set_password(password)
u.save()
return u
def add_Competition(competitionDescription, competitionImage, title, startDate, endDate, expiryDate):
c = Competition.objects.get_or_create(competitionDescription=competitionDescription, competitionImage=competitionImage, title=title, startDate=startDate, endDate=endDate, expiryDate=expiryDate)[0]
return c
def add_Submission(participant, submissionDescription, designImage, competition, votes=0, winner=False):
if winner == None:
winner = False
if votes == None:
votes = 0
c = Competition.objects.get(id=competition)
d = User.objects.get(username=participant)
s = Submission.objects.get_or_create(votes=votes, participant=d, submissionDescription=submissionDescription, designImage=designImage, competition=c)[0]
s.votes=votes
if winner == True:
Competition.objects.filter(id=competition).update(competitionWinner=s)
return s
def add_Feedback(firstName, lastName, contactNumber, contactEmail, suggestionsOrFeedback):
f = Support_Request.objects.get_or_create(firstName=firstName, lastName=lastName, contactNumber=contactNumber, contactEmail=contactEmail, suggestionsOrFeedback=suggestionsOrFeedback)
return f
def add_videos(video):
v = ItemVideo.objects.get_or_create(video=video)
return v
if __name__ == '__main__':
print('Starting designmytee population script... this may take a second or two...')
populate()
print('Population successful!')