http://www.web2pyslices.com/slices/take_slice/150
Wednesday, January 25, 2012
Friday, January 13, 2012
web2py: plugin rating widget
I was looking for a plugin for rating with starts and found this one but it doesn't give me much information how to do it so I gave up. (It's sad, I couldn't plug the plugin.)
Plugin Rating
http://www.web2py.com/plugins/default/rating
Now, kenji (s-cubism) just introduced the new plugin and it works like a charm ! It's easy to use and I strongly recommend if you're looking for the plugin.
Rating Widget
http://dev.s-cubism.com/plugin_rating_widget
Here's how I did.
1. Create new app called "rating"
2. Create models/rating.py
# coding: utf8
from plugin_rating_widget import RatingWidget
db.define_table('product',
Field('rating', 'integer',
requires=IS_IN_SET(range(1,6)), # "requires" is necessary for the rating widget
))
################################ The core ######################################
# Inject the horizontal radio widget
db.product.rating.widget = RatingWidget()
################################################################################
3. Edit controllers/default.py for def index
def index():4. Edit views/default.html
form = SQLFORM(db.product)
if form.accepts(request.vars, session):
session.flash = 'submitted %s' % form.vars
redirect(URL('index'))
return dict(form=form)
{{left_sidebar_enabled,right_sidebar_enabled=False,True}}
{{extend 'layout.html'}}
{{=form}}
5. Result
Of course, you can create another table and store the submitted value to it, calculate the average, whatever you like. This plugin is good enough for me to build some kind of user review app !
Tuesday, December 27, 2011
web2py: new appliances web site
Oh, my app I developed for final project for Massimo's class is now available on new appliances site.
Restaurants Listing
Restaurants Listing
Tuesday, December 20, 2011
web2py: social gathering in Chicago
We had a social gathering at Exchequer Restaurant & Pub which is very close to DePaul Unitversity.
http://www.exchequerpub.com/
226 S. Wabash Avenue
Chicago, IL 60604
Phone: (312) 939-5633
It was fun meeting with the small local group and let's do it again !
I missed the train at 9:40, waited until 10:40 then got home almost 12:00... feel so sleepy today.
Monday, November 21, 2011
web2py: hide register link on page
The following code will hide the link but also disable the function to register user completely even you create the record from appadmin menu.
auth.settings.actions_disabled=['register']
So here's how I do...
# all we need is login
auth.settings.actions_disabled=['change_password','request_reset_password','retrieve_username','profile']
if request.controller != 'appadmin':
auth.settings.actions_disabled +=['register']
In this way, it's disabled for users but not admin.
web2py: add additonal field in auth_user
It's actually very easy. Just add the following code in your model before auth.define_tables().
## additonal fields
auth.settings.extra_fields['auth_user']= [
Field('office')
]
So it will be like this...
from gluon.tools import Auth, Crud, Service, PluginManager, prettydate
auth = Auth(db, hmac_key=Auth.get_or_create_key())
crud, service, plugins = Crud(db), Service(), PluginManager()
## create all tables needed by auth if not custom tables
## additonal fields
auth.settings.extra_fields['auth_user']= [
Field('office')
]
auth.define_tables()
## additonal fields
auth.settings.extra_fields['auth_user']= [
Field('office')
]
So it will be like this...
auth = Auth(db, hmac_key=Auth.get_or_create_key())
crud, service, plugins = Crud(db), Service(), PluginManager()
## create all tables needed by auth if not custom tables
## additonal fields
auth.settings.extra_fields['auth_user']= [
Field('office')
]
auth.define_tables()
Wednesday, October 19, 2011
web2py: how to connect existing tables
Tested environment:
mssql 2008
DAL
You need to make sure you disable Migration otherwise it might alter your tables. I recommend to specify at connection level (not each table) so that you don't forget.
db = DAL("mssql2://YourID:YourPassword@YourServer/YourDB", migrate=False)
If table has Primary field called id
You're lucky. This meet with the convention of web2py
db.define_table('table1',
Field('name'))
If table has primary key field called ID
Shoot, it's a capital letter... don't worry the code above will still work !
If table has primary key field called myid
Why didn't I name the field carefully.... no problem. You can still connect.
Since it's not field called id/ID, you need to define your primary field just like others and set primarykey for it.
db.define_table('table1',
Field('myid'),
Field('name'),
primarykey=['myid'])
If table has No primary key field
What's wrong with me ? ... don't worry here's what I found. You know what, the above code still works !
Subscribe to:
Posts (Atom)
