def list_page(): """ Using the data layer, Jinja2, and the list.html template this function EITHER returns the default list page (containing all the projects) OR if it has been requested using a POST it instead returns the list page containing a list of projects that fit the search parameters contained in the POST. This function is called when the URL '/list' is requested. :return: The list page of our portfolio(containing all or some projects from the data layer). """ db = data.load("data.json") full_list = data.search(db) techniques = data.get_technique_stats(db) if request.method == "POST": requested_technique_list = request.form.getlist("technique") requested_search_fields_list = request.form.getlist("search_fields") if not requested_search_fields_list: requested_search_fields_list = None requested_order = request.form["sort_order"] requested_sort_field = request.form["sort_field"] requested_text_search = request.form["text_search"] if requested_text_search == "": requested_text_search = None search_results = data.search( full_list, techniques=requested_technique_list, search_fields=requested_search_fields_list, sort_order=requested_order, sort_by=requested_sort_field, search=requested_text_search, ) return render_template( "list.html", page_name="List Page", sortable_fields=sortable_fields, searchable_fields=searchable_fields, project_list=search_results, previous_search_fields=requested_search_fields_list or [], previous_text_search=requested_text_search or "", previous_techniques=requested_technique_list, previous_sort_field=requested_sort_field, techniques=sorted(techniques.keys()), stylesheets=["list.css", "project-item.css", "search-box.css"], ) else: return render_template( "list.html", page_name="List Page", sortable_fields=sortable_fields, searchable_fields=searchable_fields or [], project_list=full_list, techniques=sorted(techniques.keys()), stylesheets=["list.css", "project-item.css", "search-box.css"], )
def test_get_technique_stats(self): res = data.get_technique_stats(self.loaded_data) res = sort_dict(res, 'id') self.expected_technique_stat_data = sort_dict( self.expected_technique_stat_data, 'id') self.assertEqual(res, self.expected_technique_stat_data)
def project_tech(): """ Returns a list of techniques we have used on the website, Each technique also lists projects where the technique was used. """ techniques = data.get_technique_stats(data_json()) return render_template("tech.html", techs=techniques, info=main_json())
def test_get_technique_stats(self): """ Test the implemented get_technique_stats function """ res = data.get_technique_stats(self.loaded_data) res = sort_dict(res, 'id') self.expected_technique_stat_data = sort_dict( self.expected_technique_stat_data, 'id') self.assertEqual(res, self.expected_technique_stat_data)
def techniques(): """ Renders techniques.html with all techniques and projects using those techniques """ #Call load() in the data layer to load the database and store it's contents in the variable db db = data.load('data.json') #Call data.get_technique_stats() in the data layer, and use OrderedDict(sorted(...)) to get it sorted alphabetically tech_stat_dict = data.get_technique_stats(db) tech_stat_dict = OrderedDict(sorted(tech_stat_dict.items())) #Render techniques.html with: #tech_stat_dict --> used to display a list of all techniques, where each items contains another list of all projects using that technique return render_template('techniques.html', tech_stat_dict=tech_stat_dict)
def search(): projects = data.load("data.json") retrived_techniques = data.get_technique_stats(projects) if request.method == "GET": return render_template('search.html', keys=retrived_techniques.keys()) elif request.method == "POST": searchfields = request.form.getlist("searchfields") if len(searchfields) == 0: searchfields = None foundprojects = data.search(projects, sort_by=request.form.getlist("sortby")[0], sort_order=request.form.getlist("sortorder")[0], techniques=request.form.getlist("techniques"), search=request.form.getlist("searchstr")[0], search_fields=searchfields) return render_template('search.html', keys=retrived_techniques.keys(), projectlist=foundprojects, matches=len(foundprojects))
def test_get_technique_stats(self): res = data.get_technique_stats(self.loaded_data) # print("before sorted:") # print_tech_dict(res) res = sort_dict(res,'id') # print("after sorted:") # print_tech_dict(res) # print("res: ",res) self.expected_technique_stat_data = sort_dict(self.expected_technique_stat_data,'id') # print_tech_dict(self.expected_technique_stat_data) self.assertEqual(res, self.expected_technique_stat_data)
def techniques(): """The "technique" page. Displays all techniques in a database and all projects related to them""" status = 0 db = data.load("data.json") if db == None: status = 1 else: techs = data.get_techniques(db) template_file = "techniques.jinja" template = env.get_template( template_file ) if status == 0: templateVars = { "status": status, "techs" : techs, "stats" : data.get_technique_stats(db), "style": flask.url_for('static',filename='style/style.css') } else: templateVars = { "status": status } return template.render( templateVars )
def techniques_show(t): """ Listar projekt med specifik teknik """ db = data_load() # Kolla statistik stats = data.get_technique_stats(db) # Kolla om den sökta tekniken finns i databasen if not t in stats: # Den fanns inte, skicka till 404 return render_template("404.html", e="404") # Ladda teknikvy-sidan return render_template( "techniques_show.html", namn=t, techniques=data.get_techniques(db), db=db, stats=stats[t], id=[data.get_project(db, x) for x in range(len(db))], )
def search_page(): db = data.load('data.json') technique_dict = data.get_technique_stats(db) if request.method == 'POST': if request.form['search-text'] == '': text = None else: text = request.form['search-text'] if request.form.getlist('techniques') == []: technique = None else: technique = request.form.getlist('techniques') if request.form.getlist('fields') == []: search_fields = None else: search_fields = request.form.getlist('fields') return render_template("search.html", title = "search", techniques = technique_dict , sort=request.form['sort_by'], search_text = text, order = request.form['sort_order'] , tech = technique, search_field = search_fields, header = 'Search Results') else: return render_template("search.html", title = "search", techniques = technique_dict , sort='start_date' , search_text = None, order = 'desc' , tech = None, search_field = None, header = 'All Projects')
def technique_page(): """ Using the data layer, Jinja2, and the techniques.html template this function returns the techniques page of the portfolio populated with all the techniques found in our data layer to whoever sent the request. This function is called when the URL '/techniques' is requested. :return: The techniques page of our portfolio. """ db = data.load("data.json") result_dict = data.get_technique_stats(db) sorted_dict = OrderedDict(sorted(result_dict.items(), key=lambda t: t[0].lower())) return render_template( "techniques.html", page_name="Techniques", techniques=sorted_dict, stylesheets=["technique.css", "techniques.css"], )
def search(): projects = data.load("data.json") retrived_techniques = data.get_technique_stats(projects) if request.method == "GET": return render_template('search.html', keys=retrived_techniques.keys()) elif request.method == "POST": searchfields = request.form.getlist("searchfields") if len(searchfields) == 0: searchfields = None foundprojects = data.search( projects, sort_by=request.form.getlist("sortby")[0], sort_order=request.form.getlist("sortorder")[0], techniques=request.form.getlist("techniques"), search=request.form.getlist("searchstr")[0], search_fields=searchfields) return render_template('search.html', keys=retrived_techniques.keys(), projectlist=foundprojects, matches=len(foundprojects))
def techniques(): projects = data.load("data.json") retrived_techniques = data.get_technique_stats(projects) return render_template('techniques.html', techs=retrived_techniques, keys=retrived_techniques.keys())
def render_techniques(): db = data.load('data.json') technique_dict = data.get_technique_stats(db) return render_template("techniques.html", title = "Tekniker", techniques = technique_dict, projects = data.search(db))
def search_form(): """ Returns search form with all the available search options """ appdata = data_json() techniques = data.get_technique_stats(appdata) return render_template("searchform.html", data=appdata, techs=techniques, info=main_json())
def technique_list(): """The page listing projects based on techniques. Gets technique-info from the db with get_technique_stats() and sends it to the page for listing.""" tech_list = data.get_technique_stats(db) return render_template('techniques.html', title = u'Portfolio - Tekniker', techniques = tech_list)
def techniques(): db = data.load("data.json") return render_template("techniques.html", data=data.get_technique_stats(db))
def test_get_technique_stats(self): res = data.get_technique_stats(self.loaded_data) self.assertEqual(res, self.expected_technique_stat_data)
def techniques(): return render_template('techniques.html', config= config_load(), data= data.get_technique_stats(data_load())) # get the techs
def techniques(): db=load() techs=get_techniques(db) techniqs=get_technique_stats(db) return render_template('techniques.html',techs=techs, techniqs=techniqs)