[web2py] How to make a simple counter

2011-03-05 Thread minux
Hi guys,

I am pretty new to web2py and really enjoy learning this neat
framework. However, I've just encountered a problem, while trying to
developing a simple image gallery.

I want to put a simple counter under each image, but could not figure
out how to do so. Here are the relevant code

db.define_table('image',
   Field('title','string', required=True),
   Field('file', 'upload', required=True),
   Field('category',required=True),
   Field('created_on', 'datetime', default=request.now),
   Field('created_by', db.auth_user, default=auth.user_id),
   Field('visits', 'integer', default=0),
   format='%(name)s')

--C O N T R O L L E R (unsuccessful) --

def show():
image = db.image(request.args(0)) or redirect(URL('index'))

db.comment.image_id.default = image.id
form = crud.create(db.comment,
   message='your comment is posted',
next=URL(args=image.id))
comments = db(db.comment.image_id==image.id).select()
visits = db.image(request.args(0)).visits
visits.viist(+=1)
#visits = db.image(request.args(0)).update_record(visits)
return dict(image=image, comments=comments, form=form,
visits=visits)

#---V I E W---


{{extend 'layout.html'}}
Photo: {{=image.title}}


Visits:  {{=visits}}

{{if len(comments):}}
  Comments
  {{for comment in comments:}}
{{=comment.author}} Wrote: {{=comment.body}}
  {{pass}}
{{else:}}
  No comments posted yet
{{pass}}
Post a comment
{{=form}}


I appreciate your help.



[web2py] Re: How to make a simple counter

2011-03-07 Thread minux
Thanks a log pbreit. Your suggested perfectly solved my problem. I
fiddled a bit with update_record but had difficulty who to grab the
field in database, in order to update it. Since this seem to be a
pretty common task (and difficulty for noobs), perhaps It would be
good if this example somehow be incorporated into the web2py chapter
about DAL or example codes.

Cheers



On Mar 6, 1:53 am, pbreit  wrote:
> Wow, hard to say but you definitely have some problems. For example, the
> typo in "visits.viist(+=1)". Are you getting error messages or is it just
> not doing what you want?
>
> Something like this perhaps? This code only adds one line to what is shown
> in the Book: image.update_record(visits=image.visits + 1). One thing to do
> is only make one "db.table" call per controller. You usually only need to
> access the database once per table. And in this case, you only need to do an
> image.update_record to increment the visits.
>
> def show():
>     image = db.image(request.args(0)) or redirect(URL('index'))
>
>     db.comment.image_id.default = image.id
>     form = crud.create(db.comment,
>                        message='your comment is posted',
>             next=URL(args=image.id))
>     comments = db(db.comment.image_id==image.id).select()
>     image.update_record(visits=image.visits + 1)
>     return dict(image=image, comments=comments, form=form)
>
> === show.html ===
> ...
> Visits:  {{=image.visits}}
> ...


[web2py] Lacking nginx deployment guide

2011-03-09 Thread minux
Hi folks,

As a newbie to the fabulous framework, I am a bit put off when I
reached to the end of the web2py chapter about deployment and (as it
happened to me with Django before) I saw no receipt to deploy on
nginx, which is my favorite web server.

I searched around but could not find any complete tutorial, while
there are few scattered blog notes here and there.

As I am going to deploy on a tiny VPS, I am reluctant to use  apache
recepit (to save memory). Also  lighthttpd, does not seem to be the
best candidate, as it is discontinued and (apparently) memory
leaking.

