Пример #1
0
def update():
    (db, table) = get_table(request)
    keyed = hasattr(db[table], '_primarykey')
    record = None
    if keyed:
        key = [f for f in request.vars if f in db[table]._primarykey]
        if key:
            record = db(db[table][key[0]] == request.vars[key[0]],
                        ignore_common_filters=True).select().first()
    else:
        record = db(db[table].id == request.args(2),
                    ignore_common_filters=True).select().first()

    if not record:
        qry = query_by_table_type(table, db)
        session.flash = T('record does not exist')
        redirect(URL('select', args=request.args[:1], vars=dict(query=qry)))

    if keyed:
        for k in db[table]._primarykey:
            db[table][k].writable = False

    form = SQLFORM(db[table],
                   record,
                   deletable=True,
                   delete_label=T('Check to delete'),
                   ignore_rw=ignore_rw and not keyed,
                   linkto=URL('select', args=request.args[:1]),
                   upload=URL(r=request, f='download', args=request.args[:1]))

    if form.accepts(request.vars, session):
        session.flash = T('done!')
        qry = query_by_table_type(table, db)
        redirect(URL('select', args=request.args[:1], vars=dict(query=qry)))
    return dict(form=form, table=db[table])
Пример #2
0
def update():
    (db, table) = get_table(request)
    keyed = hasattr(db[table],'_primarykey')
    record = None
    if keyed:
        key = [f for f in request.vars if f in db[table]._primarykey]
        if key:
            record = db(db[table][key[0]] == request.vars[key[0]], ignore_common_filters=True).select().first()
    else:
        record = db(db[table].id == request.args(2),ignore_common_filters=True).select().first()

    if not record:
        qry = query_by_table_type(table, db)
        session.flash = T('record does not exist')
        redirect(URL('select', args=request.args[:1],
                     vars=dict(query=qry)))

    if keyed:
        for k in db[table]._primarykey:
            db[table][k].writable=False

    form = SQLFORM(db[table], record, deletable=True, delete_label=T('Check to delete'),
                   ignore_rw=ignore_rw and not keyed,
                   linkto=URL('select',
                   args=request.args[:1]), upload=URL(r=request,
                   f='download', args=request.args[:1]))

    if form.accepts(request.vars, session):
        session.flash = T('done!')
        qry = query_by_table_type(table, db)
        redirect(URL('select', args=request.args[:1],
                 vars=dict(query=qry)))
    return dict(form=form,table=db[table])
Пример #3
0
def edit():
    ''' The function pre-populates the data from the note instance
        that has been requested to be edited and renders it,
        once client sends in some data, it saves it in the database.'''

    note = db.notes(request.args(0)) or redirect(URL('error'))
    form = SQLFORM(db.notes, note, deletable=True)
    if form.validate():
        if form.deleted:
            db(db.notes.id == note.id).delete()
            redirect(URL('index'))
        else:
            note.update_record(**dict(form.vars))
            response.flash = 'records changed'
    else:
        response.flash = 'Something went wrong!'
    return dict(form=form)
Пример #4
0
def index():
    ''' Makes a db query to select all the notes, 
    orders the notes by the publication date and 
    returns a dictionary to the template, containing 
    all the notes.'''

    response.flash = "Welcome to the index view!"
    notes = db(db.notes).select(orderby=db.notes.pub_date)
    return dict(notes=notes)
Пример #5
0
def edit():

    ''' The function pre-populates the data from the note instance
        that has been requested to be edited and renders it,
        once client sends in some data, it saves it in the database.'''
        
    note = db.notes(request.args(0)) or redirect(URL('error'))
    form=SQLFORM(db.notes, note, deletable = True)
    if form.validate():
        if form.deleted:
            db(db.notes.id==note.id).delete()
            redirect(URL('index'))
        else:
            note.update_record(**dict(form.vars))
            response.flash = 'records changed'
    else:
        response.flash = 'Something went wrong!'
    return dict(form=form)    
