Re: [web2py] Re: Emails never making it to hotmail accounts

2012-04-29 Thread tsvim
i just looked up your domain. You should setup DKIM and SPF records for your 
domain. Don't have the links to explanations handy, but basically those are two 
different technologies that allow you to authenticate the source of the mail 
thereby proving that a spammer didn't just set the from field to your domain.
It's quite easy under Google apps. DKIM requires you to generate a key for your 
domain which you enter as a text record at your DNS provider. SPF doesn't 
require a key, just a DNS txt record telling the receiver that he should check 
with Google that this is  valid user.

Hope it helps,

Tsvi


[web2py] Viewing tickets outside of admin

2012-03-28 Thread tsvim
Hi,

Lately, I've been using pythonanywhere to work on my pet project together 
with Dropbox. It's very fun, as it allows me to test all kinds of access 
(mobile, desktop), various environments (work, home), os's etc.
Obviously I'm unable to access the admin as I'm not at a local machine and 
I don't want to enable remote access to the admin.
I was wondering since I'm using Dropbx to sync my files, I do have local 
access to the ticket files themselves.
Is there some parser that would allow me to look at the tickets without 
needing to run web2py locally to have access to the admin?
I would even imagine a hook that would automagically parse the ticket into 
text form and save a text version of it.

Thanks,

Tsvi


Re: [web2py] Re: DAL or SQL?

2012-03-26 Thread tsvim

Not sure if this is relevant, but you can do the following with datetime.

>>> import datetime
>>> a = datetime.datetime(2007, 12, 6, 16, 29, 43, 79043)
>>> b = datetime.datetime(2011, 10, 3, 12, 0, 0, 0)
>>> c = b-a
>>> c
datetime.timedelta(1396, 70216, 920957)
>>> (c.microseconds + (c.seconds + c.days * 3600 * 24) * 10**6) / 10**6
120684616

(I have Python 2.6 at work, otherwise you can do c.total_seconds())

On Monday, March 26, 2012 1:41:09 AM UTC+2, Niphlod wrote:
>
> Doh, you're right. All the "datetime" api on fields are extracting, not 
> converting the actual value
> At this point you can sum up years difference, month difference, etc etc 
> etc separately and then extract the time passed by.
> .
> duration_ye = (db.periods.end_time.year() - 
> db.periods.start_time.year()).​sum()
> duration_mo = (db.periods.end_time.month() - 
> db.periods.start_time.month())​.sum()
> duration_da = (db.periods.end_time.day() - 
> db.periods.start_time.day()).​sum()
> .
>
> This will be a "itchy" shot anyway even if you know that the months 
> difference is "1" you can't really say how many days passed
>
> Maybe at this stage is better to save unix time, that is an integer, and 
> proceed simply with
>
> duration = (db.periods.end_time - db.periods.start_time).sum()
>
> Or, having the application filling in the seconds elapsed when it 
> completes something like
> period_to_update = db(db.periods.id==1).select().​first()
> start_time = period_to_update.start_time
> period_to_update.update_​record(end_time=request.now, 
> seconds_elapsed=(request.now - start_time).seconds)
>
> Sorry for the wrong previous advices, really, I should have tested with 
> all kinds of values (instead of 2012-01-01 00:00:00 and 2012-01-01 
> 00:00:15).
>


[web2py] Re: auth.login() from inside a component in a dialog

2012-03-22 Thread tsvim
I think this actually is a bug. I haven't looked at it more, but I changed 
my default controller/function to home/index
When I login (regular login except for the following lines in my model) it 
returns me to default/index (my old controller still exists there until I 
finished refactoring the code).

def get_last_opened(form):
if auth.has_membership(auth.user.last_opened):
session.table_token = auth.user.last_opened
else:
redirect(URL('error','index'))

auth.settings.login_onaccept = get_last_opened

If I have more time next week and the issue is not solved, I'll take a 
better look at it.

