def index(): pform=project_form() tform=task_form() sform=strategy_form() gform=goal_form() P=models.Projects.query.all() if gform.validate_on_submit(): u=models.Projects.query.get(1) p=models.Goals(goal=gform.goal.data,proj=u) db.session.add(p) db.session.commit() return redirect(url_for('index')) return render_template("baseindex.html",pform=pform,gform=gform,tform=tform,sform=sform,P=P)
def get(self, slug=None): f = project_form() if slug: try: project = Project.one({'slug': slug}) project.check_edit_permission(self.get_current_user()) project.formify() f.fill(project) except EditDisallowedError: self.set_flash(self._("You are not allowed to edit this project.")) self.redirect(project.get_url()) return except: raise tornado.web.HTTPError(500) else: project = Project() self.render("project-edit", f=f, project=project, user=self.current_user)
def post(self, slug=None): f = project_form() data = self.get_arguments() attachments = self.get_argument('attachments', None) is_edit = bool(slug) _ = self._ try: if attachments: data['attachments'] = parse_attachments( data['attachments'], is_edit) project = Project.one({'slug': slug}) \ if is_edit else Project() if f.validates(tornado.web._O(data)): project.save(data, user=self.current_user) if attachments and not is_edit: project['attachments'] = move_attachments( self.settings.upload_path, data['attachments']) project.update_html() project.save() self.set_flash(_("Project has been saved.")) url = project.get_url( ) if project.status == 'published' else '/dashboard' self.redirect(url) return raise Exception( _("Form still have errors. Please check for required fields.")) except EditDisallowedError: self.set_flash(_("You are not allowed to edit the project.")) self.redirect(project.get_url()) except Exception, e: if attachments: project['attachments'] = data['attachments'] f.note = f.note if f.note else e self.render("project-edit", f=f, project=project, user=self.current_user)
def start(): pform=project_form() P=models.Projects.query.all() q_sum = (db.session.query( Projects.id.label("project_id"), func.sum(case([(Tasks.complete == True, 1)], else_=0)).label("x"), func.sum(case([(and_(Tasks.deadline != None, Tasks.completeDate != None, Tasks.deadline > Tasks.completeDate), 1)], else_=0)).label("y"), func.count(Tasks.id).label("total"), ).outerjoin(Goals, Projects.goals).outerjoin(Strategies, Goals.strategies).outerjoin(Tasks, Strategies.tasks).group_by(Projects.id)) if request.method == 'POST': if pform.validate() == False: flash('Failed Field validation.') flash_errors(pform) return redirect(url_for('start')) else: p=models.Projects(name=pform.project.data,projectleader=pform.projectleader.data) db.session.add(p) db.session.commit() return redirect(url_for('start')) return render_template("index_for_project.html",pform=pform,P=P,zipit=zip(P,q_sum))
def get(self, slug=None): f = project_form() if slug: try: project = Project.one({'slug': slug}) project.check_edit_permission(self.get_current_user()) project.formify() f.fill(project) except EditDisallowedError: self.set_flash( self._("You are not allowed to edit this project.")) self.redirect(project.get_url()) return except: raise tornado.web.HTTPError(500) else: project = Project() self.render("project-edit", f=f, project=project, user=self.current_user)
def post(self, slug=None): f = project_form() data = self.get_arguments() attachments = self.get_argument('attachments', None) is_edit = bool(slug) _ = self._ try: if attachments: data['attachments'] = parse_attachments(data['attachments'], is_edit) project = Project.one({'slug': slug}) \ if is_edit else Project() if f.validates(tornado.web._O(data)): project.save(data, user=self.current_user) if attachments and not is_edit: project['attachments'] = move_attachments(self.settings.upload_path, data['attachments']) project.update_html() project.save() self.set_flash(_("Project has been saved.")) url = project.get_url() if project.status == 'published' else '/dashboard' self.redirect(url) return raise Exception(_("Form still have errors. Please check for required fields.")) except EditDisallowedError: self.set_flash(_("You are not allowed to edit the project.")) self.redirect(project.get_url()) except Exception, e: if attachments: project['attachments'] = data['attachments'] f.note = f.note if f.note else e self.render("project-edit", f=f, project=project, user=self.current_user)