new file upload controller, new upload template, new utils lib, some elixir basics

git-svn-id: http://yolanda.mister-muffin.de/svn@373 7eef14d0-6ed0-489d-bf55-20463b2d70db
main
josch 16 years ago
parent 124c37f6f8
commit 6a851c384b

@ -7,6 +7,9 @@ import yolanda.lib.app_globals as app_globals
import yolanda.lib.helpers
from yolanda.config.routing import make_map
from sqlalchemy import engine_from_config
from yolanda.model import init_model
def load_environment(global_conf, app_conf):
"""Configure the Pylons environment via the ``pylons.config``
object
@ -31,3 +34,6 @@ def load_environment(global_conf, app_conf):
# CONFIGURATION OPTIONS HERE (note: all config options will override
# any Pylons config options)
engine = engine_from_config(config, 'sqlalchemy.')
init_model(engine)

@ -0,0 +1,23 @@
import logging
from yolanda.lib.base import *
log = logging.getLogger(__name__)
class UploadController(BaseController):
def index(self):
return render('/xhtml/upload.mako')
def upload(self):
myfile = request.params['file']
permanent_file = open(os.path.join(
myfile.filename.lstrip(os.sep)),
'w')
u.copyfileobj(myfile.file, permanent_file)
myfile.file.close()
permanent_file.close()
return 'Successfully uploaded: %s'%myfile.filename

@ -11,7 +11,9 @@ from pylons.i18n import _, ungettext, N_
from pylons.templating import render
import yolanda.lib.helpers as h
import yolanda.lib.utils as u
import yolanda.model as model
import os
class BaseController(WSGIController):
@ -21,7 +23,10 @@ class BaseController(WSGIController):
# the request is routed to. This routing information is
# available in environ['pylons.routes_dict']
response.headers['Content-type'] = "application/xml"
return WSGIController.__call__(self, environ, start_response)
try:
return WSGIController.__call__(self, environ, start_response)
finally:
Session.remove()
# Include the '_' function in the public names
__all__ = [__name for __name in locals().keys() if not __name.startswith('_') \

@ -0,0 +1,8 @@
#borrowed from shutil to minimize dependencies
def copyfileobj(fsrc, fdst, length=16*1024):
"""copy data from file-like object fsrc to file-like object fdst"""
while 1:
buf = fsrc.read(length)
if not buf:
break
fdst.write(buf)

@ -0,0 +1,21 @@
from sqlalchemy.orm import scoped_session, sessionmaker
import elixir
# replace the elixir session with our own
Session = scoped_session(sessionmaker(autoflush=True, transactional=True))
elixir.session = Session
elixir.options_defaults.update({
'shortnames': True
})
# use the elixir metadata
metadata = elixir.metadata
# this will be called in config/environment.py
def init_model(engine):
metadata.bind = engine
# import your entities, and set them up
from entities import *
elixir.setup_all()

@ -0,0 +1,8 @@
from elixir.entity import *
from elixir.fields import *
from sqlalchemy.types import *
from datetime import datetime
class Person(Entity):
name = Field(Unicode(128))
birthdate = Field(DateTime, default=datetime.now)

@ -0,0 +1,17 @@
<%inherit file="base.mako"/>
<%def name="title()">
front page
</%def>
<%def name="heading()">
Upload Video
</%def>
${h.form(h.url_for(action='upload'), multipart=True)}
${h.file_field('file')}<br />
${h.text_field('name')}<br />
${h.submit('Upload')}
${h.end_form()}

@ -6,9 +6,16 @@ from pylons import config
from yolanda.config.environment import load_environment
from yolanda.model import metadata
log = logging.getLogger(__name__)
def setup_config(command, filename, section, vars):
"""Place any commands to setup yolanda here"""
conf = appconfig('config:' + filename)
load_environment(conf.global_conf, conf.local_conf)
log.info("Creating tables")
metadata.create_all()
log.info("Successfully setup")

Loading…
Cancel
Save