I've watched every web2py video I could find and read through all the
material. Still not getting it. I'm new to web2py and webapps.
Here's what I want to do:
1. Have a page to upload multiple configuration files (plaintext.txt)
2. Parse items out of those files and store the results in the sqlite
database.
3. Retrieve the stored items (variables) and show them in a table.
For Example...let's say I upload the following files:
document_a.txt
grep_a Merry
Blah blah blah
Words words words
grep_b Christmas
More Words More Words
grep_d I need help
document_b.txt
grep_a Halloween
Blah blah blah
Words words words
grep_b Easter
More Words More Words
grep_c This document has a line with grep_c the other one doesn't
For each file i will be parsing out variable_a, variable_b, variable_c, &
variable_d which will essentially be grepping out the grep_a, b, c & d
statements (via regex mostly).
In my stand alone python script I do this by defining a class with several
methods. The results are stored in a dictionary. So for example:
document_a.parse() would yield an object that contains a dictionary with
the different settings I want to extract. I can then do what I want with
them.
I have no idea how to do this within the context of a web app using a
database.
----------------------------------------------------------------------
That's what I want, here's what I've done so far.
Model: db.py
from gluon.tools import Auth
db = DAL("sqlite://storage.sqlite")
auth = Auth(db)
auth.define_tables(username=True)
db.define_table('config_file',
#Field('title', unique=True),
Field('file', 'upload', requires=IS_NOT_EMPTY()),
format = '%(title)s')
Controller: default.py
def showconfig():
files = db().select(db.config_file.ALL)
return dict(files=files)
View: default/showconfig.html
{{extend 'layout.html'}}
<h1>
Current Files
</h1>
<ul>
{{for file in files:}}
{{=LI(A(file, _href=URL('showconfig')))}}
{{pass}}
</ul>
I then upload a few files using the database manager built in.
<https://lh3.googleusercontent.com/-kHe6iJKI9_4/UrxxS8N_m9I/AAAAAAAADQ4/LoNw-sLgzqA/s1600/Contour-2.png>
....and then call the showconfig.html view which prints a list of the
uploaded file names (which web2py has changed).
<https://lh6.googleusercontent.com/-k9QApJ0V4Cw/UrxwlnwnsxI/AAAAAAAADQw/q89QuaJ2YkA/s1600/Contour-1.png>
<https://lh6.googleusercontent.com/-k9QApJ0V4Cw/UrxwlnwnsxI/AAAAAAAADQw/q89QuaJ2YkA/s1600/Contour-1.png>
<https://lh6.googleusercontent.com/-k9QApJ0V4Cw/UrxwlnwnsxI/AAAAAAAADQw/q89QuaJ2YkA/s1600/Contour-1.png>
Really sorry for the newb questions, but I can't find any good web2py
tutorials that show uploading files, parsing the data/putting that data
into a db, and then sending that data to the screen.
1. Where do I define the variables to extract the info I want (regex
grepping mostly)?......I assume in a controller?
2. How do I then get that data into the sqlite database stored under the
corresponding document?
3. How do I then get select that info out of the database for a specific
document and send it to the screen in the form of a table?
Any guidance you can give is greatly appreciated. If anyone has a sample
web2py app that can do this I can reverse engineer it, but i haven't found
anything out there that does this.
Merry Christmas!
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.