On Thursday, March 22, 2012 3:33:30 PM UTC+2, Anthony wrote:
>
> > I believe auth.settings.login_next only has an effect when there is no 
>> > session._auth_next (i.e., when the user goes directly to the login URL 
>> > rather than getting there via an internal link or redirect). 
>>
>> Your logic is sound, but I'm afraid this is not the case. I am 
>> directly going to myapp/login and then getting redirected via 
>> session._auth_next to default/index. 
>>
>
> Puzzling. Could be a bug.
>  
>
>> I thought this is what the auth.settings.login_onaccept = [myonaccept] 
>> was supposed to do (see my example stated earlier). That was my first 
>> attempt as it seemed the most logical. Am I doing something wrong 
>> there?
>>
>
> auth.settings.login_onaccept gets called after a successful login, but 
> it's not the very last thing that happens in auth.login() -- after the 
> callback, auth.login() still proceeds to do its usual redirect. The 
> redirect starts a whole new request, so if you set response.js before the 
> redirect, it will get lost. Here's why -- when you set response.js, it adds 
> the JS code to a special web2py-component-command header. However, because 
> of the redirect, that header will arrive at the browser as part of a 303 
> redirect response. When the browser receives a redirect response, it 
> immediately issues the redirect request without further processing the XHR 
> object, so the client-side web2py JS code never gets to process the 
> web2py-component-command header. Instead, you have to set response.js 
> *after* the redirect, or simply prevent the redirect altogether (hence my 
> suggestion to have your callback raise an HTTP() response).
>
> Anthony
>


[web2py] Re: Possible bug with a referenced field?

2012-03-01 Thread tsvim
This issue seems to be related to the one that was mentioned sone time ago 
about multi-tenancy and validators. I think IS IN DB should deal with this. So 
unless you specify the request tenant field IS IN DB should only relate to the 
specific tenant. I'll build a patch accordingly. Please notify me if that's not 
the way you envision it. 


[web2py] Re: Possible bug with a referenced field?

2012-02-29 Thread tsvim
Hi,

I attached a file with code that reproduces the problem.
For this example I expect to only return options African and Swallow, not 
John and not Doe.
I traced the problem back to the call from sqlhtml.py on line 217 to the 
IS_IN_DB validators function options(). I'm not sure if the fix should be 
in the widget or in the IS_IN_DB validator.
Personally I'd fix it in the IS_IN_DB validator, but then that might break 
the way request_tenant was intended to behave and/or break backwards 
compatibiity.

If you tell me where you want it fixed I might be able to cook up a patch 
over the weekend,

Thanks,

Tsvi

On Wednesday, February 29, 2012 12:47:04 AM UTC+2, tsvim wrote:
>
> Hi,
>
> In my models I have 2 tables, where table 1 has field "a" referencing
> table 2. As each user has a bunch of fields both in table 1 as well as
> in table 2, I used the request_tenant field with some uuid in both
> tables which is tied to the user (I'm not using the users ID for
> various reasons).
> I tried creating a form for table 1 with SQLFORM, but the select
> dropdown for field "a" returns all the items in table 2, and doesn't
> filter them according to the request_tenant field, which I would
> consider the correct behavior.
>
> I'll show some code tomorrow.
> Can you confirm this being a bug? Or am I missing something?
>
> Thanks,
>
> Tsvi
> Sent from my phone
>
>
On Wednesday, February 29, 2012 12:47:04 AM UTC+2, tsvim wrote:
>
> Hi,
>
> In my models I have 2 tables, where table 1 has field "a" referencing
> table 2. As each user has a bunch of fields both in table 1 as well as
> in table 2, I used the request_tenant field with some uuid in both
> tables which is tied to the user (I'm not using the users ID for
> various reasons).
> I tried creating a form for table 1 with SQLFORM, but the select
> dropdown for field "a" returns all the items in table 2, and doesn't
> filter them according to the request_tenant field, which I would
> consider the correct behavior.
>
> I'll show some code tomorrow.
> Can you confirm this being a bug? Or am I missing something?
>
> Thanks,
>
> Tsvi
> Sent from my phone
>
>db = DAL('sqlite://storage.sqlite')
db._common_fields.append(Field('request_tenant',default=lambda: session.token,writable=False))
db.define_table('a',Field('name','string'),format='%(name)s')
db.define_table('b',Field('a_name','reference a'))
session.token = '1234'
sample_list = [{'name':'John'},{'name':'Doe'}]
db.a.bulk_insert(sample_list)
session.token = '4567'
sample_list = [{'name':'African'},{'name':'Swallow'}]
db.a.bulk_insert(sample_list)
form = SQLFORM(db.b)
print form


