Ejemplo n.º 1
0
def editProject(title):
    proj = Project.query.filter_by(user_id=current_user.id,
                                   title=title).first()
    form = EditProjectForm(proj.title)
    print(form.validate_on_submit())
    #print()
    for key, err in form.errors.items():
        message = err[0].replace("Field", key)
        flash(message.capitalize(), 'bg-danger')
    if form.validate_on_submit():
        # take username and query database with it
        print("We're here")
        proj.title = form.title.data
        proj.description = form.description.data
        proj.study_length = form.study_length.data
        proj.summary_length = form.summary_length.data
        proj.s_break_length = form.s_break_length.data
        proj.l_break_length = form.l_break_length.data
        proj.pom_num = form.pom_num.data
        #proj.cycle_num=form.cycle_num.data
        db.session.commit()
        flash('Your project has been edited!', 'bg-success')
        return redirect(url_for('project', title=proj.title))
    else:

        return render_template('edit_project.html',
                               form=form,
                               project=proj,
                               title='Edit project')
Ejemplo n.º 2
0
def projectView(username, project):
    form = EditProjectForm()
    allUsers = User.query.filter(User.username != "admin").all()
    currentRole = User.query.filter_by(
        username=current_user.username).first_or_404()
    user = User.query.filter_by(username=username).first_or_404()
    proj = Projects.query.filter_by(id=project).first_or_404()
    comments = Comments(comment_id=proj.id).query.filter_by(
        comment_id=project).all()
    comment = Comments(comment_id=proj.id)
    if form.validate_on_submit():
        proj.description = form.description.data
        proj.company = form.company.data
        if form.priority.data == "":
            form.priority.data = "9999"
        proj.priority = form.priority.data
        proj.priority_dept = form.priority_dept.data
        proj.requester = form.requester.data
        proj.status = form.status.data
        proj.department = form.department.data
        proj.ticket = form.ticket.data
        proj.hours = form.hours.data
        comment.comment = form.comment.data
        if comment.comment != "":
            db.session.add(comment)
        db.session.commit()
        flash('Project Updated!')
        return redirect(
            url_for('projectView',
                    username=username,
                    comment=comments,
                    project=project))
    elif request.method == 'GET':
        form.description.data = proj.description
        form.company.data = proj.company
        if proj.priority == "9999":
            proj.priority = ""
        if proj.priority_dept == "9999":
            proj.priority_dept = ""
        form.priority.data = proj.priority
        form.priority_dept.data = proj.priority_dept
        form.requester.data = proj.requester
        form.status.data = proj.status
        form.department.data = proj.department
        form.ticket.data = proj.ticket
        form.hours.data = proj.hours

    return render_template('editprojects.1.html',
                           title='Edit Project',
                           user=user,
                           form=form,
                           comment=comments,
                           project=proj,
                           allUsers=allUsers,
                           currentRole=currentRole,
                           jfilesize=jfilesize,
                           cfilesize=cfilesize,
                           dev=username)
Ejemplo n.º 3
0
def editProjectPage():
    form = EditProjectForm()
    if form.validate_on_submit():
        if form.email.data != "":
            insertEmailAccount(company, form.email.data)
        if form.twitter.data != "":
            insertTwitterAccount(company, form.twitter.data)
        if form.linkedin.data != "":
            insertLinkedInAccount(company, form.linkedin.data)
        return redirect(url_for('home'))
    return render_template('editProject.html', title='Edit Project', form=form)
Ejemplo n.º 4
0
def completedprojectView(project):
    dev = "Projects"
    form = EditProjectForm()
    allUsers = User.query.filter(User.username != "admin").all()
    currentRole = User.query.filter_by(
        username=current_user.username).first_or_404()
    proj = CompleteProjects.query.filter_by(id=project).first_or_404()
    comments = CompleteComments(comment_id=proj.id).query.filter_by(
        comment_id=project).all()

    form.description.data = proj.description
    form.company.data = proj.company
    if proj.priority == "9999":
        proj.priority = ""
    if proj.priority_dept == "9999":
        proj.priority_dept = ""
    form.priority.data = proj.priority
    form.priority_dept.data = proj.priority_dept
    form.requester.data = proj.requester
    form.department.data = proj.department
    form.ticket.data = proj.ticket
    form.hours.data = proj.hours

    return render_template('viewprojects.html',
                           title='Completed Project',
                           form=form,
                           comment=comments,
                           project=proj,
                           allUsers=allUsers,
                           currentRole=currentRole,
                           jfilesize=jfilesize,
                           cfilesize=cfilesize,
                           dev=dev)
