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)
def addcomment(request): if request.POST: comment = Comments() comment.fname = request.POST.get('firstname') comment.name = request.POST.get('lastname') comment.lname = request.POST.get('secondname') comment.region_id = int(request.POST.get('region')) comment.city_id = int(request.POST.get('city')) comment.phone = request.POST.get('phone') comment.email = request.POST.get('email') comment.comment = request.POST.get('comment') comment.save() return HttpResponse(json.dumps("")) else: raise Http404