예제 #1
0
파일: views.py 프로젝트: dnguyen22/ClickFox
def mean(attribute):
    if request.method == 'GET':
        limit = request.args.get('limit', default=20, type=int)
        visitor_key = request.args.get('visitor_key', default=None, type=str)

        if visitor_key:
            query = {"visitor_key": visitor_key}
        else:
            query = None

        projection = [attribute]
        data = DB.find(collection, query, projection, limit=limit)
        accum = 0
        count = 0
        for result in data:
            accum += result[attribute]
            count += 1

        if count == 0:
            return jsonify({
                'ok': False,
                'message': 'No results matching criteria!'
            }), 400

        return jsonify({'value': accum / count}), 200
예제 #2
0
def jobs():
    """Get all jobs"""
    result = DB.find("jobs")
    print(result)
    if result:
        return dumps(result)
    else:
        return ({"response": "no user found for"})
예제 #3
0
def friends():
    user = DB.find_one(collection="Profile",
                       query={"email": current_user.email})
    if user is None:
        flash('Please create your profile first!')
        return redirect(url_for('edit_profile'))
    # all users
    users = list(DB.find_all(collection="Profile"))

    myFriendList = []
    mySentList = []
    for f in user['friends']:
        profile = DB.find_one(collection="Profile",
                              query={'_id': f['friend_id']})
        if f['status'] == 'accepted':
            myFriendList.append(profile)
        else:
            mySentList.append(profile)
    incoming = DB.find(collection="Profile",
                       query={
                           "friends": {
                               "$elemMatch": {
                                   "friend_id": user['_id'],
                                   "status": "pending"
                               }
                           }
                       })
    requests = get_cursor(cursor_obj=incoming,
                          key="friends",
                          subkey="friend_id",
                          subkey2="status",
                          query=user['_id'],
                          query2="pending")

    return render_template('friend.html',
                           title='Friend List',
                           users=users,
                           myFriendList=myFriendList,
                           mySentList=mySentList,
                           requests=requests)
예제 #4
0
 def fetch(created_by):
     return DB.find("studentactivity", {"created_by": created_by})
예제 #5
0
 def getActivitiesByUser(userName):
     return DB.find("studentactivity", {"created_by": userName})
예제 #6
0
 def fetch_all_company_details():
     return DB.find("company", {}, {"name": 1, "summary": 1, "website": 1})
예제 #7
0
 def fetch_all_companies():
     return DB.find("company")
예제 #8
0
파일: job.py 프로젝트: technoroots/projects
    def find(self):
        result = DB.find("sinfo", self.name)

        #        for keys in result:
        return dumps(result, indent=2)
예제 #9
0
    def search(self):
        result = DB.find("sinfo", self.query.to_dict())

        return dumps(result, indent=2)
예제 #10
0
 def fetch_all_postings():
     return DB.find("jobPostings")
예제 #11
0
 def fetch_by_company(companyList):
     return DB.find("jobPostings", {"company": {"$in": companyList}})
예제 #12
0
 def find_by_student_and_course(self, student, course):
     result = []
     tasks = DB.find("Tasks", {"student": student, "course_id": course})
     for task in tasks:
         result.append(task)
     return jsonify(result)
예제 #13
0
 def find_by_student(self, student_id):
     result = []
     tasks = DB.find("Tasks", {"student": student_id}).sort("created", -1)
     for task in tasks:
         result.append(task)
     return jsonify(result)
예제 #14
0
def display_event(id):
    user = DB.find_one(collection="Profile",
                       query={"email": current_user.email})
    if user is None:
        flash('Please create your profile first!')
        return redirect(url_for('edit_profile'))
    #get the event name or more so the ID
    eventDetails = DB.find_one(collection="Events",
                               query={"_id": ObjectId(id)})

    # if  not any(person['email'] == current_user.email for person in eventDetails['invitees']):
    # 	if eventDetails['private']:
    # 		flash('The event you were looking for is unavailable')
    # 		return redirect(url_for('view_events'))
    invited = []
    going = []
    maybe = []
    declined = []
    status = "invited"  # this user has not  responded to the event
    host = 0  # whether this person is the host of the event being displayed
    cohosts = []
    invitePrivleges = 0
    eventDetails = DB.find_one(collection="Events",
                               query={"_id": ObjectId(id)})

    # get event posts and corresponding author information
    posts = None
    if 'eventPosts' in eventDetails:
        posts = list(
            DB.find(collection="Post",
                    query={'_id': {
                        '$in': eventDetails['eventPosts']
                    }}))
    if not posts:
        posts = {}
    else:
        for post in posts:
            post['authorDetails'] = DB.find_one(
                collection="Profile", query={'_id': post['author_id']})

    # gets all the friends of the user
    friends = []
    for person in user['friends']:
        if person['status'] == "accepted":
            friendId = str(person['friend_id'])
            friendDetails = DB.find_one(collection="Profile",
                                        query={"_id": person['friend_id']})
            element = {
                "id": friendId,
                "firstName": friendDetails['firstName'],
                "lastName": friendDetails['lastName']
            }
            friends.append(element)
    # Sees whether this person has invite privleges or is a host
    if eventDetails['host'] == user['_id']:
        host = 1
    else:
        for cohost in eventDetails['invitePrivleges']:
            if (cohost['email'] == current_user.email):
                invitePrivleges = 1
                break
    cohosts = eventDetails['invitePrivleges']
    # see whether the person has accepted or not to give them the option to accept your invite
    for invitee in eventDetails["invitees"]:
        details = DB.find_one(collection="Profile",
                              query={"email": invitee['email']},
                              projection={
                                  "firstName": 1,
                                  "lastName": 1,
                                  "pictureDir": 1
                              })
        #get pictureDir
        fullName = details['firstName'] + " " + details['lastName']
        pictureDir = details['pictureDir']
        dictionaryItem = {"name": fullName, "pictureDir": pictureDir}
        if invitee['status'] == "going":
            going.append(dictionaryItem)
        elif invitee['status'] == "declined":
            declined.append(dictionaryItem)
        elif invitee['status'] == "maybe":
            maybe.append(dictionaryItem)
        else:
            invited.append(dictionaryItem)
        if invitee["email"] == current_user.email and invitee[
                'status'] != "invited":
            status = invitee['status']  # user has already responded
    nameDetails = DB.find_one(collection="Profile",
                              query={"_id": eventDetails['host']},
                              projection={
                                  "firstName": 1,
                                  "lastName": 1
                              })
    hostName = nameDetails['firstName'] + " " + nameDetails['lastName']
    return render_template('display-event.html',
                           event=eventDetails,
                           friends=json.dumps(friends),
                           host=host,
                           status=status,
                           invited=invited,
                           maybe=maybe,
                           going=going,
                           declined=declined,
                           canInvite=invitePrivleges,
                           cohosts=cohosts,
                           posts=posts,
                           hostName=hostName)
