def login_sso(request, *args, **kwargs): try: json_body = json.loads(request.body) username = json_body.get("username") password = json_body.get("password") if username == "admin" and password == "123": store_coordinator(username) request.session['coordinator_id'] = Coordinator.objects.filter( coordinator_name=username)[0].id request.session['coordinator_name'] = username resp = init_http_response(RespCode.success.value.key, RespCode.success.value.msg) return HttpResponse(json.dumps(resp), content_type="application/json") url = 'https://sso.unimelb.edu.au/api/v1/authn' data = {"username": username, "password": password} res = requests.post(url=url, json=data) logger = logging.getLogger("django") logger.info(res.json()) if operator.eq(res.json().get("status"), "SUCCESS"): resp = init_http_response(RespCode.success.value.key, RespCode.success.value.msg) store_coordinator(username) # put username into session request.session['coordinator_id'] = Coordinator.objects.filter( coordinator_name=username)[0].id request.session['coordinator_name'] = username else: resp = {'code': -2, 'msg': 'authentication failed'} return HttpResponse(json.dumps(resp), content_type="application/json") except Exception as e: print(e) resp = {'code': -1, 'msg': 'error'} return HttpResponse(json.dumps(resp), content_type="application/json")
def delete_subject(request, *args, **kwargs): """ :param request: :param args: :param kwargs: :return: """ subject_id = kwargs.get('id') if not subject_id: print("f**k") resp = init_http_response(RespCode.invalid_parameter.value.key, RespCode.invalid_parameter.value.msg) return make_json_response(HttpResponse, resp) try: subject = Subject.objects.get(subject_id=subject_id) except ObjectDoesNotExist as e: print("f**k two") resp = init_http_response(RespCode.invalid_parameter.value.key, RespCode.invalid_parameter.value.msg) return make_json_response(HttpResponse, resp) subject.status = Status.invalid.value.key subject.save() resp = init_http_response(RespCode.success.value.key, RespCode.success.value.msg) return make_json_response(HttpResponse, resp)
def delete_subject(request, *args, **kwargs): """ :param request: :param args: :param kwargs: :return: """ subject_id = None for arg in args: if isinstance(arg, dict): subject_id = arg.get('id', None) if not subject_id: resp = init_http_response(RespCode.invalid_parameter.value.key, RespCode.invalid_parameter.value.msg) return make_json_response(HttpResponseBadRequest, resp) try: subject = Subject.objects.get(subject_id=subject_id) except ObjectDoesNotExist as e: resp = init_http_response(RespCode.invalid_parameter.value.key, RespCode.invalid_parameter.value.msg) return make_json_response(HttpResponseBadRequest, resp) subject.status = Status.invalid subject.save() resp = init_http_response(RespCode.success.value.key, RespCode.success.value.msg) return make_json_response(HttpResponse, resp)
def update_subject(request, *args, **kwargs): """ :param request: :param args: :param kwargs: :return: """ subject_id = None for arg in args: if isinstance(arg, dict): subject_id = arg.get('id', None) if not subject_id: resp = init_http_response(RespCode.invalid_parameter.value.key, RespCode.invalid_parameter.value.msg) return make_json_response(HttpResponseBadRequest, resp) subject_code = request.POST.get('code', '') subject_name = request.POST.get('name', '') coordinator_id = int(request.POST.get('coordinator_id', 0)) try: subject = Subject.objects.get(subject_id=subject_id) except ObjectDoesNotExist as e: resp = init_http_response(RespCode.invalid_parameter.value.key, RespCode.invalid_parameter.value.msg) return make_json_response(HttpResponseBadRequest, resp) subject.subject_code = subject_code subject.subject_name = subject_name subject.coordinator_id = coordinator_id subject.save() resp = init_http_response(RespCode.success.value.key, RespCode.success.value.msg) return make_json_response(HttpResponse, resp)
def get_subject(request, subject_id: int): """ Get certain subject :param request: :param subject_id: :return: """ try: subject = Subject.objects.get(subject_id=subject_id) coordinator = User.objects.get(user_id=subject.coordinator_id) if subject.coordinator_id else None except ObjectDoesNotExist as e: resp = init_http_response(RespCode.invalid_parameter.value.key, RespCode.invalid_parameter.value.msg) return make_json_response(HttpResponseBadRequest, resp) data = dict( id=subject.subject_id, code=subject.subject_code, name=subject.name, coordinator=dict( id=coordinator.user_id, name=coordinator.get_name(), email=coordinator.email, join_date=coordinator.create_date, status=coordinator.status, ), supervisors=[], teams=[], status=subject.status, ) resp = init_http_response(RespCode.success.value.key, RespCode.success.value.msg) resp['data'] = data return make_json_response(HttpResponse, resp)
def add_subject(request): """ :param request: :return: """ subject_code = request.POST.get('code', '') subject_name = request.POST.get('name', '') coordinator_id = int(request.POST.get('coordinator_id', 0)) # if the parameter is not sufficient if not subject_code or not subject_name or coordinator_id == 0: resp = init_http_response(RespCode.invalid_parameter.value.key, RespCode.invalid_parameter.value.msg) return make_json_response(HttpResponseBadRequest, resp) # if the subject code existed if Subject.objects.filter(subject_code=subject_code).exists(): resp = init_http_response(RespCode.subject_existed.value.key, RespCode.subject_existed.value.msg) return make_json_response(HttpResponseBadRequest, resp) # if user is not coordinator try: user = User.objects.get(user_id=coordinator_id, role=Roles.coordinator.value.key, status=Status.valid.value.key) except ObjectDoesNotExist: resp = init_http_response(RespCode.invalid_op.value.key, RespCode.invalid_op.value.msg) return make_json_response(HttpResponseBadRequest, resp) subject = Subject(subject_code=subject_code, name=subject_name, coordinator_id=coordinator_id, create_date=int(now().timestamp()), status=Status.valid.value.key) subject.save() resp = init_http_response(RespCode.success.value.key, RespCode.success.value.msg) return make_json_response(HttpResponse, resp)
def import_team(request, body, *args, **kwargs): """ Import team from confluence with supervisor_id :param request: :param body: :param args: :param kwargs: :return: """ add_team_dto = AddTeamDTO() body_extract(body, add_team_dto) # Check parameters if not add_team_dto.not_empty(): resp = init_http_response(RespCode.invalid_parameter.value.key, RespCode.invalid_parameter.value.msg) return make_json_response(HttpResponse, resp) team_members = get_members(request, add_team_dto.team) if not team_members: logger.info('Empty team member: %s', add_team_dto.team) resp = init_http_response(RespCode.invalid_parameter.value.key, RespCode.invalid_parameter.value.msg) return make_json_response(HttpResponse, resp) # If the team existed if Team.objects.filter(name=add_team_dto.team).exists(): resp = init_http_response(RespCode.team_existed.value.key, RespCode.team_existed.value.msg) return make_json_response(HttpResponse, resp) try: with transaction.atomic(): team = Team(name=add_team_dto.team, subject_code=add_team_dto.subject, year=add_team_dto.year, project_name=add_team_dto.project, create_date=mills_timestamp()) team.save() for member in team_members: try: student = Student.objects.get(email=member['email']) except ObjectDoesNotExist as e: student = Student(fullname=member['name'], email=member['email']) student.save() import_team_member(team.team_id, student.student_id) except Exception as e: logger.error(e) resp = init_http_response(RespCode.server_error.value.key, RespCode.server_error.value.msg) return make_json_response(HttpResponse, resp) resp = init_http_response(RespCode.success.value.key, RespCode.success.value.msg) return make_json_response(HttpResponse, resp)
def get_invitation(request, subject_id: int): """ TODO: update expired status :param request: :param subject_id: :return: """ finished = request.GET.get('finished', None) offset = int(request.POST.get('offset', 0)) has_more = 0 kwargs = dict(subject_id=subject_id, ) if finished is not None: if int(finished) == 0: kwargs['status__lt'] = InvitationStatus.accepted.value.key else: kwargs['status__gte'] = InvitationStatus.accepted.value.key invitations = Invitation.objects.filter( **kwargs).order_by('invitation_id')[offset:offset + SINGLE_PAGE_LIMIT + 1] if len(invitations) > SINGLE_PAGE_LIMIT: invitations = invitations[:SINGLE_PAGE_LIMIT] has_more = 1 offset += len(invitations) if len(invitations) == 0: data = dict( invitations=[], has_more=has_more, offset=offset, ) resp = init_http_response(RespCode.success.value.key, RespCode.success.value.msg) resp['data'] = data return make_json_response(HttpResponse, resp) data = dict(invitation=[ dict(id=invitation.invitation_id, name=invitation.get_name(), email=invitation.email, expired=invitation.expired, status=invitation.status) for invitation in invitations ], offset=offset, has_more=has_more) resp = init_http_response(RespCode.success.value.key, RespCode.success.value.msg) resp['data'] = data return make_json_response(HttpResponse, resp)
def get_all_page_contributions(request, space_key): """ Get all the page contributions made by each team member Method: GET Request: space_key Return: a dictionary of {"username": [list of contributed page_ids]} """ user = request.session.get('user') username = user['atl_username'] password = user['atl_password'] conf = confluence.log_into_confluence(username, password) # Read confluence config yaml file config_dict = read_confluence_config() if config_dict == -1: resp = init_http_response( RespCode.config_not_found.value.key, RespCode.config_not_found.value.msg) return make_json_response(HttpResponse, resp) # Build query url host = config_dict["common"]["host"] port = config_dict["common"]["port"] base_path = config_dict["common"]["path"] api_path = config_dict["api"]["get-all-page-contributors"]["path"] query_expand = config_dict["api"]["get-all-page-contributors"]["query"]["expand"] query_limit = config_dict["api"]["get-all-page-contributors"]["query"]["limit"] base_url = f"{host}:{port}{base_path}{api_path}?expand={query_expand}&limit={query_limit}" # Get list of contributors to a page url = base_url.replace("{space_key}", space_key, 1) conf_resp = requests.get( url, auth=HTTPBasicAuth(username, password)).json() # Create a dictionary of team members and the number of contributions made to a confluence space member_contributions = {} # Loop through every page and store in a dictionary {"page": set of members} for page in conf_resp["results"]: page_contributors = page["history"]["contributors"]["publishers"]["users"] for user in page_contributors: if not user["username"] in member_contributions: member_contributions[user["username"]] = 0 member_contributions[user["username"]] += 1 resp = init_http_response( RespCode.success.value.key, RespCode.success.value.msg) resp['data'] = member_contributions return make_json_response(HttpResponse, resp)
def get_imported_project(request): """ get the imported projects Method: GET Request: coordinator_id Return: status code, message, list of project space keys and space names """ # user = request.session.get('user') # username = user['atl_username'] # password = user['atl_password'] username = config.atl_username password = config.atl_password coordinator_id = request.session.get('coordinator_id') try: confluence = log_into_confluence(username, password) data = [] # get all the space keys from DB where coordinator_id = given id for project in ProjectCoordinatorRelation.objects.filter( coordinator_id=coordinator_id): space_key = project.space_key space = confluence.get_space(space_key) space_name = space['name'] data.append({'space_key': space_key, 'space_name': space_name}) resp = init_http_response(RespCode.success.value.key, RespCode.success.value.msg) resp['data'] = data return HttpResponse(json.dumps(resp), content_type="application/json") except: resp = {'code': -1, 'msg': 'error'} return HttpResponse(json.dumps(resp), content_type="application/json")
def get_issues_per_sprint(request, team): try: jira = jira_login(request) resp = init_http_response(RespCode.success.value.key, RespCode.success.value.msg) issues = json.dumps(jira.get_all_project_issues(team, fields='*all')) split = issues.split("[id=") sprint_ids = [] for str in split[1:]: split2 = str.split(",") id = split2[0] if id not in sprint_ids: sprint_ids.append(id) sprint_ids.sort() i = 1 for id in sprint_ids: jql_request = 'Sprint = id' jql_request = jql_request.replace('id', id) issues = jira.jql(jql_request) count_issues_total = issues['total'] resp[i] = count_issues_total i += 1 return HttpResponse(json.dumps(resp), content_type="application/json") except Exception: resp = {'code': -1, 'msg': 'error'} return HttpResponse(json.dumps(resp), content_type="application/json")
def getSpace(request, space_key): """Get a Confluence Space Method: Get Request: space_key """ try: print('session looks like ' + str(request.session.items())) confluence = logIntoConfluence() conf_resp = confluence.get_space( space_key, expand='homepage') conf_homepage = conf_resp['homepage'] data = { 'id': conf_resp['id'], 'key': conf_resp['key'], 'name': conf_resp['name'], 'homepage': { 'id': conf_homepage['id'], 'type': conf_homepage['type'], 'title': conf_homepage['title'], } } resp = init_http_response( RespCode.success.value.key, RespCode.success.value.msg) resp['data'] = data return HttpResponse(json.dumps(resp), content_type="application/json") except: resp = {'code': -1, 'msg': 'error'} return HttpResponse(json.dumps(resp), content_type="application/json")
def get_group_members(request, group): """Get all the members under 'group_name' of the Confluence Space Method: GET Request: group_name """ try: user = request.session.get('user') username = user['atl_username'] password = user['atl_password'] group_name = group confluence = log_into_confluence(username, password) conf_resp = confluence.get_group_members(group_name) data = [] for user in conf_resp: data.append({ # 'type': user['type'], # 'userKey': user['userKey'], # 'profilePicture': user['profilePicture'], 'name': user['displayName'], 'email': user['username'] + "@student.unimelb.edu.au" }) resp = init_http_response(RespCode.success.value.key, RespCode.success.value.msg) resp['data'] = data return HttpResponse(json.dumps(resp), content_type="application/json") except: resp = {'code': -1, 'msg': 'error'} return HttpResponse(json.dumps(resp), content_type="application/json")
def get_user_details(request, member): """Get a specific Confluence Space member's details Method: POST Request: member's username """ user = request.session.get('user') username = user['atl_username'] password = user['atl_password'] try: confluence = log_into_confluence(username, password) conf_resp = confluence.get_user_details_by_username(member) data = { 'type': conf_resp['type'], 'username': conf_resp['username'], 'userKey': conf_resp['userKey'], 'profilePicture': conf_resp['profilePicture'], 'displayName': conf_resp['displayName'] } resp = init_http_response(RespCode.success.value.key, RespCode.success.value.msg) resp['data'] = data return HttpResponse(json.dumps(resp), content_type="application/json") except: resp = {'code': -1, 'msg': 'error'} return HttpResponse(json.dumps(resp), content_type="application/json")
def getPageContributors(request, *args, **kwargs): """Get a Confluence page's contributors Method: Get Request: page_id """ try: confluence = logIntoConfluence() page_id = kwargs['page_id'] # Todo: change these to configurable inputs domain = "https://confluence.cis.unimelb.edu.au" port = "8443" url = f"{domain}:{port}/rest/api/content/{page_id}/history" parameters = {"expand": "contributors.publishers.users"} conf_resp = requests.get( url, params=parameters, auth=HTTPBasicAuth('yho4', 'mil1maci')).json() data = { "createdBy": conf_resp["createdBy"], "createdDate": conf_resp["createdDate"], "contributors": conf_resp["contributors"] } resp = init_http_response( RespCode.success.value.key, RespCode.success.value.msg) resp['data'] = data return HttpResponse(json.dumps(resp), content_type="application/json") except: resp = {'code': -1, 'msg': 'error'} return HttpResponse(json.dumps(resp), content_type="application/json")
def get_subject_supervisors(request, subjectcode, year): user = request.session.get('user') username = user['atl_username'] password = user['atl_password'] try: confluence = log_into_confluence(username, password) conf_resp = confluence.get_all_groups() supervisors = [] data = [] for group in conf_resp: if "staff" in group['name'] and year in group[ 'name'] and subjectcode in group['name']: supervisors = confluence.get_group_members(group['name']) for each in supervisors: data.append({ # 'type': user['type'], # 'userKey': user['userKey'], # 'profilePicture': user['profilePicture'], 'name': each['displayName'], 'email': each['username'] }) resp = init_http_response(RespCode.success.value.key, RespCode.success.value.msg) resp['data'] = data return HttpResponse(json.dumps(resp), content_type="application/json") except: resp = {'code': -1, 'msg': 'error'} return HttpResponse(json.dumps(resp), content_type="application/json")
def get_meeting_minutes(request, space_key): """ return all the meeting minutes titles and links from the specific confluence space step1: get the space_key step2: find all the minutes which have the same space key step3: return the titles and links """ # user = request.session.get('user') # username = user['atl_username'] # password = user['atl_password'] key = space_key try: # find all the meeting minutes which have the specific space key meeting_minutes = MeetingMinutes.objects.filter(space_key=key) data = [] for meeting in meeting_minutes: data.append({ 'title': meeting.meeting_title, 'link': meeting.meeting_link }) resp = init_http_response(RespCode.success.value.key, RespCode.success.value.msg) resp['data'] = data return HttpResponse(json.dumps(resp), content_type="application/json") except: resp = {'code': -1, 'msg': 'error'} return HttpResponse(json.dumps(resp), content_type="application/json")
def update_contributions(jira_url): """Immediately updates jira contribution""" jira = jira_login(request) team = get_url_from_db(jira_url) students, names = get_done_contributor_names(team, jira) count = [] for student in students: count.append( jira.jql('assignee = ' + student + ' AND project = "' + team + '" AND status = "Done"')['total']) result = dict(zip(names, count)) data = [] for name, count in result.items(): data.append({'student': name, 'done_count': count}) if IndividualContributions.objects.filter(space_key=team, student=name).exists(): IndividualContributions.objects.filter( space_key=team, student=name).update(done_count=count) else: jira_obj = IndividualContributions(space_key=team, student=name, done_count=count) jira_obj.save() resp = init_http_response(RespCode.success.value.key, RespCode.success.value.msg) resp['data'] = data return HttpResponse(json.dumps(resp), content_type="application/json")
def get_space(request, space_key): """Get a Confluence Space Method: GET Request: space_key """ user = request.session.get('user') username = user['atl_username'] password = user['atl_password'] try: confluence = log_into_confluence(username, password) conf_resp = confluence.get_space(space_key, expand='homepage') conf_homepage = conf_resp['homepage'] data = { 'id': conf_resp['id'], 'key': conf_resp['key'], 'name': conf_resp['name'], 'homepage': { 'id': conf_homepage['id'], 'type': conf_homepage['type'], 'title': conf_homepage['title'], } } resp = init_http_response(RespCode.success.value.key, RespCode.success.value.msg) resp['data'] = data return HttpResponse(json.dumps(resp), content_type="application/json") except: resp = {'code': -1, 'msg': 'error'} return HttpResponse(json.dumps(resp), content_type="application/json")
def get_issues_per_sprint(request, team): user = request.session.get('user') username = user['atl_username'] password = user['atl_password'] jira = Jira(url='https://jira.cis.unimelb.edu.au:8444', username=username, password=password) resp = init_http_response(RespCode.success.value.key, RespCode.success.value.msg) issues = json.dumps(jira.get_all_project_issues(team, fields='*all')) split = issues.split("[id=") sprint_ids = [] for str in split[1:]: split2 = str.split(",") id = split2[0] if id not in sprint_ids: sprint_ids.append(id) sprint_ids.sort() i = 1 for id in sprint_ids: jql_request = 'Sprint = id' jql_request = jql_request.replace('id', id) issues = jira.jql(jql_request) count_issues_total = issues['total'] resp[i] = count_issues_total i += 1 return HttpResponse(json.dumps(resp), content_type="application/json")
def get_pages_of_space(request, space_key): """Get all the pages under the Confluence Space Method: GET Request: space """ user = request.session.get('user') username = user['atl_username'] password = user['atl_password'] try: confluence = log_into_confluence(username, password) conf_resp = confluence.get_all_pages_from_space(space_key) data = [] for page in conf_resp: data.append({ 'id': page['id'], 'type': page['type'], 'title': page['title'] }) resp = init_http_response(RespCode.success.value.key, RespCode.success.value.msg) resp['data'] = data return HttpResponse(json.dumps(resp), content_type="application/json") except: resp = {'code': -1, 'msg': 'error'} return HttpResponse(json.dumps(resp), content_type="application/json")
def get_issues_team(request, team): """ Return a HttpResponse, data contains count of all categories of issues (of a team)""" try: jira = jira_login(request) total = jira.jql('project = ' + team)['total'] todo = jira.jql('project = ' + team + ' AND status = "To Do"')['total'] in_progress = jira.jql('project = ' + team + ' AND status = "In Progress"')['total'] done = jira.jql('project = ' + team + ' AND status = "Done"')['total'] in_review = jira.jql('project = ' + team + ' AND status = "In Review"')['total'] review = jira.jql('project = ' + team + ' AND status = "Review"')['total'] data = { 'count_issues_total': total, 'count_issues_to_do': todo, 'count_issues_progress': in_progress, 'count_issues_in_review': in_review, 'count_issues_done': done, 'count_issues_review': review } resp = init_http_response(RespCode.success.value.key, RespCode.success.value.msg) resp['data'] = data return HttpResponse(json.dumps(resp), content_type="application/json") except Exception: resp = {'code': -1, 'msg': 'error'} return HttpResponse(json.dumps(resp), content_type="application/json")
def import_project(request, *args, **kwargs): # Method: POST start = time.time() try: json_body = json.loads(request.body) space_key = json_body.get("space_key") # get coordinator_id based on coordinator_name coordinator_id = request.session['coordinator_id'] if len( ProjectCoordinatorRelation.objects.filter( coordinator_id=coordinator_id, space_key=space_key)) == 0: relation = ProjectCoordinatorRelation( coordinator_id=coordinator_id, space_key=space_key) relation.save() Timer(0, insert_space_user_list, args=(space_key, )).start() Timer(0, insert_space_page_history, args=(space_key, )).start() Timer(0, insert_space_meeting, args=(space_key, )).start() resp = init_http_response(RespCode.success.value.key, RespCode.success.value.msg) logger = logging.getLogger('django') logger.info("import project " + space_key + " takes " + str(time.time() - start) + "s") return HttpResponse(json.dumps(resp), content_type="application/json") except Exception as e: tb = sys.exc_info()[2] logger.error(e.with_traceback(tb)) resp = {'code': -1, 'msg': 'error'} return HttpResponse(json.dumps(resp), content_type="application/json")
def get_contributions(request, team): """ Return a HttpResponse, data contains display names and Done Counts""" try: jira = jira_login(request) students, names = get_done_contributor_names( get_project_key(team, jira), jira) team = get_project_key(team, jira) count = [] for student in students: count.append( jira.jql('assignee = ' + student + ' AND project = "' + team + '" AND status = "Done"')['total']) result = dict(zip(names, count)) data = [] for name, count in result.items(): data.append({'student': name, 'done_count': count}) if IndividualContributions.objects.filter(space_key=team, student=name).exists(): IndividualContributions.objects.filter( space_key=team, student=name).update(done_count=count) else: jira_obj = IndividualContributions(space_key=team, student=name, done_count=count) jira_obj.save() resp = init_http_response(RespCode.success.value.key, RespCode.success.value.msg) resp['data'] = data return HttpResponse(json.dumps(resp), content_type="application/json") except Exception: resp = {'code': -1, 'msg': 'error'} return HttpResponse(json.dumps(resp), content_type="application/json")
def get_spaces_by_key(request, key_word): """Get a list of Confluence space keys that contains the key word Method: GET Request: key_word """ username = config.atl_username password = config.atl_password try: confluence = log_into_confluence(username, password) spaces = confluence.get_all_spaces() space_keys = [ space['key'] for space in spaces if key_word.lower() in space['key'].lower() ] while len(spaces) > 0: spaces = confluence.get_all_spaces(start=len(spaces)) space_keys.extend([ space['key'] for space in spaces if key_word.lower() in space['key'].lower() ]) resp = init_http_response(RespCode.success.value.key, RespCode.success.value.msg) resp['data'] = space_keys return HttpResponse(json.dumps(resp), content_type="application/json") except: resp = {'code': -1, 'msg': 'error'} return HttpResponse(json.dumps(resp), content_type="application/json")
def get_sprints_dates(request, team): user = request.session.get('user') username = user['atl_username'] password = user['atl_password'] jira = Jira(url='https://jira.cis.unimelb.edu.au:8444', username=username, password=password) resp = init_http_response(RespCode.success.value.key, RespCode.success.value.msg) issues = json.dumps(jira.get_all_project_issues(team, fields='*all')) pprint(issues) split = issues.split("name=Sprint 1,startDate=", 1) split2 = split[1].split("endDate=", 1) if split[1][:10].startswith('20'): resp['sprint_1_start'] = split[1][:10] else: resp['sprint_1_start'] = "null" if split[1][:10].startswith('20'): resp['sprint_1_end'] = split2[1][:10] else: resp['sprint_1_end'] = "null" split = issues.split("name=Sprint 2,startDate=", 1) split2 = split[1].split("endDate=", 1) if split[1][:10].startswith('20'): resp['sprint_2_start'] = split[1][:10] else: resp['sprint_2_start'] = "null" if split[1][:10].startswith('20'): resp['sprint_2_end'] = split2[1][:10] else: resp['sprint_2_end'] = "null" split = issues.split("name=Sprint 3,startDate=", 1) split2 = split[1].split("endDate=", 1) if split[1][:10].startswith('20'): resp['sprint_3_start'] = split[1][:10] else: resp['sprint_3_start'] = "null" if split[1][:10].startswith('20'): resp['sprint_3_end'] = split2[1][:10] else: resp['sprint_3_end'] = "null" split = issues.split("name=Sprint 4,startDate=", 1) split2 = split[1].split("endDate=", 1) if split[1][:10].startswith('20'): resp['sprint_4_start'] = split[1][:10] else: resp['sprint_4_start'] = "null" if split[1][:10].startswith('20'): resp['sprint_4_end'] = split2[1][:10] else: resp['sprint_4_end'] = "null" return HttpResponse(json.dumps(resp), content_type="application/json")
def get_sprints_dates(request, team): try: jira = jira_login(request) resp = init_http_response(RespCode.success.value.key, RespCode.success.value.msg) issues = json.dumps(jira.get_all_project_issues(team, fields='*all')) split = issues.split("name=Sprint 1,startDate=", 1) split2 = split[1].split("endDate=", 1) if split[1][:10].startswith('20'): resp['sprint_1_start'] = split[1][:10] else: resp['sprint_1_start'] = "null" if split[1][:10].startswith('20'): resp['sprint_1_end'] = split2[1][:10] else: resp['sprint_1_end'] = "null" split = issues.split("name=Sprint 2,startDate=", 1) split2 = split[1].split("endDate=", 1) if split[1][:10].startswith('20'): resp['sprint_2_start'] = split[1][:10] else: resp['sprint_2_start'] = "null" if split[1][:10].startswith('20'): resp['sprint_2_end'] = split2[1][:10] else: resp['sprint_2_end'] = "null" split = issues.split("name=Sprint 3,startDate=", 1) split2 = split[1].split("endDate=", 1) if split[1][:10].startswith('20'): resp['sprint_3_start'] = split[1][:10] else: resp['sprint_3_start'] = "null" if split[1][:10].startswith('20'): resp['sprint_3_end'] = split2[1][:10] else: resp['sprint_3_end'] = "null" split = issues.split("name=Sprint 4,startDate=", 1) split2 = split[1].split("endDate=", 1) if split[1][:10].startswith('20'): resp['sprint_4_start'] = split[1][:10] else: resp['sprint_4_start'] = "null" if split[1][:10].startswith('20'): resp['sprint_4_end'] = split2[1][:10] else: resp['sprint_4_end'] = "null" return HttpResponse(json.dumps(resp), content_type="application/json") except Exception: resp = {'code': -1, 'msg': 'error'} return HttpResponse(json.dumps(resp), content_type="application/json")
def get_total_issues_team(request, team): user = request.session.get('user') username = user['atl_username'] password = user['atl_password'] jira = Jira(url='https://jira.cis.unimelb.edu.au:8444', username=username, password=password) jql_request = 'project = project_name' jql_request = jql_request.replace('project_name', team) issues = jira.jql(jql_request) count_issues_total = issues['total'] jql_request = 'project = project_name AND status = "To Do"' jql_request = jql_request.replace('project_name', team) issues = jira.jql(jql_request) count_issues_to_do = issues['total'] jql_request = 'project = project_name AND status = "In Review"' jql_request = jql_request.replace('project_name', team) issues = jira.jql(jql_request) count_issues_in_review = issues['total'] jql_request = 'project = project_name AND status = "Review"' jql_request = jql_request.replace('project_name', team) issues = jira.jql(jql_request) count_issues_review = issues['total'] jql_request = 'project = project_name AND status = "Done"' jql_request = jql_request.replace('project_name', team) issues = jira.jql(jql_request) count_issues_done = issues['total'] jql_request = 'project = project_name AND status = "In Progress"' jql_request = jql_request.replace('project_name', team) issues = jira.jql(jql_request) count_issues_progress = issues['total'] data = { 'team': team, 'count_issues_total': count_issues_total, 'count_issues_to_do': count_issues_to_do, 'count_issues_progress': count_issues_progress, 'count_issues_in_review': count_issues_in_review, 'count_issues_done': count_issues_done, 'count_issues_review': count_issues_review } resp = init_http_response(RespCode.success.value.key, RespCode.success.value.msg) resp['data'] = data return HttpResponse(json.dumps(resp), content_type="application/json")
def update_subject(request, body, *args, **kwargs): """ :param body: :param request: :param args: :param kwargs: :return: """ subject_id = kwargs.get('id') if not subject_id: resp = init_http_response(RespCode.invalid_parameter.value.key, RespCode.invalid_parameter.value.msg) return make_json_response(HttpResponse, resp) add_subject_dto = AddSubjectDTO() body_extract(body, add_subject_dto) try: subject = Subject.objects.get(subject_id=subject_id, status=Status.valid.value.key) if add_subject_dto.code is not None: subject.subject_code = add_subject_dto.code if add_subject_dto.name is not None: subject.name = add_subject_dto.name if add_subject_dto.coordinator_id is not None: subject.coordinator_id = add_subject_dto.coordinator_id subject.save() except ObjectDoesNotExist as e: resp = init_http_response(RespCode.invalid_parameter.value.key, RespCode.invalid_parameter.value.msg) return make_json_response(HttpResponse, resp) resp = init_http_response(RespCode.success.value.key, RespCode.success.value.msg) return make_json_response(HttpResponse, resp)
def add_subject(request, body, *args, **kwargs): """ :param request: :return: """ add_subject_dto = AddSubjectDTO() body_extract(body, add_subject_dto) # if the parameter is not sufficient if not add_subject_dto.not_empty(): resp = init_http_response(RespCode.invalid_parameter.value.key, RespCode.invalid_parameter.value.msg) return make_json_response(HttpResponseBadRequest, resp) # if the subject code existed if Subject.objects.filter(subject_code=add_subject_dto.code).exists(): resp = init_http_response(RespCode.subject_existed.value.key, RespCode.subject_existed.value.msg) return make_json_response(HttpResponseBadRequest, resp) if not User.objects.filter( user_id=add_subject_dto.coordinator_id).exists(): resp = init_http_response(RespCode.invalid_parameter.value.key, RespCode.invalid_parameter.value.msg) return make_json_response(HttpResponseBadRequest, resp) subject = Subject(subject_code=add_subject_dto.code, name=add_subject_dto.name, coordinator_id=add_subject_dto.coordinator_id, create_date=mills_timestamp(), status=Status.valid.value.key) subject.save() resp = init_http_response(RespCode.success.value.key, RespCode.success.value.msg) return make_json_response(HttpResponse, resp)