def search_subject(self): q = self.request.get('q', '') index = search.Index(name='subjectIndex') query = index.search(q) subjects = [Subject.get_by_id(int(result.doc_id)) for result in query.results] subjects = [sub for sub in subjects if sub != None] return self.render('app/search_result.html', subjects=subjects, search_term=q)
def by_subject(self, subject_id): subject = Subject.get_by_id(int(subject_id)) if not subject: return self.abort(404) alerts = [] if self.request.method == 'POST': title = self.request.get('title') desc = self.request.get('desc') if not title: alerts.append('Title field is required!') else: clazz = Class(title=title, description=desc, subject=subject.key) clazz.put() return self.render('app/class_detail.html', cls=clazz) classes = subject.get_classes() return self.render('app/classes.html', classes=classes, alerts=alerts, subject=subject)
def add_event(self): course_id = self.request.get('course', 1) start_date = self.request.get('date') start_time = self.request.get('time') text = self.request.get('text') course = Subject.get_by_id(int(course_id)) evt_date = datetime.datetime.strptime(start_date+start_time, '%Y-%m-%d%H:%M') cal_event = CalendarEvent(profile=self.logged.key, summary=text, start=evt_date) if course: cal_event.course = course.key cal_event.put() event = { 'summary': text, 'start_date': datetime.datetime.strftime(cal_event.start, '%Y-%m-%d %H:%M'), 'id': cal_event.key.id(), 'course': cal_event.course.id() if course else 1, 'course_title': cal_event.course.get().title if course else '', } return self.render_json(event)