Created
September 22, 2013 19:44
-
-
Save danielwatson6/6663100 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### | |
### This is an example on how to use blobs with the webapp_enhanced project | |
### Author: djwatt5 | |
### | |
### Most of the content here can be automatically generated | |
### using the console tool from webapp_enhanced. The only | |
### piece of code below that is custom can be found in the | |
### `self.create()` method (see line 43). | |
### | |
### File: models/book.py | |
from lib import db | |
class BookModel(db.BlobModel): | |
title = db.string(required = True) | |
description = db.text(required = True) | |
### File: controllers/book.py | |
from models.book import BookModel | |
from controllers.core import BlobController | |
class Book(BlobController): | |
r'/book' # path | |
# Associated model | |
model = BookModel | |
### File: controllers/book_upload.py | |
from controllers.core import UploadController | |
from controllers.book import Book as BookController | |
class Book(UploadController): | |
r'/books/upload' | |
# Associated controller | |
default_class = BookController | |
# Determine whether to create a new entity or not | |
# Called on POST request | |
def create(self): | |
# Get the arguments from the html form | |
args = self.get_data('title', 'blob') | |
# The library stores `self.create()` in a variable, | |
# and then if it has a dict value, it will create a | |
# new entity of the associated model with kwargs based | |
# on the dict's contents. The `blob` value is required. | |
if data['title'] and data['blob']: | |
return data | |
### File: controllers/book_download.py | |
from controllers.core import DownloadController | |
from controllers.book import Book as BookController | |
class Book(DownloadController): | |
r'/books/serve/([^/]+)?' | |
# Associated controller | |
default_class = BookController | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment