Ejemplo n.º 1
0
    def post(self):
        form = ProjectForm(request.form)

        if form.validate():
            Project.add_project(form.name.data, form.description.data,
                                form.deadline.data)
            flash('success')
            return redirect('/')

        else:
            flash('fail')
            return redirect(url_for('api.new'))
Ejemplo n.º 2
0
def create_project():
    user_id = get_jwt_identity()
    user = User.query.filter_by(user_id=user_id).first_or_404()
    body = request.get_json()
    project = Project(**body)
    user_project = UserProject(user=user,
                               project=project,
                               role=UserProjectRole.ADMIN)
    project.user_project.append(user_project)
    db.session.add(project)
    db.session.commit()
    return jsonify(project.to_dict())
Ejemplo n.º 3
0
def register():
    body = request.get_json()
    errors = register_schema.validate(body)
    if errors:
        return jsonify({'error': errors}), 400
    user = User(**body)
    user.hash_password()
    user.email_verification_token = random_str()

    # Create default project for user
    # INSERT INTO project (name) VALUES (%s)
    # INSERT INTO user (...) VALUES ()
    # INSERT INTO user_project (user_id, project_id, `role`) VALUES (%s, %s, %s)
    project = Project(name='First project')
    user_project = UserProject(user=user, project=project, role=UserProjectRole.ADMIN)
    project.user_project.append(user_project)
    db.session.add(user)
    db.session.commit()
    welcome_email(user)
    return jsonify(user_schema.dump(user)), 201
Ejemplo n.º 4
0
def search_project(project_name):

    result = Project.search(project_name)

    return render_template('search.html', result=result)
Ejemplo n.º 5
0
def view_draft(project_name, headings):

    project = Project.get_by_name(project_name)
    draft = Draft.get_by_id_headings(project.id, headings)

    return render_template('view_draft.html', project=project, draft=draft)
Ejemplo n.º 6
0
def view_project(project_name):

    project = Project.get_by_name(project_name)
    drafts = Draft.get_by_id(project.id)

    return render_template('view.html', project=project, drafts=drafts)
Ejemplo n.º 7
0
 def get(self, project_name):
     data = Project.get_by_name(project_name)
     return render_template(self.html, data=data)