def new(lang): page = int(request.args.get('page', 0)) newlog = json.loads(from_log('data/' + lang + '/new', 0, 'end'))['data'] if page <= 0: page = 0 elif page > (len(newlog) - 1) // 5: page = (len(newlog) - 1) // 5 if request.method == "GET": return render_template('new.html', news=newlog[page * 5:page * 5 + 5], page=page, lang=lang) else: name = next_element(lang, 'new') content = { 'icon': base64.b64encode(request.files['icon'].read()).decode(), 'name': request.form['name'], 'date': request.form['date'] } with open('data/' + lang + '/new/' + name, 'w') as f: f.write(json.dumps(content)) update_log('data/' + lang + '/new', name) newlog.insert(0, content) return render_template('new.html', news=newlog[page * 5:page * 5 + 5], page=page, lang=lang)
def delnew(lang): newitem = json.loads(from_log('data/' + lang + '/new', 0, 'end'))['data'][int(request.form['num'])] if str(newitem) == str(request.form['value']): del_log('data/' + lang + '/new', int(request.form['num'])) return redirect(url_for('ui.new', lang=lang)) else: return "Please do not use this API incorrectly"
def delevent(lang): event = json.loads(from_log('data/' + lang + '/events', 0, 'end'))['data'][int(request.form['num'])] if str(event) == str(request.form['value']): del_log('data/' + lang + '/events', int(request.form['num'])) return redirect(url_for("ui.events", lang=lang)) else: return "Please do not use this API incorrectly"
def announcements(lang): page = int(request.args.get('page', 0)) announcementlog = json.loads( from_log('data/' + lang + '/announcements', 0, 'end'))['data'] if page <= 0: page = 0 elif page > (len(announcementlog) - 1) // 5: page = (len(announcementlog) - 1) // 5 return render_template('announcements.html', page=page, names=announcementlog[page * 5:page * 5 + 5], lang=lang)
def events(lang): page = int(request.args.get('page', 0)) eventlog = json.loads(from_log('data/' + lang + '/events', 0, 'end'))['data'] if page <= 0: page = 0 elif page > (len(eventlog) - 1) // 5: page = (len(eventlog) - 1) // 5 return render_template('events.html', events=eventlog[page * 5:page * 5 + 5], lang=lang, page=page)
def ret(lang): start = int(request.args.get('start', 0)) end = request.args.get('end', 'end') if end != 'end': end = int(end) if (os.path.isdir('data/' + lang)): r = make_response(from_log('data/' + lang + '/' + name, start, end)) r.mimetype = 'application/json' return r else: return send_file('data/error.json')
def teachers(lang): teacherdata = json.loads(from_log('data/' + lang + '/teachers', 0, 'end'))['data'] return render_template('teachers.html', lang=lang, teachers=teacherdata)