Пример #1
0
def main():
    global app, db, web, database, pages
    parser = OptionParser()
    parser.add_option("-t", "--test-all", action="store_true", default=False, dest="test_all", help="Run all the tests.")
    parser.add_option("-d", "--test-db", action="store_true", default=False, dest="test_db", help="Run the database tests.")
    parser.add_option("-w", "--test-web", action="store_true", default=False, dest="test_web", help="Run the web tests.")
    parser.add_option("-r", "--reset-db", action="store_true", default=False, dest="reset_db", help="Reset the database.")
    parser.add_option("-s", "--script", metavar="SCRIPT", dest="script", default=None)
    parser.add_option("--server",  action="store_true", default=False, dest="start_server", help="Run the test webserver.")
    (options, args) = parser.parse_args()
    
    if options.test_all or options.test_db or options.test_web:
        app = Flask(__name__.split('.')[0])
        app.config['TESTING'] = True
        app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite://'
        db = SQLAlchemy(app)
        suite = unittest.TestSuite()
        if options.test_all or options.test_db:
            import tests.database
            suite.addTest(tests.database.suite)
        if options.test_all or options.test_web:
            import tests.web
            suite.addTest(tests.web.suite)
        unittest.TextTestRunner(verbosity=2).run(suite)
    elif options.script is not None:
        app = Flask(__name__.split('.')[0])
        app.config.from_object(config.FlaskConfig)
        db = SQLAlchemy(app)
        import scripts
        scripts = scripts.load_scripts()
        if options.script in scripts:
            scripts[options.script].main()
    elif options.reset_db or options.start_server:
        # Setup the application and database
        app = Flask(__name__.split('.')[0])
        app.config.from_object(config.FlaskConfig)
        app.jinja_env.add_extension('jinja2.ext.do')
        db = SQLAlchemy(app)
        import database
        import web
        if options.reset_db:
            db.drop_all()
            db.create_all()
            dataset.populate()
            print 'Database reset.'
            exit(0)
        import pages
        app.run(host='0.0.0.0', port=config.dev_port, use_reloader=True)
    else:
        parser.print_help()
Пример #2
0
from flask import Flask
from flaskext.sqlalchemy import SQLAlchemy
from flaskext.uploads import configure_uploads, UploadSet, IMAGES

app = Flask(__name__)

# Load default configuration values, override with whatever is specified
# in configuration file. This is, I think, the sanest approach.
app.config.from_object('kremlin.config_defaults')
app.config.from_envvar('KREMLIN_CONFIGURATION')

# Set database from configuration values
app.config['SQLALCHEMY_DATABASE_URI'] = app.config['DATABASE_URI']
db = SQLAlchemy(app)

uploaded_images = UploadSet("images", IMAGES)

# Create upload set
# and configure like a m**********r.
uploaded_images = UploadSet("images", IMAGES)
configure_uploads(app, uploaded_images)

# Import relevant modules
# this is done last to avoid touchy situations
import kremlin.dbmodel
import kremlin.core
import kremlin.forms

# Create all database tables
db.create_all()
Пример #3
0
# create our little application :)
app = Flask(__name__)
app.config.from_object(__name__)
app.config.from_envvar('FLASKR_SETTINGS', silent=True)

db = SQLAlchemy(app)

class Entry(db.Model):
    
    __tablename__ = "entries"

    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.Unicode(200))
    text = db.Column(db.UnicodeText)
    
db.create_all()

class EntryForm(Form):

    title = TextField("Title", validators=[Required()])
    text = TextAreaField("Text")
    submit = SubmitField("Share")

class LoginForm(Form):

    username = TextField("Username")
    password = PasswordField("Password")
    submit = SubmitField("Login")
    
    def validate_username(self, field):
        if field.data != USERNAME:
Пример #4
0
    hello = UDF field 3

    Restrictions - none of your fields can include the / character
    """
    # - Check if this order has already been paid
    t = Transaction.query.filter_by(order_id=id, result='CAPTURED').first()
    if t is not None:
        return 'You have already paid for this order.'

    # 2 - Build and dispatch KNET URL
    trackid = trackingid or '{0.year}{0.month}{0.day}-{1}-{0.hour}{0.minute}{0.second}'.format(
        datetime.now(), id)

    knet.parse()
    if udf is not None:
        udf = {'udf%s' % udf.find(x): x for x in udf if x is not ','}
    payment_id, payment_url = knet.transaction(trackid, amount=total, udf=udf)

    # Store information in DB
    t = Transaction(trackid, id, total)
    t.payment_id = payment_id
    db.session.add(t)
    db.session.commit()
    return redirect(payment_url + '?PaymentID=' + payment_id)


if __name__ == '__main__':
    db.create_all(
    )  # This will reset and recreate the database on each restart of the system
    app.run(debug=True)
Пример #5
0
def reinit_db():
    global db

    db = SQLAlchemy(app)
    db.create_all()
Пример #6
0
    ABC-TRACK = Tracking ID
    abc = UDF field 1
    [email protected] = UDF field 2
    hello = UDF field 3

    Restrictions - none of your fields can include the / character
    """
    # - Check if this order has already been paid
    t = Transaction.query.filter_by(order_id=id, result='CAPTURED').first()
    if t is not None:
        return 'You have already paid for this order.'

    # 2 - Build and dispatch KNET URL
    trackid = trackingid or '{0.year}{0.month}{0.day}-{1}-{0.hour}{0.minute}{0.second}'.format(datetime.now(), id)

    knet.parse()
    if udf is not None:
        udf = {'udf%s' % udf.find(x): x for x in udf if x is not ','}
    payment_id, payment_url = knet.transaction(trackid, amount=total, udf=udf)

    # Store information in DB
    t = Transaction(trackid, id, total)
    t.payment_id = payment_id
    db.session.add(t)
    db.session.commit()
    return redirect(payment_url + '?PaymentID=' + payment_id)

if __name__ == '__main__':
    db.create_all()  # This will reset and recreate the database on each restart of the system
    app.run(debug=True)