Guest User

Untitled

a guest
Oct 23rd, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. ## Model
  2. db.define_table('staff_photographs',
  3. Field('created_on', 'datetime', default=request.now, readable=False, writable=False),
  4. Field('created_by', db.auth_user, default=auth.user_id, readable=False, writable=False),
  5. Field('staff_id', db.staff, readable=False, writable=False),
  6. Field('image','upload', uploadfolder=os.path.join(request.folder, 'staff_images')),
  7. Field('file_name', 'string', default='', readable=False, writable=False),
  8. Field('default_image', 'boolean', default=False),
  9. Field('tags', 'list:string'),
  10. )
  11.  
  12. ## Controller
  13. def add_photograph():
  14. """
  15. Display a form asking for the path to upload, add photograph and then return
  16. to the index page
  17. """
  18. person=None
  19. staff_img_form=None
  20. if request.vars.has_key('staff_id'):
  21. person=db.staff(request.vars.staff_id)
  22. url=URL('default', 'download')
  23. staff_img_form=crud.create(db.staff_photographs)
  24. staff_img_form.vars.staff_id=person.id
  25. if staff_img_form.accepts(request.vars, session):
  26. img_id=staff_img_form.vars.id
  27. response.flash="%d updated" % img_id
  28.  
  29. return dict(staff_img_form=staff_img_form, person=person)
Add Comment
Please, Sign In to add comment