Ejemplo n.º 1
0
def edit_project(title):
    import __init__, models, forms
    from __init__ import db
    from models import Project
    from forms import ProjectForm

    project = Project.query.filter_by(title=title).first()
    if not project:
        abort(404)
    project_form = ProjectForm(obj=project)

    if request.method == "POST":
        if project_form.validate():
            project_form.populate_obj(project)
            db.session.commit()
            flash("Edit was successful.")
            return redirect(url_for("main._portfolio"))
        else:
            flash("Project editing failed.")

    return render_template("edit_form.html",
                           form=project_form,
                           title="Edit Projects",
                           right=random.choice(rights),
                           is_web=True)
Ejemplo n.º 2
0
def create_project():
    config.reload()
    form = ProjectForm()
    ds_forms = dict([
        (cls.populates, cls()) for cls in DataSourceForm.__subclasses__()])

    form.datasource_type.choices = [
        (cls.populates, cls.name) for cls in DataSourceForm.__subclasses__()]
    form.datasource_type.choices.insert(0, (None, "-- Select Data Source --"))
    new_project = Project()

    if form.validate_on_submit():
        form.populate_obj(new_project)
        ds_form = ds_forms[form.datasource_type.data]

        if ds_form.validate():
            new_project.datasource = \
                getattr(models, form.datasource_type.data)()
            ds_form.populate_obj(new_project.datasource)

            db.session.add(new_project)
            db.session.commit()
            flash("New project successfully created.")
            return redirect(url_for('view_project', id=new_project.id))

    return render_template("project/create.html",
                           form=form, ds_forms=ds_forms, project=new_project)
Ejemplo n.º 3
0
def edit_project(id):
    project = Project.query.get_or_404(id)

    ds_forms = dict([
        (cls.populates, cls()) for cls in DataSourceForm.__subclasses__()])
    for populates, ds_form in ds_forms.items():
        if populates == project.datasource.__class__.__name__:
            ds_forms[populates] = ds_form.__class__(obj=project.datasource)
            current_ds_type = populates

    form = ProjectForm(obj=project, datasource_type=current_ds_type)
    form.datasource_type.choices = [
        (cls.populates, cls.name) for cls in DataSourceForm.__subclasses__()]
    form.datasource_type.choices.insert(0, (None, "-- Select Data Source --"))

    if form.validate_on_submit():
        form.populate_obj(project)
        ds_form = ds_forms[form.datasource_type.data]

        if ds_form.validate():
            project.datasource = getattr(models, form.datasource_type.data)()
            ds_form.populate_obj(project.datasource)

            db.session.add(project)
            db.session.commit()
            flash("Project %s successfully updated." % project.name)
            return redirect(url_for('view_project', id=project.id))

    return render_template("project/edit.html",
                           form=form, ds_forms=ds_forms, project=project)
Ejemplo n.º 4
0
def edit_project(id):
    project = Project.query.get_or_404(id)

    ds_forms = dict([(cls.populates, cls())
                     for cls in DataSourceForm.__subclasses__()])
    for populates, ds_form in ds_forms.items():
        if populates == project.datasource.__class__.__name__:
            ds_forms[populates] = ds_form.__class__(obj=project.datasource)
            current_ds_type = populates

    form = ProjectForm(obj=project, datasource_type=current_ds_type)
    form.datasource_type.choices = [(cls.populates, cls.name)
                                    for cls in DataSourceForm.__subclasses__()]
    form.datasource_type.choices.insert(0, (None, "-- Select Data Source --"))

    if form.validate_on_submit():
        form.populate_obj(project)
        ds_form = ds_forms[form.datasource_type.data]

        if ds_form.validate():
            project.datasource = getattr(models, form.datasource_type.data)()
            ds_form.populate_obj(project.datasource)

            db.session.add(project)
            db.session.commit()
            flash("Project %s successfully updated." % project.name)
            return redirect(url_for('view_project', id=project.id))

    return render_template("project/edit.html",
                           form=form,
                           ds_forms=ds_forms,
                           project=project)
Ejemplo n.º 5
0
def create_project():
    config.reload()
    form = ProjectForm()
    ds_forms = dict([(cls.populates, cls())
                     for cls in DataSourceForm.__subclasses__()])

    form.datasource_type.choices = [(cls.populates, cls.name)
                                    for cls in DataSourceForm.__subclasses__()]
    form.datasource_type.choices.insert(0, (None, "-- Select Data Source --"))
    new_project = Project()

    if form.validate_on_submit():
        form.populate_obj(new_project)
        ds_form = ds_forms[form.datasource_type.data]

        if ds_form.validate():
            new_project.datasource = \
                getattr(models, form.datasource_type.data)()
            ds_form.populate_obj(new_project.datasource)

            db.session.add(new_project)
            db.session.commit()
            flash("New project successfully created.")
            return redirect(url_for('view_project', id=new_project.id))

    return render_template("project/create.html",
                           form=form,
                           ds_forms=ds_forms,
                           project=new_project)
Ejemplo n.º 6
0
def project_new():
    project = Project()
    form = ProjectForm(request.form, project)
    if form.validate_on_submit():
        counter = Counter.objects(id_for="project")[0]
        counter.set_next_id()
        counter.save()
        form.populate_obj(project)
        project.number = counter.number
        project.save()
        return redirect('/projects/')
    return render_template('projects_create.html', project=project, form=form)
Ejemplo n.º 7
0
def project_edit(project_id):
    project = Project.query.filter_by(id=project_id).first_or_404()
    form = ProjectForm(obj=project)

    if request.method == 'POST' and form.validate():
        form.populate_obj(project)
        db.session.commit()

        flash('Project has been updated successfully.', 'success')
        return redirect(url_for('project', project_id=project.id))

    return render_template('project/form.html', form=form, action_url=url_for('project_edit', project_id=project.id))
Ejemplo n.º 8
0
def project_new():
    project = Project()
    form = ProjectForm(request.form, project)
    if form.validate_on_submit():
        counter = Counter.objects(id_for="project")[0]
        counter.set_next_id()
        counter.save()
        form.populate_obj(project)
        project.number = counter.number
        project.save()
        return redirect('/projects/')
    return render_template('projects_create.html',
                           project=project,
                           form=form)
Ejemplo n.º 9
0
def project(id_project=None):
    from forms import ProjectForm
    if id_project != None:
        project = Project.query.get(id_project)
        action = "Save"
    else:
        project = Project()
        action = "Create"
        
    form = ProjectForm(obj=project)
    if form.validate_on_submit():
        form.populate_obj(project)
        project.users.append(current_user)
        db.session.add(project)
        db.session.commit()
        return redirect('/projects')
    
    return render_template('project/form.html', form=form, action=action)