Esempio n. 1
0
    def post(self):
        form = StoreTimeCreationForm(request.form)
        if int(form.open_h.data) > 24 or int(form.open_h.data) < 0 or \
            int(form.close_h.data) > 24 or int(form.close_h.data) < 0:
            return 'ko | check hour !', 400

        if int(form.open_min.data) >= 60 or int(form.open_min.data) < 0 or \
            int(form.close_min.data) >= 60 or int(form.close_min.data) < 0:
            return 'ko | check min !', 400
        open = datetime(year=1970,
                        month=01,
                        day=01,
                        hour=int(form.open_h.data),
                        minute=int(form.open_min.data))
        close = datetime(year=1970,
                         month=01,
                         day=01,
                         hour=int(form.close_h.data),
                         minute=int(form.close_min.data))
        open_str = open.strftime("%H%M00")
        close_str = close.strftime("%H%M00")

        tmp = {
            "store_id": ObjectId(form.id.data),
            "open_time": open_str,
            "close_time": close_str,
            "week_day": form.day.data,
        }
        try:
            engine = MongoDb.init(DATABASE_Settings, "opening_time")
            engine.save_data(tmp)
        except Exception, e:
            logging.error("{0} // {0}".format(self.__class__.__name__,
                                              e.message))
            return 'ko', 500
Esempio n. 2
0
 def get_flavours(self):
     engine = MongoDb.init(DATABASE_Settings, "flavours")
     res = engine.get_data({})
     if res == False:
         logging.error("Find data error ! //{0}//".format(
             self.__class__.__name__))
     ret = []
     for row in res:
         logging.debug(row)
         check = ['name', 'status', 'CN_name', 'price', '_id']
         error = 0
         for x in check:
             if x not in row:
                 error = 1
                 break
         if error == 0:
             tmp = {
                 'flavour': row['name'],
                 'status': row['status'],
                 'CN_name': row['CN_name'],
                 'price': row['price'],
                 'id': str(row['_id'])
             }
             ret.append(tmp)
     return ret
Esempio n. 3
0
 def save_order(self, data, ingredients, price, ran_string):
     data = {
         "user": {
             "name": data.name.data,
             "age": data.age.data,
             "height": data.height.data,
             "weight": data.weight.data,
             "sport_level": data.sport.data
         },
         "amount": data.amount.data,
         "address": data.address.data,
         "recipe": ingredients,
         "price": price,
         "flavour": data.flavour.data,
         "secret": ran_string,
         "phone": data.phone.data,
         "status": "new",
         "history": {
             str(int(time.time())): "created",
         },
         "created": str(int(time.time()))
     }
     engine = MongoDb.init(DATABASE_Settings, "orders")
     id = engine.save_data(data, get_id=True)
     return id
Esempio n. 4
0
 def ChangeOrderStat(self, oid, status):
     engine = MongoDb.init(DATABASE_Settings, "orders")
     query = {"status": "new", "_id": ObjectId(oid)}
     status = {1: "u_acepted", 2: "u_canceled"}[status]
     key = "history.{0}".format(int(time.time()))
     new_data = {"$set": {"status": status, key: "ConfimOrder"}}
     return engine.edit_data(query, new_data)
Esempio n. 5
0
 def save_flavour(self, flavour, cn_name, price):
     engine = MongoDb.init(DATABASE_Settings, "flavours")
     tmp = engine.save_data({
         'name': flavour,
         "CN_name": cn_name,
         "price": price,
         "status": False
     })
     return tmp
Esempio n. 6
0
 def post(self):
     form = StoreForm_2(request.form)
     logging.debug("Goint to delete : {0}".format(form.id.data))
     try:
         engine = MongoDb.init(DATABASE_Settings, "opening_time")
         engine.delete_data({"_id": ObjectId(form.id.data)})
     except Exception, e:
         logging.error("Find data error ! //{0}//".format(
             self.__class__.__name__))
Esempio n. 7
0
 def post(self):
     res = []
     form = StoreForm(request.form)
     id = form.id.data
     engine = MongoDb.init(DATABASE_Settings, "opening_time")
     try:
         ret = engine.get_data({"store_id": ObjectId(id)})
     except Exception, e:
         logging.error("Find data error ! //{0}//".format(
             self.__class__.__name__))
Esempio n. 8
0
 def edit_value(self, id, field, value):
     try:
         engine = MongoDb.init(DATABASE_Settings, "flavours")
         tmp = engine.edit_data({"_id": ObjectId(id)},
                                {"$set": {
                                    field: value
                                }})
     except Exception, e:
         logging.error("{0} // {1}".format(self.__class__.__name__,
                                           e.message))
Esempio n. 9
0
 def OCStoreDB(self, id, status):
     engine = MongoDb.init(DATABASE_Settings, "stores")
     try:
         tmp = engine.edit_data({"_id": ObjectId(id)},
                                {"$set": {
                                    "open": status
                                }})
         logging.debug("matched_count {0}".format(tmp.matched_count))
     except Exception, e:
         logging.error("{0} // {1}".format(self.__class__.__name__,
                                           e.message))
Esempio n. 10
0
 def change_status(self, oid, isecret):
     engine = MongoDb.init(DATABASE_Settings, "orders")
     query = {
         "status": "m_done",
         "_id": ObjectId(oid),
         "secret": isecret,
     }
     status = "shipped"
     key = "history.{0}".format(time.time())
     new_data = {"$set": {"status": status, key: "Sent"}}
     engine.edit_data(query, new_data)
