def get_new_project_form(project_dict): form = NewProjectForm() drone_dir = os.path.join(base_dir, 'drones') if not os.path.exists(drone_dir): os.mkdir(drone_dir) drones = next(os.walk(drone_dir))[2] drones = [x for x in drones if x.endswith('.txt')] form.drone.choices = [(d, d[:-4]) for d in drones] if form.validate_on_submit(): project_title = form.name.data logger.debug(f'Creating a new project with name {project_title}') description = form.description.data drone = form.drone.data if project_title in project_dict: flask.flash('A project with that name already exist!') else: os.mkdir(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) shutil.copyfile( os.path.join(base_dir, 'drones', drone[:-4] + '.cam.npz'), os.path.join(base_dir, 'projects', project_title, 'drone.cam.npz')) log_file = os.path.join(base_dir, 'projects', project_title, 'drone_log.csv') form.log_file.data.save(log_file) return flask.redirect( flask.url_for('projects.upload', project=project_title)), form return None, form
def add_project_view(request): context = {'current':'projects'} if request.method == "POST": form = NewProjectForm(data=request.POST) if form.is_valid(): project = form.save(commit=False) project.creator = request.user project.save() project.owners = [request.user] return HttpResponseRedirect(reverse('project_detail_view', args=[project.id])) else: context['form'] = form else: context['form'] = NewProjectForm() return render_response(request, 'project/add_project.html', context)
def new_project(): form = NewProjectForm(request.form) if form.validate_on_submit(): project = { 'name': form.name.data , 'start': form.start_date.data , 'end': form.end_date.data , 'keywords': [k.strip() for k in form.keywords.data.split(',')] , 'owner' : current_user.id } existing = db.projects.find_one({'name':form.name.data, 'owner':current_user.id}) if existing == None: db.projects.insert(project) return redirect(url_for('project', username=current_user.name, project_name=form.name.data)) else: flash('Sorry, that name is already taken.') return render_template('new-project.html', form=form)
def main(): newProjectForm = NewProjectForm() dropbox_users = get_team_members(session['dropbox_mgmt_token']) newProjectForm.user_id.choices = ( [ (u['profile']['team_member_id'], u['profile']['email'] if u['profile']['status']['.tag'] == "active" else "(inactive) " + u['profile']['email']) for u in dropbox_users['members'] ] ) dropbox_groups = get_dropbox_groups(session['dropbox_mgmt_token']) newProjectForm.project_rw_members.choices = [ (g['group_id'], g['group_name']) for g in dropbox_groups['groups']] newProjectForm.project_ro_members.choices = [ (g['group_id'], g['group_name']) for g in dropbox_groups['groups']] if newProjectForm.validate_on_submit(): return complete_sf_create(newProjectForm) return render_template('main.html', db_auth=True, newProjectForm=newProjectForm)
def project_list(request): """ return projects own by the current user. The result list is paginated """ context = {} projects = Project.objects.filter(owner=request.user).order_by("-creation_date") if request.method == "POST": form = NewProjectForm(request.POST, owner=request.user) if form.is_valid(): new_project = form.save(commit=False) new_project.owner = request.user new_project.save() else: form = NewProjectForm(owner=request.user) context['projects'] = paginate(projects, request) context['new_project_form'] = form return render_response(request, 'project/project_list.html', context)
def create_project(): project_form = NewProjectForm() search_form = SearchForm_v2(csrf_enabled=True) project=ProjectMap() project.project_name=project_form.project_name.data if project_form.validate_on_submit(): project_name=project_form.project_name.data #if ProjectMap.query.filter_by(project_name=project_name) project.project_name=project_form.project_name.data project.field_1=project_form.field_1.data project.field_2=project_form.field_2.data project.field_3=project_form.field_3.data project.field_4=project_form.field_4.data project.field_5=project_form.field_5.data project.field_6=project_form.field_6.data project.field_7=project_form.field_7.data project.field_8=project_form.field_8.data project.field_9=project_form.field_9.data project.field_10=project_form.field_10.data project.field_11=project_form.field_11.data project.field_12=project_form.field_12.data project.field_13=project_form.field_13.data project.field_14=project_form.field_14.data project.field_15=project_form.field_15.data project.field_16=project_form.field_16.data project.field_17=project_form.field_17.data project.field_18=project_form.field_18.data project.field_19=project_form.field_19.data project.field_20=project_form.field_20.data try: if ProjectMap.query.filter_by(project_name=project_name).count() > 1: flash('Project name already exists!','error') return render_template('create_project.html',form=search_form,project_form=project_form) report_db.session.add(project) report_db.session.commit() #ProjectTab.__tablename__='project_%s'%project_name #ProjectTab.set_tablename('project_%s'%project_name) #project.__table__.create(report_db.get_engine()) flash("Added successfully!") return redirect(url_for('main.view',project_name=project_name)) except Exception as err: flash(err,'error') return render_template('create_project.html',form=search_form,project_form=project_form)
def test_project_list_view(self): from forms import NewProjectForm view_project_list_url = reverse('project_list') self.connect_user() response = self.client.get(view_project_list_url) # Check response self.assertEqual(response.status_code, 200) # Check response contains a form self.assertEqual(response.context['new_project_form'].as_p(), NewProjectForm(owner=response.context['user']).as_p())
def get_new_project_form(): form = NewProjectForm() drones = Drone.query.all() form.drone.choices = [(x.id, x.name) for x in drones if x.calibration] if form.validate_on_submit(): project_title = form.name.data description = form.description.data drone_id = form.drone.data projects = Project.query.all() if project_title in [x.name for x in projects]: flask.flash('A project with that name already exist!') else: logger.debug(f'Creating project with name {project_title}') log_file = None if form.log_file.data: log_error = None log_filename = get_random_filename(form.log_file.data.filename) log_file = os.path.join(data_dir, log_filename) form.log_file.data.save(log_file) success = drone_log.test_log(log_file) if not success: remove_file(log_file) log_filename = None log_error = 'Error interpreting the drone log file. Try and upload the log file again.' else: log_error = 'No drone log file added. Please add a log file.' project = Project(name=project_title, description=description, drone_id=drone_id, log_file=log_file, log_error=log_error) db.session.add(project) db.session.commit() return flask.redirect( flask.url_for('projects.projects', project_id=project.id)), form return None, form
def main(): if 'dropbox_user_token' not in session: return redirect('/') newProjectForm = NewProjectForm() dropbox_groups = get_dropbox_groups(DB_BUSINESS_AUTH) newProjectForm.project_rw_members.choices = [ (g['group_id'], g['group_name']) for g in dropbox_groups['groups']] newProjectForm.project_ro_members.choices = [ (g['group_id'], g['group_name']) for g in dropbox_groups['groups']] if newProjectForm.validate_on_submit(): return complete(newProjectForm) basic_team_information = get_info(DB_BUSINESS_AUTH) user_account_detail = get_user_account_detail(session['dropbox_user_token']) template_folder_info = get_file_or_folder_metadata(session['dropbox_user_token'], template_folder) if "error" in template_folder_info: if template_folder_info['error']['path']['.tag'] == 'not_found': create_dropbox_folder(session['dropbox_user_token'], template_folder) session['account_id'] = user_account_detail['account_id'] return render_template('main.html', db_auth=True, newProjectForm=newProjectForm, user_detail=user_account_detail, basic_team_information=basic_team_information, template_folder=template_folder)
def project_list(request): """ return projects own by the current user. The result list is paginated """ context = {} projects = Project.objects.filter( owner=request.user).order_by("-creation_date") if request.method == "POST": form = NewProjectForm(request.POST, owner=request.user) if form.is_valid(): new_project = form.save(commit=False) new_project.owner = request.user new_project.save() else: form = NewProjectForm(owner=request.user) context['projects'] = paginate(projects, request) context['new_project_form'] = form return render_response(request, 'project/project_list.html', context)