def main(global_config, **settings): connect(settings.get("mongodb_default_db"), host=settings.get("mongodb_host"), port=int(settings.get("mongodb_port")), username=settings.get("mongodb_username"), password=settings.get("mongodb_password")) config = Configurator(settings=settings) # I18N files config.add_translation_dirs("i18n:locale/") web.config(config) config.add_route('duty', '/duty') config.scan() return config.make_wsgi_app()
def config(**args): handler = None for name in ('controller' , 'handler' , 'tcphandler' , 'httphandler', 'fcgihandler', 'wsgihandler', 'application', 'wsgi', 'app', 'wsgi_app', 'wsgi_application'): if name in args: if handler is not None: raise TypeError('too many handlers') handler = name if 'fcgihandler' in args or args.get('fcgi', False) or ( 'port' not in args and 'bind' not in args): if handler in ('tcphandler', 'httphandler'): raise ValueError('%s handler not support fcgi mode, need address' %handler) import fcgi globals()['fcgi_mainloop'] = fcgi.mainloop return fcgi.config(**args) if handler in ('handler', 'controller', 'httphandler', 'wsgihandler', 'application', 'wsgi', 'app', 'wsgi_app', 'wsgi_application'): import web return web.config(**args) if handler == 'tcphandler': import socket2 return socket2.config(**args)
def main(global_config, **settings): # Taobao config add mongo_client = MongoClient(settings.get("mongodb_host", "localhost"), int(settings.get("mongodb_port", "27017"))) global mongo_db mongo_db = mongo_client.palms assert mongo_db.authenticate(settings.get("mongodb_username", ""), settings.get("mongodb_password", "")), \ "Mongo authentication error." """ This function returns a Pyramid WSGI application. """ config = Configurator(settings=settings) # I18N files config.add_translation_dirs("i18n:locale/") config.add_route('register_token', '/access_token/register') config.add_route('sign_in', '/account/sign.in') config.add_route('sign_out', '/account/sign.out') config.add_route('get_signs', '/account/signs.get') import web web.config(config) config.scan() return config.make_wsgi_app()
def main(global_config, **settings): # Taobao config add mongo_client = MongoClient(settings.get("mongodb_host", "localhost"), int(settings.get("mongodb_port", "27017"))) global mongo_db mongo_db = mongo_client.palms assert mongo_db.authenticate( settings.get("mongodb_username", ""), settings.get("mongodb_password", "") ), "Mongo authentication error." """ This function returns a Pyramid WSGI application. """ config = Configurator(settings=settings) # I18N files config.add_translation_dirs("i18n:locale/") config.add_route("register_token", "/access_token/register") config.add_route("sign_in", "/account/sign.in") config.add_route("sign_out", "/account/sign.out") config.add_route("get_signs", "/account/signs.get") import web web.config(config) config.scan() return config.make_wsgi_app()
def post_share(request, id): post = get_object_or_404(Post, id=id, status='published') sent = False if request.method == 'POST': form = EmailSendForm(request.POST) if form.is_valid(): cd = form.cleaned_data post_url = request.build_absolute_uri(post.get_absolute_url()) subject = '{} ({}) recommends you reading "{}"'.format( cd['name'], cd['email'], post.title) message = 'Read "{}" at {}\n\n{}\'s comments: {}'.format( post.title, post_url, cd['name'], cd['comments']) send_mail(subject, message, config('DEFAULT_FROM_EMAIL'), [cd['to']]) sent = True else: form = EmailSendForm() return render(request, 'blog/sharebyemail.html', { 'post': post, 'form': form, 'sent': sent })