def on_post(self): try: title = self.get_argument("title-inp", None) s = Section() s.title = title s.save() except Exception, e: print e
def on_post(self): try: ordering = self.get_argument("ordering", None) data = tornado.escape.json_decode(ordering) new_ordering = [] for item in data.items(): new_ordering.append(item) sorted_order = sorted(new_ordering, key=lambda tup: tup[1]) l = len(sorted_order) #We iterate through the preferences and we update the next #and previous nugget for each nugget. The first one has the last #one as its previous and the last one has next the first one. for i, nugget_tuple in enumerate(sorted_order): n = Nugget.objects(id=nugget_tuple[0]).get() if i==0: #Update the first nugget of this section s = Section.objects(id=n.section).get() s.first_nugget = str(n.id) s.save() n.next_nugget = sorted_order[i+1][0] if i<l-1 else sorted_order[0][0] n.previous_nugget = sorted_order[i-1][0] n.save() except Exception, e: print e
def on_get(self): try: sid = self.get_argument("sid", None) cursor = self.get_argument("cursor", None) section = Section.objects(id=sid).get() # #Update user's cursor self.current_user.update_section_cursor(sid, len(section.nuggets), int(cursor)) except Exception, e: self.log.warning("Error while getting next nugget: " + str(e))
def on_get(self): try: sid = self.get_argument("sid") #Get section object section = Section.objects(id=sid).get() if self.current_user.get_section_cursor(sid) == len(section.nuggets)-1: cursor=0 else: cursor = self.current_user.get_section_cursor(sid) self.base_render("learn/learn-content.html", section=section, cursor=cursor, section_length=len(section.nuggets)) except Exception, e: self.log.warning(str(e))
def on_post(self): try: title = self.get_argument("title-inp", None) content = self.get_argument("content-inp", None) img_name = self.get_argument("img-name-inp", None) sid = self.get_argument("section", None) s = Section.objects(id=sid).get() n = Nugget() n.title = title n.content = content n.img = img_name s.nuggets.append(n) s.save() except Exception, e: print e
def get_overall_progress(self): try: number_nuggets = 0 #When the traffic signs sections is split into section delete this and #uncomment the next line: #sections = Section.objects() sections = Section.objects(title__ne="Traffic Signs") for section in sections: number_nuggets += len(section.nuggets) completed_nuggets = 0 for cursor in self.cursors.values(): completed_nuggets += cursor + 1 #We need to add one cz the cursors start at 0 return 100*completed_nuggets/number_nuggets except Exception, e: print e
def get_overall_progress(self): try: number_nuggets = 0 #When the traffic signs sections is split into section delete this and #uncomment the next line: #sections = Section.objects() sections = Section.objects(title__ne="Traffic Signs") for section in sections: number_nuggets += len(section.nuggets) completed_nuggets = 0 for cursor in self.cursors.values(): completed_nuggets += cursor + 1 #We need to add one cz the cursors start at 0 return 100 * completed_nuggets / number_nuggets except Exception, e: print e
def on_get(self): sid = self.get_argument("sid", None) cursor = self.get_argument("cursor", None) section = Section.objects(id=sid).get() new_cursor = int(cursor)-1 return (section, new_cursor)