Browse Source

Add project functionality

master
Burathar 4 years ago
parent
commit
335686ff8b
  1. 1
      biscd/biscd/models/__init__.py
  2. 13
      biscd/biscd/models/project.py
  3. 6
      biscd/biscd/models/utils.py
  4. 1
      biscd/biscd/models/yaml_serializable.py
  5. 26
      biscd/biscd/routes.py
  6. 13
      biscd/biscd/templates/base.html
  7. 11
      biscd/biscd/templates/index.html
  8. 2
      biscd/biscd/templates/project.html
  9. 15
      biscd/biscd/templates/project_add.html
  10. 27
      biscd/biscd/templates/projects.html

1
biscd/biscd/models/__init__.py

@ -1,3 +1,4 @@ @@ -1,3 +1,4 @@
from .project import Project
from .user import User
from .yaml_serializable import YamlSerializable
from .utils import *

13
biscd/biscd/models/project.py

@ -8,6 +8,7 @@ from flask import current_app as app @@ -8,6 +8,7 @@ from flask import current_app as app
from biscd import config
from .yaml_serializable import YamlSerializable
from .utils import to_bool
class Project(YamlSerializable):
@ -27,6 +28,7 @@ class Project(YamlSerializable): @@ -27,6 +28,7 @@ class Project(YamlSerializable):
self.branch = branch
self.relative_production_path = None
self.git_repo = None
self.access = {'public': False, 'owners': []}
def __eq__(self, other):
"""Overrides the default implementation"""
@ -101,3 +103,14 @@ class Project(YamlSerializable): @@ -101,3 +103,14 @@ class Project(YamlSerializable):
full_path.mkdir(parents=True)
self.relative_production_path = str(full_path.relative_to(prod_path_dir))
self.save()
def user_access(self, user):
# pylint: disable=no-member
if not hasattr(self, 'access') or self.access is None:
return None
if hasattr(user,('name')) and user.name in self.access.get('owners', []):
return 'Owner'
public = to_bool(self.access.get('public', False))
if public:
return 'Public'
return None

6
biscd/biscd/models/utils.py

@ -0,0 +1,6 @@ @@ -0,0 +1,6 @@
def to_bool(value):
if isinstance(value, bool):
return value
if isinstance(value, int):
return value >= 1
return value.lower() in ['true', '1', 't', 'y', 'yes']

1
biscd/biscd/models/yaml_serializable.py

@ -1,6 +1,7 @@ @@ -1,6 +1,7 @@
from abc import ABCMeta, abstractmethod
from flask import abort
import yaml
import inspect
from .recursive_property import RecursiveProperty

26
biscd/biscd/routes.py

@ -4,7 +4,7 @@ from werkzeug.urls import url_parse @@ -4,7 +4,7 @@ from werkzeug.urls import url_parse
from biscd import app
from .utils import flash_result
from .models import Project, User
from .froms import NewProjectForm, LoginForm, RegistrationForm, EmptyForm
from .froms import NewProjectForm, LoginForm, RegistrationForm
@app.route('/', methods=['GET', 'POST'])
@app.route('/index', methods=['GET', 'POST'])
@ -47,16 +47,34 @@ def register(): @@ -47,16 +47,34 @@ def register():
user = User(name=form.username.data, email=form.email.data)
user.set_password(form.password.data)
user.save()
flash('Congratulations, you are now a registered user!', 'info')
flash('Congratulations, you are now a registered user!', 'success')
return redirect(url_for('login'))
return render_template('register.html', title='Register', form=form)
@app.route('/project/public', methods=['GET'])
def public_projects():
projects = Project.get(access__public = True)
return render_template('projects.html', projects=projects)
@app.route('/project/<project_name>', methods=['GET'])
@app.route('/project/add', methods=['GET', 'POST'])
@login_required
def project_add():
form = NewProjectForm()
if form.validate_on_submit():
project = Project(name=form.projectname.data)
project.access['owners'] = [current_user.name]
project.save()
flash('Your project is created!', 'success')
return redirect(url_for('project_dashboard', project_name=project.name))
return render_template('project_add.html', form=form)
@app.route('/project/<project_name>', methods=['GET'])
def project_dashboard(project_name):
project = Project.first_or_404(name=project_name)
return render_template('project.html', project=project)
access = project.user_access(current_user)
if access is None:
abort(404)
return render_template('project.html', project=project, owner=(access == 'Owner'))
@app.route('/project/<project_name>/update', methods=['GET'])
@login_required

