def project(project_id): """Project view Returns a view of the project page. Takes as input a GET variable from Flask's route method and requests the desired project from the database based upon this integer value. Parameters ---------- project_id : int The integer representing the desired project_id key in the database. Returns -------- render_template """ db = data.load("data.json") if project_id.isdigit(): valid_project = data.get_project(db, int(project_id)) images = get_images(project_id) print(images) if valid_project: return render_template("project.html", project=data.get_project( db, int(project_id)), images=images) else: abort(404) else: abort(404)
def test_get_project(self): self.assertEqual( data.get_project(self.loaded_data, 1)['project_id'], 1) self.assertEqual( data.get_project(self.loaded_data, 2)['project_id'], 2) self.assertEqual( data.get_project(self.loaded_data, 3)['project_id'], 3) self.assertEqual( data.get_project(self.loaded_data, 4)['project_id'], 4) self.assertEqual(data.get_project(self.loaded_data, 42), None)
def project(id): try: id = int(id) # is the id an int ? except: app.logger.error('projektet kunde inte hittas [id]: %s', id) # quarystring input was a no number abort(404,id) if data.get_project(data_load(), id) == None: # can not find the project with id app.logger.error('projektet kunde inte hittas [id]: %d', id) abort(404,id) return render_template('project.html', data= data.get_project(data_load(), int(id)), config= config_load()) # render the page
def project_single(id): """ Returns a page with description for a single project """ single_project = data.get_project(data_json(), id) if single_project is not None: return render_template("single.html", data=single_project, info=main_json()) else: return page_not_found(404)
def project_page(id): """ Using the data layer, Jinja2, and the project.html template this function returns a page containing information regarding the project that in the database has the specified id. If the specified project does not exist, it returns the "404" page. This function is called when the URL '/project/<int:id>' is requested. :return: The specified projects page """ db = data.load("data.json") project = data.get_project(db, id) pprint(project) if project is not None: return render_template( "elements/project.html", page_name="Project", project_data=project, stylesheets=["full-project.css"] ) else: return render_template( "status_codes/404.html", page_name="Project", non_existent_url=request.path, stylesheets=["status_codes/404.css"], )
def test_get_project(self): """ Test the implemented function get_project """ # Try to get project 1, 2, 3 and 4 and check that a project with # the correct project_id is returned. self.assertEqual( data.get_project(self.loaded_data, 1)['project_id'], 1) self.assertEqual( data.get_project(self.loaded_data, 2)['project_id'], 2) self.assertEqual( data.get_project(self.loaded_data, 3)['project_id'], 3) self.assertEqual( data.get_project(self.loaded_data, 4)['project_id'], 4) # Try to get a non-existing project and check that None is returned self.assertEqual(data.get_project(self.loaded_data, 42), None)
def project(project_id): """Redirects to project.html and sends the project with the ID given in the URL""" log('project.html', ('id: ' + str(project_id))) project = data.get_project(db, project_id) if not project_id in data.get_ids(db): project = None return render_template('project.html', data=data, db=db, project=project)
def show_project(project_no): """ Laddar sidan med detaljerad projektvy """ db = data_load() # Kolla så att vi får ett heltal try: int(project_no) # Skicka tillbaka användaren except Exception: # return redirect(url_for('start_page')) return render_template("404.html", e="404"), 404 # Kolla att det sökta projektet finns if data.get_project(db, int(project_no)) == None: # Finns inte, skicka till 404 # return redirect(url_for('start_page')) return render_template("404.html", e="404"), 404 # Hittat projektet return render_template("projects.html", project=data.get_project(db, int(project_no)), db=db)
def id_page(id): """ Portfolio id page """ db = data.init() #loads the given id project = data.get_project(db,id) #if project dont exist, display 404 error if project == None: return render_template("404.html") return render_template("portfolio.html",dataB = project)
def view_project(project_id): """The page for specific projects. Shows the project with the ID given in the URL, renders an error page if the ID is invalid.""" project = None try: project = data.get_project(db, int(project_id)) except: pass if project == None: return render_template("invalid_id.html") return render_template("project.html", title = project['project_name'], project = project)
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 addit(): """The "modify/add" page. Lets the admin modify an existing project, or add a new one""" db = data.load("data.json") projectdb = data.load('empty_project.json') project = projectdb[0] is_logged_in = False user = "" passwd = "" if flask.request.method == 'POST': user = flask.request.form['user_name'] passwd = flask.request.form['passwd'] edit = flask.request.form['edit'] try: for key in project.keys(): if key == 'project_no' and not edit.isdigit(): project[key] = flask.request.form[key] elif key == 'group_size' or key == 'project_no': project[key] = int(flask.request.form[key]) elif key == 'techniques_used': project[key] = [s.strip("' ") for s in flask.request.form[key][1:-1].split(',')] else: project[key] = flask.request.form[key] if not edit.isdigit(): db = data.add_project(db,'data.json',project) else: db = data.edit_project(db,'data.json',int(flask.request.form['project_no']),project) except: logging.info('Error when trying to add or edit post in db') if user == 'admin' and passwd == 'h': is_logged_in = True if edit.isdigit() and is_logged_in: project = data.get_project(db,int(edit)) template_file = "addit.jinja" template = env.get_template( template_file ) templateVars = { 'db':db, 'is_logged_in': is_logged_in, 'user_name': user, 'passwd': passwd, 'project': project } return template.render( templateVars )
def project(id): ''' Function that renders a single project based of the project id given as parameter. Parameter: id (int):The project id Returns: Render the project-page ''' #global db db = load_json() # uses the get_project() function from the API that return a project where the project_id matches the id given as a parameter found_project = data.get_project(db, id) # if the project couldn't be found then render a HTML page containing an error message notifying the user about the error. if found_project is None: return render_template('404.html'), 404 return render_template("project.html", project=found_project)
def project(projectID): """The "project" page. Displays a single project from a database by a given ID""" status = 0 db = data.load('data.json') if db == None: status = 1 else: if projectID.isdigit(): projectID = int(projectID) p = data.get_project(db, projectID) if p == None: status = 2 template_file = "project.jinja" template = env.get_template( template_file ) if status == 0: templateVars = { "status": status, "project": p, "style": flask.url_for('static',filename='style/style.css') } else: templateVars = { "status": status } return template.render( templateVars )
def project(id): """ Renders project.html based on the <id>-variable """ #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 get_project() in the data layer and store the project in the variable project project = data.get_project(db, id) #If None was returned by get_project(): #No project with the specified ID exists, ergo a nonexistent page has been visited, ergo abort with a 404 if project is None: abort(404) else: #adding a counter to the project-page. counter = open("doc/counter.log", "r+") #opens counter.log count = 1 pid = str("project ") + str(project['project_id']) + "\n" for line in counter: if pid in line: count += 1 project['counter'] = count counter.write(pid) counter.close() #Render project.html with: #project --> used to display information about the project return render_template('project.html', project=project)
def test_get_project(self): self.assertEqual(data.get_project(self.loaded_data, 1)['project_no'], 1) self.assertEqual(data.get_project(self.loaded_data, 2)['project_no'], 2) self.assertEqual(data.get_project(self.loaded_data, 3)['project_no'], 3) self.assertEqual(data.get_project(self.loaded_data, 4)['project_no'], 4) self.assertEqual(data.get_project(self.loaded_data, 42), None)
def get_project_id(project_id): projectlist = data.load("data.json") retrivedproject = data.get_project(projectlist, project_id) return render_template('project.html', project=retrivedproject)
def project(id): db = data.load("data.json") return render_template("project.html", data=data.get_project(db, int(id)))
def project(pid): db=load() project=get_project(db, pid) return render_template('project.html',project=project)
def project(id): db = data.load("data.json") if data.get_project(db, int(id)) == None: return render_template("not_found.html", data=id) else: return render_template("project.html", data=data.get_project(db, int(id)))