added tagcloud
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
#########################################################################
|
||||
## This scaffolding model makes your app work on Google App Engine too
|
||||
#########################################################################
|
||||
|
||||
if request.controller.endswith('_examples'): response.generic_patterns.append('*')
|
||||
|
||||
from gluon.settings import settings
|
||||
|
||||
# if running on Google App Engine
|
||||
if settings.web2py_runtime_gae:
|
||||
from gluon.contrib.gql import *
|
||||
# connect to Google BigTable
|
||||
db = DAL('gae')
|
||||
# and store sessions there
|
||||
session.connect(request, response, db=db)
|
||||
else:
|
||||
# if not, use SQLite or other DB
|
||||
db = DAL('sqlite://storage.sqlite')
|
||||
|
||||
db.define_table(
|
||||
'users',
|
||||
Field('name'),
|
||||
Field('email')
|
||||
)
|
||||
|
||||
# ONE (users) TO MANY (dogs)
|
||||
|
||||
db.define_table(
|
||||
'dogs',
|
||||
Field('owner_id', db.users),
|
||||
Field('name'),
|
||||
Field('type'),
|
||||
Field('vaccinated', 'boolean', default=False),
|
||||
Field('picture', 'upload', default=''),
|
||||
)
|
||||
|
||||
db.define_table(
|
||||
'products',
|
||||
Field('name'),
|
||||
Field('description', 'text')
|
||||
)
|
||||
|
||||
# MANY (users) TO MANY (purchases)
|
||||
|
||||
db.define_table(
|
||||
'purchases',
|
||||
Field('buyer_id', db.users),
|
||||
Field('product_id', db.products),
|
||||
Field('quantity', 'integer')
|
||||
)
|
||||
|
||||
# if running on Google App Engine
|
||||
if settings.web2py_runtime_gae:
|
||||
# quick hack to skip the join
|
||||
purchased = None
|
||||
else:
|
||||
# use a joined view
|
||||
purchased = (db.users.id == db.purchases.buyer_id) & (db.products.id
|
||||
== db.purchases.product_id)
|
||||
|
||||
db.users.name.requires = IS_NOT_EMPTY()
|
||||
db.users.email.requires = [IS_EMAIL(), IS_NOT_IN_DB(db, 'users.email')]
|
||||
db.dogs.owner_id.requires = IS_IN_DB(db, 'users.id', 'users.name')
|
||||
db.dogs.name.requires = IS_NOT_EMPTY()
|
||||
db.dogs.type.requires = IS_IN_SET(['small', 'medium', 'large'])
|
||||
db.purchases.buyer_id.requires = IS_IN_DB(db, 'users.id', 'users.name')
|
||||
db.purchases.product_id.requires = IS_IN_DB(db, 'products.id',
|
||||
'products.name')
|
||||
db.purchases.quantity.requires = IS_INT_IN_RANGE(0, 10)
|
||||
@@ -0,0 +1,69 @@
|
||||
#########################################################################
|
||||
## This scaffolding model makes your app work on Google App Engine too
|
||||
#########################################################################
|
||||
|
||||
if request.controller.endswith('_examples'): response.generic_patterns.append('*')
|
||||
|
||||
from gluon.settings import settings
|
||||
|
||||
# if running on Google App Engine
|
||||
if settings.web2py_runtime_gae:
|
||||
from gluon.contrib.gql import *
|
||||
# connect to Google BigTable
|
||||
db = DAL('gae')
|
||||
# and store sessions there
|
||||
session.connect(request, response, db=db)
|
||||
else:
|
||||
# if not, use SQLite or other DB
|
||||
db = DAL('sqlite://storage.sqlite')
|
||||
|
||||
db.define_table(
|
||||
'users',
|
||||
Field('name'),
|
||||
Field('email')
|
||||
)
|
||||
|
||||
# ONE (users) TO MANY (dogs)
|
||||
|
||||
db.define_table(
|
||||
'dogs',
|
||||
Field('owner_id', db.users),
|
||||
Field('name'),
|
||||
Field('type'),
|
||||
Field('vaccinated', 'boolean', default=False),
|
||||
Field('picture', 'upload', default=''),
|
||||
)
|
||||
|
||||
db.define_table(
|
||||
'products',
|
||||
Field('name'),
|
||||
Field('description', 'text')
|
||||
)
|
||||
|
||||
# MANY (users) TO MANY (purchases)
|
||||
|
||||
db.define_table(
|
||||
'purchases',
|
||||
Field('buyer_id', db.users),
|
||||
Field('product_id', db.products),
|
||||
Field('quantity', 'integer')
|
||||
)
|
||||
|
||||
# if running on Google App Engine
|
||||
if settings.web2py_runtime_gae:
|
||||
# quick hack to skip the join
|
||||
purchased = None
|
||||
else:
|
||||
# use a joined view
|
||||
purchased = (db.users.id == db.purchases.buyer_id) & (db.products.id
|
||||
== db.purchases.product_id)
|
||||
|
||||
db.users.name.requires = IS_NOT_EMPTY()
|
||||
db.users.email.requires = [IS_EMAIL(), IS_NOT_IN_DB(db, 'users.email')]
|
||||
db.dogs.owner_id.requires = IS_IN_DB(db, 'users.id', 'users.name')
|
||||
db.dogs.name.requires = IS_NOT_EMPTY()
|
||||
db.dogs.type.requires = IS_IN_SET(['small', 'medium', 'large'])
|
||||
db.purchases.buyer_id.requires = IS_IN_DB(db, 'users.id', 'users.name')
|
||||
db.purchases.product_id.requires = IS_IN_DB(db, 'products.id',
|
||||
'products.name')
|
||||
db.purchases.quantity.requires = IS_INT_IN_RANGE(0, 10)
|
||||
@@ -0,0 +1,12 @@
|
||||
import random
|
||||
quotes = [
|
||||
("web2py was the life saver today for me, my blog post: Standalone Usage of web2py's", "caglartoklu", "http://twitter.com/#!/caglartoklu/status/84292131707031553"),
|
||||
("Get Things Done - Faster, Better and More Easily with web2py",
|
||||
"Bruno Rocha", "http://twitter.com/#!/rochacbruno/status/73583156044890112"),
|
||||
("Please use www.web2py.com when using MVC , no PHP/SQL stuff please...its 2011 not 1999", "rabblesoft", "http://twitter.com/#!/rabblesoft/status/79189028431343616"),
|
||||
('web2py rules! as a sysadmin I like the no installation and no configuration approach a lot)', "kjogut", "http://twitter.com/#!/jkogut/status/61414554273447936"),
|
||||
("web2py it is. Compatible with everything under the sun and great interfaces to googleappengine", "comamitc","http://twitter.com/#!/comamitc/status/51744719071477760"),
|
||||
("If you are still learning python, web2py is best tool by far", "pbreit", "http://twitter.com/#!/pbreit/status/48260905775017984")
|
||||
]
|
||||
random.shuffle(quotes)
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
|
||||
def group_feed_reader(group,mode='div',counter='5'):
|
||||
"""parse group feeds"""
|
||||
|
||||
url = "http://groups.google.com/group/%s/feed/rss_v2_0_topics.xml?num=%s" %\
|
||||
(group,counter)
|
||||
from gluon.contrib import feedparser
|
||||
g = feedparser.parse(url)
|
||||
|
||||
if mode == 'div':
|
||||
html = XML(TAG.BLOCKQUOTE(UL(*[LI(A(entry['title']+' - ' +\
|
||||
entry['author'][entry['author'].rfind('('):],\
|
||||
_href=entry['link'],_target='_blank'))\
|
||||
for entry in g['entries'] ]),\
|
||||
_class="boxInfo",\
|
||||
_style="padding-bottom:5px;"))
|
||||
|
||||
else:
|
||||
html = XML(UL(*[LI(A(entry['title']+' - ' +\
|
||||
entry['author'][entry['author'].rfind('('):],\
|
||||
_href=entry['link'],_target='_blank'))\
|
||||
for entry in g['entries'] ]))
|
||||
|
||||
return html
|
||||
|
||||
|
||||
def code_feed_reader(project,mode='div'):
|
||||
"""parse code feeds"""
|
||||
|
||||
url = "http://code.google.com/feeds/p/%s/hgchanges/basic" % project
|
||||
from gluon.contrib import feedparser
|
||||
g = feedparser.parse(url)
|
||||
if mode == 'div':
|
||||
html = XML(DIV(UL(*[LI(A(entry['title'],_href=entry['link'],\
|
||||
_target='_blank'))\
|
||||
for entry in g['entries'][0:5]]),\
|
||||
_class="boxInfo",\
|
||||
_style="padding-bottom:5px;"))
|
||||
else:
|
||||
html = XML(UL(*[LI(A(entry['title'],_href=entry['link'],\
|
||||
_target='_blank'))\
|
||||
for entry in g['entries'][0:5]]))
|
||||
|
||||
|
||||
return html
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
import gluon.template
|
||||
|
||||
markmin_dict = dict(
|
||||
code_python=lambda code: str(CODE(code)),
|
||||
template=lambda \
|
||||
code:gluon.template.render(code,context=globals()),
|
||||
sup=lambda \
|
||||
code:'<sup style="font-size:0.5em;">%s</sup>'%code,
|
||||
br=lambda n:'<br>'*int(n),
|
||||
groupdates=lambda group:group_feed_reader(group),
|
||||
)
|
||||
|
||||
def get_content(b=None,\
|
||||
c=request.controller,\
|
||||
f=request.function,\
|
||||
l='en',\
|
||||
format='markmin'):
|
||||
"""Gets and renders the file in
|
||||
<app>/private/content/<lang>/<controller>/<function>/<block>.<format>
|
||||
"""
|
||||
|
||||
def openfile():
|
||||
import os
|
||||
path = os.path.join(request.folder,'private','content',l,c,f,b+'.'+format)
|
||||
return open(path)
|
||||
|
||||
try:
|
||||
openedfile = openfile()
|
||||
except Exception, IOError:
|
||||
l='en'
|
||||
openedfile = openfile()
|
||||
|
||||
if format == 'markmin':
|
||||
html = MARKMIN(str(T(openedfile.read())),markmin_dict)
|
||||
else:
|
||||
html = str(T(openedfile.read()))
|
||||
openedfile.close()
|
||||
|
||||
return html
|
||||
@@ -0,0 +1,44 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
response.menu = [
|
||||
(T('Home'),False,URL('default','index')),
|
||||
(T('About'),False,URL('default','what')),
|
||||
(T('Download'),False,URL('default','download')),
|
||||
(T('Docs & Resources'),False,URL('default','documentation')),
|
||||
(T('Support'),False,URL('default','support')),
|
||||
(T('Contributors'),False,URL('default','who'))]
|
||||
|
||||
#########################################################################
|
||||
## Changes the menu active item
|
||||
#########################################################################
|
||||
def toggle_menuclass(cssclass='pressed',menuid='headermenu'):
|
||||
"""This function changes the menu class to put pressed appearance"""
|
||||
|
||||
positions = dict(
|
||||
index='',
|
||||
what='-108px -115px',
|
||||
download='-211px -115px',
|
||||
who='-315px -115px',
|
||||
support='-418px -115px',
|
||||
documentation='-520px -115px'
|
||||
)
|
||||
|
||||
|
||||
if request.function in positions.keys():
|
||||
jscript = """
|
||||
<script>
|
||||
$(document).ready(function(){
|
||||
$('.%(menuid)s a').removeClass('%(cssclass)s');
|
||||
$('.%(function)s').toggleClass('%(cssclass)s').css('background-position','%(cssposition)s')
|
||||
|
||||
});
|
||||
</script>
|
||||
""" % dict(cssclass=cssclass,
|
||||
menuid=menuid,
|
||||
function=request.function,
|
||||
cssposition=positions[request.function]
|
||||
)
|
||||
|
||||
return XML(jscript)
|
||||
else:
|
||||
return ''
|
||||
Reference in New Issue
Block a user