def run(self):
     session = models.get_session()
     store_entry = Store()
     store_entry.payload = self.payload.decode("utf-8")
     store_entry.topic = self.topic
     session.add(store_entry)
     session.commit()
示例#2
0
 def post(self, request):
     # 创建商店
     owner = request.u
     name = request.json.get("name")
     address = request.json.get("address")
     announcement = request.json.get("announcement")
     description = request.json.get("description")
     phone = request.json.get("phone")
     image_ids = request.json.get("image_ids")
     if not all([owner, name, address, announcement, description]):
         return JsonErrorResponse("owner, name, address, announcement, description, phone are needed", 400)
     new_store = Store(
         name=name,
         address=address,
         announcement=announcement,
         description=description,
         phone=phone,
         image_ids=image_ids,
         owner=owner
     )
     try:
         new_store.save()
     except Exception, e:
         print e
         return JsonErrorResponse("Fail:" + e.message)
示例#3
0
def get_store(store_id):
    s = Store.get_store(g._db, store_id)
    obj = {
        "store_id": store_id,
        "name": ''
    }

    if s:
        obj['name'] = s['name']

    return make_response(200, obj)
示例#4
0
def post(data):
    if data:
        store = {
            'shop_address': data['address'],
            'store_name': data['name'],
            'tagline': data['tagline'],
            'Phone_number': data['phone'],
            'email': data[
                'email'],  # todo: we might have to take this from the shop-creator's account
        }
        try:
            new_store = Store(**store).save()
        except NotUniqueError:
            return jsonify({
                'status': 'fail',
                'message': 'Store already exists',
            }), 403
        except Exception as e:
            return jsonify({'message': "No valid data"}), 400

        return jsonify({'result': new_store}), 201

    else:
        return jsonify({'message': "No valid data"}), 400
    def post(self, name):

        claims = get_jwt_claims()
        print(claims)

        if not claims["isAdmin"]:
            return {"message": "you are not admin"}, 401

        props = StoreController.parser.parse_args()

        if Store.findByName(name):
            return {"message": "A store with the same already exists."}, 400

        store = Store(name, **props)

        try:
            store.save()

        except:
            return {
                "message": "something was wrong when creating the store."
            }, 500

        return store.json(), 201
示例#6
0
    def delete(self, name):
        store = Store.find_by_name(name)
        if store:
            store.delete_from_db()

        return {'message': 'Store deleted'}
示例#7
0
 def get(self, name):
     store = Store.find_by_name(name)
     if store:
         return store.json()
     return {"message": "store not found"}, 404
示例#8
0
 def get(self, name):
     store = Store.find_by_name(name)
     return store.json(), 200 if Store else 404
示例#9
0
from models.user import User
from models.store import Store
from models.products import Product
from models.category import Category, CategoriesProducts

if CategoriesProducts.table_exists:
    CategoriesProducts.drop_table()

if Category.table_exists():
    Category.drop_table()

if Product.table_exists():
    Product.drop_table()

if Store.table_exists():
    Store.drop_table()

if User.table_exists():
    User.drop_table()

User.create_table()
Store.create_table()
Product.create_table()
Category.create_table()
CategoriesProducts.create_table()

# Insert data

# 1
user1 = User()
user1.username = '******'
示例#10
0
def index():
    stores = Store.all()
    return render_template('stores/index.html', stores=stores)
 def get(self):
     return {
         "stores":
         [store.jsonWithoutProducts() for store in Store.findAll()]
     }
