From e2c4151b9e177128a83ea0d1bb3949f39e0964d4 Mon Sep 17 00:00:00 2001 From: Burathar Date: Sat, 27 Mar 2021 23:07:11 +0100 Subject: [PATCH] Show projects for user --- biscd/biscd/models/project.py | 13 +++++++++++++ biscd/biscd/models/user.py | 2 +- biscd/biscd/routes.py | 8 ++++---- biscd/biscd/templates/index.html | 6 +++--- 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/biscd/biscd/models/project.py b/biscd/biscd/models/project.py index 41acf7d..a9b95e1 100644 --- a/biscd/biscd/models/project.py +++ b/biscd/biscd/models/project.py @@ -22,13 +22,26 @@ class Project(YamlSerializable): return 'projects' def __init__(self, name=None, branch='master'): + super().__init__() self.name = name self.branch = branch self.relative_production_path = None self.git_repo = None + def __eq__(self, other): + """Overrides the default implementation""" + if isinstance(other, Project): + if self.name == other.name: + return True + return False + + def __hash__(self): + return hash(self.name) + @property def absulute_path(self): + if not hasattr(self, 'production_path') or not self.relative_production_path: + return None return Path(config['production_path'].get()) / self.relative_production_path def update(self): diff --git a/biscd/biscd/models/user.py b/biscd/biscd/models/user.py index 7a8697f..df4ea9a 100644 --- a/biscd/biscd/models/user.py +++ b/biscd/biscd/models/user.py @@ -31,7 +31,7 @@ class User(UserMixin, YamlSerializable): @property def projects(self): - pass #all_projects = Project.get() + return set(Project.get(access__owners = self.name) + Project.get(access__public = True)) @projects.setter def projects(self, projects): diff --git a/biscd/biscd/routes.py b/biscd/biscd/routes.py index 893e7c6..c39e8f4 100644 --- a/biscd/biscd/routes.py +++ b/biscd/biscd/routes.py @@ -10,10 +10,10 @@ from .froms import NewProjectForm, LoginForm, RegistrationForm, EmptyForm @app.route('/index', methods=['GET', 'POST']) def index(): if current_user.is_authenticated: - project_names = Project.list_names() + projects = current_user.projects else: - project_names = None - return render_template('index.html', project_names=project_names) + projects = None + return render_template('index.html', projects=projects) @app.route('/login', methods=['GET', 'POST']) def login(): @@ -72,4 +72,4 @@ def project_delete_files(project_name): project = Project.first_or_404(name=project_name) result = project.delete_files() flash_result(result) - return redirect(url_for('project_dashboard', project_name=project.name)) \ No newline at end of file + return redirect(url_for('project_dashboard', project_name=project.name)) diff --git a/biscd/biscd/templates/index.html b/biscd/biscd/templates/index.html index 7addd14..b521914 100644 --- a/biscd/biscd/templates/index.html +++ b/biscd/biscd/templates/index.html @@ -9,16 +9,16 @@ - {% if project_names %} + {% if projects %}

Your Projects

- {% for project_name in project_names %} + {% for project in projects %} - + {% endfor %}
{{ project_name }}{{ project.name }}