[web2py] Re: web2py as Grafana endpoint

2016-11-27 Thread Dave S
Any suggestions on how to force the response to ASCII instead of UFT-8?

/dps


On Tuesday, November 22, 2016 at 11:36:27 PM UTC-8, Dave S wrote:
>
>
>
> On Thursday, November 17, 2016 at 11:09:27 PM UTC-8, Dave S wrote:
>>
>>
>>
>> On Thursday, November 17, 2016 at 2:38:57 PM UTC-8, Niphlod wrote:
>>>
>>> if the request comes in either as a POST or as a PUT it has a body 
>>> (since all examples report a faily nested query structure, I'd say it's the 
>>> case vs a simple querystring in a GET)
>>>
>>> If the body carries the correct content-encoding, it's automatically 
>>> parsed into request.vars. You can still read the raw body as usual in 
>>> request.body .
>>>
>>>
>> Thanks, that helped me to know what to look for.  I got the Grafana stuff 
>> installed, it does the fake-json-source ok, and with FF developer tools 
>>  I'm seeing the traffic to my nascent endpoint.
>>
>> When configuring the datasource URL, it does a GET to the base URL (the 
>> one just for "checking in", return an HTTP 200; I put a little status json 
>> into the response body just for grins).  When you configure a panel (the 
>> youtube videos they provide are important here) and select a metric , it 
>> will do an OPTIONS and then a POST.
>>
>> I had put some CORS headers into my response, because FF is seeing me 
>> return data when it accesses the Gravana server.   [Sidebar question:  does 
>> the book cover anything about valid CORS?  I didn't find it if it's there; 
>> fortunately, there were some good posts in the GG archive.  The book does 
>> have little bits about providing protection against against black-hat 
>> CORS.]  The request to me seems to come from the client JS -- since it 
>> shows in the network panel -- but FF gives CORS errors if I don't have the 
>> headers.
>>
>> So now I just have to make a good response to the metric requests.
>>
>> /dps
>>
>>  
> I may have to force the response to ASCII, and I don't remember how to do 
> that.  My JSON is currently being decoded as 36 or so objects, each a 
> single character, while the fake source response is being decoded as a 
> single compound object (per the FF devtool network tab), and the Grafana 
> display is saying "datapoints is undefined".
>
> My  content header line says "application/json;encoding/utf-8", theirs 
> says only "application/json".
>
> /dps
>
>
>>>
>>> On Tuesday, November 15, 2016 at 10:50:23 PM UTC+1, Dave S wrote:

 I'm trying to implement a simple json endpoint for Grafana.  Does 
 anyone here have experience with doing this?

 >>> https://github.com/grafana/simple-json-datasource/blob/master/README.md
 >

 I'm looking at using @service.json, but I'm not sure how to get the 
 body on a /query.

 (The sample fake-simple-json-datasource is a server written in 
 javascript!  It doesn't make clear if the /query is a POST or a GET, and 
 if 
 it's a GET how the body gets done.)

 /dps



-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] S3 Fineuploader with web2py

2016-11-27 Thread Sharjeel Ali Shaukat
Does anyone done work on fineuploaders3 with web2py need multipart upload 
tutorial regarding that
Please help

-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: REST especification - Documentation RESTFul services in web2py

2016-11-27 Thread Massimo Di Pierro
You are right. That documentation is 10 years old and needs a revision.

On Saturday, 26 November 2016 17:08:33 UTC-6, Marlysson Silva wrote:
>
> In web2py's documentation about RESTFul services it shows how retrieve 
> resources by people , example:
>
> http://127.0.0.1/myapp/default/api/persons.json
>
>
> And after it shown how retrieve a unique person :
>
> http://127.0.0.1/myapp/default/api/person/1.json
>
> But in REST especification ( or at least by convention ) is recommended 
> handle all resources in plural .. and too to stay an api clean .. without 
> many endpoints..
>
> Just observation about the diference in how web2py handle data endpoints 
> and the convention in world. :D 
>
> Have you some consideration?
>
>
>

-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: web2py with IIS and Postgresql

2016-11-27 Thread Massimo Di Pierro
Can you access it from the shell. I would be surprised if there are no 
restrictions to connect to a remote prostgres. You may need a SSL tunnel.