示例#12
0
def chat():
    store = request.args.get('store')
    uid = request.args.get('uid')
    appid = request.args.get('appid')
    token = request.args.get('token')
    username = request.args.get('name', '')
    device_id = request.args.get('device_id', '')
    if not store and appid:
        store = App.get_store_id(g._db, int(appid))
        print "store id:", store
        if not store:
            return render_template_string(error_html, error="非法的应用id")

    if not store:
        return render_template_string(error_html, error="未指定商店id")

    s = Store.get_store(g._db, int(store))
    if s:
        name = s['name']
    else:
        name = ""

    if uid and appid and token:
        return render_template("customer/pc_chat.html",
                               host=config.HOST,
                               customerAppID=int(appid),
                               customerID=int(uid),
                               customerToken=token,
                               name=name,
                               apiURL=config.APIURL,
                               storeID=int(store))

    #check cookie
    co_username = request.cookies.get('username', '')
    co_uid = request.cookies.get('uid')
    co_token = request.cookies.get('token')

    if co_username == username and co_uid and co_token:
        appid = config.ANONYMOUS_APP_ID
        uid = int(co_uid)
        token = co_token
        return render_template("customer/pc_chat.html",
                               host=config.HOST,
                               customerAppID=appid,
                               customerID=uid,
                               customerToken=token,
                               name=name,
                               apiURL=config.APIURL,
                               storeID=int(store))

    # 生成临时用户
    rds = g.rds
    key = "anonymous_id"
    uid = rds.incr(key)
    appid = config.ANONYMOUS_APP_ID
    token = login_gobelieve(uid,
                            username,
                            config.ANONYMOUS_APP_ID,
                            config.ANONYMOUS_APP_SECRET,
                            device_id=device_id)
    resp = flask.make_response(
        render_template("customer/pc_chat.html",
                        host=config.HOST,
                        customerAppID=appid,
                        customerID=uid,
                        customerToken=token,
                        name=name,
                        apiURL=config.APIURL,
                        storeID=int(store)))

    resp.set_cookie('token', token)
    resp.set_cookie('uid', str(uid))
    resp.set_cookie('username', username)
    return resp
示例#13
0
	def get(self, name):
		store = Store.findByName(name)
		if store:
			return store.json() #returns also a list of items
		return {"message":"store {} not found".format(name)}
示例#14
0
def index():
    stores = Store.all()  # get all stores
    return render_template(
        'stores/store_index.html',
        stores=stores)  # give the stores variable inside the template
示例#15
0
def test_create_quiz():
    """quizes can be created"""
    store = Store()
    quiz_id = store.create_quiz(FakeSource)
    assert store.quizes[quiz_id]
示例#16
0
def test_get_quiz():
    """quizes can be retrieved from the app"""
    store = Store()
    quiz_id = store.create_quiz(FakeSource)
    quiz = store.get_quiz_by_id(quiz_id)
    assert quiz
示例#17
0
def chat():
    store = request.args.get('store')
    uid = request.args.get('uid')
    appid = request.args.get('appid')
    token = request.args.get('token')
    username = request.args.get('name', '')
    device_id = request.args.get('device_id', '')
    if not store and appid:
        store = App.get_store_id(g._db, int(appid))
        print "store id:", store
        if not store:
            return render_template_string(error_html, error="非法的应用id")
        
    if not store:
        return render_template_string(error_html, error="未指定商店id")
        
    s = Store.get_store(g._db, int(store))
    if s:
        name = s['name']
    else:
        name = ""

    if uid and appid and token:
        return render_template("customer/pc_chat.html",
                               host=config.HOST,
                               customerAppID=int(appid),
                               customerID=int(uid),
                               customerToken=token,
                               name=name,
                               apiURL=config.APIURL,
                               storeID=int(store))


    #check cookie
    co_username = request.cookies.get('username', '')
    co_uid = request.cookies.get('uid')
    co_token = request.cookies.get('token')

    if co_username == username and co_uid and co_token:
        appid = config.ANONYMOUS_APP_ID
        uid = int(co_uid)
        token = co_token
        return render_template("customer/pc_chat.html",
                               host=config.HOST,
                               customerAppID=appid,
                               customerID=uid,
                               customerToken=token,
                               name=name,
                               apiURL=config.APIURL,
                               storeID=int(store))
    
    # 生成临时用户
    rds = g.rds
    key = "anonymous_id"
    uid = rds.incr(key)
    appid = config.ANONYMOUS_APP_ID
    token = login_gobelieve(uid, username,
                            config.ANONYMOUS_APP_ID,
                            config.ANONYMOUS_APP_SECRET,
                            device_id=device_id)
    resp = flask.make_response(render_template("customer/pc_chat.html",
                                               host=config.HOST,
                                               customerAppID=appid,
                                               customerID=uid,
                                               customerToken=token,
                                               name=name,
                                               apiURL=config.APIURL,
                                               storeID=int(store)))

    resp.set_cookie('token', token)
    resp.set_cookie('uid', str(uid))
    resp.set_cookie('username', username)
    return resp
    def get(self, name):

        store = Store.findByName(name)
        if store:
            return store.json()
        return {"message": "Store not found."}, 404