[web2py] Re: Nesting HTML tables

2012-01-31 Thread tsvim
Well apparently you're correct.
Nesting a table within a table is only possible if the inner table is 
within a td according to the HTML spec. (Not that it doesn't render ok in 
most browsers)
I was copying from some Google result on nested tables.
I managed to get my wanted result by setting a correct colspan on the td 
tag.

Thanks everyone.


[web2py] Re: Auth.registration_requires_invitation

2012-01-23 Thread tsvim
Hi all,

I'd be happy to collaborate on such a feature if needed, as it is something 
on my roadmap for my app.
Basically, I want to allow 2 users to collaborate on the same data, by 
allowing a user to invite a friend to collaborate.
If you have some code already, please share.

Tsvi


[web2py] session.token does not get picked up by default value for database entry

2012-01-18 Thread tsvim
Hi all,

I get the following weird behavior. I defined a common_fields, being 
request_tenant as such:

db._common_fields.append(Field('request_tenant',default=session.table_token,writable=False))

session.table_token is a uuid generated by  the controller.
There I have the following code:

session.table_token = generate_table_token()

if db(db.table).isempty():
   field_name = 'MyField'
   db.table.insert(name=field_name)
   populate(db.table2,100)

But for some reason it won't take the default value for request_tenant the 
first time. When I reload the page it creates new entriees with the session 
variable correct this time.

I suppose session.table_token does not get evaluated when I first generate 
it, so how can I get the requested behavior? (Both with populate and insert)

Thanks a million for your help,

Tsvi


[web2py] Inherit type from parent

2012-01-15 Thread tsvim
Hi all, once again I turn to you with my latest question.
I have a self-referencing table:

db.define_table('accounts',
Field('name','string'),
Field('parent_account','reference accounts'),
Field('account_type','string'))

What I'm trying to achieve is to create a tree-like structure. So we have 5 
"root" accounts, which can each hold some sub-accounts etc.
Now the account_type must be the same for all the children of a certain 
account. So the root accounts pre-determine all of the children's account 
type, rendering it unwritable for a child account.
For some reason the following didn't work for me:

account_types = ['a','b','c']
db.accounts.account_type.requires  = IS_IN_SET(account_types)
db.accounts.account_type.required  = True
db.accounts.account_type.compute = lambda x: 
x['parent_account'].account_type
db.accounts.account_type.writeable = lambda x: (x['parent_account'] == 0)

Thanks for your help,

Tsvi


[web2py] global functions in models

2012-01-04 Thread tsvim
Hi all,

I'm trying to use the callbacks for auth.settings.register_onvalidation.
I first put the function in controllers, when I discovered it should be in 
models as the settings are there.
Now I have them in models, but I get a invalid syntax error on the last 
line:

def register_new_table_token():
auth.user.last_opened = session.table_token
auth.add_membership(auth.add_group(session.table_token),auth.user.id)
auth.user.my_budgets.append(session.table_token)
return

This happens both when I have pass instead of return or I don't enter a 
return statement.

Please help,

Thanks,

Tsvi


[web2py] Custom registration action

2012-01-03 Thread tsvim
Ok, I changed my code again.

Incredible how so many things were though through before. (Multi-tenancy, 
common_fields, extra_fields in auth, ...)
A big thumbs up to all the devs on this.

What I'd like to do now is have a custom registration action (not form).
I added an extra_field to the auth_user table which should be stored from a 
session variable.
I also would like to create a group based on that same variable and add the 
user to that group.
So I should have something like this in my registration action:
  auth.user.last_opened = session.token
  auth.add_membership(auth.add_group(session.token), auth.user.id)
  
