Browse Source

Show projects for user

master
Burathar 4 years ago
parent
commit
e2c4151b9e
  1. 13
      biscd/biscd/models/project.py
  2. 2
      biscd/biscd/models/user.py
  3. 8
      biscd/biscd/routes.py
  4. 6
      biscd/biscd/templates/index.html

13
biscd/biscd/models/project.py

@ -22,13 +22,26 @@ class Project(YamlSerializable): @@ -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):

2
biscd/biscd/models/user.py

@ -31,7 +31,7 @@ class User(UserMixin, YamlSerializable): @@ -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):

8
biscd/biscd/routes.py

@ -10,10 +10,10 @@ from .froms import NewProjectForm, LoginForm, RegistrationForm, EmptyForm @@ -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): @@ -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))
return redirect(url_for('project_dashboard', project_name=project.name))

6
biscd/biscd/templates/index.html

@ -9,16 +9,16 @@ @@ -9,16 +9,16 @@
</div>
</div>
</div>
{% if project_names %}
{% if projects %}
<div class="col-lg-12">
<h2 id="typography">Your Projects</h2>
</div>
<div class="table-responsive">
<table class="table">
<tbody>
{% for project_name in project_names %}
{% for project in projects %}
<tr>
<td><a href="{{ url_for('project_dashboard', project_name = project_name) }}">{{ project_name }}</a></td>
<td><a href="{{ url_for('project_dashboard', project_name = project.name) }}">{{ project.name }}</a></td>
</tr>
{% endfor %}
</tbody>

Loading…
Cancel
Save