13
biscd/biscd/templates/base.html

@ -23,9 +23,18 @@ @@ -23,9 +23,18 @@
<div class="navbar-collapse collapse" id="navbarResponsive">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" href="{{ url_for('index') }}">Home
</a>
<a class="nav-link" href="{{ url_for('index') }}">Home</a>
</li>
{% if current_user.is_anonymous %}
<li class="nav-item">
<a class="nav-link" href="{{ url_for('public_projects') }}">Projects</a>
</li>
{% endif%}
{% if current_user.is_authenticated %}
<li class="nav-item">
<a class="nav-link" href="{{ url_for('project_add') }}">Add Project</a>
</li>
{% endif %}
<!--
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">Dropdown</a>

11
biscd/biscd/templates/index.html

@ -14,11 +14,20 @@ @@ -14,11 +14,20 @@
<h2 id="typography">Your Projects</h2>
</div>
<div class="table-responsive">
<table class="table">
<table class="table table-hover">
<thead>
<tr>
<th scope="col">Name</th>
<th scope="col">Access</th>
<th scope="col">State</th>
</tr>
</thead>
<tbody>
{% for project in projects %}
<tr>
<td><a href="{{ url_for('project_dashboard', project_name = project.name) }}">{{ project.name }}</a></td>
<td>{{ project.user_access(current_user) or 'None' }}</td>
<td>{{ project.state or '-' }}</td>
</tr>
{% endfor %}
</tbody>

2
biscd/biscd/templates/project.html

@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
{% block app_content %}
<h1>{{ project.name }}</h1>
{% if owner %}
<row>
<a href="{{ url_for('project_update', project_name=project.name) }}">
<button class="btn btn-success">Update Repo</button>
@ -12,6 +13,7 @@ @@ -12,6 +13,7 @@
</a>
<br><br>
</row>
{% endif %}
<div class="table-responsive col-lg-6">
<table class="table table-hover">

15
biscd/biscd/templates/project_add.html

@ -0,0 +1,15 @@ @@ -0,0 +1,15 @@
{% extends "base.html" %}
{% import 'bootstrap/wtf.html' as wtf %}
{% block app_content %}
<div class="row">
<div class="col-xs-0 col-md-1"></div>
<div class="col-xs-8 col-md-4">
<h1>Add Project</h1>
<br>
{{ wtf.quick_form(form, button_map={'submit': 'primary'}) }}
</div>
<div class="col-xs-0 col-md-7"></div>
</div>
{% endblock %}

27
biscd/biscd/templates/projects.html

@ -0,0 +1,27 @@ @@ -0,0 +1,27 @@
{% extends "base.html" %}
{% block app_content %}
<div class="col-lg-12">
<h2 id="typography">Public Projects</h2>
</div>
<div class="table-responsive">
<table class="table table-hover">
<thead>
<tr>
<th scope="col">Name</th>
<th scope="col">Access</th>
<th scope="col">State</th>
</tr>
</thead>
<tbody>
{% for project in projects %}
<tr>
<td><a href="{{ url_for('project_dashboard', project_name = project.name) }}">{{ project.name }}</a></td>
<td>{{ project.user_access(current_user) or 'None' }}</td>
<td>{{ project.state or '-' }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endblock %}
Loading…
Cancel
Save