예제 #1
0
def updatecase(casecode=None):
    form=CaseForm()
    mtop=''
    casecode = casecode
    if casecode is None:
        return redirect( url_for('index') )
    errormessage = None

    if request.method == 'POST' and not form.validate_on_submit():
        errormessage = 'One or more fields is not correct'
    elif request.method == 'POST' and form.validate_on_submit():
        print 'forms are alright'
        to_add = []
        print ''
        for field in form:
            if ('table_' in field.name):
                if (field.data != ''):
                    print field.name, field.data
                    if field.name == 'table_Arrest' or field.name == 'table_Domestic':
                        to_add.append(1 if field.data is True else 0)
                    else:
                        to_add.append(field.data)
        to_add.insert(0, None)

        print to_add, '\n'
        mtop='New entry added'
        db = get_DB()
        # NOTE I could use the UPDATE query, but I use DELETE as it is much more simple
        # to remove entire row and add a new one.
        cur = db.execute('delete from tblData where tblData.caseCode=?', (casecode,))
        cur = db.execute('insert into tblData values(?,?,?,?,?,?,?,?,?,?)', to_add)
        # Permenantly change record in database
        db.commit()
        flash('Entry updated')

    if len(casecode) < 10:
        db = get_DB()
        cur = db.execute('select caseCode,caseDateOfOccurrence,caseBlock,\
        caseArrest,caseDomestic,caseFBICD,caseBeat,caseWard,caseIUCR \
        from tblData where tblData.caseCode=?', (casecode,))
        headings=['Case#', 'Date Of Occurrence', 'Block', 'Arrest', \
        'Domestic', 'FBI CD', 'Beat', 'Ward', 'IUCR']
        result = cur.fetchall()
        if len(result)>0:
            return render_template('editordelete.html', title='Reports', form=form,
            headings=headings, results=result, casecode=casecode, errormessage=errormessage, active='update')

    return redirect(url_for('index'))
예제 #2
0
def newcase():
    form=CaseForm()
    mtop=''
    if request.method == 'POST' and form.validate_on_submit():
        to_add = []
        casecode = None
        print ''
        for field in form:
            if ('table_' in field.name):
                if (field.data != ''):
                    print field.name, field.data
                    if field.name == 'table_Arrest' or field.name == 'table_Domestic':
                        to_add.append(1 if field.data is True else 0)
                    elif field.name == 'table_Code':
                        casecode = field.data
                        to_add.append(field.data)
                    else:
                        to_add.append(field.data)
        to_add.insert(0, None)

        if getcase_noview(casecode) is not None:
            deletecase_noview(casecode)

        print to_add, '\n'
        mtop='New entry added'
        db = get_DB()
        cur = db.execute('insert into tblData values(?,?,?,?,?,?,?,?,?,?)', to_add)
        result = cur.fetchall()
        # Permenantly add record to the database
        db.commit()
        flash('Entry added')

    return render_template('newcase.html', title='New Case', form=form, messagetop=mtop, active='create')