def install_migration_projects(): """Migrate the projects data from the old CouchDB storage""" from models.account import Account from models.project import Project, Component, Label, Role for row in __couchdb().view('_design/projects/_view/list'): value = row['value'] value['_id'] = value.get('_id', '').replace(':', '/') # resolve the labels INT or EXT value['labels'] = [] if value.get('_id', '').startswith('INT'): value['labels'].append(Label.LABEL_INTERNAL) elif value.get('_id', '').startswith('EXT'): value['labels'].append(Label.LABEL_EXTERNAL) elif value.get('_id', '').startswith('MGM') or value.get('_id', '').startswith('OUT'): value['labels'].append(Label.LABEL_VACATION) elif value.get('_id', '') == 'NOKIA/OFFICIAL': value['labels'].append(Label.LABEL_VACATION) value['_id'] = value.get('_id', '').replace('EXT/', '').replace('INT/', '') project = Project.query.filter_by(alias=value.get('_id', '')).first() if not project: project = Project() project.alias = value.get('_id', '') project.title = value.get('title') project.info = value.get('description') if value.get('deleted', False): project.status = Project.STATUS_ACTIVE | Project.STATUS_DELETED project.save() print '[MIGRATION:PROJECT]', project.__str__() items = [(None, value.get('title'))] for k,v in value.get('partitions', {}).items(): treeRecursion(k, v, None, items) for component_alias, component_title in items: if not component_alias: continue component = Component.query.filter_by(project=project, alias=component_alias).first() if not component: component = Component() component.alias = component_alias component.title = component_title component.project = project component.save() print '[MIGRATION:COMPONENT]', project.__str__(), component.__str__() for labelItem in value.get('labels', []): label = Label.query.filter_by(title=labelItem, project=project).first() if not label: label = Label() label.title = labelItem label.project = project label.save()
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()