On Friday, 25 November 2016 22:11:41 UTC-6, Alvaro Diaz Valenzuela wrote:
>
> Hi, I have successfully installed web2py behind IIS on an Azure VM with 
> Windows Server 2012R (following Remco Boerma's great tutorial on youtube). 
> However, I am not able to establish a connection with a postgresql database 
> hosted on AWS. I am pretty sure my connection string is Ok and I have 
> granted the necessary permissions on AWS. Will pg8000 work in this context? 
> Has anyone been able to make this kind of configuration work? I am not sure 
> what other info is necessary to get some help. I f anyone can lend a hand 
> it would be greatly appreciated.
> Thanks,
> ADV
>

-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] bulk insert and it's data type have a strange behaviour

2016-11-27 Thread 黄祥
just wondering about bulk insert and it's data type have a strange 
behaviour (error traceback occured), while the same code using DAL insert 
syntax and using import csv don't have a problem
*e.g.*
*models/db.py*
def __before_insert_attendance(f):
chosen_employee = db(db.employee.id == f['employee'] ).iterselect().first()
f['basic_salary'] = int(chosen_employee.basic_salary)
f['meal'] = int(chosen_employee.meal)
f['transport'] = int(chosen_employee.transport)
f['total'] = f['basic_salary'] + f['meal'] + f['transport']

db.define_table('attendance', 
Field('attendance_date', 'date'),
Field('employee', 'reference employee'), 
Field('basic_salary', 'integer'), 
Field('meal', 'integer'), 
Field('transport', 'integer'), 
Field('total', 'integer'), 
format = lambda r: '%s - %s %s' % (r.attendance_date, 
r.employee.first_name, r.employee.last_name) )

db.attendance._before_insert.append(__before_insert_attendance)
db.attendance.basic_salary.represent = lambda value, field: SPAN('%s' % 
(format(value, ",d").replace(",", ".") ) )

*controllers/install_demo.py*
def index():
if db(db.attendance).isempty():
db.employee.bulk_insert([
{'first_name' : 'User', 'last_name' : 'Staff', 
 'basic_salary' : 1, 'meal' : 0, 'transport' : 0}, 
{'first_name' : 'User', 'last_name' : 'Packing', 
 'basic_salary' : 1, 'meal' : 1500, 'transport' : 0}, ] )

#db.attendance.insert(attendance_date = "2016-11-01", employee = 1) # DAL 
insert syntax run well
db.attendance.bulk_insert([
  {'attendance_date' : '2016-11-01', 'employee' : 1}, 
  {'attendance_date' : '2016-11-02', 'employee' : 2}, ] )

*test.csv*
TABLE attendance
attendance_date,employee
2016-11-25,1

*error traceback using bulk insert when access attendance SQLFORM.grid*
db.attendance.basic_salary.represent = lambda value, field: SPAN('%s' % 
(format(value, ",d").replace(",", ".") ) )
ValueError: Unknown format code 'd' for object of type 'str'

i know i can simply comment the represent in the attendance table, but the 
same code using the different syntax have the different result.

any idea how to face it using web2py way?

thanks and best regards,
stifan

-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Smart-joins helper needs peer review :)

2016-11-27 Thread Jurgis Pralgauskis
Hi, 

Web2py is nice for its expression brevity -- but  joins still need quite 
long texting..
I wanted to make it simpler, because "readability counts" 
 :)

now you can write

build_joins( ['auth_user', 'auth_membership', 'auth_group', 
'auth_permission'] )

instead of 

[
  db.auth_membership.on( db.auth_membership.user_id == db.auth_user.id ) ),
  db.auth_group.on( db.auth_group.id == db.auth_membership.group_id ) ),
  db.auth_permission.on( db.auth_permission.group_id == db.auth_group.id ) ),]


Helper can use DB model to figure out the needed fields for join'ing 
(if it finds more than one possible field -- would throw an error with 
explatnation)

Alpha version
https://github.com/dz0/web2py_grand_helpers/blob/master/joins_builder.py

Sugestions/patches welcome :)

-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [web2py] Adding user to a group after registration

2016-11-27 Thread Joe Lwe
Hi Kumar,
am at the wall with the same problem you hard, am not having success
below is my code, its from the account type table that i have defined 
account type
Any assistance is so much appreciated.
Thank you


/dbypy file
db.define_table('account_type', 
  Field('name', 'string', length=20, notnull=True, label='Account Type'),
  migrate=True,
  format='%(name)s'
  )



#adding extra fields required on registration

auth.settings.extra_fields['auth_user']= [
Field('country', 'reference country'),
Field('district', 'reference district'),
Field('account_type', 'reference account_type', label='Account Type')
]




default.py
def __add_user_membership(form):
group_id = auth.id_group(role=form.vars.account_type)
user_id = form.vars.id
auth.add_membership(group_id, user_id)


