def post(self): monday = getMonday(getFormDate(self)) books = Books.all().filter("monday = ", monday); weeklyIncome = books.get() if weeklyIncome == None: weeklyIncome = Books() weeklyIncome.monday = monday weeklyIncome.mondayIncome = int(self.request.get("value_0")) weeklyIncome.tuesdayIncome = int(self.request.get("value_1")) weeklyIncome.wednesdayIncome = int(self.request.get("value_2")) weeklyIncome.thursdayIncome = int(self.request.get("value_3")) weeklyIncome.fridayIncome = int(self.request.get("value_4")) weeklyIncome.put() self.redirect(self.URL +"?" + FORM_DAY +"=" + str(monday))
def get(self): if(not isUserAdmin(self)): self.session[LOGIN_NEXT_PAGE_KEY] = self.URL self.redirect("/") return monday = getMonday(getFormDate(self)) prevMonday=monday + datetime.timedelta(days=-7) nextMonday=monday + datetime.timedelta(days=7) days=[] books = Books.all().filter("monday = ", monday); weeklyIncome = books.get() if weeklyIncome == None: weeklyIncome = Books() for i in range(0,5): actualDayObject={} actualDate=monday+datetime.timedelta(days=i) actualDayObject["day"] = dayNames[i] actualDayObject["index"] = i actualDayObject["date"] = actualDate days.append(actualDayObject) days[0]['total'] = weeklyIncome.mondayIncome days[1]['total'] = weeklyIncome.tuesdayIncome days[2]['total'] = weeklyIncome.wednesdayIncome days[3]['total'] = weeklyIncome.thursdayIncome days[4]['total'] = weeklyIncome.fridayIncome template_values={ 'days': days, 'monday':monday, 'prev':prevMonday, 'next':nextMonday } template = jinja_environment.get_template('templates/admin/weeklyFacebookVisits.html') self.printPage("Facebook", template.render(template_values), False, False)
def add_book(name, author, price, img): """ Add a student to the database, given their name, year, and whether they have finished the lab. """ Book_object = Books(title=name, price=price, authorname=author, pic=img) session.add(Book_object) session.commit()
@auth.error_handler def unauthorized(): return make_response(jsonify({'error': 'Unauthorized access'}), 403) @app.errorhandler(400) def bad_request(error): return make_response(jsonify({'error': 'Bad request'}), 400) @app.errorhandler(404) def not_found(error): return make_response(jsonify({'error': 'Not found'}), 404) lib = Books(books) #get all books @app.route('/api/books', methods=['GET']) def get_books(): return jsonify(lib.get_all()), 200 @app.route('/api/books/<int:book_id>', methods=['GET']) def get_book(book_id): return jsonify(lib.get_bookbyid(book_id)), 200 #add book @app.route('/api/books', methods=['POST'])
def get(self): if not isUserAdmin(self): self.session[LOGIN_NEXT_PAGE_KEY] = self.URL self.redirect("/") return today=datetime.date.today() monday = getMonday(today) maxWeeks = 20 weekTotals = [] daysOfWeek = [ {'name':dayNames[0], 'dailyTotals':[]}, {'name':dayNames[1], 'dailyTotals':[]}, {'name':dayNames[2], 'dailyTotals':[]}, {'name':dayNames[3], 'dailyTotals':[]}, {'name':dayNames[4], 'dailyTotals':[]}, ] for i in range(0, maxWeeks): weekTotal = 0 actualMonday = monday + datetime.timedelta(days = (i - maxWeeks + 2) * 7) books = Books.all().filter("monday = ", actualMonday) weeklyIncome = books.get() if weeklyIncome == None: weeklyIncome = Books() daysOfWeek[0]['dailyTotals'].append(weeklyIncome.mondayIncome) weekTotal = weekTotal + weeklyIncome.mondayIncome daysOfWeek[1]['dailyTotals'].append(weeklyIncome.tuesdayIncome) weekTotal = weekTotal + weeklyIncome.tuesdayIncome daysOfWeek[2]['dailyTotals'].append(weeklyIncome.wednesdayIncome) weekTotal = weekTotal + weeklyIncome.wednesdayIncome daysOfWeek[3]['dailyTotals'].append(weeklyIncome.thursdayIncome) weekTotal = weekTotal + weeklyIncome.thursdayIncome daysOfWeek[4]['dailyTotals'].append(weeklyIncome.fridayIncome) weekTotal = weekTotal + weeklyIncome.fridayIncome weekTotalITem = { 'total' : weekTotal, 'monday' : actualMonday } weekTotals.append(weekTotalITem) template_values = { 'weekTotals':weekTotals, 'daysOfWeek' : daysOfWeek } template = jinja_environment.get_template('templates/admin/weeklyFacebookVisitsOverview.html') self.printPage("Facebook", template.render(template_values), False, False)