Octavian G | 1 Aug 13:12 2015
Picon

Implementing a notification system using session table

Hello,

     I'd like to implement a notification system for various events happening in the app. I'd like it to work with the web2py_session_appname table, because it would mean I could piggyback that select. For that, I'd like to add a field to the sessions table, pointing to the user's ID in auth_user. This way, when I have an event, I could look up users' sessions and update their session data to reflect the fact that they have new notifications.

     I added a field to the session table (in gluon/globals), so that when it gets created it has a new field, user_id. Problem is, it can't reference auth_user. Further, I need to insert the user id in that field when a user logs in.  How would I do that ?

     Is there another way to programatically get a user's session(s), provided they're stored in the DB ?

--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
backseat | 1 Aug 00:24 2015
Picon

Patch: LDAP AUTH TLS

I found that I was unable to authenticate to an OpenLDAP server running TLS on port 389 (which is the recommended way apparently). The following patch to ldap_auth.py fixes things for me; YMMV.

Please add to upstream source if helpful.

--- gluon/contrib/login_methods/ldap_auth.py.original   2015-07-31 23:22:45.931751184 +0100
+++ gluon/contrib/login_methods/ldap_auth.py    2015-07-31 23:19:14.116922831 +0100
<at> <at> -33,6 +33,7 <at> <at>
               group_name_attrib
='cn',
               group_member_attrib
='memberUid',
               group_filterstr
='objectClass=*',
+              tls=False,
               logging_level
