Re: [web2py] Re: Proper way to reference logged user

2012-12-02 Thread Daniele Pestilli
Hmm I'm still confused. Sorry guys.

So the way I'm displaying the two forms is through two tables in the database 
that I've defined. Consequently, in the controller I have something like

form = SQLFORM(db.tutor)

Below that I will have something like if form.process().accepted:
 If not auth.has_membership(group):
  auth.add_membership(group)

However, one of the elements in the form is a checkbox. If that box is 
unchecked, it needs to remove the user from the group. How can I check whether 
the checkbox is checked or not from the controller? Also, since the tables are 
defined in the database, this will all be going into two other tables. I don't 
think this is the right behavior though...




On Dec 2, 2012, at 3:34 PM, lyn2py  wrote:

> You can still use SQLFORM, and append additional fields. The code is here:
> http://web2py.com/books/default/chapter/29/07#Adding-extra-form-elements-to-SQLFORM
> 
> You need to add code to ensure that the user is being added to the particular 
> groups under form.process().
> 
> form=SQLFORM(db.table)
> //additional elements to add to the form goes here
> if form.process().accepted: 
> // add them to the relevant group here
> response.flash = 'record inserted'
> 
> 
> 
> 
> On Sunday, December 2, 2012 9:35:38 PM UTC+8, Daniele wrote:
>> 
>> Alright I've created the two groups with the web2py appadmin interface. Now 
>> I suppose the rest of the logic goes in the controller.
>> I have a SQLFORM right now but it probably makes more sense to just use a 
>> FORM, right? And then when that is processed, I can run the command 
>> auth.add_membership(group_id, user_id)
>> 
>> Am I on the money or is this incorrect?
>> Thanks guys :D
>> 
>> On Sunday, December 2, 2012 1:27:26 PM UTC, Daniele wrote:
>>> 
>>> OK I think that's probably the easiest solution for now.
>>> How can I do this? Do I need to add 
>>> 
>>> auth.add_group('role', 'description')
>>> 
>>> in my db.py file and then have a form that when a user submits, runs
>>> 
>>> auth.add_membership(group_id, user_id)
>>> 
>>> in the controller? Or do both of these go inside the controller? I guess 
>>> the 
>>> groups only need to be created once, which is why I am assuming the first 
>>> line goes in db.py
>>> 
>>> Thanks
>>> 
>>> On Saturday, December 1, 2012 6:11:24 PM UTC, villas wrote:
 
 Put everyone in the auth_user table and use groups.  That could save you 
 heaps of time down the line.  Otherwise I can imagine you'll start 
 reinventing what's already available to you in web2py.  Use the framework 
 and the force will be with you!
 
 If you need to keep lots of different info depending on what group they 
 are in,  then you can always think about splitting that into different 
 tables,  but only as a last resort.
 
 Best wishes for your app,  D
 
 On Saturday, 1 December 2012 13:13:13 UTC, Daniele wrote:
> 
> Hmmm that's one option, but here's the problem.
> Basically, I want users to sign up very easily. So I'm just using 
> web2py's default auth for that.
> Then, I'd like them to pick if they are tutors/students or both. There is 
> additional information they'd have to input in some forms for both roles.
> While I could just create two groups, the way I have it now as tutors are 
> a table and students are another table in the database.
> 
> I guess I'm a bit lost as to how the correct way to let the signed up 
> users be either students/tutors or both is. Should it all be part of the 
> signed up users table? Or should I have three tables? Should I just make 
> groups?
> 
> Any advice is much appreciated,
> Thanks!
> 
> 
> On Friday, November 23, 2012 7:24:42 PM UTC, Joe Barnhart wrote:
>> 
>> Why not create a group for each class -- tutor and student -- and assign 
>> group membership for each student?  A student can participate in more 
>> than one group.  It's easy to test for group membership -- just use the 
>> decorator:
>> 
>> @auth.requires_membership('tutor')
>> 
>> -- Joe B.
>> 
>> 
>> On Tuesday, November 20, 2012 5:57:57 PM UTC-8, Daniele wrote:
>>> 
>>> I am trying to build a model where each logged user can decide if 
>>> he/she is a tutor or student or both.
>>> So the tutor table has to 'reference auth.settings.table_user_name' and 
>>> student also has to have the same reference.
>>> 
>>> The tutor/student/logged user have to be related by their id key I 
>>> imagine.
>>> 
>>> Is this the proper way to go about this? Moreover, how can I check that 
>>> the relationship is working?
> 
> -- 
>  
>  
>  

-- 





Re: [web2py] Re: Check if a from's boolean is true or false from the controller

2012-12-04 Thread Daniele Pestilli
How can I blank out all the **form.vars in the event that the
form.vars.is_tutor returns false? Is there a simple way to do this or
should I manually put in None for all the fields?


On Tue, Dec 4, 2012 at 8:16 PM, Niphlod  wrote:

> depends on where do you use that kind of logic. If the user is already
> logged, you need to UPDATE the corresponding "auth_user" row with the data
> inserted, something among the lines of
>
> db(db.auth_user.id == auth.user_id).update(**form.vars)
>
> If instead you are requesting the user to fill that form without being
> logged already, you'd need to CREATE the row, so you should use
> insertin that case you should also ask for username/email and the
> password.
>
> summary: form.vars holds a dictionary composed of fieldname --> values.
> Both .insert() and .update() take a dictionary, in which case the columns
> corresponding to a table are updated/created with the correct values.
>
> On Tuesday, December 4, 2012 8:34:31 PM UTC+1, Daniele wrote:
>>
>> And the same goes for db.auth_user.insert() ... does it imply the logged
>> user or not?
>>
>> On Monday, December 3, 2012 2:27:29 PM UTC, Daniele wrote:
>>>
>>> Hey guys, I'm wondering if there's a way from the controller to know
>>> whether a form's boolean field (checkbox) is selected or not. I only want
>>> to add the info in the form to the database if the checkbox is selected,
>>> otherwise the controller should not process that form.
>>>
>>> Thanks!
>>>
>>  --
>
>
>
>