示例#19
0
def delete_store(store_id):
    store = Store.get_by_id(store_id)
    store.remove_from_db()
    return redirect(url_for('.index'))
示例#20
0
 def get(self):
     return [store.json() for store in Store.find_all()]
示例#21
0
 def get(self, name):
     store = Store.find_by_name(name)
     if store:
         return store.json(), 200
     else:
         return {'message': 'Store not found'}, 401
示例#22
0
def index():
    """Shows all saved stores."""
    stores = Store.fetch_all()
    return render_template('stores/index.html', stores=stores)
示例#23
0
def index():
    stores_present = Store.all()
    print("RKS: STORE INDEX ALL done")
    return render_template('stores/store_index.html', stores=stores_present)
示例#24
0
def index():
    stores = Store.all()
    return render_template("store_index.html", stores=stores)
示例#25
0
def delete_store(store_id):
    store = Store.find_by_id(store_id)
    store.remove_from_mongo()
    return redirect(url_for(".index"))
示例#26
0
    def get(self, name):
        store = Store.find_by_name(name)
        if store:
            return item.json(), 201

        return {"message": "Store not found"}, 404
示例#27
0
def delete(store_id: str):
    """Deletes an existing store."""
    Store.fetch_by_id(store_id).delete()
    return redirect(url_for('.index'))
示例#28
0
#!/usr/bin/python3
from models.base import BaseModel
from models.store import Store
from models.food import Food
from models.drink import Drink
from models.order import Order
from models import storage
from models.confirmation import Confirmation

my_store = Store(name="JV")
my_store.save()

my_food = Food(price=4000, store_id=my_store.id, name="Tinto")
my_food.save()

my_drink = Drink(price=5000, store_id=my_store.id, name="Cafe")
my_drink.save()

my_order = Order(order_number=1,
                 drink_id=my_drink.id,
                 store_id=my_store.id,
                 user_name="Juan")
my_order.save()
all_order = storage.all(Order)

my_confirmation = Confirmation(store_id=my_store.id,
                               order_id=my_order.id,
                               order_number=3,
                               status="In Progress")
my_confirmation.save()
示例#29
0
def delete_store(store_id):
    store = Store.get_by_id(store_id).remove_from_mongo()
    return(redirect(url_for("stores.index")))
示例#30
0
 def post(self, name):
     if Store.find_by_name(name):
         return {'message': f'Store {name} already exists.'}, 400
     store = Store(name)
     store.save()
     return store.dict_repr(), 201
示例#31
0
def delete_store(store_id):
    Store.get_by_id(store_id).remove_from_mongo()
    return redirect(url_for('.index'))
示例#32
0
def index():
    stores = Store.all()  # loading all items from mongodb to display on page
    return render_template('stores/index.html', stores=stores)
    def get(self, name):
        store = Store.search_name(name)
        if store:
            return store.json()

        return {'message': 'Store not found'}, 404
示例#34
0
 def delete(self, name):
     store = Store.find_by_name(name)
     if store:
         store.delete_from_db()
     return {"Message":"store deleted"}