='error'):
 
     
"""
<at> <at> -80,6 +81,13 <at> <at>
     If ldap is using GnuTLS then you need cert_file="
..." instead cert_path
     because cert_path isn't implemented in GnuTLS :(
 
+    To enable TLS, set tls=True:
+
+        auth.settings.login_methods.append(ldap_auth(
+            server='my.ldap.server',
+            base_dn='ou=Users,dc=domain,dc=com',
+            tls=True))
+
     If you need to bind to the directory with an admin account in order to
     search it then specify bind_dn & bind_pw to use for this.
     - currently only implemented for Active Directory
<at> <at> -610,6 +618,8 <at> <at>
                 ldap_port = 389
             con = ldap.initialize(
                 "
ldap://" + ldap_server + ":" + str(ldap_port))
+        if tls:
+            con.start_tls_s()
         
return con
 
     
def get_user_groups_from_ldap(username,


--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
Picon

Test1

Test

--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
Picon

Binding a form field to a user field

Hello Guys,


Just starting with Web2Py.


I'm working on a project and need to do the following:


I have image defined in the DB like this:

db.define_table('image',
                Field('user_id', 'reference auth_user'),
                Field('file', 'upload'),
                Field('description', 'text'))

And then:

db.image.user_id.requires = IS_IN_DB(db, db.auth_user.id, '%(displayed_name)s')


Then I created a function, so only registered users may upload or send pictures:

<at> auth.requires_login()
def upload():
    form = SQLFORM(db.image)
    if form.process().accepted:
        response.flash = 'Your Photo has been sent!'
    return dict(form=form)



The problem I've been having is I need to bind every uploaded picture by a user to that specific user. I don't even need the form to show a list of users to select which one is the owner of the photo, because the owner must always be the logged in user.

However, I haven't managed to find a way of doing that. Read the documentation but couldn't find an example.

Right now, with the code I have, the form would show me the list of all registered users to select one to bind the photo with.


I really appreciate your help.


Thanks!

--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
Rohit Raj Sharma | 31 Jul 06:22 2015
Picon

date format of date picker

I have form with date field i have setup default format(dd/mm/yyyy). i am using web2py sqlform. when i select date from date picker. it used to take dd/mm/yy. i know its very silly question. i had tried in ajax.html file and check my db file also but i am not able to find the solution. can any one help me to solve.

i set default value: dd/mm/yyyy.

when i edit the date it change to dd/mm/yy

my ajax file

<script type="text/javascript"><!--
    // These variables are used by the web2py_ajax_init function in web2py_ajax.js (which is loaded below).
    var w2p_ajax_confirm_message = "{{=T('Are you sure you want to delete this object?')}}";
    var w2p_ajax_disable_with_message = "{{=T('Working...')}}";
    var w2p_ajax_date_format = "{{=T('%d-%m-%y')}}";
    var w2p_ajax_datetime_format = "{{=T('%Y-%m-%d %H:%M:%S')}}";
    var ajax_error_500 = '{{=T.M('An error occured, please [[reload %s]] the page') % URL(args=request.args, vars=request.get_vars) }}'
    //--></script>
{{
response.files.insert(0,URL('static','js/jquery.js'))
response.files.insert(1,URL('static','css/calendar.css'))
response.files.insert(2,URL('static','js/calendar.js'))
response.files.insert(3,URL('static','js/web2py.js'))
response.include_meta()
response.include_files()
}}

--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
eric cuver | 30 Jul 23:13 2015
Picon

web2py inspired framework

What do you think of this framework which is clearly inspired by web2py

http://weppy.org/

--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
Sandro | 31 Jul 13:42 2015
Picon

Good way to implement multiple file upload with previews?

I'd like to implement an editor interface for posting articles to my site. The left side of the interface will be the editor window, and the right side is the preview window (which shows changes, as they are made by the user, in real-time).

The editor interface will also allow the user to bring up (by pressing a hotkey combo) a multi-part file-upload dialog, of the sort which is found in popular blogging platforms - I've attached an image of an example of such a dialog:



The editor window of the file dialog contains some markup which permits the user to assign a label/title to the image. The preview window of the file dialog contains a image dropbox. Once the image is dropped in, the dropbox shows a preview of the image.

The user should be able to create these ad hoc image upload boxes at any point of the article which they are writing/editing.

Has anyone here implemented anything similar to this in web2py? Can you offer me some recommendations on how to go about implementing this feature? Thank you.

--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
Pablo Angulo | 31 Jul 13:45 2015
Picon

web2py on arch linux, for development and production

Hello!

I've been developing with web2py in arch linux for some time now with no problem (just recall to run "python2 web2py.py"). It's a fine distro, and if you think it takes ages to install (it does), you can use manjaro linux which is basically archlinux preconfigured with very sensible choices (and xfce, of course (no flamewar intended ;-) )).

Yesterday I had to reinstall a webapp, and found out that ovh offers arch linux for its vps, so I couldn't resist and tried to install web2py for production with nginx. As there is no deployment script, I looked at the other distros and translated as necessary. This is the log:

- changing the package manager is as simple as always (but there is no build-essentials package, instead there's a collection called base-devel: "pacman -S base-devel").
- nginx and mariadb are pretty much the same everywhere, no problem there. However I liked the way ubuntu splits the nginx configuration into different sites, mimicking apache, so I borrowed the /etc/nginx from my earlier ubuntu server.
- uwsgi compiles fine, install fine, but you have to write its own systemd unit. I was having a hard time configuring uwsgi.service (I had never done it) until I found the centos7 install script prepares a systemd unit, so I copied that one from there and it's working with minor changes.
- archlinux has python=python3, so I have to adapt the deploy instructions here and there and change python for python2.
- arch linux does less things by default, but I only recall having to edit /etc/locale.gen and then running locale-gen

If there are more people interested, I can help them and eventually write a script, but I'm not an expert sysadmin and I prefer not to write a install script until someone else can proof read it. There's also the thing that the different install script for different distros have taken different choice for example for deploying uwsgi, and I don't have a clue which are best. For example, for ubuntu:

[uwsgi]

socket = /tmp/web2py.socket
pythonpath = /home/www-data/web2py/
mount = /=wsgihandler:application
processes = 4
master = true
harakiri = 60
reload-mercy = 8
cpu-affinity = 1
stats = /tmp/stats.socket
max-requests = 2000
limit-as = 512
reload-on-as = 256
reload-on-rss = 192
uid = www-data
gid = www-data
touch-reload = /home/www-data/web2py/routes.py
cron = 0 0 -1 -1 -1 python /home/www-data/web2py/web2py.py -Q -S welcome -M -R scripts/sessions2trash.py -A -o
no-orphans = true

but for centos7

[uwsgi]
chdir = WEB2PY_PATH_PLACEHOLDER/WEB2PY_APP_PLACEHOLDER
module = wsgihandler:application

master = true
processes = 5

uid = USERNAME_PLACEHOLDER
socket = /run/uwsgi/WEB2PY_APP_PLACEHOLDER.sock
chown-socket = USERNAME_PLACEHOLDER:nginx
chmod-socket = 660
vacuum = true

and I have the gutt feeling that does options in the ubuntu version of uwsgi.ini would be fine too for centos7, but damn if I know :-\ !

Another example: in the ubuntu install script it is possible to repackage all the static files whenever you call

restart uwsgi-emperor

That's a very good idea, isn't it? I've certainly grabbed that idea, so my uwsgi.service goes like this:

[Unit]
Description=uWSGI Emperor service

[Service]
ExecStartPre=/usr/bin/bash -c 'mkdir -p /run/uwsgi; chown www-data:www-data /run/uwsgi; su www-data -c  "python2 /home/www-data/web2py/web2py.py -S YOUR_APP_HERE/appadmin -R scripts/zip_static_files.py"'
ExecStart=/usr/bin/uwsgi --emperor /etc/uwsgi/sites
Restart=always
KillSignal=SIGQUIT
Type=notify
NotifyAccess=all

[Install]
WantedBy=multi-user.target


--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.

Angelo Compagnucci | 31 Jul 08:48 2015
Picon

Multiprocessing queue and web2py

Dear Developers,

I really would like to use multiprocessing python queue in web2py but
I'm asking for an advice. I googled the forum but cannot find an
answer.

I have a worker process (a can bus message processing daemon) that
actually it's a web2py application that shares a database table with
the main application.

Unfortunately I'm on an embedded arm (400mhz with slow uSD card) and
accessing the database for sharing messages it's really killing my
app.

Using multiprocessing queues would solve my problems but I have a
several questions popping around:

* I have to maintain a queue handler in main process but web2py
doesn't support writing a singleton shared by all controllers, is a
cache.ram that never expires the only way to keep that handler in
memory for the application lifetime?

* The worker process should be spawned by web2py, but again, I should
keep an handler in cache.ram and check if the process was previously
spawned at each request, right?

* This is not the most elegant solution, do you know of a more elegant one?

Thank you for you advice!

-- 
Profile: http://it.linkedin.com/in/compagnucciangelo

--

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

Tom Campbell | 31 Jul 00:55 2015
Picon

GAE/Google AppEngine problem with web2py: "Deployment successful" but GAE does not launch

My AppEngine ID is memberable0.
I copied examples/app.example.yaml to web2py root as app.yaml
Only change I made was:
application: memberable0
Web2py lives in /Users/tom/Dropbox/work/m/web2py and that path shows successfully in GoogleAppEngineLauncher, which shows port 8081 for the web server (not running web2py's Rocket server).

Nothing happens. GoogleAppEngineLauncher just sits there with the yellow wait icon in the leftmost column.
The Log Console for memberable0 shows literally nothing.
In Chrome the Network tab in the dev tools shows nothing was ever loaded.

If I run this from the shell:
$ appcfg.py update .

I get tons of output, with thousand of lines that look like this:

# Tons of the following:
Could not guess mimetype for applications/lte/static/css/fontawesome/src/3.2.1/assets/less/bootstrap-2.3.2/responsive.less. Using application/octet-stream.

# Finally ending with:
03:25 PM Cloning 8105 static files.
03:25 PM Cloned 2000 files.
03:25 PM Cloned 4000 files.
03:25 PM Cloned 6000 files.
03:25 PM Cloned 8000 files.
03:25 PM Cloning 1097 application files.
03:25 PM Compilation starting.
03:25 PM Compilation completed.
03:25 PM Starting deployment.
03:25 PM Checking if deployment succeeded.
03:25 PM Deployment successful.
03:25 PM Checking if updated app version is serving.
03:25 PM Completed update of app: memberable0, version: 1

Nonetheless, when I click Run, GoogleAppEngineLauncher is still inert. Out of desperation I have tried other ports like 12080 but to no avail.

Can anyone tell me what I'm doing wrong or if there's some other diagnostic tool I'm missing?

Version 2.9.12-stable+timestamp.2015.01.17.06.11.03
Running on a high end Mac, OS X Yosemite 10.10.4

--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
Lisandro | 30 Jul 18:06 2015
Picon

Error in scheduler.py when scheduled task uses a jsonrpc webservice

I've been several hours trying to figure out what's happening, thinking that my code had a bug. But I think the problem is in scheduler.py. I think, not sure.

The simplified scenario is the following. Two web2py apps running on the same web2py installation.


App "A" defines a public jsonrpc service with a simple "test()" function. All defined in controller ws.py:

# -*- coding: utf-8 -*-
# appA/controllers/ws.py
 
from gluon.tools import Service
service = Service()


def call():
    session.forget()
    return service()


<at> service.jsonrpc
def test():
    return True



App "B" has the function "newsletter()" defined in db.py model, that consumes the webservice:

# -*- coding: utf-8 -*-
# appB/models/db.py

# ... here, the table definitions, etc

def newsletter():
    from gluon.contrib.simplejsonrpc import ServerProxy
    ws
= ServerProxy(CONFIG.url_webservice)
    ws
.test()
    
return True



When I call the "newsletter()" function from inside app B (for example, from a controller), the function works ok: it connects to the webservice, calls the webservice function, and returns True.
However, when I schedule the "newsletter()" function as a scheduler task, it always fails with this traceback:

Traceback (most recent call last): 
    File "/home/gonguinguen/medios/gluon/scheduler.py", line 315, in executor result = dumps(_function(*args, **vars)) 
    File "applications/demo/models/db.py", line 837, in newsletter ws.test() 
    File "/home/gonguinguen/medios/gluon/contrib/simplejsonrpc.py", line 108, in <lambda> return lambda *args: self.call(attr, *args) 
    File "/home/gonguinguen/medios/gluon/contrib/simplejsonrpc.py", line 140, in call self.error.get('data', None)) 
    File "/home/gonguinguen/medios/gluon/contrib/simplejsonrpc.py", line 37, in __init__ value = "%s: %s\n%s" % (code, message, '\n'.join(data)) TypeError


One detail that has been really confusing me: if I rename the "test" function to "get_stats", it works. Don't ask me how. I've done a search in ALL files of both apps, the "get_stats" function isn't defined anywhere, it doesn't exists. The scheduled function fails always when calling the webservice method, except when the method is called "get_stats". Really confusing. I've found a "get_stats" function defined in gluon/contrib/memcache.py, but I don't know if it has something to do with this scenario.

If anyone is seeing something that I don't, please point it out! I'm pulling my hair off with this :P

--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.

Gmane