Пример #1
0
def new():
    if request.method == 'POST':
        if not (request.form['erpm'] and request.form['engine_load']
                and request.form['table_name'] and
                (request.form['table_name'] > 0)):
            print("Reached")
            #flash('Please enter all the fields', 'error')
            return ("Empty attempt")
        else:
            if ((int(request.form['table_name']) <= 0)
                    or (int(request.form['table_name']) > deviceNumbers)):
                return ('Device not registered to database')
            else:
                erpm = request.form['erpm']
                engine_load = request.form['engine_load']
                table_name = request.form['table_name']
                clear_mappers()
                devices = Table("device" + table_name, metadata, autoload=True)
                mapper(Device, devices)
                device = Device(erpm, engine_load)
                db_session.add(device)
                db_session.commit()
                clear_mappers()
                #flash('Record was successfully added')
                return ('added successfully')
    return ('Yooo')
Пример #2
0
def store_message(text,time):
    try:
        queuedmessage = Message(text,time)
        db_session.add(queuedmessage)
        db_session.commit()
    except Exception:
        logging.error("Could not store message '%s', \
                      check your database settings." % text)
        raise
Пример #3
0
def store_direct(text):
    """ This will sstore a message directly to the database,
    bypassing the redis queue async workflow """
    try:
        entry = Message(text, datetime.now().replace(microsecond=0))
        db_session.add(entry)
        db_session.commit()
    except Exception:
        logging.error("Could not store message '%s', check your database settings." % text)
Пример #4
0
def CSRF():
    if request.method == "POST":
        name = request.values.get('name')
        email = request.values.get('email')
        u = User(name=name, email=email)
        db_session.add(u)
        db_session.commit()
        return Response("Success")
    else:
        return render_template('csrf.html')
Пример #5
0
 def event_choose(self, path):
     d = json.loads(open(path).read())
     num = d['data']['num']
     answer = d['data']['answer']
     if num != self.num_choose:
         self.num_choose = num
         if num in self.hist:
             question = self.hist[num]
             options = json.loads(question.options)
             answers = json.loads(question.answer)
             anstxt = options[answer - 1]
             if anstxt not in answers:
                 question.answer = json.dumps(answers + [anstxt])
                 db_session.commit()
Пример #6
0
    def question_flush(self, d):
        def _ansdisp(idx):
            return chr(ord('A') + idx)

        answerformat = '%s    %s  %s             (%s)'

        quiz = d['data']['quiz']
        options = d['data']['options']
        num = d['data']['num']

        print '\n================================================\n'
        print str(num) + '. ' + quiz
        print
        for i, op in enumerate(options):
            print '  ' + _ansdisp(i) + '. ' + op
        print

        question = Question.query.get(quiz)
        if question:
            question.options = json.dumps(options)
        else:
            question = Question()
            db_session.add(question)
            question.quiz = quiz
            question.school = d['data']['school']
            question.type = d['data']['type']
            question.options = json.dumps(options)
            question.answer = json.dumps([])
        db_session.commit()
        self.hist[num] = question

        answers = json.loads(question.answer)
        if set(answers) & set(options):
            anstxt = (set(answers) & set(options)).pop()
            ansidx = _ansdisp(options.index(anstxt))
            print answerformat % (u'[题库]', ansidx, anstxt, ansidx)

        else:
            anssort = QuizAnswer(quiz, options).getanswer()
            ans = anssort[0]
            print answerformat % (u'[guess]', _ansdisp(ans), options[ans],
                                  ' '.join(_ansdisp(i) for i in anssort))

        print
        print
        print
Пример #7
0
 def mutate(cls, _, args, context, info):
     family = FamiliesModel(name=args.get('name'), rank=args.get('rank'), house=args.get('house'))
     db_session.add(family)
     db_session.commit()
     ok = True
     return CreateFamily(family=family, ok=ok)
Пример #8
0
 def mutate(cls, _, args, context, info):
     member = MembersModel(name=args.get('name'), gender=args.get('gender'), families_id=args.get('families_id'))
     db_session.add(member)
     db_session.commit()
     ok = True
     return CreateMember(member=member, ok=ok)
Пример #9
0
import datetime
import logging
import sys
import traceback

from datetime import datetime
from databases import init_db, db_session
from models import Message

logging.basicConfig(level=logging.DEBUG)

logging.info("Attempting DB initialization...")

try:
    init_db()
    m = Message("DB migration complete", datetime.now().replace(microsecond=0))
    db_session.add(m)
    db_session.commit()
    db_session.remove()
    logging.info("Done!")
except Exception:
    traceback.print_exc(file=sys.stderr)
    logging.error("DB initialization failed, verify the DATABASE_URL setting.")