Esempio n. 11
0
 def change_status(self, oid, isecret, status):
     engine = MongoDb.init(DATABASE_Settings, "orders")
     query = {
         "status": "u_acepted",
         "_id": ObjectId(oid),
         "secret": isecret,
     }
     status = {1: "m_acepted", 2: "m_canceled"}[status]
     key = "history.{0}".format(time.time())
     new_data = {"$set": {"status": status, key: "MakerOrderAccept"}}
     engine.edit_data(query, new_data)
Esempio n. 12
0
 def save_store(self, name, city, lat, lng):
     engine = MongoDb.init(DATABASE_Settings, "stores")
     tmp = engine.save_data({
         'name': name,
         'city': city,
         'lat': lat,
         'lng': lng,
         'open': False,
         'timezone': "Asia/Shanghai"
     })
     return tmp
Esempio n. 13
0
 def post(self):
     #TZ Asia/Shanghai
     SZtimezone = timezone('Asia/Shanghai')
     SZtime = datetime.now(SZtimezone)
     SQL = """SELECT COUNT(1) FROM `opening_time`
               INNER JOIN `stores`
               ON opening_time.store_id = stores.id
               AND stores.open = 1
               WHERE `week_day`={0} AND `open_time` < "{1}"
               AND `close_time` > "{2}"
     """.format(SZtime.strftime("%w"), SZtime.strftime("%H:%M:00"),
                SZtime.strftime("%H:%M:00"))
     #ret = Sql_run(DATABASE, SQL)
     query_1 = {"open": 1}
     query_2 = {
         "week_day": SZtime.strftime("%w"),
         "open_time": {
             "$lt": SZtime.strftime("%H%M00")
         },
         "close_time": {
             "$gt": SZtime.strftime("%H%M00")
         },
         "store_id": 42
     }
     try:
         engine_1 = MongoDb.init(DATABASE_Settings, "stores")
         engine_2 = MongoDb.init(DATABASE_Settings, "opening_time")
         res = engine_1.get_data(query_1)
         logging.debug("found {0}".format(res))
         for store in res:
             logging.debug("found {0}".format(store))
             query_2['store_id'] = store.get('_id')
             tmp = engine_2.exists(query_2)
             logging.debug("query2 : {0}".format(query_2))
             if tmp is True:
                 return True
         logging.debug("Nothing wrong ")
     except Exception, e:
         logging.error("{0} // {1}".format(self.__class__.__name__,
                                           e.message))
Esempio n. 14
0
    def checkrequest(self, id, secret):
        query = {
            "_id": ObjectId(id),
            "secret": secret,
        }
        engine = MongoDb.init(DATABASE_Settings, "orders")
        res = engine.get_data(query)
        if res == []:
            return 'ERROR'
        logging.debug("Order : {0}".format(res[0]))
        data = res[0]
        status = data.get("status", "ERROR")

        return status
Esempio n. 15
0
 def post(self):
     form = AdminCheckForm(request.form)
     if not form.validate():
         return 'ko', 400
     query = {"status": "m_done"}
     engine = MongoDb.init(DATABASE_Settings, "orders")
     res = engine.get_data(query)
     ret = []
     for row in res:
         tmp = row
         tmp["id"] = str(tmp["_id"])
         del tmp["_id"]
         tmp['flavour'] = json.loads(tmp['flavour'])
         ret.append(tmp)
     return ret
Esempio n. 16
0
 def post(self):
     form = AdminCheckForm(request.form)
     print request.form
     if not form.validate():
         return 'ko', 400
     query = {"status": "m_acepted"}
     engine = MongoDb.init(DATABASE_Settings, "orders")
     res = engine.get_data(query)
     ret = []
     for row in res:
         logging.debug("Row : {0}".format(row))
         tmp = row
         tmp["id"] = str(tmp["_id"])
         del tmp["_id"]
         ret.append(tmp)
     return ret
Esempio n. 17
0
    def edit_time(self, _id, _open, _close, day):
        try:
            logging.debug("id : {0}, open: {1}, close: {2}, day: {3}".format(
                _id, _open, _close, day))
            engine = MongoDb.init(DATABASE_Settings, "opening_time")
            tmp = engine.edit_data({"_id": ObjectId(_id)}, {
                "$set": {
                    "open_time": _open,
                    "close_time": _close,
                    "week_day": day
                }
            })

        except Exception, e:
            logging.error("{0} // {1}".format(self.__class__.__name__,
                                              e.message))
Esempio n. 18
0
 def get_stores(self):
     engine = MongoDb.init(DATABASE_Settings, "stores")
     res = engine.get_data({})
     if res == False:
         logging.error("Find data error ! //{0}//".format(
             self.__class__.__name__))
     ret = []
     for row in res:
         tmp = {
             'id': str(row.get('_id')),
             'name': row.get('name'),
             'city': row.get('city'),
             'open': row.get('open')
         }
         ret.append(tmp)
     return ret
Esempio n. 19
0
 def post(self):
     form = AdminCheckForm(request.form)
     print request.form
     if not form.validate():
         return 'ko', 400
     ret = []
     query = {"status": "u_acepted"}
     engine = MongoDb.init(DATABASE_Settings, "orders")
     res = engine.get_data(query)
     for row in res:
         tmp = dict(row.items())
         tmp['flavour'] = json.loads(tmp['flavour'])
         logging.debug(tmp)
         tmp["id"] = str(tmp["_id"])
         del tmp["_id"]
         ret.append(tmp)
     return ret
Esempio n. 20
0
 def checkrequest(self, id, secret):
     engine = MongoDb.init(DATABASE_Settings, "orders")
     query = {"status": "new", "secret": secret, "_id": ObjectId(id)}
     return engine.exists(query)