forked from ShenghaoHuang/ZipScrumForum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
70 lines (62 loc) · 1.92 KB
/
setup.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
from database import *
import os
def init_site():
admin = add_subforum("News", "Announcements")
add_subforum("Announcements", "View forum announcements here",admin)
add_subforum("Bugs", "Report bugs with the forum here", admin)
add_subforum("Learn to Code", "Share resources, tips, and tricks")
add_subforum("Lab Help", "Ask questions related to labs")
add_subforum("Alumni", "Zip Code alumni networking")
add_subforum("Favorite", "Bookmarks")
def add_subforum(title, description, parent=None):
sub = Subforum(title, description)
if parent:
for subforum in parent.subforums:
if subforum.title == title:
return
parent.subforums.append(sub)
else:
subforums = Subforum.query.filter(Subforum.parent_id == None).all()
for subforum in subforums:
if subforum.title == title:
return
db.session.add(sub)
print("adding " + title)
db.session.commit()
return sub
def interpret_site_value(subforumstr):
segments = subforumstr.split(':')
identifier = segments[0]
description = segments[1]
parents = []
hasparents = False
while('.' in identifier):
hasparents = True
dotindex = identifier.index('.')
parents.append(identifier[0:dotindex])
identifier = identifier[dotindex + 1:]
if hasparents:
directparent = subforum_from_parent_array(parents)
if directparent is None:
print(identifier + " could not find parents")
else:
add_subforum(identifier, description, directparent)
else:
add_subforum(identifier, description)
def subforum_from_parent_array(parents):
subforums = Subforum.query.filter(Subforum.parent_id == None).all()
top_parent = parents[0]
parents = parents[1::]
for subforum in subforums:
if subforum.title == top_parent:
cur = subforum
for parent in parents:
for child in subforum.subforums:
if child.title == parent:
cur = child
return cur
return None
def setup():
siteconfig = open('./config/subforums', 'r')
for value in siteconfig:
interpret_site_value(value)