Example #1
0
def handle_battle_form():
    comp1 = request.forms.get('comp1')
    comp2 = request.forms.get('comp2')
    question = request.forms.get('question')
    # [TODO] make slug safe, no dupes possible, safe to be used in a URL
    slug = comp1 + '-vs-' + comp2
    # [TODO] create the 2 QRCodes contents (what's encoded)
    qr_content1 = comp1
    qr_content2 = comp2
    # starting points
    points1 = 0
    points2 = 0
    # dummy content for "question" field
    question = "nog niks" 
    try:
        # connect to database
        con = sqlite3.connect('qrbattle.db')
        # write QR Codes to the filesystem, [TODO] off course these names
        # should be added to the database record, otherwise we can not couple
        # them afterwards
        qrcode_file1 = save_qrcode(qr_content2, QR_IMG_TYPES[1], QR_FS_ROOT,
toolbox.random_identifier(), 2, QRErrorCorrectLevel.L)
        qrcode_file2 = save_qrcode(qr_content1, QR_IMG_TYPES[1], QR_FS_ROOT,
toolbox.random_identifier(), 2, QRErrorCorrectLevel.L)
        # write to db
        # [TODO] check database availability of "slug" name in db
        c = con.cursor()
        c.execute("INSERT INTO qrbattle VALUES (NULL,?,?,?,?,?,?,?,?)", (slug, question, comp1, comp2, qr_content1, qr_content2, points1, points2))
        new_id = c.lastrowid
        print "new_id is " + str(new_id)
        con.commit()
        c.close()
        # serve page with QR Codes
        return template('battlefield',
                        qrimg1=qrcode_file1,
                        qrimg2=qrcode_file2,
                        error_msg=''
                        )
    except ValueError:
        # show error messages
        return template('index', error_msg='fill in both competitors')
    except IOError:
        # show message saying the qrcode can't be written to the system
        return template('index', error_msg='technical error, probably a\
filesystem issue, check config and permissions')
Example #2
0
 def create_qrcode(self, content, alttag, titletag, img_types=settings.QR_IMG_TYPES):
     # determine the name of the QRCode file
     # HACK, just calling it something random [TODO] refactor
     print("in create_qrcode: " + content)
     name = toolbox.random_identifier()
     # first make the file(s)
     def qrcode_files(qr_img_types):
         for t in qr_img_types:
             qrcode_filename, full_file_path = self.create_qrcode_file(content, t, name)
             yield qrcode_filename, full_file_path
     qrcode_fullpaths = [y for x,y in qrcode_files(settings.QR_IMG_TYPES)]
     # then make the qrcode record
     qr_id = self.create_qrcode_record(self.author_id, content, self.eclevel, self.qrtypenumber, qrcode_fullpaths[0], alttag, titletag, datetime.datetime.now())
     return qr_id, name
Example #3
0
def handle_form():
    # check the text
    text = request.forms.get('qrtext')
    try:
        # write qr code to filesystem
        qrcode_filename = save_qrcode(text, QR_IMG_TYPES[1], QR_FS_ROOT,
toolbox.random_identifier(), 2, QRErrorCorrectLevel.L)
        # serve page with qrcode and download link(s)
        return template('yourqr', qrcode_filename=qrcode_filename, text=text)
    except ValueError:
        # show error messages
        return template('index', error_msg='please enter some text')
    except IOError:
        # show message saying the qrcode can't be written to the system
        return template('index', error_msg='technical error, probably a\
filesystem issue, check config and permissions')