Browse Source

Add project update

master
Burathar 4 years ago
parent
commit
135f199c03
  1. 4
      biscd/biscd/errors.py
  2. 16
      biscd/biscd/froms.py
  3. 4
      biscd/biscd/models/project.py
  4. 34
      biscd/biscd/routes.py
  5. 3
      biscd/biscd/templates/400.html
  6. 6
      biscd/biscd/templates/401.html
  7. 3
      biscd/biscd/templates/project.html
  8. 15
      biscd/biscd/templates/project_add.html
  9. 20
      biscd/biscd/templates/project_settings.html
  10. 21
      installation-files/projects_example.yaml

4
biscd/biscd/errors.py

@ -5,6 +5,10 @@ from biscd import app, utils @@ -5,6 +5,10 @@ from biscd import app, utils
def bad_request(error):
return render_template('400.html', title='400', error=error), 400
@app.errorhandler(401)
def unauthorized_error(error):
return render_template('401.html', title='401'), 401
@app.errorhandler(404)
def not_found_error(error):
return render_template('404.html', title='404'), 404

16
biscd/biscd/froms.py

@ -1,6 +1,7 @@ @@ -1,6 +1,7 @@
from flask_wtf import FlaskForm
from wtforms import SubmitField, StringField, PasswordField, BooleanField
from wtforms.validators import DataRequired, Email, EqualTo, Length, ValidationError
from git import cmd as git_cmd, GitCommandError
from .models import User, Project
@ -28,14 +29,27 @@ class RegistrationForm(FlaskForm): @@ -28,14 +29,27 @@ class RegistrationForm(FlaskForm):
if any(user):
raise ValidationError('Please use a different email adress.')
class NewProjectForm(FlaskForm):
class ProjectForm(FlaskForm):
projectname = StringField('Project Name', validators=[DataRequired()])
git_repo = StringField('Git Repo')
public = BooleanField('Public Project')
submit = SubmitField('Add Project')
old_name = ''
def validate_projectname(self, projectname):
if projectname.data == self.old_name:
return
project = Project.get(name=projectname.data)
if any(project):
raise ValidationError('Please use a different projectname.')
def validate_git_repo(self, git_repo):
if not git_repo.data:
return
try:
git_cmd.Git().ls_remote(git_repo.data)
except GitCommandError as gce:
raise ValidationError('Please enter a valid git repository url') from gce
class EmptyForm(FlaskForm):
submit = SubmitField('Submit')

4
biscd/biscd/models/project.py

@ -22,12 +22,12 @@ class Project(YamlSerializable): @@ -22,12 +22,12 @@ class Project(YamlSerializable):
def _yaml_object_name(cls):
return 'projects'
def __init__(self, name=None, branch='master'):
def __init__(self, name=None, branch='master', git_repo = None):
super().__init__()
self.name = name
self.branch = branch
self.relative_production_path = None
self.git_repo = None
self.git_repo = git_repo
self.access = {'public': False, 'owners': []}
def __eq__(self, other):

34
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
from .froms import ProjectForm, LoginForm, RegistrationForm
@app.route('/', methods=['GET', 'POST'])
@app.route('/index', methods=['GET', 'POST'])
@ -59,14 +59,40 @@ def public_projects(): @@ -59,14 +59,40 @@ def public_projects():
@app.route('/project/add', methods=['GET', 'POST'])
@login_required
def project_add():
form = NewProjectForm()
project = Project(name='')
form = ProjectForm()
if form.validate_on_submit():
project = Project(name=form.projectname.data)
project = Project(name=form.projectname.data, git_repo=form.git_repo.data)
project.access['public'] = form.public.data
if project.access['owners'] == []:
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)
return render_template('project_settings.html', form=form, project=project)
@app.route('/project/<project_name>/settings', methods=['GET', 'POST'])
@login_required
def project_change_settings(project_name):
project = Project.first_or_404(name=project_name)
if project.user_access(current_user) != 'Owner':
abort(401)
form = ProjectForm()
form.old_name = project.name
if request.method == 'GET':
# pylint: disable=no-member
form.process()
form.public.data = project.access.get('public', False)
if form.validate_on_submit():
project = Project(name=form.projectname.data, git_repo=form.git_repo.data)
project.access['public'] = form.public.data
if project.access['owners'] == []:
project.access['owners'] = [current_user.name]
project.save()
flash(f"{project.name} was updated!", 'success')
return redirect(url_for('project_dashboard', project_name=project.name))
return render_template('project_settings.html', form=form, project=project)
@app.route('/project/<project_name>', methods=['GET'])
def project_dashboard(project_name):

3
biscd/biscd/templates/400.html

@ -1,10 +1,9 @@ @@ -1,10 +1,9 @@
{% extends "base.html" %}
{% block app_content %}
<h1>404 Page Not Found</h1>
<h1>400 Bad Request</h1>
<p><a href="{{ url_for('index') }}">Back</a></p>
<h1>400 Bad Request</h1>
<h2>Error Message:</h2>
{{ error }}
{% endblock %}

6
biscd/biscd/templates/401.html

@ -0,0 +1,6 @@ @@ -0,0 +1,6 @@
{% extends "base.html" %}
{% block app_content %}
<h1>401 Unauthorized</h1>
<p><a href="{{ url_for('index') }}">Back</a></p>
{% endblock %}

3
biscd/biscd/templates/project.html

@ -5,6 +5,9 @@ @@ -5,6 +5,9 @@
<h1>{{ project.name }}</h1>
{% if owner %}
<row>
<a href="{{ url_for('project_change_settings', project_name=project.name) }}">
<button class="btn btn-primary">Change Settings</button>
</a>
<a href="{{ url_for('project_update', project_name=project.name) }}">
<button class="btn btn-success">Update Repo</button>
</a>

15
biscd/biscd/templates/project_add.html

@ -1,15 +0,0 @@ @@ -1,15 +0,0 @@
{% 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 %}

20
biscd/biscd/templates/project_settings.html

@ -0,0 +1,20 @@ @@ -0,0 +1,20 @@
{% 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">
<div class="row">
<form action="" method="post" class="form" role="form">
{{ form.hidden_tag() }}
{{ wtf.form_field(form.projectname, class='form-control', value=project.name) }}
{{ wtf.form_field(form.git_repo, class='form-control', value=(project.git_repo or '')) }}
{{ wtf.form_field(form.public, class='form-control') }}
{{ wtf.form_field(form.submit, class='btn btn-primary', value="Update") }}
</form>
</div>
</div>
</div>
{% endblock %}

21
installation-files/projects_example.yaml

@ -1,18 +1,31 @@ @@ -1,18 +1,31 @@
projects:
- The Hunt:
access:
owners:
- Carl
public: true
branch: master
git_repo: https://git.sciuro.org/Burathar/The-Hunt
- Foo:
branch: master
git_repo: https://git.sciuro.org/Burathar/The-Hunt
relative_production_path: Foo045878
requirements_file: requirements.txt
secret: thisissecret
tests: tests.py
- Bar:
access:
public: true
owners:
- Carl
- Foo:
public: false
branch: master
git_repo: https://git.sciuro.org/Burathar/The-Hunt
relative_production_path: Foo045878
requirements_file: requirements.txt
secret: thisissecret
tests: tests.py
- biscd:
access:
owners:
- Carl
public: false
branch: master
git_repo: git@git.sciuro.org:Burathar/biscd.git
Loading…
Cancel
Save