def project_components(project_id): from models.project import Project, Component project_id = urllib.unquote_plus(project_id) project = Project.query.filter_by(id=project_id).first() if not project: abort(404) elif not app.access('project', action='update', project=project): abort(403) title = g._t('project components') breadcrumbs = ( (g._t('projects'), url_for('project_index')), (project.__str__(), url_for('project_view', project_id=urllib.quote_plus(str(project_id)))), (title, "#") ) if (request.form.get('method') == 'PUT' or request.method == 'PUT') and request.form.get('csrf_token'): submittedComponent = Component.query.filter_by(id=request.form.get('component_id')).first() if submittedComponent: submittedComponent.alias = request.form.get('component_alias', '') submittedComponent.title = request.form.get('component_title', '') submittedComponent.info = request.form.get('component_info', '') if not submittedComponent.validate(): submittedComponent.save() flash( g._t('component update success')) return redirect(url_for('project_components', project_id=urllib.quote_plus(str(project_id)))) else: flash( g._t('component not found'), 'error') elif (request.form.get('method') == 'DELETE' or request.method == 'DELETE') and request.form.get('csrf_token'): submittedComponent = Component.query.filter_by(id=request.form.get('component_id')).first() if submittedComponent: submittedComponent.delete() flash( g._t('component delete success')) return redirect(url_for('project_components', project_id=urllib.quote_plus(str(project_id)))) else: flash( g._t('component not found'), 'error') elif (request.form.get('method') == 'POST' or request.method == 'POST') and request.form.get('csrf_token'): submittedComponent = Component() submittedComponent.project_id = project.id submittedComponent.alias = request.form.get('component_alias', '') submittedComponent.title = request.form.get('component_title', '') submittedComponent.info = request.form.get('component_info', '') if not submittedComponent.validate(): submittedComponent.save() flash( g._t('component create success')) return redirect(url_for('project_components', project_id=urllib.quote_plus(str(project_id)))) else: submittedComponent = Component() return render_template('project/components.html', project_id=project_id, project=project, submittedComponent=submittedComponent, title=title, breadcrumbs=breadcrumbs)
def install_project_data(): """Create all the required projects if not defined""" from application import db from models.project import Project, Component, Label projectList = [ { 'alias': 'MGM', 'title': 'Management records', 'info': None, 'components': [ { 'alias': 'VAC', 'title': 'Vacation', 'info': None }, { 'alias': 'VAC/KZOT', 'title': 'Vacation. Days off by KZoT', 'info': None }, { 'alias': 'VAC/NP', 'title': 'Vacation. Unpaid Leave', 'info': None }, { 'alias': 'VAC/EDU', 'title': 'Vacation. Education', 'info': None } ], 'labels': [Label.LABEL_GENERAL, Label.LABEL_VACATION] }, { 'alias': 'OUT', 'title': 'N/A Time', 'info': """Hours sink for time that an employee was available in XMPP but was neither doing work or in stand-by""", 'components': [], 'labels': [Label.LABEL_GENERAL, Label.LABEL_VACATION] }, { 'alias': 'EDU', 'title': 'Self Education', 'info': """Self Education. Report summary is obligatory!""", 'components': [], 'labels': [Label.LABEL_GENERAL, Label.LABEL_INTERNAL] }, { 'alias': 'IDLE', 'title': 'Idle Time', 'info': """Hours sink for time that an employee is online and available but doesn't have a specific task""", 'components': [], 'labels': [Label.LABEL_GENERAL, Label.LABEL_INTERNAL] }, { 'alias': 'PP', 'title': 'P-Product internal tasks', 'info': None, 'components': [], 'labels': [Label.LABEL_GENERAL, Label.LABEL_INTERNAL] }, { 'alias': 'OFFICE', 'title': 'Office Tasks', 'info': """Shopping for Office, Psychotherapy, Interviews, etc.""", 'components': [], 'labels': [Label.LABEL_INTERNAL] } ] for projectItem in projectList: project = Project.query.filter_by(alias=projectItem['alias']).first() if not project: project = Project() project.alias = projectItem['alias'] project.title = projectItem['title'] project.info = projectItem['info'] project.save() for componentItem in projectItem['components']: component = Component.query.filter_by(alias=componentItem['alias'], project=project).first() if not component: component = Component() component.alias = componentItem['alias'] component.title = componentItem['title'] component.info = componentItem['info'] component.project = project component.save() for labelItem in projectItem['labels']: label = Label.query.filter_by(title=labelItem, project=project).first() if not label: label = Label() label.title = labelItem label.project = project label.save()