Example #1
0
def update_project(project_id):
    project = Project.query.get_or_404(project_id)
    if current_user.is_authenticated:
        form = AddProjectForm()
        if form.validate_on_submit():
            if form.header_image.data:
                header_image = save_picture(form.header_image.data)
                project.header_image = header_image
            if form.project_images.data:
                for image in form.project_images.data:
                    if image:
                        image = save_picture(image)
                        project.project_images.append(ImageSet(image=image))
                        time.sleep(2)
            project.title = form.title.data
            project.description = form.description.data
            project.show_in_home = form.show_in_home.data
            db.session.commit()
            flash(_('Project has been updated'), 'success')
            return redirect(url_for('project', project_id=project.id))
        elif request.method == 'GET':
            form.title.data = project.title
            form.description.data = project.description
            form.show_in_home.data = project.show_in_home
        header_image = url_for('static',
                               filename="images/project_images/" +
                               project.header_image)

    return render_template('update_project.html',
                           title=_("Update Project"),
                           project=project,
                           form=form)
Example #2
0
def index():
    formUpdate = UpdateProjectForm(prefix="formUpdate")
    d = Projects.query.order_by(Projects.id).all()
    data = []
    for p in d:
        t = p.read.split(" ")
        if len(data) == 0:
            data.append(p)
        elif str(session['author_id']) in t:
            data.append(p)
        elif t.count("0") == len(t):
            data.append(p)
    form = AddProjectForm(prefix='form')
    formAdd = AddUserToProjectForm(prefix='formAdd')
    if form.validate_on_submit() and form.submit.data:
        a.createProject(session['author_id'], session['session_id'], form.name.data, form.description.data)
    if formUpdate.validate_on_submit() and formUpdate.submit.data:
        p = Projects.query.filter_by(id = int(formUpdate.idProject.data)).all()
        p = p[0]
        read = filter (lambda a: a != 0, [int(s) for s in p.read.split(" ")])
        a.updateProject(session['author_id'], session['session_id'], int(formUpdate.idProject.data), formUpdate.name.data, formUpdate.description.data, read)
    if formAdd.validate_on_submit() and formAdd.submit.data:
        p = Projects.query.filter_by(id = int(formAdd.idProject.data)).all()
        p = p[0]
        read = filter (lambda a: a != 0, [int(s) for s in p.read.split(" ")])
        a.getUserByName(session['author_id'], session['session_id'], formAdd.name.data)
        time.sleep(1)
        u = Users.query.filter_by(name = formAdd.name.data).all()
        if not u:
            flash("User not found or the server don't send the user information!")
        else:
            u = u[0]
            read.append(u.id)
            a.updateProject(session['author_id'], session['session_id'], int(formAdd.idProject.data), p.name, p.content, read)
    return render_template('index.html', data = data, form = form, formUpdate = formUpdate, formAdd = formAdd)
Example #3
0
def add_project():
    form = AddProjectForm()
    if form.validate_on_submit():
        if form.header_image.data:
            header_image = save_picture(form.header_image.data)
        else:
            header_image = 'default_header.png'
        project = Project(title=form.title.data,
                          description=form.description.data,
                          header_image=header_image,
                          show_in_home=form.show_in_home.data,
                          user_id=current_user.id)
        if form.project_images.data:
            for image in form.project_images.data:
                if image:
                    image = save_picture(image)
                    project.project_images.append(ImageSet(image=image))
                    time.sleep(2)
        db.session.add(project)
        db.session.commit()
        flash(_('Project Successfully Added'), 'success')
        return render_template('add_project.html',
                               title=_('Add Project'),
                               form=form)
    return render_template('add_project.html',
                           title=_('Add Project'),
                           form=form)