From 3f018733cca2594d2da0bf22605bd0bc4495fb30 Mon Sep 17 00:00:00 2001 From: Burathar Date: Sun, 7 Mar 2021 20:00:34 +0100 Subject: [PATCH] add project overview --- biscd/biscd/models/project.py | 24 +++++++++++++------- biscd/biscd/routes.py | 14 +++++++++--- biscd/biscd/templates/index.html | 4 ++-- biscd/biscd/templates/project.html | 29 ++++++++++++++++++++++++ installation-files/projects_example.yaml | 6 +++-- 5 files changed, 62 insertions(+), 15 deletions(-) create mode 100644 biscd/biscd/templates/project.html diff --git a/biscd/biscd/models/project.py b/biscd/biscd/models/project.py index a57fed2..492d494 100644 --- a/biscd/biscd/models/project.py +++ b/biscd/biscd/models/project.py @@ -7,15 +7,15 @@ class Project: storage = {} - def __init__(self, name): + def __init__(self, name, branche='master'): self.name = name - self.branche = 'master' + self.branche = branche @property def config_dict(self): - dictionary = self.__dict__.copy() - dictionary.pop('name') - return {self.name: dictionary} + project_dict = self.__dict__.copy() + project_dict.pop('name') + return {self.name: project_dict} def save(self): projects = self._get_projects_from_file() @@ -28,10 +28,18 @@ class Project: @classmethod def get(cls, name): - project = cls._get_projects_from_file().get(name) - if project is None: + project_dict = next(project for project in cls._get_projects_from_file() if [*project][0] == name) + if project_dict is None: return None - return cls(project.get('name')) + project_name = [*project_dict][0] + project_dict = project_dict.get(project_name) + + project_dict['name'] = project_name + + project = cls('placeholder') + project.__dict__ = project_dict + return project + @classmethod def list(cls): diff --git a/biscd/biscd/routes.py b/biscd/biscd/routes.py index ad42b3b..eb37f6b 100644 --- a/biscd/biscd/routes.py +++ b/biscd/biscd/routes.py @@ -1,6 +1,6 @@ -from flask import render_template, flash +from flask import render_template, flash, abort from biscd import app -from .models.project import Project +from .models import Project from .froms import NewProjectForm @app.route('/', methods=['GET', 'POST']) @@ -12,4 +12,12 @@ def index(): project.save() flash('You added a project!') project_names = Project.list() - return render_template('index.html', form=form, projects=project_names) + return render_template('index.html', form=form, project_names=project_names) + +@app.route('/project/', methods=['GET', 'POST']) +def project_dashboard(project_name): + print(project_name) + project = Project.get(project_name) + if project is None: + abort(404) + return render_template('project.html', project=project) diff --git a/biscd/biscd/templates/index.html b/biscd/biscd/templates/index.html index f9596b3..4eb5a61 100644 --- a/biscd/biscd/templates/index.html +++ b/biscd/biscd/templates/index.html @@ -6,9 +6,9 @@
- {% for project in projects %} + {% for project_name in project_names %} - + {% endfor %} diff --git a/biscd/biscd/templates/project.html b/biscd/biscd/templates/project.html new file mode 100644 index 0000000..23159e5 --- /dev/null +++ b/biscd/biscd/templates/project.html @@ -0,0 +1,29 @@ +{% extends "base.html" %} +{% import 'bootstrap/wtf.html' as wtf %} + +{% block app_content %} +

{{ project.name }}

+
+
{{ project }}{{ project_name }}
+ + + + + + + + + + + + + + + + + + +
BranchGit RepoRequirements fileTestsUrl
{{ project.branch }}{{ project.git_repo }}{{ project.requirements_file }}{{ project.tests }}{{ project.url }}
+
+ +{% endblock %} diff --git a/installation-files/projects_example.yaml b/installation-files/projects_example.yaml index 3089692..d1bae11 100644 --- a/installation-files/projects_example.yaml +++ b/installation-files/projects_example.yaml @@ -2,14 +2,16 @@ projects: - The Hunt: branch: master git_repo: https://git.sciuro.org/Burathar/The-Hunt - requirements-file: requirements.txt + requirements_file: requirements.txt secret: thisissecret tests: tests.py url: thehunt - Foo: branch: master git_repo: https://git.sciuro.org/Burathar/The-Hunt - requirements-file: requirements.txt + requirements_file: requirements.txt secret: thisissecret tests: tests.py url: bar +- Test: + branche: master