コード例 #1
0
ファイル: views.py プロジェクト: gabrielmahia/somAI_MongoDB
def index(request):
    config = Config()
    conn = Connection(config.getConfig('db'))
    db = conn.getDatabase('biglittle')
    main = render_to_string('home.html')
    home = render_to_string('layout.html', {'contents': main})
    return HttpResponse(home)
コード例 #2
0
def index(request):
    config = Config()
    conn   = Connection(config.getConfig('db'))
    db     = conn.getDatabase()
    html   = '<h1>Welcome to Book Someplace!</h1>'
    html  += '<hr>'
    html  += '<ul>'
    import pprint
    for item in db.common.find() :
        html  += '<li>' +  pprint.saferepr(item) + '</li>'
    html  += '</ul>'
    main   = render_to_string('home.html')
    home   = render_to_string('layout.html', {'contents' : main})
    return HttpResponse(home)
コード例 #3
0
 def __init__(self, config, result_class=None, publisher=None):
     if config.getConfig('db'):
         db_conf = config.getConfig('db')
         if result_class == 'User':
             conn = Connection(db_conf['host'], db_conf['port'], User)
         elif result_class == 'Loan':
             conn = Connection(db_conf['host'], db_conf['port'], Loan)
         else:
             conn = Connection(db_conf['host'], db_conf['port'])
     else:
         conn = Connection()
     self.db = conn.getDatabase(self.dbName)
     self.publisher = publisher
     self.collection = conn.getCollection(self.collectName)
コード例 #4
0
 def __init__(self, config):
     if config.getConfig('db'):
         conn = Connection(config.getConfig('db'))
     else:
         conn = Connection()
     self.db = conn.getDatabase(self.dbName)
     self.collection = conn.getCollection(self.collectName)
コード例 #5
0
# testing database connection to biglittle.loan collection

# tell python where to find module source code
import pprint
import os, sys

sys.path.append(os.path.realpath("src"))
from config.config import Config
from db.mongodb.connection import Connection

# setting up the connection + collection
conn = Connection('localhost', 27017)
common = conn.getCollection('biglittle.common')

# testing common collection query
result = common.find()
for item in result:
    pprint.pprint(item)

key = 'paymentLen'
query = {'key': key}
result = common.find_one(query)
print('Value for ' + key + ':')
pprint.pprint(result.get('value'))
コード例 #6
0
from web.responder import Html
html_out = Html('templates/index.html')

# check for form posting
import cgi
form = cgi.FieldStorage()
if 'username' in form and 'password' in form:
    # pull username and pasword
    username = form['username'].value
    password = form['password'].value
    # do imports for authentication
    from web.auth import SimpleAuth
    from db.mongodb.connection import Connection
    from sweetscomplete.domain.customer import CustomerService
    from sweetscomplete.entity.customer import Customer
    # create CustomerService instance
    conn = Connection('localhost', 27017, Customer)
    cust_service = CustomerService(conn, 'sweetscomplete')
    # perform simple auth
    auth = SimpleAuth(cust_service, sess_storage)
    if auth.authenticate(username, password):
        success = True
        html_out.addHeader('Set-Cookie: token=' + auth.getToken() + ';path=/')
        message = "<b>HOORAY!  Successful Login.</b>"
    else:
        message = "<b>SORRY!  Unable to Login.</b>"

# output login form + message
html_out.addInsert('%message%', message)
print(html_out.render())
コード例 #7
0
# testing database connection to sweetscomplete.customer collection

# tell python where to find module source code
import os, sys

sys.path.append(os.path.realpath("src"))

from db.mongodb.connection import Connection
from sweetscomplete.entity.product import Product

# setting up the connection + collection
conn = Connection('localhost', 27017, Product)
prodCollect = conn.getCollection("sweetscomplete.products")

# testing products collection query
result = prodCollect.find_one()
print("\nResult from Query:")
print('Class:    ' + str(type(result)))
print('Key:      ' + result.getKey())
print('Title:    ' + result.getTitle())
print('Category: ' + result.get('category'))
print('JSON:     ' + result.toJson(['productPhoto']))
コード例 #8
0
cgitb.enable(display=1, logdir=".")

# custom imports
from web.responder import Html
from web.auth import SimpleAuth
from db.mongodb.connection import Connection
from sweetscomplete.domain.customer import CustomerService
from sweetscomplete.entity.customer import Customer
from sweetscomplete.domain.product import ProductService
from sweetscomplete.entity.product import Product
from sweetscomplete.entity.product_purchased import ProductPurchased
from sweetscomplete.domain.purchase import PurchaseService
from sweetscomplete.entity.purchase import Purchase