-- 





Re: [web2py] Re: Check if a from's boolean is true or false from the controller

2012-12-04 Thread Daniele Pestilli
There's some problem with what I'm doing now.

I have form = SQLFORM.factory() with all the fields in my controller.

In my db.py file, I am extending auth with


auth.settings.extra_fields['auth_user']= [

Field <http://127.0.0.1:8000/examples/global/vars/Field>('t_image'),

Field <http://127.0.0.1:8000/examples/global/vars/Field>('t_location'),

Field <http://127.0.0.1:8000/examples/global/vars/Field>('t_subjects'),

Field 
<http://127.0.0.1:8000/examples/global/vars/Field>('t_qualifications'),

Field <http://127.0.0.1:8000/examples/global/vars/Field>('t_biography'),

Field <http://127.0.0.1:8000/examples/global/vars/Field>('t_hourly_rate'),

Field <http://127.0.0.1:8000/examples/global/vars/Field>('t_modified_on'),

Field <http://127.0.0.1:8000/examples/global/vars/Field>('s_location')]

However, when I visit the page I am getting a bunch of 'None' fields
without input boxes. Am I supposed to somehow

put the SQLFORM.factory info in my db.py file? I can't understand why
it's doing this...




On Wed, Dec 5, 2012 at 12:49 AM, Daniele Pestilli wrote:

> How can I blank out all the **form.vars in the event that the
> form.vars.is_tutor returns false? Is there a simple way to do this or
> should I manually put in None for all the fields?
>
>
>
> On Tue, Dec 4, 2012 at 8:16 PM, Niphlod  wrote:
>
>> depends on where do you use that kind of logic. If the user is already
>> logged, you need to UPDATE the corresponding "auth_user" row with the data
>> inserted, something among the lines of
>>
>> db(db.auth_user.id == auth.user_id).update(**form.vars)
>>
>> If instead you are requesting the user to fill that form without being
>> logged already, you'd need to CREATE the row, so you should use
>> insertin that case you should also ask for username/email and the
>> password.
>>
>> summary: form.vars holds a dictionary composed of fieldname --> values.
>> Both .insert() and .update() take a dictionary, in which case the columns
>> corresponding to a table are updated/created with the correct values.
>>
>> On Tuesday, December 4, 2012 8:34:31 PM UTC+1, Daniele wrote:
>>>
>>> And the same goes for db.auth_user.insert() ... does it imply the logged
>>> user or not?
>>>
>>> On Monday, December 3, 2012 2:27:29 PM UTC, Daniele wrote:
>>>>
>>>> Hey guys, I'm wondering if there's a way from the controller to know
>>>> whether a form's boolean field (checkbox) is selected or not. I only want
>>>> to add the info in the form to the database if the checkbox is selected,
>>>> otherwise the controller should not process that form.
>>>>
>>>> Thanks!
>>>>
>>>  --
>>
>>
>>
>>
>
>

-- 





Re: [web2py] Re: Displaying an image

2012-12-05 Thread Daniele Pestilli
hmm still not working. I think it's because I set the upload directory to
uploads/profiles/ so it's not finding the image. Maybe if I change that
setting it will work...


On Wed, Dec 5, 2012 at 5:43 PM, Niphlod  wrote:

> ehm in html you need to do .
> {{=URL('default', 'download', args=row.image)}} is just the portion to put
> into the img tag as the src's attribute value
>
> {{=IMG(
> _src=URL('default', 'download', args=row.image)
> )
> }}
>
> is the right one!
>
> On Wednesday, December 5, 2012 6:36:10 PM UTC+1, Daniele wrote:
>>
>> I have def download(): return response.download(request,db) in my
>> controller. But when I put {{=URL('default', 'download', args=row.image)}}
>> in my view I'm just getting a string. Perhaps because the file was not
>> saved to this directory?
>>
>> On Wednesday, December 5, 2012 2:25:57 PM UTC, Anthony wrote:
>>>
>>> You do not specify the "uploads" directory in the URL. Instead, you need
>>> to define a function that calls response.download() and pass the filename
>>> to that function via the last URL argument (i.e., request.args[-1]). In
>>> fact, this function is already provided for you in the "welcome" app:
>>>
>>> def download():
>>> """
>>> allows downloading of uploaded files
>>> http:///[app]/default/**download/[filename]
>>> """
>>> return response.download(request,db)
>>>
>>> So, your URL should be URL('default', 'download', args=row.image).
>>>
>>> This is discussed 
>>> here,
>>> here ,
>>> here , and 
>>> here(example
>>>  33).
>>>
>>> Anthony
>>>
>>> On Wednesday, December 5, 2012 9:06:57 AM UTC-5, Daniele wrote:

 Guys I know this sounds simple but I'm having a hard time displaying
 uploaded images. I have an upload field in my model where logged in users
 can upload an image. But in my views when I try to do
 {{=IMG(_src=URL('uploads/', row.image))}} where row is a variable that
 refers to db(db.auth_user.id > 0).select() nothing is being returned.
 However, row.image returns a string which is the name of the file.
 How can I display the image correctly?

 Thanks!

>>>  --
>
>
>
>

-- 





Re: [web2py] Re: Displaying an image

2012-12-05 Thread Daniele Pestilli
Yeah I checked my controller and it's uploading images to
Field('image', 'upload',
uploadfolder=os.path.join(request.folder,'uploads/profiles/')

Is there a default directory where the download() function wants images to
be?


On Wed, Dec 5, 2012 at 5:55 PM, Daniele Pestilli wrote:

> hmm still not working. I think it's because I set the upload directory to
> uploads/profiles/ so it's not finding the image. Maybe if I change that
> setting it will work...
>
>
>
> On Wed, Dec 5, 2012 at 5:43 PM, Niphlod  wrote:
>
>> ehm in html you need to do .
>> {{=URL('default', 'download', args=row.image)}} is just the portion to
>> put into the img tag as the src's attribute value
>>
>> {{=IMG(
>> _src=URL('default', 'download', args=row.image)
>> )
>> }}
>>
>> is the right one!
>>
>> On Wednesday, December 5, 2012 6:36:10 PM UTC+1, Daniele wrote:
>>>
>>> I have def download(): return response.download(request,db) in my
>>> controller. But when I put {{=URL('default', 'download', args=row.image)}}
>>> in my view I'm just getting a string. Perhaps because the file was not
>>> saved to this directory?
>>>
>>> On Wednesday, December 5, 2012 2:25:57 PM UTC, Anthony wrote:
>>>>
>>>> You do not specify the "uploads" directory in the URL. Instead, you
>>>> need to define a function that calls response.download() and pass the
>>>> filename to that function via the last URL argument (i.e.,
>>>> request.args[-1]). In fact, this function is already provided for you
>>>> in the "welcome" app:
>>>>
>>>> def download():
>>>> """
>>>> allows downloading of uploaded files
>>>> http:///[app]/default/**download/[filename]
>>>> """
>>>> return response.download(request,db)
>>>>
>>>> So, your URL should be URL('default', 'download', args=row.image).
>>>>
>>>> This is discussed 
>>>> here<http://web2py.com/books/default/chapter/29/03#An-image-blog>,
>>>> here<http://web2py.com/books/default/chapter/29/07#SQLFORM-and-uploads>,
>>>> here <http://web2py.com/books/default/chapter/29/04#response>, and 
>>>> here<http://www.web2py.com/examples/default/examples#database_examples>(example
>>>>  33).
>>>>
>>>> Anthony
>>>>
>>>> On Wednesday, December 5, 2012 9:06:57 AM UTC-5, Daniele wrote:
>>>>>
>>>>> Guys I know this sounds simple but I'm having a hard time displaying
>>>>> uploaded images. I have an upload field in my model where logged in users
>>>>> can upload an image. But in my views when I try to do
>>>>> {{=IMG(_src=URL('uploads/', row.image))}} where row is a variable that
>>>>> refers to db(db.auth_user.id > 0).select() nothing is being returned.
>>>>> However, row.image returns a string which is the name of the file.
>>>>> How can I display the image correctly?
>>>>>
>>>>> Thanks!
>>>>>
>>>>  --
>>
>>
>>
>>
>
>

-- 





Re: [web2py] Re: Displaying an image

2012-12-06 Thread Daniele Pestilli
I noticed that I am missing upload=URL('download') in my SQLFORM.factory,
so I added that in there but it's still not working.

I double checked the image name and you were right, I don't know how I must
have mistakenly deleted that part but it was indeed
"[table_name].[field_name].[rand_string]"

I can't think of why else this is not working...I am following the web2py
book verbatim...


On Thu, Dec 6, 2012 at 3:06 AM, Anthony  wrote:

>
> Hmm for some reason it's not working for me. I took a look at the source
>> code and this is the HTML that is being generated:
>>
>> 
>>
>>
>> And this is what I have in my view that is generating that code:
>>
>> {{=IMG(_src=URL('default', 'download', args=row.image))}}
>>
>> so it seems to be taking the 'download' directory and looking for the
>> image there, but as aforementioned, I've set the directory for these images
>> to be in:
>>
>> Field('image', 'upload', uploadfolder=os.path.join(**
>> request.folder,'uploads/**profiles/')
>>
>
> No, the URL /download/image... does not imply web2py is looking the the
> "download" directory. Remember, URLs do not map to directories (with the
> exception of static files). In web2py, URLs always map to applications,
> controllers, and functions. In your URL, it looks like the application and
> controller are excluded, so "download" will be interpreted by web2py as the
> function, and then the filename will be interpreted as request.args(0).
> This URL will call the download() function in default.py, which will
> ultimately call response.download(request, db), and that function will pull
> the filename from request.args(0).
>
> There is a problem with the filename, though. It starts with "image",
> which appears to be the field name, but it should actually start with
> "[table_name].[field_name]". I'm not sure how that could have happened. Do
> you have the same problem with new images that you upload? Do their
> filenames start with the table name, or just with "image"?
>
> Anthony
>
> --
>
>
>
>

-- 





Re: [web2py] Re: Displaying an image

2012-12-06 Thread Daniele Pestilli
I saw in the book that a line is being used, namely record =
db.person(request.args(0)) or redirect(URL('index'))  but I am not using
this line. I tried inserting it and removing the uploadfolder option in the
Field('image', 'upload', uploadfolder='...') field but it's giving me all
sorts of errors now. I never thought uploading and viewing an image could
be this complicated.


On Thu, Dec 6, 2012 at 1:33 PM, Daniele Pestilli wrote:

> I noticed that I am missing upload=URL('download') in my SQLFORM.factory,
> so I added that in there but it's still not working.
>
> I double checked the image name and you were right, I don't know how I
> must have mistakenly deleted that part but it was indeed
> "[table_name].[field_name].[rand_string]"
>
> I can't think of why else this is not working...I am following the web2py
> book verbatim...
>
>
>
> On Thu, Dec 6, 2012 at 3:06 AM, Anthony  wrote:
>
>>
>> Hmm for some reason it's not working for me. I took a look at the source
>>> code and this is the HTML that is being generated:
>>>
>>> 
>>>
>>>
>>> And this is what I have in my view that is generating that code:
>>>
>>> {{=IMG(_src=URL('default', 'download', args=row.image))}}
>>>
>>> so it seems to be taking the 'download' directory and looking for the
>>> image there, but as aforementioned, I've set the directory for these images
>>> to be in:
>>>
>>> Field('image', 'upload', uploadfolder=os.path.join(**
>>> request.folder,'uploads/**profiles/')
>>>
>>
>> No, the URL /download/image... does not imply web2py is looking the the
>> "download" directory. Remember, URLs do not map to directories (with the
>> exception of static files). In web2py, URLs always map to applications,
>> controllers, and functions. In your URL, it looks like the application and
>> controller are excluded, so "download" will be interpreted by web2py as the
>> function, and then the filename will be interpreted as request.args(0).
>> This URL will call the download() function in default.py, which will
>> ultimately call response.download(request, db), and that function will pull
>> the filename from request.args(0).
>>
>> There is a problem with the filename, though. It starts with "image",
>> which appears to be the field name, but it should actually start with
>> "[table_name].[field_name]". I'm not sure how that could have happened. Do
>> you have the same problem with new images that you upload? Do their
>> filenames start with the table name, or just with "image"?
>>
>> Anthony
>>
>> --
>>
>>
>>
>>
>
>

-- 





Re: [web2py] Re: Displaying an image

2012-12-06 Thread Daniele Pestilli
Ok here's my code:

in db.py

from gluon.tools import Auth, Crud, Service, PluginManager, prettydate

auth = Auth(db)
auth.settings.extra_fields['auth_user']= [

# t denote tutor fields, s denote student fields.
Field ('t_image'),

Field ('t_location'),

Field ('t_subjects'),

Field 
('t_qualifications'),

Field ('t_biography'),

Field ('t_hourly_rate'),

Field ('t_modified_on'),

Field ('s_location')]


in my controller:


@auth.requires_login()
def edit_profile():
response .subtitle
= T ("Edit Profile")

# Tutor form
tform = SQLFORM
.factory(

Field ('is_tutor',
'boolean'),

Field ('image',
'upload', requires=IS_EMPTY_OR
(IS_IMAGE
(extensions=('jpeg',
'jpg', 'png', 'gif',

Field ('location',
'list:string', requires=IS_NOT_EMPTY
()),

Field ('subjects',
'list:string', requires=IS_NOT_EMPTY
()),

Field 
('qualifications',
'list:string', requires=IS_NOT_EMPTY
()),

Field ('biography',
'text'),

Field ('hourly_rate',
'decimal(7,2)', requires=IS_NOT_EMPTY
()),

Field ('modified_on',
'datetime', requires=IS_DATETIME
(),
writable=False, readable=False, default=request
.utcnow),

upload=URL ('download'),

table_name='tutor')

# Student form

sform = SQLFORM
.factory(

Field ('is_student',
'boolean'),

Field ('location',
'list:string', requires=IS_NOT_EMPTY
()),

table_name='student')

tform['_class'] = "form-horizontal"

sform['_class'] = "form-horizontal"

tform.custom.submit['_class'] = "btn btn-success"

sform.custom.submit['_class'] = "btn btn-success"

tform.custom.begin = XML
("<%s %s>" %
(tform.tag, tform._xml()[0]))

sform.custom.begin = XML
("<%s %s>" %
(sform.tag, sform._xml()[0]))


if tform.errors or sform.errors:

response
.flash = T
('There was an error
with your submission')

else:
if tform.process().accepted:

if tform.vars.is_tutor:
if not auth.has_membership('Tutors'):

auth.add_membership('Tutors')
db(db.auth_user.id == auth.user_id).update(

t_image = tform.vars.image,
t_location = tform.vars.location,

t_subjects = tform.vars.subjects,
t_qualifications = tform.vars.qualifications,

t_biography = tform.vars.biography,
t_hourly_rate = tform.vars.hourly_rate,

t_modified_on = tform.vars.modified_on
)

else:
if auth.has_membership('Tutors'):

auth.del_membership('Tutors')
#db.auth_user.delete() delete the records

response
.flash = T
('Profile updated!')


if sform.process().accepted:

if sform.vars.is_student:
if not auth.has_membership('Students'):

auth.add_membership('Students')

db(db.auth_user.id == auth.user_id

Re: [web2py] Re: Displaying an image

2012-12-06 Thread Daniele Pestilli
this just completely broke my website -_- 
Now I can't even sign a user up anymore because it's requesting all those
additional fields.


On Thu, Dec 6, 2012 at 2:33 PM, Anthony  wrote:

> You are using SQLFORM.factory to handle the upload, but the table and
> field names used there do not match the table or field names where the
> records are actually stored, so response.download() cannot find the
> appropriate table or field. By default, SQLFORM.factory uses "no_table" as
> the dummy table name, and your code uses "image" as the field name. So,
> your image files will end up with names that start with "no_table.image".
> As a result, response.download(request, db) will look for a db.no_table
> table with an "image" field, but obviously won't find it. Instead, your
> image filenames are actually stored in db.auth_user.t_image, so you need to
> make sure the filenames get generated with names starting with
> "auth_user.t_image".
>
> Also, if you specify a custom uploadfolder, you'll need to make sure that
> the db.auth_user.t_image field has that uploadfolder specified as well,
> because response.download() checks the actual db field to determine the
> uploadfolder. The easiest approach might be to define the field once and
> reference both in the appended auth_user fields and in SQLFORM.factory.
>
> Finally, you can specify the name of the dummy table used by
> SQLFORM.factory by passing a "table_name" argument.
>
> So, maybe something like this:
>
> image_field = Field('t_image', 'upload', ..., uploadfolder=[your upload
> folder])
> auth.settings.extra_fields['auth_user'] = [..., image_field, ...]
> ...
> tform = SQLFORM.factory(..., image_field, ..., table_name='auth.user')
>
> Actually, you should probably do that with all the fields in
> SQLFORM.factory -- define them all once and use them in db.auth_user and to
> make the form. As it is, the field definitions in db.auth_user don't even
> have the correct field types defined. You could first add all the fields to
> db.auth_user, and then do something like this:
>
> tform = SQLFORM.factory(*[f for f in db.auth_user if f.name.startswith(
> 't_')], ...)
>
> That will include all the fields from db.auth_user that start with "t_".
>
> Finally, note that there will not be any errors in the form until you
> process it, so your condition that checks for errors will never find any.
> First call, form.process(), and then check for errors.
>
> Anthony
>
>
> On Thursday, December 6, 2012 8:51:02 AM UTC-5, Daniele wrote:
>
>> Ok here's my code:
>>
>> in db.py
>>
>> from gluon.tools import Auth, Crud, Service, PluginManager, prettydate
>>
>>
>>
>> auth = Auth(db)
>> auth.settings.extra_fields['**auth_user']= [
>>
>>
>>
>> # t denote tutor fields, s denote student fields.
>> Field ('t_image'),
>>
>>
>>
>> Field ('t_location'),
>>
>>
>>
>> Field ('t_subjects'),
>>
>>
>>
>> Field 
>> ('t_qualifications'),
>>
>>
>>
>> Field ('t_biography'),
>>
>>
>>
>> Field 
>> ('t_hourly_rate'),
>>
>>
>>
>> Field 
>> ('t_modified_on'),
>>
>>
>>
>> Field ('s_location')]
>>
>>
>>
>>
>> in my controller:
>>
>>
>> @auth.requires_login()
>> def edit_profile():
>> response .subtitle 
>> = T ("Edit Profile")
>>
>>
>>
>> # Tutor form
>> tform = SQLFORM 
>> .factory(
>>
>>
>>
>> Field ('is_tutor', 
>> 'boolean'),
>>
>>
>>
>> Field ('image', 
>> 'upload', requires=IS_EMPTY_OR 
>> (IS_IMAGE 
>> (**extensions=('jpeg', 
>> 'jpg', 'png', 'gif',
>>
>>
>>
>> Field ('location', 
>> 'list:string', requires=IS_NOT_EMPTY 
>> ()),
>>
>>
>>
>> Field ('subjects', 
>> 'list:string', requires=IS_NOT_EMPTY 
>> ()),
>>
>>
>>
>> Field 
>> ('qualifications', 
>> 'list:string', requires=IS_NOT_EMPTY 
>> ()),
>>
>>
>>
>> Field 
>> ('biography', 'text'),
>>
>>
>>
>> Field 
>> 

Re: [web2py] Re: Displaying an image

2012-12-06 Thread Daniele Pestilli
maybe instead of adding on to auth, I should just create two separate
tables and have them reference auth


On Thu, Dec 6, 2012 at 3:05 PM, Daniele Pestilli wrote:

> this just completely broke my website -_- 
> Now I can't even sign a user up anymore because it's requesting all those
> additional fields.
>
>
>
> On Thu, Dec 6, 2012 at 2:33 PM, Anthony  wrote:
>
>> You are using SQLFORM.factory to handle the upload, but the table and
>> field names used there do not match the table or field names where the
>> records are actually stored, so response.download() cannot find the
>> appropriate table or field. By default, SQLFORM.factory uses "no_table" as
>> the dummy table name, and your code uses "image" as the field name. So,
>> your image files will end up with names that start with "no_table.image".
>> As a result, response.download(request, db) will look for a db.no_table
>> table with an "image" field, but obviously won't find it. Instead, your
>> image filenames are actually stored in db.auth_user.t_image, so you need to
>> make sure the filenames get generated with names starting with
>> "auth_user.t_image".
>>
>> Also, if you specify a custom uploadfolder, you'll need to make sure that
>> the db.auth_user.t_image field has that uploadfolder specified as well,
>> because response.download() checks the actual db field to determine the
>> uploadfolder. The easiest approach might be to define the field once and
>> reference both in the appended auth_user fields and in SQLFORM.factory.
>>
>> Finally, you can specify the name of the dummy table used by
>> SQLFORM.factory by passing a "table_name" argument.
>>
>> So, maybe something like this:
>>
>> image_field = Field('t_image', 'upload', ..., uploadfolder=[your upload
>> folder])
>> auth.settings.extra_fields['auth_user'] = [..., image_field, ...]
>> ...
>> tform = SQLFORM.factory(..., image_field, ..., table_name='auth.user')
>>
>> Actually, you should probably do that with all the fields in
>> SQLFORM.factory -- define them all once and use them in db.auth_user and to
>> make the form. As it is, the field definitions in db.auth_user don't even
>> have the correct field types defined. You could first add all the fields to
>> db.auth_user, and then do something like this:
>>
>> tform = SQLFORM.factory(*[f for f in db.auth_user if f.name.startswith(
>> 't_')], ...)
>>
>> That will include all the fields from db.auth_user that start with "t_".
>>
>> Finally, note that there will not be any errors in the form until you
>> process it, so your condition that checks for errors will never find any.
>> First call, form.process(), and then check for errors.
>>
>> Anthony
>>
>>
>> On Thursday, December 6, 2012 8:51:02 AM UTC-5, Daniele wrote:
>>
>>> Ok here's my code:
>>>
>>> in db.py
>>>
>>> from gluon.tools import Auth, Crud, Service, PluginManager, prettydate
>>>
>>>
>>>
>>>
>>> auth = Auth(db)
>>> auth.settings.extra_fields['**auth_user']= [
>>>
>>>
>>>
>>>
>>> # t denote tutor fields, s denote student fields.
>>> Field <http://127.0.0.1:8000/examples/global/vars/Field>('t_image'),
>>>
>>>
>>>
>>>
>>> Field <http://127.0.0.1:8000/examples/global/vars/Field>('t_location'),
>>>
>>>
>>>
>>>
>>> Field <http://127.0.0.1:8000/examples/global/vars/Field>('t_subjects'),
>>>
>>>
>>>
>>>
>>> Field 
>>> <http://127.0.0.1:8000/examples/global/vars/Field>('t_qualifications'),
>>>
>>>
>>>
>>>
>>> Field <http://127.0.0.1:8000/examples/global/vars/Field>('t_biography'),
>>>
>>>
>>>
>>>
>>> Field 
>>> <http://127.0.0.1:8000/examples/global/vars/Field>('t_hourly_rate'),
>>>
>>>
>>>
>>>
>>> Field 
>>> <http://127.0.0.1:8000/examples/global/vars/Field>('t_modified_on'),
>>>
>>>
>>>
>>>
>>> Field <http://127.0.0.1:8000/examples/global/vars/Field>('s_location')]
>>>
>>>
>>>
>>>
>>>
>>> in my controller:
&

Re: [web2py] Re: Displaying an image

2012-12-06 Thread Daniele Pestilli
Yes I did but, the reason why I hadn't extended those directly in auth_user
was precisely because I had noticed that, since some of those fields are
required, when a user signs up they are prevented from signing up because
those other auth fields have not been input. So what I'll do instead is
just create another table for tutors and put all the fields there. Then in
the SQLFORM.factory I'll use that list comprehension that you wrote to add
all the fields. This is what I had done initially but I was having lots of
trouble referencing the current logged in user.


On Thu, Dec 6, 2012 at 3:20 PM, Anthony  wrote:

> The last line was just an example -- if you don't need all the fields,
> then don't use that (or modify it accordingly). Did you try the first
> solution (i.e., properly naming and defining both the image field and the
> SQLFORM.factory table)?
>
> Anthony
>
>
> On Thursday, December 6, 2012 10:05:43 AM UTC-5, Daniele wrote:
>
>> this just completely broke my website -_- 
>> Now I can't even sign a user up anymore because it's requesting all those
>> additional fields.
>>
>>
>> On Thu, Dec 6, 2012 at 2:33 PM, Anthony  wrote:
>>
>>> You are using SQLFORM.factory to handle the upload, but the table and
>>> field names used there do not match the table or field names where the
>>> records are actually stored, so response.download() cannot find the
>>> appropriate table or field. By default, SQLFORM.factory uses "no_table" as
>>> the dummy table name, and your code uses "image" as the field name. So,
>>> your image files will end up with names that start with "no_table.image".
>>> As a result, response.download(request, db) will look for a db.no_table
>>> table with an "image" field, but obviously won't find it. Instead, your
>>> image filenames are actually stored in db.auth_user.t_image, so you need to
>>> make sure the filenames get generated with names starting with
>>> "auth_user.t_image".
>>>
>>> Also, if you specify a custom uploadfolder, you'll need to make sure
>>> that the db.auth_user.t_image field has that uploadfolder specified as
>>> well, because response.download() checks the actual db field to determine
>>> the uploadfolder. The easiest approach might be to define the field once
>>> and reference both in the appended auth_user fields and in SQLFORM.factory.
>>>
>>> Finally, you can specify the name of the dummy table used by
>>> SQLFORM.factory by passing a "table_name" argument.
>>>
>>> So, maybe something like this:
>>>
>>> image_field = Field('t_image', 'upload', ..., uploadfolder=[your upload
>>> folder])
>>> auth.settings.extra_fields['**auth_user'] = [..., image_field, ...]
>>> ...
>>> tform = SQLFORM.factory(..., image_field, ..., table_name='auth.user')
>>>
>>> Actually, you should probably do that with all the fields in
>>> SQLFORM.factory -- define them all once and use them in db.auth_user and to
>>> make the form. As it is, the field definitions in db.auth_user don't even
>>> have the correct field types defined. You could first add all the fields to
>>> db.auth_user, and then do something like this:
>>>
>>> tform = SQLFORM.factory(*[f for f in db.auth_user if f.name.startswith(
>>> 't_')], ...)
>>>
>>> That will include all the fields from db.auth_user that start with "t_".
>>>
>>> Finally, note that there will not be any errors in the form until you
>>> process it, so your condition that checks for errors will never find any.
>>> First call, form.process(), and then check for errors.
>>>
>>> Anthony
>>>
>>>
>>> On Thursday, December 6, 2012 8:51:02 AM UTC-5, Daniele wrote:
>>>
 Ok here's my code:

 in db.py

 from gluon.tools import Auth, Crud, Service, PluginManager, prettydate





 auth = Auth(db)
 auth.settings.extra_fields['**au**th_user']= [





 # t denote tutor fields, s denote student fields.
 Field ('t_image'),





 Field ('t_location'),





 Field ('t_subjects'),





 Field 
 ('t_qualifications'),





 Field 
 ('t_biography'),





 Field 
 ('t_hourly_rate'),





 Field 
 ('t_modified_on'),





 Field ('s_location')]






 in my controller:


 @auth.requires_login()
 def edit_profile():
 response 
 .subtitle = T 
 

Re: [web2py] Re: Add button to form & access from view

2012-12-18 Thread Daniele Pestilli
Sure thing Massimo,

here's my view: http://bpaste.net/show/nSrzmYsurH2CnXLrpdwJ/

here's my controller: http://bpaste.net/show/KEx38v6ARYgsUwG8oXMd/

Daniele


On Tue, Dec 18, 2012 at 5:07 PM, Massimo Di Pierro <
massimo.dipie...@gmail.com> wrote:

> Please post your code so we can try it.
>
> Are you sure the edit_profile is not being called? Can you use the JS
> console in chorme to see what is going on?
>
> Massimo
>
> On Tuesday, 18 December 2012 10:49:28 UTC-6, Daniele wrote:
>>
>> Still isn't working for me :'(
>>
>> In my view, I have:
>> {{=A('Delete Role',_class="btn
>> btn-danger",_id='deltutorlink'**, callback=URL('edit_profile'),**
>> delete='#deltutor')}
>>
>> in my controller, under the edit_profile method, I have:
>>
>> if request.vars.deltutorlink:
>> response.flash = T('deltutorlink reached!')
>>
>> but this response.flash is never reached. I can't figure out why
>>
>>
>> On Saturday, December 15, 2012 7:36:34 PM UTC, Massimo Di Pierro wrote:
>>>
>>>  {{=A('delete 
>>> 123',callback=URL('delete',**args=123),delete='#row123')}}
>>> ... 
>>>
>>>
>>> The delete argument indicates that upon success you want to remove the
>>> ... from the page. If there is a "delete" argument
>>> the confirmation popup is automatic. ;-)
>>>
>>> On Saturday, 15 December 2012 11:35:28 UTC-6, Daniele wrote:

 I want to do something very simple but it's taking me eons to do this~

 When the button is clicked, I want a javascript alert to pop up that
 asks, are you sure? Yes/No.
 If Yes, then run this code: auth.del_membership('role')

 No redirection, just delete the role.
 That's all -_- this is taking me way too long

 On Saturday, December 15, 2012 3:32:22 PM UTC, Massimo Di Pierro wrote:
>
> None. You are asking to ":eval" the result. It meas the action is
> supposed to return JS
>
> def test():
> return "alert('hello')"
>
> anyway, you should debug this with the JS console in chrome. We do not
> know exactly how your code looks like.
>
> On Saturday, 15 December 2012 09:08:37 UTC-6, Daniele wrote:
>>
>> I am trying with:
>> {{=A('Delete Role', _class="btn btn-danger", _id="del_role_tutor",
>> callback=URL('test'), target=":eval")}}
>>
>> and in my controller:
>>
>> def test():
>> return "Hello"
>>
>> or
>>
>> def test():
>> return dict()
>>
>> but when I click the button, nothing happens. Why is this??
>>
>> On Monday, December 10, 2012 9:15:30 PM UTC, Daniele wrote:
>>>
>>> When I use form.add_button() I am able to add a button to a form,
>>> which I can display with {{=form}} in my view.
>>>
>>> However, if I'm making a custom form using form.custom, how can I
>>> display that button??
>>>
>>> Thanks
>>>
>>  --
>
>
>
>

-- 





Re: [web2py] Delete a user

2013-01-07 Thread Daniele Pestilli
Well, I know I can do this from the admin interface but I was wondering how
a user can remove himself from the website if he so wishes.

Should I put the code `db(db.auth_user.email=="some...@domain.com").delete()`
in a {{=A(_href=action)}} or is that bad practice? I want the user to be
able to delete himself.


On Mon, Jan 7, 2013 at 9:56 PM, Bruno Rocha  wrote:

>
> If you have shell access.
>
> Go to your shell
>
> python web2py.py -S yourappname -M
>
> >>> db(db.auth_user.email=="some...@domain.com").delete()
> >>> db.commit()
>
> The user with "some...@domain.com" is now deleted!
>
> If you dont hace shell access, just go to your admi  interface, database
> adminitration and delete from auth_user table.
>
> --
>
>
>
>

-- 





Re: [web2py] Re: Resizing a user uploaded image

2013-01-08 Thread Daniele Pestilli
I put imageutils in my app's modules directory, then I added:
Field("thumbnail", "upload", uploadfolder=os.path.join(request.folder,
'uploads', 'profiles', 'thumbs')),
to the appropriate database table, and below that, in the same file (db.py)
I wrote:

from imageutils import THUMB
db.tutor.thumbnail.compute = lambda row: THUMB(row.picture, 200, 200)

but the resizing doesn't seem to work. Am I doing something wrong?


On Tue, Jan 8, 2013 at 9:29 PM, Michele Comitini  wrote:

> I use wand for the task: http://pypi.python.org/pypi/Wand/0.1.10
> there are many other bindings on the impressive *magick libraries, but
> this one being a ctypes implementation is light and fast enough..
>
> mic
>
>
> 2013/1/8 Bruno Rocha :
> > I am using this recipe:
> >
> >
> http://www.web2pyslices.com/slice/show/1522/generate-a-thumbnail-that-fits-in-a-box
> >
> > I have plans to integrate it with a JavaScript Cropper plugin to get the
> > dimensions.
> >
> > --
> >
> >
> >
>
> --
>
>
>
>

-- 





Re: [web2py] Re: Resizing a user uploaded image

2013-01-08 Thread Daniele Pestilli
Hmm still not working.
I'm wondering if this is the problem:
uploadfolder=os.path.join(request.folder, 'uploads', 'profiles', 'thumbs')
should it be
uploadfolder=os.path.join(request.folder, 'uploads', 'profiles/thumbs')  or
something?


On Wed, Jan 9, 2013 at 12:43 AM, Bruno Rocha  wrote:

> Yeah it is a problem in THUMB function, thumb function looks for files
> under /uploads and you are defining another folder.
>
> change the imageutils module replacing /uploads with /uploads/profile
>
> On Tue, Jan 8, 2013 at 9:30 PM, Daniele Pestilli wrote:
>
>> I put imageutils in my app's modules directory, then I added:
>> Field("thumbnail", "upload", uploadfolder=os.path.join(request.folder,
>> 'uploads', 'profiles', 'thumbs')),
>> to the appropriate database table, and below that, in the same file
>> (db.py) I wrote:
>>
>> from imageutils import THUMB
>> db.tutor.thumbnail.compute = lambda row: THUMB(row.picture, 200, 200)
>>
>> but the resizing doesn't seem to work. Am I doing something wrong?
>>
>>
>> On Tue, Jan 8, 2013 at 9:29 PM, Michele Comitini <
>> michele.comit...@gmail.com> wrote:
>>
>>> I use wand for the task: http://pypi.python.org/pypi/Wand/0.1.10
>>> there are many other bindings on the impressive *magick libraries, but
>>> this one being a ctypes implementation is light and fast enough..
>>>
>>> mic
>>>
>>>
>>> 2013/1/8 Bruno Rocha :
>>> > I am using this recipe:
>>> >
>>> >
>>> http://www.web2pyslices.com/slice/show/1522/generate-a-thumbnail-that-fits-in-a-box
>>> >
>>> > I have plans to integrate it with a JavaScript Cropper plugin to get
>>> the
>>> > dimensions.
>>> >
>>> > --
>>> >
>>> >
>>> >
>>>
>>> --
>>>
>>>
>>>
>>>
>>  --
>>
>>
>>
>>
>
>  --
>
>
>
>

-- 





Re: [web2py] Re: Resizing a user uploaded image

2013-01-08 Thread Daniele Pestilli
It seems to be uploading the full-sized image properly but for the thumb it
says 'thumbnail': None where thumbnail is the field name in the db.py file.


On Wed, Jan 9, 2013 at 1:06 AM, Daniele Pestilli wrote:

> Hmm still not working.
> I'm wondering if this is the problem:
>
> uploadfolder=os.path.join(request.folder, 'uploads', 'profiles', 'thumbs')
> should it be
> uploadfolder=os.path.join(request.folder, 'uploads', 'profiles/thumbs')
> or something?
>
>
> On Wed, Jan 9, 2013 at 12:43 AM, Bruno Rocha wrote:
>
>> Yeah it is a problem in THUMB function, thumb function looks for files
>> under /uploads and you are defining another folder.
>>
>> change the imageutils module replacing /uploads with /uploads/profile
>>
>> On Tue, Jan 8, 2013 at 9:30 PM, Daniele Pestilli 
>> wrote:
>>
>>> I put imageutils in my app's modules directory, then I added:
>>> Field("thumbnail", "upload", uploadfolder=os.path.join(request.folder,
>>> 'uploads', 'profiles', 'thumbs')),
>>> to the appropriate database table, and below that, in the same file
>>> (db.py) I wrote:
>>>
>>> from imageutils import THUMB
>>> db.tutor.thumbnail.compute = lambda row: THUMB(row.picture, 200, 200)
>>>
>>> but the resizing doesn't seem to work. Am I doing something wrong?
>>>
>>>
>>> On Tue, Jan 8, 2013 at 9:29 PM, Michele Comitini <
>>> michele.comit...@gmail.com> wrote:
>>>
>>>> I use wand for the task: http://pypi.python.org/pypi/Wand/0.1.10
>>>> there are many other bindings on the impressive *magick libraries, but
>>>> this one being a ctypes implementation is light and fast enough..
>>>>
>>>> mic
>>>>
>>>>
>>>> 2013/1/8 Bruno Rocha :
>>>> > I am using this recipe:
>>>> >
>>>> >
>>>> http://www.web2pyslices.com/slice/show/1522/generate-a-thumbnail-that-fits-in-a-box
>>>> >
>>>> > I have plans to integrate it with a JavaScript Cropper plugin to get
>>>> the
>>>> > dimensions.
>>>> >
>>>> > --
>>>> >
>>>> >
>>>> >
>>>>
>>>> --
>>>>
>>>>
>>>>
>>>>
>>>  --
>>>
>>>
>>>
>>>
>>
>>  --
>>
>>
>>
>>
>
>

-- 





Re: [web2py] Re: Resizing a user uploaded image

2013-01-09 Thread Daniele Pestilli
No, just regular web2py webserver on my machine.

Jan 9, 2013 2:36 AM、Bruno Rocha  のメッセージ:

> are you running on Google App Engine?
> -- 
>  
>  
>  

--