Ejemplo n.º 1
0
def load_db():
	if os.path.isfile('minivdb') and os.stat('minivdb').st_size > 0:
		logutil.get_logger('main').info('SQLite DB exists. Using existing database.')
	else:
		logutil.get_logger('main').info('SQLite DB cannot be found. Creating new database.')
		with open('sql/schema.sql') as f:
			for q in f.read().split(';'):
				db().query(q)
		logutil.get_logger('main').info('Created new databases. Imported default schema to database.')
Ejemplo n.º 2
0
from api import logutil
from decimal import Decimal

import re

logger =  logutil.get_logger('validator.common')

def validate_string(field_name, pattern=None, minlength=0, maxlength=0):
	"""
	Decorator to ensure that value of JSON entry mets requirements.
	"""
        def validate(f):
                def new_f(*args, **kwds):
                        if kwds['data'] is None:
                                return 'error.no_json_data'
                        data = kwds['data']
                        if data[field_name] is None:
                                return 'error.str.' + str(field_name) + '.required'
                        value = data[field_name]
                        if maxlength > 0:
                                if not (maxlength >= len(value) >= minlength):
                                        return 'error.str.' + str(field_name) + '.validate.length.between_' + str(minlength) + '_and_' + str(maxlength)
                        else:
                                if not (len(value) >= minlength):
                                        return 'error.str.' + str(field_name) + '.validate.length.higher_than_' + str(minlength)
                        if pattern is not None:
                                if not re.match(pattern, value):
                                        return 'error.str.' + str(field_name) + '.validate.pattern.' + str(pattern)

                        return f(*args, **kwds)
                new_f.func_name = f.func_name
Ejemplo n.º 3
0
Archivo: base.py Proyecto: hkerem/miniv
 def __init__(self, table):
     __metaclass__ = SingletonModel
     self.className = table
     self.logger = logutil.get_logger("model." + self.className)
Ejemplo n.º 4
0
Archivo: base.py Proyecto: hkerem/miniv
 def __init__(self, name):
         self.viewName = name;
         self.logger = logutil.get_logger('view.' + self.viewName)
Ejemplo n.º 5
0
Archivo: base.py Proyecto: hkerem/miniv
from common import *
from api import logutil

logger = logutil.get_logger('view.base')

class ViewBase():
	"""
	Abstact class implementation for View objects
	"""
        viewName=''
        logger=None

        def __init__(self, name):
                self.viewName = name;
                self.logger = logutil.get_logger('view.' + self.viewName)

def json(f):
	"""
	Decorator to handle arguemnts and return types will be converted from/to JSON.
	This JSON decorator will parse data in web context, decodes as JSON and add resulting value to function arguments. 
	Also, decorator will encode result to JSON string.
	"""
	def new_f(*args, **kwds):
		if f.func_name in ['POST', 'PUT']:
			data = {}
			try:
				data = read_json()
			except Exception as e:
				logger.exception('Cannot parse JSON')
				return to_json('error.server.cannot_parse_json')
			kwds['data']=data
Ejemplo n.º 6
0
import web
from api import logutil
from api import dbutil
from view.user import *
from view.credit_card import CreditCardView
from view.payment import PaymentView
import os.path
from model.common import db

urls = (
	'/user', 'UserView',
	'/user/(.+)/balance', 'UserBalanceView',
	'/user/(.+)/feed', 'UserFeedView',
	'/user/(.+)/pay', 'PaymentView',
	'/user/(.+)/card', 'CreditCardView'
)
app = web.application(urls, globals())


if __name__ == '__main__':
	logutil.setup_logger()
	logutil.get_logger('main').info('Starting application')
	dbutil.load_db()
	app.run()