forked from khushbu14/webportal
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpopulate_wb.py
More file actions
208 lines (147 loc) · 5.8 KB
/
populate_wb.py
File metadata and controls
208 lines (147 loc) · 5.8 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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
import os
import sys
#import store
import contributors_list
import reviewers_list
import subject_list
import class_list
import comment_list
import language_list
def populate_users():
"""Populate Contributors."""
# Admin
os.system("python manage.py syncdb --noinput")
os.system("python manage.py createsuperuser --username=admin --email=admin@example.com")
for u in contributors_list.users:
# Normal users
print "Adding user: %s" % u['USERNAME']
u['USERNAME'] = add_user(u['USERNAME'],
u['FIRSTNAME'],
u['LASTNAME'],
u['EMAIL'],
u['PASSWORD'],)
add_contributor(user=u['USERNAME'],
contact=u['CONTACT'],
picture=u['PHOTO'],
validation_docs=u['validation_docs'])
for u in reviewers_list.users:
# Normal users
print "Adding user: %s" % u['USERNAME']
u['USERNAME'] = add_user(u['USERNAME'],
u['FIRSTNAME'],
u['LASTNAME'],
u['EMAIL'],
u['PASSWORD'],)
add_reviewer(user=u['USERNAME'],
contact=u['CONTACT'],
picture=u['PHOTO'],)
user_list = User.objects.all()
if user_list:
print "Following user(s) created successfully."
for i in user_list:
print i.username
def populate_class():
for Class in class_list.classes:
add_Class( class_number=Class['class_number'] , remark=Class['remark'])
def populate_language():
for Language in language_list.languages:
add_language(language=Language['language'])
def populate_subject():
for Subject in subject_list.subjects:
print "Adding Topic: %s has contributors: %s" % (Subject['topic'], Subject['contributor'])
usr_instance = User.objects.get(username=Subject['contributor'])
contributor_instance = Contributor.objects.get(user=usr_instance)
class_num_instance = Class.objects.get(class_number=Subject['class'])
lang_instance = Language.objects.get(language=Subject['language'])
add_sub(
topic=Subject['topic'],
name=Subject['name'],
contributor=contributor_instance,
class_number=class_num_instance,
language=lang_instance,
summary=Subject['summary'],
)
def populate_comments():
for Comment in comment_list.comment:
print "Adding Comment: %s has Reviewer: %s" % (Comment['comment'], Comment['user'])
usr_instance = User.objects.get(username=Comment['user'])
reviewer_instance = Reviewer.objects.get(user=usr_instance)
sub_instance = Subject.objects.filter(name=Comment['subject'])
for subjec in sub_instance:
add_comment(
subject=subjec,
user=reviewer_instance,
comment=Comment['comment'],
submit_date=Comment['submit_date'])
def populate_faq():
"""Populate FAQs.
"""
print "Populating FAQ"
q1 = add_faq(
question="I have forgotten the pattern set by me, how can I login to Aakash tablet?",
answer="""
1. Foremost make sure that you USB debugging is enabled.
2. Connect your tablet to the computer.
For Window User.
3. Go to the Start option. Open command prompt. Type cmd and press enter.
4. A window will pop up with a C: prompt.
Ex :- C:\Users\user>
5. Type the following commands
C:\Users\user>adb shell
sh-3.2# rm/data/system/gesture.key
rm/data/system/gesture.key
sh-3.2#
Once this is done, one has to restart/reboot their tablet. Now
the tablet is ready to use.
For Ubuntu User.
6. Go to the terminal.
7. Then go to the folder where adb is installed.
8. Repeat the commands from step number 5.
In addition to the above steps, a link has been provided for
your reference(http://www.youtube.com/watch?v=QYdkgO1KHmk)"""
)
print "FAQ successfully populated"
def add_user(username, first_name, last_name, email, password):
u = User.objects.create_user(username=username, first_name=first_name,
last_name=last_name,
email=email, password=password)
u.is_active=True
u.save()
return u
def add_contributor(user, contact, picture, validation_docs):
up = Contributor(user=user, contact=contact, picture=picture, validation_docs=validation_docs)
up.save()
def add_reviewer(user, contact, picture,):
up = Reviewer(user=user, contact=contact, picture=picture)
up.save()
def add_Class(class_number, remark):
class_no = Class(class_number=class_number, remark=remark)
class_no.save()
def add_language(language):
lang = Language(language=language)
lang.save()
def add_sub(topic, name, contributor, class_number, summary, language):
sub = Subject(topic=topic, name=name, contributor=contributor, class_number=class_number, summary=summary, language=language)
sub.save()
def add_faq(question, answer):
faq = Faq(question=question, answer=answer)
faq.save()
def add_comment(subject, user, comment, submit_date):
com = Comment(subject=subject, user=user, comment=comment, submit_date=submit_date)
com.save()
# start execution here!
if __name__ == '__main__':
print "Starting Webportal population script..."
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'webportal.settings')
from webapp.models import Contributor, Reviewer
from webapp.models import Faq, Language
from webapp.models import Class, Subject, Comment
from django.contrib.auth.models import User
if os.path.exists('webportal.db'):
os.system("rm webportal.db")
populate_users()
populate_class()
populate_language()
populate_subject()
populate_comments()
populate_faq()