# create CustomerService instance
cust_conn = Connection('localhost', 27017, Customer)
cust_service = CustomerService(cust_conn, 'sweetscomplete')
prod_conn = Connection('localhost', 27017, Product)
prod_service = ProductService(prod_conn, 'sweetscomplete')
purch_conn = Connection('localhost', 27017, Purchase)
purch_service = PurchaseService(purch_conn, 'sweetscomplete')

# init vars
sess_storage = os.path.realpath("../data")
auth = SimpleAuth(cust_service, sess_storage)
cust = auth.getIdentity()
html_out = Html('templates/purchase.html')

# go to login page if not authenticated
if not cust:
    print("Location: /chapter_05/index.py\r\n")
コード例 #9
0
ファイル: details.py プロジェクト: gabrielmahia/somAI_MongoDB
# enable error display
import cgitb
cgitb.enable(display=1, logdir='../data')

# custom imports
from config.config import Config
from web.responder.html import HtmlResponder
from db.mongodb.connection import Connection
from sweetscomplete.domain.product import ProductService
from sweetscomplete.entity.product import Product

# create CustomerService instance
config = Config()
db_config = config.getConfig('db')
prod_conn = Connection(db_config['host'], db_config['port'], Product)
prod_service = ProductService(prod_conn, db_config['database'])

# HTML output
message = 'SORRY! Unable to find information on this product'
response = HtmlResponder('templates/details.html')

# check for form posting
import cgi
form = cgi.FieldStorage()

if 'product' in form:

    # get product key
    key = form['product'].value
コード例 #10
0
cgitb.enable(display=1, logdir='../data')

# custom imports
from config.config import Config
from web.responder.html import HtmlResponder
from web.auth import SimpleAuth
from db.mongodb.connection import Connection
from sweetscomplete.domain.customer import CustomerService
from sweetscomplete.entity.customer import Customer
from sweetscomplete.domain.product import ProductService
from sweetscomplete.entity.product import Product

# create CustomerService instance
config       = Config()
db_config    = config.getConfig('db')
cust_conn    = Connection(db_config['host'], db_config['port'], Customer)
cust_service = CustomerService(cust_conn, db_config['database'])
prod_conn    = Connection(db_config['host'], db_config['port'], Product)
prod_service = ProductService(prod_conn, db_config['database'])

# init vars
auth     = SimpleAuth(cust_service, config.getConfig('session_storage'))
cust     = auth.getIdentity()

# HTML output
response = HtmlResponder('templates/select.html')
response.addInsert('%message%', '<br>')
response.addInsert('%ajax_url%', config.getConfig('ajax_url'))

# output
if cust :
# sweetscomplete.entity.product.Product read/add/edit/delete

# tell python where to find module source code
import os,sys
sys.path.append(os.path.realpath("src"))

import pprint
from db.mongodb.connection import Connection

from datetime import date
from sweetscomplete.entity.product import Product
from sweetscomplete.domain.product import ProductService

# setting up the connection + collection
conn = Connection('localhost',27017,Product)
service = ProductService(conn, 'sweetscomplete')

# initialize test data
key        = '00000000'
doc        = '''\
{
    "productKey"  : "%key%",
    "productPhoto": "TEST",
    "skuNumber"   : "TEST0000",
    "category"    : "test",
    "title"       : "Test",
    "description" : "test",
    "price"       : 1.11,
    "unit"        : "test",
    "costPerUnit" : 2.22,
    "unitsOnHand" : 333
コード例 #12
0
cgitb.enable(display=1, logdir=".")

# custom imports
from config.config import Config
from web.responder.html import HtmlResponder
from web.auth import SimpleAuth
from db.mongodb.connection import Connection
from sweetscomplete.domain.customer import CustomerService
from sweetscomplete.entity.customer import Customer
from sweetscomplete.domain.purchase import PurchaseService
from sweetscomplete.entity.purchase import Purchase

# create CustomerService instance using configuration class
config = Config()
db_config = config.getConfig('db')
cust_conn = Connection(db_config['host'], db_config['port'], Customer)
cust_service = CustomerService(cust_conn, db_config['database'])
purch_conn = Connection(db_config['host'], db_config['port'], Purchase)
purch_service = PurchaseService(purch_conn, db_config['database'])

# init vars
auth = SimpleAuth(cust_service, config.getConfig('session_storage'))
cust = auth.getIdentity()
response = HtmlResponder('templates/history.html')

# get page number
import cgi
info = cgi.FieldStorage()

if 'page' in info:
    pageNum = int(info['page'].value)