Пример #6
0
def index():

    ''' Makes a db query to select all the notes, 
    orders the notes by the publication date and 
    returns a dictionary to the template, containing 
    all the notes.'''

    response.flash = "Welcome to the index view!"
    notes = db(db.notes).select(orderby=db.notes.pub_date)    
    return dict(notes=notes)
Пример #7
0
def csv():
    import gluon.contenttype
    response.headers['Content-Type'] = \
        gluon.contenttype.contenttype('.csv')
    db = get_database(request)
    query = get_query(request)
    if not query:
        return None
    response.headers['Content-disposition'] = 'attachment; filename=%s_%s.csv'\
         % tuple(request.vars.query.split('.')[:2])
    return str(db(query, ignore_common_filters=True).select())
Пример #8
0
def csv():
    import gluon.contenttype
    response.headers['Content-Type'] = \
        gluon.contenttype.contenttype('.csv')
    db = get_database(request)
    query = get_query(request)
    if not query:
        return None
    response.headers['Content-disposition'] = 'attachment; filename=%s_%s.csv'\
         % tuple(request.vars.query.split('.')[:2])
    return str(db(query,ignore_common_filters=True).select())
Пример #9
0
                _action=URL(r=request, args=request.args))
    if request.vars.csvfile != None:
        try:
            import_csv(db[request.vars.table], request.vars.csvfile.file)
            response.flash = T('data uploaded')
        except Exception, e:
            response.flash = DIV(T('unable to parse csv file'), PRE(str(e)))
    if form.accepts(request.vars, formname=None):
        #         regex = re.compile(request.args[0] + '\.(?P<table>\w+)\.id\>0')
        regex = re.compile(request.args[0] + '\.(?P<table>\w+)\..+')

        match = regex.match(form.vars.query.strip())
        if match:
            table = match.group('table')
        try:
            nrows = db(query).count()
            if form.vars.update_check and form.vars.update_fields:
                db(query).update(**eval_in_global_env('dict(%s)' %
                                                      form.vars.update_fields))
                response.flash = T('%s rows updated', nrows)
            elif form.vars.delete_check:
                db(query).delete()
                response.flash = T('%s rows deleted', nrows)
            nrows = db(query).count()
            if orderby:
                rows = db(query, ignore_common_filters=True).select(
                    limitby=(start, stop), orderby=eval_in_global_env(orderby))
            else:
                rows = db(query,
                          ignore_common_filters=True).select(limitby=(start,
                                                                      stop))
Пример #10
0
    if request.vars.csvfile != None:
        try:
            import_csv(db[request.vars.table],
                       request.vars.csvfile.file)
            response.flash = T('data uploaded')
        except Exception, e:
            response.flash = DIV(T('unable to parse csv file'),PRE(str(e)))
    if form.accepts(request.vars, formname=None):
#         regex = re.compile(request.args[0] + '\.(?P<table>\w+)\.id\>0')
        regex = re.compile(request.args[0] + '\.(?P<table>\w+)\..+')

        match = regex.match(form.vars.query.strip())
        if match:
            table = match.group('table')
        try:
            nrows = db(query).count()
            if form.vars.update_check and form.vars.update_fields:
                db(query).update(**eval_in_global_env('dict(%s)'
                                  % form.vars.update_fields))
                response.flash = T('%s rows updated', nrows)
            elif form.vars.delete_check:
                db(query).delete()
                response.flash = T('%s rows deleted', nrows)
            nrows = db(query).count()
            if orderby:
                rows = db(query,ignore_common_filters=True).select(limitby=(start, stop), orderby=eval_in_global_env(orderby))
            else:
                rows = db(query,ignore_common_filters=True).select(limitby=(start, stop))
        except Exception, e:
            (rows, nrows) = ([], 0)
            response.flash = DIV(T('Invalid Query'),PRE(str(e)))