Ejemplo n.º 5
0
def edit(id):
  errors = []
  form = EditProjectForm(request.form)
  project = None

  if id == NEW_PROJECT_ID:
    project = Project()
  else:
    if not g.db.doc_exist(id):
      abort(404)
    project = Project.get(id)
    if request.method == 'GET':
      form = EditProjectForm(obj=project)
      pass

  if request.method == 'POST' and form.validate():
    form.populate_obj(project)
    project.author = session['username']

    '''
    if id != NEW_PROJECT_ID:
      for ff in request.files.keys():
        f = request.files[ff]
        if f:
          fname = secure_filename(f.filename)
          fld = os.path.join(UPLOADED_FILES, id)
          if not os.path.exists(fld):
            os.mkdir(fld)
          target_path = os.path.join(fld, fname)
          while os.path.exists(target_path):
            filename, ext = os.path.splitext(target_path)
            r = ''.join(random.choice('0123456789abcdef') for i in range(8))
            target_path = os.path.join(fld, filename + '-' + r + ext)
          f.save(target_path)
          flash('Successfully uploaded %s' % fname)
    '''
    project.save()
    flash('Project was successfully %s' % ('created' if id == NEW_PROJECT_ID else 'updated'))
    return redirect(url_for('index.index'))

  errors.extend(format_form_errors(form.errors.items()))
  return render_template('project_edit.html', id = id, form = form, errors = errors)
Ejemplo n.º 6
0
def edit(project):
    print "edit"
    form = EditProjectForm()
    if form.validate_on_submit():
        project.name = form.name.data
        project.slug = form.slug.data
        project.path = form.path.data
        if form.password.data:
            project.password_hash = form.get_password_hash()
            project.boot_all_users()
        db.session.commit()
        return redirect(url_for('.project', project=project))

    if request.method == 'POST':
        print form.errors
        print form.data

    form = EditProjectForm(name=project.name,
                           slug=project.slug,
                           old_slug=project.slug,
                           path=project.path)

    return render_template('edit.html', form=form, project=project)
Ejemplo n.º 7
0
def edit(id):
    errors = []
    form = EditProjectForm(request.form)
    project = None

    if id == NEW_PROJECT_ID:
        project = Project()
    else:
        if not g.db.doc_exist(id):
            abort(404)
        project = Project.get(id)
        if request.method == 'GET':
            form = EditProjectForm(obj=project)
            pass

    if request.method == 'POST' and form.validate():
        form.populate_obj(project)
        project.author = session['username']
        '''
    if id != NEW_PROJECT_ID:
      for ff in request.files.keys():
        f = request.files[ff]
        if f:
          fname = secure_filename(f.filename)
          fld = os.path.join(UPLOADED_FILES, id)
          if not os.path.exists(fld):
            os.mkdir(fld)
          target_path = os.path.join(fld, fname)
          while os.path.exists(target_path):
            filename, ext = os.path.splitext(target_path)
            r = ''.join(random.choice('0123456789abcdef') for i in range(8))
            target_path = os.path.join(fld, filename + '-' + r + ext)
          f.save(target_path)
          flash('Successfully uploaded %s' % fname)
    '''
        project.save()
        flash('Project was successfully %s' %
              ('created' if id == NEW_PROJECT_ID else 'updated'))
        return redirect(url_for('index.index'))

    errors.extend(format_form_errors(form.errors.items()))
    return render_template('project_edit.html',
                           id=id,
                           form=form,
                           errors=errors)
Ejemplo n.º 8
0
def edit(project):
    print "edit"
    form = EditProjectForm()
    if form.validate_on_submit():
        project.name = form.name.data
        project.slug = form.slug.data
        project.path = form.path.data
        if form.password.data:
            project.password_hash = form.get_password_hash()
            project.boot_all_users()
        db.session.commit()
        return redirect(url_for('.project', project=project))

    if request.method == 'POST':
        print form.errors
        print form.data

    form = EditProjectForm(name=project.name,
                           slug=project.slug,
                           old_slug=project.slug,
                           path=project.path)

    return render_template('edit.html', form=form, project=project)
