Beispiel #1
0
 def update(self, project):
     form = EditProjectForm(csrf_enabled=False)
     if form.validate():
         form.update(project)
         db.session.commit()
         return 200, "UPDATED"
     return 400, form.errors
Beispiel #2
0
def edit_blog(id):
    form = EditProjectForm()
    if request.method == 'GET':
        project = get_project(id)  # type: Projects
        if project:
            form.name.data = project.name
            form.short_description.data = project.short_description
            form.full_description.data = project.full_description
            form.collaborators.data = 'Only owner now'
            form.image_field.data = project.image_path
        else:
            abort(404)
    if form.validate_on_submit():
        sesion = db_session.create_session()
        project = sesion.query(Projects).get(id)  # type: Projects
        if project:
            project.name = form.name.data
            project.short_description = form.short_description.data
            project.full_description = form.full_description.data
            project.edit_date = datetime.datetime.now()
            last_id = sesion.query(func.max(Projects.id)).one()
            image = request.files.get('image_field')
            if image and image.filename.rsplit('.')[1] in [
                    'png', 'jpg', 'jpeg'
            ]:
                res = last_id[0]
                if not res:
                    res = 1
                filename = f'{current_user.id}_{res + 1}.jpg'
                image.save(
                    os.path.join(app.config['UPLOAD_FOLDER'],
                                 os.path.join('project_imgs', filename)))
                project.image_path = url_for(
                    'static',
                    filename=
                    f'imgs/project_imgs/{current_user.id}_{res + 1}.jpg')
            else:
                project.image_path = project.image_path
                # project.image_path = url_for('static',
                #                              filename='imgs/project_imgs/no_project_image.jpg')

            sesion.commit()
            print('commited editions')
            # subprocess.call(f'python3 analyze_description.py {last_id} --editing', shell=True)
            return redirect(f'/project/show/{id}')
        else:
            abort(404)
    return render_template('edit_project.html',
                           title='Edit project',
                           form=form)
Beispiel #3
0
def edit_project():
    form = EditProjectForm()
    if request.method == "POST":
        if form.validate():
            project = form.update(g.project)
            db.session.commit()
            session[project.id] = project.password

            return redirect(url_for(".list_bills"))
    else:
        form.name.data = g.project.name
        form.password.data = g.project.password
        form.contact_email.data = g.project.contact_email

    return render_template("edit_project.html", form=form)
def get_edit_project_form(project_dict):
    form = EditProjectForm()
    drones = next(os.walk(os.path.join(base_dir, 'drones')))[2]
    drones = [x for x in drones if x.endswith('.txt')]
    form.edit_drone.choices = [(d, d[:-4]) for d in drones]
    if form.validate_on_submit():
        project_before = form.edit_project_before.data
        description = form.edit_description.data
        project_title = form.edit_name.data
        drone = form.edit_drone.data
        logger.debug(
            f'Editing project {project_before} with new name {project_title}')
        if project_title in project_dict and not project_title == project_before:
            flask.flash('A project with that name already exist!')
        else:
            project_dict.pop(project_before, None)
            shutil.copyfile(
                os.path.join(base_dir, 'drones', drone[:-4] + '.cam.npz'),
                os.path.join(base_dir, 'projects', project_title,
                             'drone.cam.npz'))
            os.rename(os.path.join(base_dir, 'projects', project_before),
                      os.path.join(base_dir, 'projects', project_title))
            with open(
                    os.path.join(base_dir, 'projects', project_title,
                                 'description.txt'), 'w') as file:
                file.write(description)
            last_updated = get_last_updated_time_as_string(0)
            project = project_tuple(project_title, description, last_updated)
            project_dict.update({project_title: project})
            if form.edit_log_file.data:
                video_info_files = glob.glob(
                    os.path.join(base_dir, 'projects', project_title, '*.txt'))
                for video_info_file in video_info_files:
                    if video_info_file.rsplit(os.sep)[-1] != 'description.txt':
                        os.remove(video_info_file)
                log_file = os.path.join(base_dir, 'projects', project_title,
                                        'drone_log.csv')
                form.edit_log_file.data.save(log_file)
    return form
