Example #1
0
 def query_form_metas(cls, query_dict: dict = None, unscoped: bool = False):
     if query_dict is None:
         query_dict = dict()
     from app.utils.mongodb import mongo
     if not unscoped:
         query_dict['using'] = [True]
     url_condition = mongodb_url_condition.UrlCondition(query_dict)
     if len(url_condition.filter_dict) == 0:
         try:
             datas = mongo.db.form_meta.find()
         except Exception as e:
             raise (500, 500, str(e))
         return datas, datas.count()
     if '_id' in url_condition.filter_dict:
         url_condition.filter_dict['_id']['$in'] = [
             mongodb_url_condition.ObjectId(item)
             for item in url_condition.filter_dict['_id']['$in']
         ]
     try:
         datas = mongo.db.form_meta.find(url_condition.filter_dict)
     except Exception as e:
         raise CustomError(500, 500, str(e))
     datas = mongodb_url_condition.sort_limit(datas,
                                              url_condition.sort_limit_dict)
     paginate = mongodb_url_condition.Paginate(datas,
                                               url_condition.page_dict)
     datas = paginate.data_page
     return [cls.formatter_simple(data) for data in datas], paginate.total
Example #2
0
 def get_form_meta(cls, query_dict: dict = None, unscoped: bool = False):
     if query_dict is None:
         query_dict = dict()
     if not query_dict.get('name', None):
         raise CustomError(500, 200, 'name must be given')
     from app.utils.mongodb import mongo
     if not unscoped:
         query_dict['using'] = [True]
     url_condition = mongodb_url_condition.UrlCondition(query_dict)
     try:
         data = mongo.db.form_meta.find_one(url_condition.filter_dict)
     except Exception as e:
         raise CustomError(500, 500, str(e))
     return cls.formatter_total(data)
Example #3
0
 def get_form(cls, query_dict: dict = None, unscoped: bool = False):
     print(query_dict)
     if query_dict is None:
         query_dict = dict()
     if query_dict.get('_id', None) is None:
         raise CustomError(500, 500, '_id must be given')
     from app.utils.mongodb import mongo
     if not unscoped:
         query_dict['using'] = [True]
     url_condition = mongodb_url_condition.UrlCondition(query_dict)
     if '_id' in url_condition.filter_dict:
         url_condition.filter_dict['_id']['$in'] = [
             mongodb_url_condition.ObjectId(item)
             for item in url_condition.filter_dict['_id']['$in']
         ]
     print(url_condition.filter_dict)
     try:
         data = mongo.db.form.find_one(url_condition.filter_dict)
     except Exception as e:
         raise CustomError(500, 500, str(e))
     return cls.formatter_total(data)