def temp(): try: data = request.json if ProjectTable.select().where( (ProjectTable.name == data['name']) & (ProjectTable.date_start == data['date_start']) & (ProjectTable.date_end == data['date_end'])).exists(): message = ResponseClass.project_existing.value obj = ResponseClass.creationerror_message(message) client_response = Response(obj, mimetype='application/json') return client_response, status.HTTP_400_BAD_REQUEST else: proj_data = { 'name': data['name'], 'description': data['description'], 'date_start': data['date_start'], 'date_end': data['date_end'], 'project_manager': data['project_manager'] } proj_object = ProjectTable(**proj_data) proj_object.save() team_member_data = data['team_member'] project_lead_data = data['project_lead'] for member in team_member_data: team_member_object = {} team_member_object['project'] = proj_object.id team_member_object['team_type'] = member.team_type team_member_array = member.members_id for members in team_member_array: team_member_array_object = {} team_member_array_object['team_member'] = members team_member_object.append(team_member_array_object) save_team_member_object = ProjectUser(**team_member_object) save_team_member_object.save() for lead in project_lead_data: team_lead_object = {} team_lead_object['project'] = lead.id team_lead_object['team_type'] = lead.team_type team_lead_object['team_lead'] = lead.lead_id save_project_lead_object = ProjectLead(**team_lead_object) save_project_lead_object.save() message = { 'name': data['name'], 'description': data['description'] } obj = ResponseClass.creationsuccess_message(message) client_response = Response(obj, mimetype='application/json') return client_response, status.HTTP_201_CREATED except Exception as e: print(e)
def createProject(): return_response = validate_user() return_data = json.loads(return_response.text) if return_response.status_code == 200: authority = authorisation(return_data['User_id']) if authority: data = request.json if ProjectTable.select().where( (ProjectTable.name == data['name']) & (ProjectTable.date_start == data['date_start']) & (ProjectTable.date_end == data['date_end'])).exists(): message = ResponseClass.project_existing.value obj = ResponseClass.creationerror_message(message) client_response = Response(obj, mimetype='application/json') return client_response, status.HTTP_400_BAD_REQUEST else: proj_data = { 'name': data['name'], 'description': data['description'], 'date_start': data['date_start'], 'date_end': data['date_end'] } proj_object = ProjectTable(**proj_data) proj_object.save() team_member_data = data['team_member'] for member in team_member_data: team_member_object = {} team_member_object['project'] = proj_object.id team_member_object['team_member'] = member team_member_object['team_lead'] = 1 save_object = ProjectUser(**team_member_object) save_object.save() message = { 'name': data['name'], 'description': data['description'] } obj = ResponseClass.creationsuccess_message(message) client_response = Response(obj, mimetype='application/json') return client_response, status.HTTP_201_CREATED else: client_message = ResponseClass.authority_exception.value obj = ResponseClass.creationerror_message(client_message) client_response = Response(obj, mimetype='application/json') return client_response, status.HTTP_400_BAD_REQUEST else: obj = json.dumps(return_data) ret_status = return_response.status_code client_response = Response(obj, mimetype='application/json') return client_response, ret_status
def editLog(): return_response = validate_user() return_data = json.loads(return_response.text) if return_response.status_code == 200: data = request.json if ProjectUser.select().where( (ProjectUser.team_member == return_data['User_id']) & (ProjectUser.project == data['proj_id'])).exists(): proj_query = ProjectTable.get(ProjectTable.id == data['proj_id']) log_query = LogTable.select().where( (LogTable.user == return_data['User_id']) & (LogTable.logged_date == data['log_date'])) total_hours = 0 for hours in log_query: total_hours = total_hours + hours.log_hours if total_hours < 24: if data['log_hours'] < 24: time_now = datetime.now() project_expiry = proj_query.date_end date = datetime.strptime(project_expiry, '%Y-%m-%d %H:%M:%S') if date >= time_now: check_log_query = LogTable.select().where( (LogTable.logged_date == data['log_date']) & (LogTable.user == return_data['User_id']) & (LogTable.project == data['proj_id']) & (LogTable.job_type == data['jobtype_id'])) if check_log_query.exists(): update_log_query = LogTable.select().where( (LogTable.logged_date == data['log_date']) & (LogTable.user == return_data['User_id']) & (LogTable.project == data['proj_id']) & (LogTable.job_type == data['jobtype_id']) ).get() update_log = { 'description': data['description'], 'log_hours': data['log_hours'] } update_log_object = LogTable.update( **update_log).where( LogTable.id == update_log_query.id) update_log_object.execute() last_update = LogTable.get( LogTable.id == update_log_query.id) last_update.modified_date = datetime.now() last_update.save() message = ResponseClass.re_edit.value obj = ResponseClass.creationsuccess_message( message) client_response = Response( obj, mimetype='application/json') return client_response, status.HTTP_200_OK else: log_data = { 'project': data['proj_id'], 'user': return_data['User_id'], 'job_type': data['jobtype_id'], 'description': data['description'], 'logged_date': data['log_date'], 'logged_hours': data['log_hours'] } log_object = LogTable(**log_data) log_object.save() message = ResponseClass.editsuccess.value obj = ResponseClass.creationsuccess_message( message) client_response = Response( obj, mimetype='application/json') return client_response, status.HTTP_200_OK else: message = ResponseClass.log_expiry.value obj = ResponseClass.creationerror_message(message) client_response = Response(obj, mimetype='application/json') return client_response, status.HTTP_400_BAD_REQUEST else: message = ResponseClass.day_threshold_error.value obj = ResponseClass.creationerror_message(message) client_response = Response(obj, mimetype='application/json') return client_response, status.HTTP_400_BAD_REQUEST else: message = ResponseClass.log_threshold_error.value obj = ResponseClass.creationerror_message(message) client_response = Response(obj, mimetype='application/json') return client_response, status.HTTP_400_BAD_REQUEST else: message = ResponseClass.log_failure.value obj = ResponseClass.creationerror_message(message) client_response = Response(obj, mimetype='application/json') return client_response, status.HTTP_400_BAD_REQUEST else: obj = json.dumps(return_data) ret_status = return_response.status_code client_response = Response(obj, mimetype='application/json') return client_response, ret_status