Beispiel #5
0
def get_edit_project_form():
    form = EditProjectForm()
    drones = Drone.query.all()
    form.edit_drone.choices = [(x.id, x.name) for x in drones]
    projects = Project.query.all()
    if form.validate_on_submit():
        project_id = form.edit_project_id.data
        project_before = form.edit_project_before.data
        project_title = form.edit_name.data
        description = form.edit_description.data
        drone_id = form.edit_drone.data
        logger.debug(
            f'Editing project {project_before} with new name {project_title}')
        if project_title in projects and not project_title == project_before:
            flask.flash('A project with that name already exist!')
        else:
            project = Project.query.get_or_404(project_id)
            project.name = project_title
            project.description = description
            project.drone_id = drone_id
            if form.edit_log_file.data:
                remove_file(project.log_file)
                log_error = None
                log_filename = get_random_filename(
                    form.edit_log_file.data.filename)
                log_file = os.path.join(data_dir, log_filename)
                form.edit_log_file.data.save(log_file)
                success = drone_log.test_log(log_file)
                if success:
                    project.log_file = log_file
                else:
                    remove_file(log_file)
                    project.log_file = None
                    log_error = 'Error interpreting the drone log file. Try and upload the log file again.'
                project.log_error = log_error
            db.session.commit()
    return form
Beispiel #6
0
def edit_project():
    project_name=request.args.get('project_name',None)
    if project_name == None or project_name == '':
        flash('No project name specified','warning')
        return redirect(url_for('main.index'))
    
    project= ProjectMap.query.filter_by(project_name=project_name).all()
    if len(project) == 0 or project == None:
        flash('No project named %s' % project_name,'error')
        return redirect(url_for('main.index'))
    project_form=EditProjectForm()
    search_form = SearchForm_v2(csrf_enabled=True)
    drop_list=libs.init_droplist(project_name)
    search_form.set_choices(drop_list)
    
    if project_form.validate_on_submit():
        
        if project_form.submit.data:    
            try:
                project[0].project_id =  project_form.project_id.data
                project[0].project_name = project_form.project_name.data
                project[0].field_1 = project_form.field_1.data 
                project[0].field_2 = project_form.field_2.data 
                project[0].field_3 = project_form.field_3.data 
                project[0].field_4 = project_form.field_4.data 
                project[0].field_5 = project_form.field_5.data 
                project[0].field_6 = project_form.field_6.data 
                project[0].field_7 = project_form.field_7.data 
                project[0].field_8 = project_form.field_8.data 
                project[0].field_9 = project_form.field_9.data 
                project[0].field_10 = project_form.field_10.data 
                project[0].field_11 = project_form.field_11.data 
                project[0].field_12 = project_form.field_12.data 
                project[0].field_13 = project_form.field_13.data 
                project[0].field_14 = project_form.field_14.data 
                project[0].field_15 = project_form.field_15.data 
                project[0].field_16 = project_form.field_16.data 
                project[0].field_17 = project_form.field_17.data 
                project[0].field_18 = project_form.field_18.data 
                project[0].field_19 = project_form.field_19.data 
                project[0].field_20 = project_form.field_20.data 
                report_db.session.add(project[0])
                report_db.session.commit()
                flash('Update successfully!','info')
                return redirect(url_for('main.edit_project',project_name=project_name))
            except Exception as err:
                flash(err,'error')
        elif project_form.delete.data:
            try:
                report_db.session.delete(project[0])
                report_db.session.commit()
                flash('Deleted successfully!','info')
                return redirect(url_for('main.home'))
            except Exception as err:
                flash(err,'error')
    project= ProjectMap.query.filter_by(project_name=project_name).all()
    project_form.project_id.data = project[0].project_id
    project_form.project_name.data = project[0].project_name
    project_form.field_1.data = project[0].field_1
    project_form.field_2.data = project[0].field_2
    project_form.field_3.data = project[0].field_3
    project_form.field_4.data = project[0].field_4
    project_form.field_5.data = project[0].field_5
    project_form.field_6.data = project[0].field_6
    project_form.field_7.data = project[0].field_7
    project_form.field_8.data = project[0].field_8
    project_form.field_9.data = project[0].field_9
    project_form.field_10.data = project[0].field_10
    project_form.field_11.data = project[0].field_11
    project_form.field_12.data = project[0].field_12
    project_form.field_13.data = project[0].field_13
    project_form.field_14.data = project[0].field_14
    project_form.field_15.data = project[0].field_15
    project_form.field_16.data = project[0].field_16
    project_form.field_17.data = project[0].field_17
    project_form.field_18.data = project[0].field_18
    project_form.field_19.data = project[0].field_19
    project_form.field_20.data = project[0].field_20
    projects= ProjectMap.query.all()
    return render_template('edit_project.html',form=search_form,project_form=project_form,project_name=project_name,projects=projects)