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-20463b2d70dbmain
parent
124c37f6f8
commit
6a851c384b
@ -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
|
||||
|
@ -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()}
|
Loading…
Reference in New Issue