Ejemplo n.º 9
0
def user(username):
	register_form = RegistrationForm()
	login_form = LoginForm()
	if login_form.login_submit.data:
		if login_form.validate_on_submit():
			loginuser = User.query.filter_by(email=login_form.login_email.data).first()
			if loginuser is None or not loginuser.check_password(login_form.login_password.data):
				flash('Invalid email or password')
				current_page = request.url
				if not current_page or url_parse(current_page).netloc != '':
					next_page = url_for('index')
				return redirect(current_page)
			login_user(loginuser, remember=login_form.remember_me.data)
			current_page = request.url
			if not current_page or url_parse(current_page).netloc != '':
				next_page = url_for('index')
			return redirect(current_page)
	elif register_form.register_submit.data:
		if register_form.validate_on_submit():
			register_user = User(username=register_form.register_username.data, email=register_form.register_email.data)
			register_user.set_password(register_form.register_password.data)
			db.session.add(register_user)
			db.session.commit()
			flash('Thank you for registering')
			current_page = request.url
			if not current_page or url_parse(current_page).netloc != '':
				next_page = url_for('index')
			return redirect(current_page)
	user = User.query.filter_by(username=username).first_or_404()
	portfolio = Project.query.filter_by(user_id=user.id, date_quarantined=None).order_by(Project.date_published.desc()).all()
	for p in portfolio:
		pg_list = []
		for pg in p.genre:
			pg_list.append(pg.name)
		p.pg_name = ','.join(pg_list)
	library = user.books.filter_by(date_quarantined=None).order_by(Project.date_published.desc()).all()
	form = CreateProjectForm()
	form2 = EditProjectForm()
	if form.submit.data:
		if form.validate_on_submit():
			genres = form.genre.data
			genre_list = genres.split(',')
			proj = Project(title=form.title.data, synopsis=form.synopsis.data, user_id=current_user.id)
			'''if form.cover_pic.data:
				cover_pic_filename = photos.save(form.cover_pic.data)
				proj.cover_pic = photos.url(cover_pic_filename)'''
			if form.cover_pic_link.data:
				proj.cover_pic_link = form.cover_pic_link.data
			if form.cover_pic_credit.data:
				proj.cover_pic_credit = form.cover_pic_credit.data
			db.session.add(proj)
			db.session.commit()
			for g in genre_list:
				g_query = Genre.query.filter_by(name=g).first()
				if g_query is None:
					gname = Genre(name=g)
					db.session.add(gname)
					proj.genre.append(gname)
					db.session.commit()
				else:
					proj.genre.append(g_query)
					db.session.commit()
			return redirect(url_for('project', id=proj.id, title=proj.title))
	elif form2.edit_submit.data:
		if form2.validate_on_submit():
			edit_proj = Project.query.filter_by(id=form2.proj_id.data).first()
			edit_proj.title = form2.edit_title.data
			edit_proj.synopsis = form2.edit_synopsis.data
			'''if form2.edit_cover_pic.data:
				edit_cover_pic_filename = photos.save(form2.edit_cover_pic.data)
				edit_proj.cover_pic = photos.url(edit_cover_pic_filename)
				print(form2.edit_cover_pic.data)'''
			if form2.edit_cover_pic_link.data:
				edit_proj.cover_pic_link = form2.edit_cover_pic_link.data
			edit_proj.cover_pic_credit = form2.edit_cover_pic_credit.data
			db.session.commit()
			edit_genres = form2.edit_genre.data
			edit_genre_list = edit_genres.split(',')
			for g in edit_genre_list:
				g_query = Genre.query.filter_by(name=g).first()
				if g_query is None:
					gname = Genre(name=g)
					db.session.add(gname)
					edit_proj.genre.append(gname)
					db.session.commit()
				elif not edit_proj.is_genre(g_query):
					edit_proj.genre.append(g_query)
					db.session.commit()
			return redirect(url_for('project', id=edit_proj.id, title=edit_proj.title))
	'''elif request.method == 'GET':
		for p in portfolio:
			form2.proj_id.data = p.id
			form2.edit_title.data = p.title
			pg_list = []
			for pg in p.genre:
				pg_list.append(pg.name)
			p.pg_name = ','.join(pg_list)
			form2.edit_genre.data = p.pg_name
			form2.edit_synopsis.data = p.synopsis'''
	return render_template('user.html', user=user, title='User', description=user.about_me, form=form, form2=form2, portfolio=portfolio, library=library, register_form=register_form, login_form=login_form)