def user()
  """
auth.settings.register_onaccept = __add_user_membership

return dict(form=auth())












On Thursday, December 22, 2011 at 1:03:56 AM UTC+3, Chandrakant Kumar wrote:
>
> better version :
>
> def __add_user_membership(form):
>  group_id = auth.id_group(role=form.vars.user_type)
>  user_id = form.vars.id
>  auth.add_membership(group.id,user_id)
>
> On Thu, 22 Dec 2011 01:52:50 +0530, Anthony  > wrote:
>
> > You can use an auth.settings.register_onaccept function, which could use
> > auth.add_membership() to add the appropriate membership for the new user.
> >
> > Anthony
> >
> > On Wednesday, December 21, 2011 3:00:20 PM UTC-5, Chandra wrote:
> >>
> >>
> >> I'm attempting to add a user to a group , depending on the role he chose
> >>  from a dropdown list.
> >>
> >> for e.g., In the register form user is presented an option of choosing
> >> user type 1. individual 2. organisation
> >>
> >> how do i add the user to the appropriate group depending on his  
> >> selection?
> >>
> >> (i went through the group archives, and one solution was to use
> >> request.args, but i want to use single register link)
> >>
>
>
>

-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Do conditionals short circuit for DAL?

2016-11-27 Thread Anthony
On Saturday, November 26, 2016 at 5:39:49 PM UTC-5, Brian M wrote:
>
> Well even if you're writing the query using the DAL the actual data 
> processing is being done by the database itself so that's where the "short 
> circuiting" would need to happen and is dependent on the database's query 
> optimization. Try running a SQL version of the query directly against the 
> DB and see if it's any faster.
>

And as mentioned when this question was asked on Stack Overflow, the SQL 
generated by this query is:

SELECT count(*) FROM webhook_table WHERE ((webhook_table.status = 3) AND (
webhook_table.webhook_data LIKE '%form_id%'));

So, try running that outside of web2py and see if you get the same result. 
As Brian noted, the database handles any query optimization -- web2py 
simply generates the SQL and passes it to the Python driver.

Anthony

-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Action commit and scheduled task commit racing?

2016-11-27 Thread Anthony
See http://stackoverflow.com/a/40776846/440323.

On Friday, November 25, 2016 at 11:11:41 PM UTC-5, Albert Rothman wrote:
>
> My code has roughly the following form, and I am wondering if this can 
> generate a race condition or if the first insert happens right away:
>
> def receive_webhook():
>   def POST(*args, **vars):
> db.webhook_table.insert(webhook_data=data, status=0)
> scheduler.queue_task(process_update)
> #some other code happens after this
>
> The code in my Scheduler.py:
>
>  def process_update():
> import json
> record = db(db.webhook_table.status == 0).select(limitby=(0, 1), 
> orderby=~db.webhook_table.create_date).as_list()
> # CAN THIS SELECT FINISH BEFORE THE INSERT FROM receive_webhook IS 
> RECORDED IN THE DB OR IS THE INSERT FINISHED IMMEDIATEDLY
> state = json.loads(record[0]['webhook_data'])['status']
> if not state == 'Updated':
> db(db.webhook_table.id == record[0]['id']).update(status=2)
> db.commit()
> from gluon.scheduler import Scheduler
> scheduler = Scheduler(db)
>
> Can this create a race condition? If so what is the best way to fix it so 
> that it can't?
> The status update(status=2) from the second code block appears to be 
> executing sometimes but not all the time.
>

-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Action commit and scheduled task commit racing?

2016-11-27 Thread Niphlod
It absolutely can't happen.
But the logic in the code is quite prone to inconveniences: every time a task 
runs, it only processes the last record of the table...what happens if you have 
called the webhook function several times before the task has the chance to be 
executed? You end up having holes of processed webhooks

-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Action commit and scheduled task commit racing?

2016-11-27 Thread Niphlod
It absolutely can't happen.
But the logic in the code is quite prone to inconveniences: every time a task 
runs, it only processes the last record of the table...what happens if you have 
called the webhook function several times before the task has the chance to be 
executed? You end up having holes of processed webhooks

-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Action commit and scheduled task commit racing?

2016-11-27 Thread Niphlod
It absolutely can't happen.
But the logic in the code is quite prone to inconveniences: every time a task 
runs, it only processes the last record of the table...what happens if you have 
called the webhook function several times before the task has the chance to be 
executed? You end up having holes of processed webhooks

-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.