예제 #15
0
def get_product_by_currency_code(currency_code, db=None):
    if not app.config['DISABLE_TOKEN'] and not __check_authorization():
        return jsonify({'error': 'Need a valid token.'})
    products = db or DB.find('products', {'currency_code': currency_code})
    return dumps({'products': products})
예제 #16
0
def get_product(product_code):
    if not app.config['DISABLE_TOKEN'] and not __check_authorization():
        return jsonify({'error': 'Need a valid token.'})

    products = DB.find('products', {'product_code': product_code})
    return dumps({'products': products})
예제 #17
0
 def fetch_all_users():
     return DB.find("users")
예제 #18
0
def search():
    user = DB.find_one(collection="Profile",
                       query={"email": current_user.email})
    if user is None:
        flash('Please create your profile first!')
        return redirect(url_for('edit_profile'))

    # create index for text search (Profile)
    DB.createIndex(collection="Profile",
                   query=[("email", "text"), ("firstName", "text"),
                          ("lastName", "text"), ("descriptions", "text")],
                   name='profile_search')
    matched_profiles = list(
        DB.find(collection='Profile',
                query={'$text': {
                    '$search': request.args['query']
                }}))

    # since the host of an event can change, or the name of the host can
    # change, we need to look up event hosts by profile id instead of by
    # name
    matched_profile_info = {
        profile['_id']: (profile['firstName'], profile['lastName'])
        for profile in matched_profiles
    }

    DB.createIndex(collection="Events",
                   query=[("name", "text"), ("description", "text")],
                   name='event_search')
    DB.createIndex(collection="Events", query=[("host", 1)], name='event_host')
    matched_events = list(
        DB.find(collection='Events',
                query={
                    '$or': [{
                        '$text': {
                            '$search': request.args['query']
                        }
                    }, {
                        'host': {
                            '$in': list(matched_profile_info.keys())
                        }
                    }]
                }))

    for event in matched_events:
        matched_user = DB.find_one(collection="Profile",
                                   query={"_id": event['host']},
                                   projection={
                                       "firstName": 1,
                                       "lastName": 1
                                   })
        (firstname, lastname) = (matched_user['firstName'],
                                 matched_user['lastName'])
        event['host'] = '{} {}'.format(firstname, lastname)

    matched_events = [
        item for item in matched_events if item['private'] == False
    ]
    return render_template('search.html',
                           title='Search Results',
                           users=matched_profiles,
                           events=matched_events,
                           query=request.args['query'])
예제 #19
0
def dashboard():
    user = DB.find_one(collection="Profile",
                       query={"email": current_user.email})
    if user is None:
        flash('Please create your profile first!')
        return redirect(url_for('edit_profile'))

    incoming = DB.find(collection="Profile",
                       query={
                           "friends": {
                               "$elemMatch": {
                                   "friend_id": user['_id'],
                                   "status": "pending"
                               }
                           }
                       })
    requests = get_cursor(cursor_obj=incoming,
                          key="friends",
                          subkey="friend_id",
                          subkey2="status",
                          query=user['_id'],
                          query2="pending")

    allEvents = []
    allPolls = []
    myEvents = []
    # if DB.find_one(collection="Profile", query={"email":current_user.email, "events": {"$ne" : []}}):
    if user['events'] != []:
        for event_id in user['events']:
            event = DB.find_one(collection='Events', query={'_id': event_id})
            event_host = DB.find_one(collection='Profile',
                                     query={'_id': event['host']})
            if user['_id'] == event_host['_id']:
                myEvents.append(event)
            else:
                allEvents.append({
                    '_id':
                    event['_id'],
                    'name':
                    event['name'],
                    'host':
                    event_host['firstName'] + ' ' + event_host['lastName'],
                    'start':
                    event['start'],
                    'end':
                    event['end'],
                    'description':
                    event['description'],
                    'pictureDir':
                    event['pictureDir']
                })
        # allEvents = get_list_of_documents(obj_id_list=user['events'], collection='Events')
    # if DB.find_one(collection="Profile", query={"email":current_user.email, "polls": {"$ne" : []}}):
    if user['polls'] != []:
        allPolls = get_list_of_documents(obj_id_list=user['polls'],
                                         collection='Poll')
    return render_template('dashboard.html',
                           title='Dashboard',
                           polls=allPolls,
                           myEvents=myEvents,
                           invEvents=allEvents,
                           me=user,
                           requests=requests)