Where last_opened is the name of the new field in auth_user.
The reason I want to use the add_membership is I'd like multiple users to 
be able to share data according to the token.
This way new users can be added to the requested group, allowing them to 
edit the data without touching the personal user's permissions.

How do I go about creating my custom action?
Note that I'd like to still use the view available by the user action if 
possible, or at least have the other user actions still available while 
overriding the register action only.

Thanks for your help,

Tsvi



[web2py] Re: Smartgrid trouble: exceptions KeyError

2011-12-15 Thread tsvim
Ok, after reading up on user_signature, I don't really like to turn it off.
If I do turn it off, I'd like at least something that will allow the same 
for anonymous users.
Is there anyway I can generate a user_signature for some anonymous user?

Thanks,

Tsvi


[web2py] Re: Smartgrid trouble: exceptions KeyError

2011-12-14 Thread tsvim
SOLVED: I forgot to have the define_table statement in the main part, 
otherwise the table is not defined.
I still have trouble as I can'tedit the table. I get a flash response not 
authorized.
I suppose I need to change some setting when calling the smartgrid method.


[web2py] Smartgrid trouble: exceptions KeyError

2011-12-14 Thread tsvim
Ok, getting more experienced here I did some nice cleanup to my code.
I managed to get my 100+ line controller to around 30 :-)

I decided to generate new tables for every user. Instead of filtering one 
huge tabe.
The forst time I load the page everything seems fine, although I'm missing 
the add edit etc buttons.
Then I pushed the Export button and I get the aforementioned error. Now 
every time I reload the page,since I have table_token defined the call to 
smartgrid generates this error.

Here is my controller:

def index():
if session.table_token is None:
if auth.user:
session.table_token = db.budgets.last_opened
user = auth.user.first_name
else:
session.table_token = filter(lambda x: x.isalnum(), 
str(uuid.uuid4()))
user = 'Guest'
db.define_table(session.table_token + '_accounts', accounts)
db.define_table(session.table_token + '_transactions', 
transactions)

grid = SQLFORM.smartgrid(db[session.table_token + '_transactions'])
return dict(user=user,grid=grid)

accounts and transactions are db.Table objects which were previously 
defined.

Any help is kindly appreciated




[web2py] Re: Getting table a to use as default string from field in table b

2011-12-12 Thread tsvim
Ok here's what I want to do.

I want a user to be able to create multiple tables of data, with some 
information about every table.
So instead of creating more tables, I figured I'll have one big table of 
data with a reference to the record in the table_settings database so I can 
return to the user only the information pertaining to his "virtual" table.
I'd like some of the fields in the data table to take their default value 
from the "parent_table" as I call it.
Rethinking my strategy, I think maybe it would be easier performance wise 
to scale by just setting up new tables per user.

Still, if I understand correctly I'd have to setup a AJAX call requesting 
the default values to prepopulate the fields with the defaults matching the 
table?
Or else maybe when creating the table for the user, I could enter the 
default values. I'm trying to imagine though how I would go around 
implementing this.


[web2py] Re: Getting table a to use as default string from field in table b

2011-12-11 Thread tsvim
db.define_table('table_settings',
Field('name','string'),
Field('default_value','string'))

db.define_table('data',

Field('parent_table',db.table_settings,writable=False,readable=False),
Field('datetime','datetime',default=request.now),
Field('title','string'),
Field('value','string'))

db.data.value.default = db.table_settings['parent_table'].default_value
db.table_settings.default_value.requires = IS_IN_SET(['a','b'])



[web2py] Re: Getting table a to use as default string from field in table b

2011-12-11 Thread tsvim
Obviously you're right. I realized later that I needed to re-think what I 
was trying to do.
The id of current user is stored in the data table. Is there a way I can 
refernce that field in the line you gaveme?

Thanks for all your help.


[web2py] Getting table a to use as default string from field in table b

2011-12-10 Thread tsvim
Hi all,