So I left with Cherokee. However I did not like the idea of a GUI
config interface, I tried the official book's receipt as the last
resort. For some reason, I ended up with a " nohup: ignoring input and
appending output to `nohup.out'".

Cutting the long story short, I really appreciate it if someone could
point me to a complete guide for nginx deployment, or writhe one :)

cheers



[web2py] Re: Lacking nginx deployment guide

2011-03-10 Thread minux
I have used nginx + fcgi for php (before moving to php5-fmp, which is
more robust), however, I really lack technical talent to implement the
same for web2py, given the nginx.conf that you kindly shared. So I
would be grateful if you write up a complete guide, when you have
time.

Cheers


I would love to see the complete

On Mar 10, 12:23 pm, Michele Alzetta 
wrote:
> On Thu, Mar 10, 2011 at 12:09 AM, minux  wrote:
>
> > Cutting the long story short, I really appreciate it if someone could
> > point me to a complete guide for nginx deployment, or writhe one :)
>
> I have web2py on a linode.com VPS deployed on nginx with ssl access so I can
> have access to administrative interface.
>
> As linux distro I use gentoo. Nginx and spawn-fcgi I emerge, whereas web2py
> I just download and install by hand.
>
> nginx.conf contains:
>
> server {
>         listen       443;
>         ssl                  on;
>         ssl_certificate      /etc/ssl/nginx/nginx.pem;
>         ssl_certificate_key  /etc/ssl/nginx/nginx.key;
>         keepalive_timeout    70;
>         server_name  my.server.name;
>         access_log  /var/log/nginx/web2py.access.log;
>         location / {
>         set $fixed_destination $http_destination;
>         if ($http_destination ~* ^https(.*)$)
>         {
>         set $fixed_destination http$1;
>         }
>         proxy_passhttp://127.0.0.1:8000;
>         proxy_set_header Host $host;
>         proxy_set_header X-Real-IP $remote_addr;
>         proxy_set_header X-Forwarded-For $remote_addr;
>         proxy_set_header        Destination     $fixed_destination;
>         }
>
> Is this enough for you? If people really feel it is useful I could write a
> guide for nginx deployment, but give me some time!   :)


[web2py] Re: Lacking nginx deployment guide

2011-03-10 Thread minux
pbreit, thanks your concise guide

http://web2pyslices.com/main/slices/take_slice/110

I could set up cherokee+uwsgi.
However, I don't like Windowish attitude that treats users as dumbs
(like, "this settings are not meant to be changed by you"...etc) and
commercialized self-promoting approach of cherokee.

So I would love to see a nginx+uwsgi guide like yours for cherokee. As
this benchmarks shows:

http://nichol.as/benchmark-of-python-web-servers

uwsgi is among the best (if not the best) option to be used for a
python web framework. So if you want to write a guide,  I guess it
would be better to implement uwsgi, rather than fcgi.


On Mar 10, 6:31 pm, pbreit  wrote:
> OK, good to know. I think I might try it out. If so, I'll publish my
> fabfile.


[web2py] Re: Lacking nginx deployment guide

2011-03-17 Thread minux
pbreit, I tried to follow the Linode recipe along with your
instructions, but could not succeed. There were points were I really
did not know  what changes are needed to be made.
For example:
in '/etc/init.d/uwsgi' should the owner be uwsgi or www-data?
in /etc/default/uwsgi, should the 'MODULE=wsgi_configuration_module'
be included? If so, with what changes...
etc.

So I really appreciate it if you or others from web2py community can
sum up a complete recipe for deployment using nginx+uwsgi.

Cheers




 file and so I appre

On Mar 13, 11:45 pm, pbreit  wrote:
> I think I figured out the solution. Need to add one line to the nginx.conf:
> uwsgi_param     UWSGI_SCHEME    $scheme;
>
>     # HTTPS server
>     server {
>         listen       443;
>         server_name  "";
>         ssl                  on;
>         ssl_certificate      /opt/nginx/conf/server.crt;
>         ssl_certificate_key  /opt/nginx/conf/server.key;
>
>         location / {
>             uwsgi_pass      127.0.0.1:9001;
>             include         uwsgi_params;
>             uwsgi_param     UWSGI_SCHEME $scheme;
>         }
>
>         location /static {
>             root /var/web2py/applications/init/;
>         }
>     }


[web2py] Re: Lacking nginx deployment guide

2011-03-17 Thread minux
pbreit, please ignore my last post. Actually I could make nginx+uwsgi
up and running by reading carefully your posts above. I have sum up
the instructions here:

http://stackoverflow.com/questions/5335153/how-to-deply-web2py-using-nginx

Thank you so much for your help.