Skip to content

Commit 9ec0453

Browse files
committed
working mongo backend... eat it
1 parent 521a254 commit 9ec0453

File tree

8 files changed

+16
-97
lines changed

8 files changed

+16
-97
lines changed

app/contentnode.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
class ContentNode(BaseHandler):
99
def get(self):
10-
node_id = self.get_int_argument("node_id")
10+
node_id = self.get_argument("node_id")
1111
data = database.get("content_node", node_id)
1212
self.api_response(data)
1313

app/ui.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ def get(self):
1212

1313
class TextbookView(BaseHandler):
1414
def get(self):
15-
self.render("textbook_view.html")
15+
node_id = self.get_argument("node_id")
16+
self.render("textbook_view.html", node_id = node_id)
1617

1718
class EditContent(BaseHandler):
1819
def get(self):

app/user.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55

66
class User(BaseHandler):
77
def get(self):
8-
user_id = self.get_int_argument("user_id")
8+
user_id = self.get_argument("user_id")
99
data = database.get("user", user_id)
1010
self.api_response(data)

app/usernode.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55

66
class UserNode(BaseHandler):
77
def get(self):
8-
node_id = self.get_int_argument("node_id")
8+
node_id = self.get_argument("node_id")
99
data = db.get("user_node", node_id)
1010
self.api_response(data)
1111

1212

1313
class UserNodeGraph(BaseHandler):
1414
def get(self):
15-
node_id = self.get_int_argument("node_id")
15+
node_id = self.get_argument("node_id")
1616
max_depth = self.get_int_argument("max_depth", 4)
1717
data = db.get("user_node", node_id)
1818
data = extract_full_graph(data, max_depth-1)

lib/databases/base_sql.py

Lines changed: 0 additions & 83 deletions
This file was deleted.

lib/databases/mongo.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
#!/usr/bin/env python2.7
22

33
import pymongo
4+
from bson.objectid import ObjectId
5+
46
import lib
57

8+
69
_DB = None
710
_CLIENT = None
8-
def init(uri='mongodb://localhost:27017/', test=False):
11+
def init(uri='mongodb://localhost:27017/'):
912
global _DB, _CLIENT
1013
_CLIENT = pymongo.MongoClient(uri)
1114
_DB = _CLIENT["bigdipster"]
@@ -22,20 +25,22 @@ def save(table, data, require_all_fields=True, overwrite_id=False):
2225
def update(table, item_id, data, require_all_fields=True):
2326
global _DB
2427
try:
25-
_DB[table].update({"_id" : item_id}, {"$set" : data})
28+
return _DB[table].update({"_id" : ObjectId(item_id)}, {"$set" : data})
2629
except KeyError:
2730
raise lib.ItemNotFound(item_id)
2831

2932
def get(table, item_id):
3033
global _DB
3134
try:
32-
_DB[table].find_one({"_id" : item_id})
35+
item = _DB[table].find_one({"_id" : ObjectId(item_id)})
36+
item["_id"] = str(item["_id"])
37+
return item
3338
except KeyError:
3439
raise lib.ItemNotFound(item_id)
3540

3641
def exists(table, item_id):
3742
global _DB
3843
try:
39-
_DB[table].find_one({"_id" : item_id})
44+
return _DB[table].find_one({"_id" : ObjectId(item_id)})
4045
except KeyError:
4146
raise lib.ItemNotFound(item_id)

lib/schema_utils.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,12 @@ def check_data(data, fields, require_all_fields=True):
8888

8989
user_node_child_fields = {
9090
"type" : (is_in_list(["user_node", "content_node"]),),
91-
"id" : (schema_or(is_user_node, is_content_node),),
9291
"start_time" : (schema_or(is_none, is_in_range(0)),),
9392
"end_time" : (schema_or(is_none, is_in_range(0)),),
9493
"title" : (is_string, ),
9594
}
9695

9796
user_node_fields = {
98-
"id" : (is_int, ),
9997
"title" : (is_string, ),
10098
"parent" : (schema_or(is_none, is_user_node), ),
10199
"owner" : (is_user, ),
@@ -105,7 +103,6 @@ def check_data(data, fields, require_all_fields=True):
105103
}
106104

107105
user_fields = {
108-
"id" : (is_int, ),
109106
"name" : (is_string, ),
110107
"type" : (is_in_list(['admin', 'teacher', 'student']), ),
111108
"user_nodes" : (is_list, schema_list_check(is_user_node)),
@@ -114,7 +111,6 @@ def check_data(data, fields, require_all_fields=True):
114111
}
115112

116113
content_node_fields = {
117-
'id' : (is_int, ),
118114
'title' : (is_string, ),
119115
'text' : (is_string, ),
120116
'description' : (is_string, ),

templates/textbook_view.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
</head>
1313

1414
<body>
15-
<div class="textbook_root" nodeid="4"></div>
15+
<div class="textbook_root" nodeid="{{ node_id }}"></div>
1616
</body>
1717
<script>
1818
TextbookView.init();

0 commit comments

Comments
 (0)