I have 1 table with a lot of fields. Some of them, I want to have a default 
value dependent on the user.
In the user table I have a field called default_x. I tried setting the 
default for field x in the data table to 'user_table.default_x'. Which did 
not work.
Any ideas how to achieve this functionality?


Re: [web2py] Ajax and table rows.

2011-11-21 Thread tsvim
Ok, now that this works seems I'm still in trouble.
The page I'm loading is one that has a table that I'm trying to make 
clickable and a form to enter more data.
Here is the controller:

@auth.requires_login()
def budget():
db.expense.parent_table.default = request.args(0)
db.expense.category.requires = 
IS_IN_DB(db(db.categories.parent_table==request.args(0)),'categories.id','categories.name')
form = crud.create(db.expense)
expenses = db(db.expense.parent_table==request.args(0)).select()
return dict(user=auth.user.first_name, expenses=expenses, form=form)

def edit_expense():
return repr(request.vars.id)

My view:

  
Date and Time
Title
Category
Amount
Source
  

  {{ for expense in expenses: }}

  
{{=expense.datetime}}
{{=expense.title}}
{{=expense.category.name}}
{{=expense.amount}} {{=expense.denomination}}
{{=expense.source}}
  
  {{pass}}




{{=form}}


$(document).ready(function () {
 $('.expenses').click(function(){
  ajax('edit_expense?id=' + $(this).attr('id'), [], '#target') 
 });
});




I added the AJAX script to have it return to edit_expense the id of the row 
that was clicked but I get an error about the crud.create line in my 
controller.

Thanks again for your help.

Tsvi


[web2py] Re: Ajax and table rows.

2011-11-21 Thread tsvim
Thanks,

you guys rock community support.


[web2py] Ajax and table rows.

2011-11-21 Thread tsvim
Hi all,

I'm trying to have a ajax callback function whenever I click a certain row. 
I'd like that row to return the id of the record the row represents.
I'm at loss as to the middle argument for the ajax function. I checked the 
function in the controller gets called but the argument is wrong.
I created a simple example so I could try and traceback the problem but I 
think I'm doing something wrong.

This is my view:

{{extend 'layout.html'}}



HelloWorld


Row 2New world





And the following is my controller:

def one():
return dict()

def echo():
return "jQuery('#target').html(%s);" % request.vars.id

What am I doing wrong?


[web2py] Re: Passing the newly created record's id to another function in the controller

2011-11-13 Thread tsvim
Thanks for the explanation.
Taking this explanation I tried forwarding the id of the record to a 
"onaccept" action using the same logic you applied using "%(id)s" as an 
argument to the function. Again I seem to be missing something.
How can I pass the record's id to the onaccept action?

Thanks again for all your help.


[web2py] Setting the default value for the first item in a list

2011-11-13 Thread tsvim
Hi all,

Another quick question:

I want to add a user's email by default to a list:string in my db.
So I did the following:
db.table_settings.members.default = auth.user.email

Obviously that didn't work. Sending table_settings to Crud generated a list 
with each of the elements being 1 character of the user's email.
So what I did was the following:
db.table_settings.members[0].default = auth.user.email

But this returns an empty string in the form. What am I doing wrong?



[web2py] Re: Passing the newly created record's id to another function in the controller

2011-11-13 Thread tsvim
Thanks. That did the trick.

I'd like to understand though what special characters? Isn't the id just a 
number?


[web2py] Passing the newly created record's id to another function in the controller

2011-11-12 Thread tsvim
Hi,

In my current project I have a function (a) in the controller which
calls Crud to create a new record. After which function (a) sends the
user to function (b) using the "next" directive in Crud. I'd like to
have function (b) know the id of the record created which sent them
over so it could store the reference in one of it's fields.

I tried setting args=id, args=[id], args="id" but nothing seems to
work. I'd greatly appreciate your help.

Thanks,

Tsvi Mostovicz

Here follows the code I have at the moment:

def a():
form = crud.create(db.a,
   next=URL(args=[id],f='b'))
return dict(form=form)

def b():
form = crud.create(db.b)
a = db(db.b.settings==request.args(0)).select()
return dict(a=a, form=form)