def queryAll(type): """ return all queries that are pending :param type: query type pending/approved/disapproved :return: all queries """ # get all the repos # sort by star in descending order query = repos.find({'pending': type}).sort('star', -1) queries = [] # query all the repos for i in range(query.count()): # get the next data next_query = query.next() # millify star next_query['star'] = millify(next_query['star']) # version control if '<curr>' in next_query.get('new_title', []): prev_curr_title = next_query['new_title'].split('<curr>') # differentiate title diff_title = difflib.SequenceMatcher(None, prev_curr_title[1], prev_curr_title[0]) diff_title = show_diff(diff_title) next_query['new_title'] = diff_title if '<curr>' in next_query.get('new_description', []): prev_curr_desc = next_query['new_description'].split('<curr>') # differentiate description diff_des = difflib.SequenceMatcher(None, prev_curr_desc[1], prev_curr_desc[0]) diff_des = show_diff(diff_des) print(next_query['description']) next_query['new_description'] = diff_des # TODO:// Show Description and title difference # append data into the query queries.append(next_query) return queries
def queryAll(type): """ return all queries that are pending :param type: query type pending/approved/disapproved :return: all queries """ # get all the repos # sort by star in descending order query = repos.find({'pending': type}).sort('star', -1) queries = [] # query all the repos for i in range(query.count()): # get the next data next_query = query.next() # millify star next_query['star'] = millify(next_query['star']) # append data into the query queries.append(next_query) return queries
def profile(user): # validate if username is signed in if session['username'] and session['username'] == user: # get all the repos # sort by star in descending order query = global_database.query(ids['repo'], limit=global_database.count(ids['repo']),username=session['username']) queries = [] # query all the repos for query in query: # millify star query['star'] = millify(query['star']) # append data into the query queries.append(query) # render all time return render_template('pages/profile.html', queries=queries) else: # wrong url entered flash('failure page does not exist') return redirect('/')
def all_time(): # set a limit limit = request.args.get('limit', 2, type=int) # user logged in if session.get('username') is not None: # check if admin admin = global_database.find_one(ids['user'], username=session['username'], fsr=True) else: admin = None # if clicked on sections if request.args.get('section') != None: # query according to their section query = global_database.query(ids['repo'], limit=limit, approved=True, section=request.args.get('section')) elif request.args.get('tag') != None: # query according to their tags query = global_database.query(ids['repo'], limit=limit, approved=True, tags=request.args.get('tag')) else: # query all time query = global_database.query(ids['repo'], limit=limit, approved=True) queries = [] # user clicked on load_more if limit > 2 and query.count() != 0 and limit <= query.count(): try: # get the second last query nex = query[limit - 1] # store the content content = { 'username': nex['username'], '_id': str(nex['_id']), 'title': nex['title'], 'url_title': slugify.slugify(nex['title']), 'approved': nex['approved'], 'date': nex['date'], 'description': nex['description'], 'avatar': nex['avatar'], 'url_pdf': nex['url_pdf'], 'url_repo': nex['url_repo'], 'stars': millify(nex['star']), 'queries_count': query.count(), 'limit': limit, 'section': nex['section'], 'tags': nex.get('tags', []), 'heroku': nex.get('heroku', None) } if admin is not None: content.update({"admin": admin['username']}) except IndexError: content = None # upload as json return jsonify(content) # query all the repos for elem in query: # millify star elem['star'] = millify(elem['star']) elem['url_title'] = slugify.slugify(elem['title']) queries.append(elem) # get all sections sec = global_database.query(2, limit=global_database.count(2)) all_sections = [] for section in sec: # append section to the list all_sections.append(section) # render all time return render_template('pages/query.html', queries=queries, all_sections=all_sections, admin=admin)