def delete_selected_tasks(tasks): db = DBConnection('tasks') # try: db.delete_all(tasks, 'taskId') # finally: return {'tasks': []}
def update_task(task): db = DBConnection('tasks') WORK_PROGRESS_WORKFLOW = [ WORK_TYPES.get('TODO'), WORK_TYPES.get('IN_PROGRESS'), WORK_TYPES.get('DONE'), ] workflow_index = WORK_PROGRESS_WORKFLOW.index(task.get('type')) workflow_direction = task.get('workflowDirection') try: task.pop('workflowDirection') task.pop('_id') except: pass finally: if workflow_direction == 'NEXT' and workflow_index != len( WORK_PROGRESS_WORKFLOW): task['type'] = WORK_PROGRESS_WORKFLOW[workflow_index + 1] if workflow_direction == 'PREV' and workflow_index != 0: task['type'] = WORK_PROGRESS_WORKFLOW[workflow_index - 1] return {'tasks': [db.update(task, 'title')]}
def insert_companies(companies): techDb = DBConnection('companies') new_list = [Company.load_from_json(company) for company in companies] for company in new_list: company.is_valid() and techDb.update(company.to_json(), 'companyId') return {'companies': techDb.find()}
def insert_projects(project): project_db = DBConnection('projects') project_db.update(project, 'projectId') return { 'projects': project_db.find({'projectId': project.get('projectId', None)}) }
def new_task(task): tasks = DBConnection('tasks') try: return {'tasks': [tasks.save(task)], 'error': []} except DuplicateKeyError as error: return { 'tasks': [json.loads(json_util.dumps(task))], 'error': error.args }
def get_user_by_username(username, n=None): db = DBConnection('users') user = db.find({'username': username}) if not len(user): raise UserNotFound() if n is None: return user else: return user[int(n)]
def post_performance_logs(request): performance = DBConnection('performance') log = { 'browser': request.user_agent.browser, 'browser_version': request.user_agent.version, 'lang': request.user_agent.browser, 'platform': request.user_agent.platform } return { 'log': performance.save(log), }, 200
def get_all_app_config(): application = DBConnection('application') try: app_config = application.find() result = dict() for config in app_config: result[ config.get('configName') ] = config.get('value') except: result = None return { 'applicationConfig': result }
def post_url_hits(log): # log = { # 'req_path': request.full_path, # 'origin': request.origin, # 'host_url': request.host_url, # 'endpoint': request.endpoint, # 'authorization': request.authorization, # 'service_name': request.blueprint, # 'time': datetime.now(), # 'mode': 'None' # } performance = DBConnection('history') performance.save(log) print('log posted!')
def get_all_tasks(page=0, page_size=20): tasks = DBConnection('tasks') all_tasks = tasks.find_by_page({}, page=int(page), page_size=int(page_size)) return { 'tasks': all_tasks[0], 'pageData': { 'start': all_tasks[1], 'end': all_tasks[2], 'page': page, 'size': page_size, 'total': all_tasks[3] } }
def set_app_configs(app_config): application = DBConnection('application') try: for key in app_config.keys(): config = dict({ 'configName': key, 'value': app_config.get(key) }) application.update(config, 'configName') except: return { 'appConfig': False } return { 'appConfig': True }
def get_app_data(): application = DBConnection('application') links = DBConnection('links') return { 'title': application.find()[ 0 ], 'header': links.find() }
def get_app_data(): application = DBConnection('application') links = DBConnection('links') try: app_config = application.find() result = dict() for config in app_config: result[ config.get('configName') ] = config.get('value') except: result = None return { 'applicationConfig': result, 'header': { 'list': links.find(), } }
def remove_companies(companies): techDb = DBConnection('companies') techDb.delete_all(companies, 'companyId') return {'companies': techDb.find()}
def insert_technology(skill): techDb = DBConnection('technologies') techDb.update(skill, 'techId') return {'technologies': techDb.find({'techId': skill.get('techId', None)})}
def configure_company_table(): companyDb = DBConnection('companies') companyDb.collection.create_indexes([ pymongo.IndexModel([ ("companyId", pymongo.ASCENDING) ], unique=True) ])
def configure_users_table(): users = DBConnection('users') users.collection.create_indexes( [pymongo.IndexModel([("username", pymongo.TEXT)], unique=True)])
def configure_project_config_table(): projects_db = DBConnection('projects') projects_db.collection.create_indexes( [pymongo.IndexModel([("projectId", pymongo.ASCENDING)], unique=True)])
def configure_application_config_table(): application = DBConnection('application') application.collection.create_indexes([ pymongo.IndexModel([ ("configName", pymongo.ASCENDING) ], unique=True) ])
def save_user(user): db = DBConnection('users') User.load_from_json(db.update(user.to_json(), user.get_key()))
def get_experiences(): experiences = DBConnection('experiences') return { 'experiences': experiences.find() }
def get_technologies(): techDb = DBConnection('technologies') return {'technologies': techDb.find()}
def get_companies(): techDb = DBConnection('companies') return {'companies': techDb.find()}
def configure_tasks(): tasks = DBConnection('tasks') tasks.collection.create_indexes( [pymongo.IndexModel([("taskId", pymongo.ASCENDING)], unique=True)])
def get_projects(): project_db = DBConnection('projects') return {'projects': project_db.find()}
def remove_projects(projects): project_db = DBConnection('projects') project_db.delete_all(projects, 'projectId') return {'projects': project_db.find()}
def configure_technology_config_table(): techDb = DBConnection('technologies') techDb.collection.create_indexes( [pymongo.IndexModel([("techId", pymongo.ASCENDING)], unique=True)])
def remove_technologies(skills): techDb = DBConnection('technologies') techDb.delete_all(skills, 'techId') return {'technologies': []}