示例#1
0
    def create():

        query = {
            "$jsonSchema": {
                "bsonType": "object",
                "required": ['name'],
                "description": "department must be an object",
                "properties": {
                    "name": {
                        "bsonType": "string",
                        "description": "name must be a string"
                    }
                }
            }
        }

        try:
            db.command(
                OrderedDict({
                    "create": "departments",
                    "validator": query,
                    "validationLevel": "strict",
                    "validationAction": "error"
                }))
            print("Department Collection Created !!!")

        except errors.OperationFailure as error:
            print(error)
示例#2
0
def search():
    terms = request.form.get('search')
    companies = list(db.ca.find({'company_name':terms}))
    companies = db.command('text', 'ca', search=terms)['results']
    
    for company in companies:
        company.update(company['obj'])
        epa_results = db.command('text','epa', search=company['company_name'])
        company['epa_citations'] = epa_results['stats']['nscanned']
        company['epa_rating'] = (float(company['epa_citations'])/1000)
        print company['epa_citations'], company['epa_rating']
    
    return(render_template("results.html", companies = companies, get_image=get_image))
示例#3
0
    def create():
        query = {
            "$jsonSchema": {
                "bsonType": "object",
                "required": ['password', 'role', 'confirmed'],
                "properties": {
                    "_id": {
                        "bsonType": "string",
                        "description": "must be a string"
                    },
                    "name": {
                        "bsonType": "string",
                        "description": "must be a string"
                    },
                    "department": {
                        "bsonType": "string",
                        "descripion": "must be a string"
                    },
                    "password": {
                        "bsonType": "string",
                        "description": "must be a string"
                    },
                    "role": {
                        "bsonType": "string",
                        "description": "must be a string"
                    },
                    "confirmed": {
                        "bsonType": "bool",
                        "description": "must be a boolean"
                    }
                }
            }
        }

        try:
            db.command(
                OrderedDict({
                    "create": "users",
                    "validator": query,
                    "validationLevel": "strict",
                    "validationAction": "error"
                }))
            print("User Collection Created!!")

        except errors.OperationFailure as error:
            print(error)
示例#4
0
def geonear_search(skills):
    lat = float(request.args.get('lat'))
    lon = float(request.args.get('lng'))
    docs = db.command(
        SON([("geoNear", "jobs"), ("near", [lon, lat]),
             ("query", {
                 "skills": {
                     "$in": skills.split(',')
                 }
             }), ("limit", 5), ("distanceMultiplier", 111)]))

    jobs = []

    for result in docs['results']:
        job = toJob(result)
        jobs.append(job)

    return render_template('showall.html', title='All Jobs', jobs=jobs)
示例#5
0
def geonear_search(skills):
	lat = float(request.args.get('lat'))
	lon = float(request.args.get('lng'))
	docs = db.command(SON([
		("geoNear" , "jobs"),
  		("near" , [lon , lat]),
  		("query", {"skills" : {"$in" : skills.split(',')}}),
  		("limit" , 5),
  		("distanceMultiplier" , 111)
	]))

	jobs = []

	for result in docs['results']:
		job = toJob(result)
		jobs.append(job)

	return render_template('showall.html',title='All Jobs', jobs=jobs)
示例#6
0
    def create():

        query = {
            "$jsonSchema": {
                "bsonType": "object",
                "required": ["student_enrolled"],
                "properties": {
                    "name": {
                        "bsonType": "string",
                        "description": "course name must be a string"
                    },
                    "teacherAssigned": {
                        "bsonType": "string",
                        "description": "teacher must be a string"
                    },
                    "department": {
                        "bsonType": "string",
                        "description": "department must be a string"
                    },
                    "attendance": {
                        "bsonType": "array",
                        "description":
                        "attendance should me an array of objects",
                        "items": {
                            "bsonType": "object",
                            "required": ["date", "attendance_on_date"],
                            "properties": {
                                "date": {
                                    "bsonType": "string",
                                    "description":
                                    "date must be a string object"
                                },
                                "attedance_on_date": {
                                    "bsonType": "array",
                                    "description":
                                    "attendance_on_date should be a of attendances",
                                    "items": {
                                        "bsonType": "object",
                                        "required": ["roll_no", "status"],
                                        "properties": {
                                            "roll_no": {
                                                "bsonType":
                                                "string",
                                                "description":
                                                "roll_no should be a string"
                                            },
                                            "status": {
                                                "bsonType":
                                                "bool",
                                                "description":
                                                "status should be a boolean"
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "student_enrolled": {
                        "bsonType": "array",
                        "description":
                        "student_enrolled must be an array and is required",
                        "items": {
                            "bsonType": "object",
                            "required": ["roll_no", "encoding"],
                            "properties": {
                                "roll_no": {
                                    "bsonType":
                                    "string",
                                    "description":
                                    "roll must be a string and is required"
                                },
                                "encoding": {
                                    "bsonType":
                                    "array",
                                    "description":
                                    "encoding must be an array and is required"
                                }
                            }
                        }
                    }
                }
            }
        }
        try:
            db.command(
                OrderedDict({
                    "create": "courses",
                    "validator": query,
                    "validationLevel": "strict",
                    "validationAction": "error"
                }))
            print("Course Collection Created!!!")

        except errors.OperationFailure as error:
            print(error)