def journal(): #app.logger.info("message") if request.method == 'POST': #app.logger.info('Post smth') Journal.insert(request.form['student'], request.form['subject'], request.form['mark']) return render_template('journal.html', jrnl = Journal.get_all(), students = Students.get_all(), subjects = Subjects.get_all())
def submit_journal(request): user = request.__user__ todayTime = time.localtime() year = todayTime.tm_year month = todayTime.tm_mon day = todayTime.tm_mday journal = request.POST['journal'] old_journal = yield from find_journal_data(year, month, day, user.name) new_journal = Journal(user_id=user.id, user_name=user.name, content=journal) yield from new_journal.save() if not type(old_journal) == type(None): yield from old_journal.remove() return web.HTTPFound('/')
def stat(): studid = 1 subjid = 1 if request.method == 'POST': studid = int(request.form['student']) subjid = int(request.form['subject']) #app.logger.info("%s %s" %( studavg, subjavg)) #else: studid = subjid =None studavg = Journal.st_avg(studid) subjavg = Journal.disc_avg(subjid) return render_template('stat.html', students = Students.get_all(), subjects = Subjects.get_all(), studavg = studavg, subjavg = subjavg, studid = studid, subjid = subjid)
def find_journal_data(year, month, day, name): ''' 查询某用户某日日志 ''' journal_data = yield from Journal.findAll('user_name=?', [name]) journal = None if len(journal_data) > 0: for data in journal_data: created_date = time.localtime(data.created_at) if year == created_date.tm_year and month == created_date.tm_mon and day == created_date.tm_mday: journal = data return journal
def create_journal_entry(user_id, entry_name, entry_details, created_at, updated_at): """Create and return a new journal entry""" journal = Journal( user_id=user_id, entry_name=entry_name, entry_details=entry_details, created_at=created_at, updated_at=updated_at, ) db.session.add(journal) db.session.commit() return journal
session.add(event) session.commit() with open('journals_shot.tsv', encoding='utf8') as journal: journal_columns = journal.readline().split() for line in journal: line = line.strip().split('\t') journal = dict(zip(journal_columns, line)) if (re.compile('\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{1,6}').match( journal['eventTime'])): journal['eventTime'] = datetime.datetime.strptime( journal['eventTime'], '%Y-%m-%d %H:%M:%S.%f') elif (re.compile('\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}').match( journal['eventTime'])): journal['eventTime'] = datetime.datetime.strptime( journal['eventTime'], '%Y-%m-%d %H:%M:%S') hit = Journal(id=journal['id'], user_id=journal['userId'], event_time=journal['eventTime'], event_code=journal['eventCode'], content=json.loads(journal['content'].strip('"').replace( '""', '"')), additional=json.loads( journal['additional'].strip('"').replace('""', '"'))) if session.query(Journal).filter_by(id=hit.id).count() == 0: session.add(hit) session.commit() print(1) session.close()