def rally_projects(request): if request.method == u"GET" and request.GET.__contains__("chkProject"): pickedProjs = request.GET.getlist("chkProject") isFirst = True projectConfValue = "" for p in pickedProjs: if not isFirst: projectConfValue = projectConfValue + ";" isFirst = False projectConfValue = projectConfValue + p ConfigCache.store_config_value("rally.pickedprojects", projectConfValue) return redirect("/configs/") projects = [] if ConfigCache.get_config_value("rally.enabled") == "1": projlist = rallyintegration.get_projects(True) for project in projlist: projects.append(project) if ConfigCache.get_config_value("agilezen.enabled") == "1": projlist = agilezenintegration.get_projects(True) for project in projlist: projects.append(project) data = {"projects": projects} return render(request, "rally_projects.html", data)
def email_results(batch, failures, runs): long_runners = UnitTestRunResult.objects.filter(test_run__in=runs).order_by('-runtime')[:5] long_runners.select_related() long_runner_classes = UnitTestRun.objects.filter(batch=batch).order_by('-runtime')[:5] long_runner_classes.select_related() try: schedule = UnitTestSchedule.objects.get(branch=batch.branch) except ObjectDoesNotExist: logger.error( 'No Schedule exists for this branch (' + batch.branch.name + '), so no way to figure out who to email') return email_host = ConfigCache.get_config_value('email.host') conn = mail.get_connection(host=email_host) from_address = ConfigCache.get_config_value('email.from') if schedule.email_only_failures and len(failures) == 0: return template = get_template('unit_test_results_email.html') c = Context({'batch': batch, 'failures': failures, 'long_runners': long_runners, 'long_runner_classes': long_runner_classes}) subject = 'Unit test results for ' + batch.branch.name.upper() + ' started at ' + str(batch.batch_time) from_email, to = from_address, schedule.results_email_address text_content = 'Please join the 21st century and get an HTML compatible email client to see the content of this email.' html_content = template.render(c) msg = EmailMultiAlternatives(subject, text_content, from_email, [to]) msg.attach_alternative(html_content, "text/html") msg.connection = conn msg.send(fail_silently=False)
def rally_projects(request): if request.method == u'GET' and request.GET.__contains__('chkProject'): pickedProjs = request.GET.getlist('chkProject') isFirst = True projectConfValue = '' for p in pickedProjs: if not isFirst: projectConfValue = projectConfValue + ';' isFirst = False projectConfValue = projectConfValue + p ConfigCache.store_config_value('rally.pickedprojects', projectConfValue) return redirect('/configs/') projects = [] if ConfigCache.get_config_value('rally.enabled') == '1': projlist = rallyintegration.get_projects(True) for project in projlist: projects.append(project) if ConfigCache.get_config_value('agilezen.enabled') == '1': projlist = agilezenintegration.get_projects(True) for project in projlist: projects.append(project) data = {'projects': projects} return render(request, 'rally_projects.html', data)
def getAgentForBranch(branch, logger=None): if not logger: logger = logging.getLogger('root') user = branch.api_user password = branch.api_pass authkey = branch.api_auth if authkey is None: authkey = '' svcurl = 'https://' + branch.api_env + '.salesforce.com/services/Soap/u/' + CSBase.CS_SF_API_VERSION #branch.api_ver # print("user='******' path='%s' types=[%s] url='%s'", user, path, ' '.join(types), svcurl) partner_wsdl = 'file://' + os.path.join(CSBase.CSCONF_DIR, 'partner.wsdl') meta_wsdl = 'file://' + os.path.join(CSBase.CSCONF_DIR, 'metadata.wsdl') proxy_host = ConfigCache.get_config_value('proxy.host') proxy_port = ConfigCache.get_config_value('proxy.port') if len(proxy_host) > 0 and len(proxy_port) > 0: agent = SalesforceAgent(partner_wsdl, meta_wsdl, clientLogger=logger, proxy_host=proxy_host, proxy_port=proxy_port) else: agent = SalesforceAgent(partner_wsdl, meta_wsdl, clientLogger=logger) agent.login(user, password + authkey, server_url=svcurl) return agent
def refresh(): projectList = ConfigCache.get_config_value('rally.pickedprojects') #print 'project list: '+projectList if len(projectList) > 0: rallyStories = get_stories(projectList.split(';')) dbstories = Story.objects.filter(rally_id__in=rallyStories.keys()) dbStoryMap = {} for dbstory in dbstories: #print 'storing story %d' % int(dbstory.rally_id) dbStoryMap[int(dbstory.rally_id)] = dbstory for story in rallyStories.values(): dbstory = story if story.rally_id in dbStoryMap: #print 'match found %d' % story.rally_id logger.debug('Updating [%d]' % story.rally_id) # Override with database version if it exists dbstory = dbStoryMap[story.rally_id] dbstory.url = story.url dbstory.name = story.name dbstory.sprint = story.sprint else: #print 'no match found %d' % story.rally_id logger.debug('Creating [%d]' % story.rally_id) dbstory.sprint = story.sprint dbstory.save()
def configs(request): allsettings = ConfigSetting.objects.all() if request.method == u'POST': params = dict(request.POST.items()) for param in params: if param.startswith('key_'): key = smart_str(param, 'utf-8', False)[4:] value = request.POST[param] for setting in allsettings: if key == setting.key: if setting.value != value: if setting.masked: # only proceed with update if masked value is not empty if value != '': repValue = request.POST[param + '_2'] logger.debug( 'Checking if the values match!') if repValue == value: logger.debug('Values Match!') setting.value = value setting.save() else: setting.value = value setting.save() # Handle checkboxes for setting in allsettings: if setting.type == 'check': if not request.POST.__contains__('key_' + setting.key): setting.value = '0' setting.save() ConfigCache.refresh() allsettings = ConfigSetting.objects.all() return render(request, 'home.html') data = {'settings': allsettings.order_by('key')} for setting in allsettings: if setting.type == 'check': data[setting.key.replace('.', '_')] = setting.value == '1' else: data[setting.key.replace('.', '_')] = setting.value return render(request, 'configs.html', data)
def configs(request): allsettings = ConfigSetting.objects.all() if request.method == u"POST": params = dict(request.POST.items()) for param in params: if param.startswith("key_"): key = smart_str(param, "utf-8", False)[4:] value = request.POST[param] for setting in allsettings: if key == setting.key: if setting.value != value: if setting.masked: # only proceed with update if masked value is not empty if value != "": repValue = request.POST[param + "_2"] logger.debug("Checking if the values match!") if repValue == value: logger.debug("Values Match!") setting.value = value setting.save() else: setting.value = value setting.save() # Handle checkboxes for setting in allsettings: if setting.type == "check": if not request.POST.__contains__("key_" + setting.key): setting.value = "0" setting.save() ConfigCache.refresh() allsettings = ConfigSetting.objects.all() return render(request, "home.html") data = {"settings": allsettings.order_by("key")} for setting in allsettings: if setting.type == "check": data[setting.key.replace(".", "_")] = setting.value == "1" else: data[setting.key.replace(".", "_")] = setting.value return render(request, "configs.html", data)
def email_results(batch, failures, runs): long_runners = UnitTestRunResult.objects.filter( test_run__in=runs).order_by('-runtime')[:5] long_runners.select_related() long_runner_classes = UnitTestRun.objects.filter( batch=batch).order_by('-runtime')[:5] long_runner_classes.select_related() try: schedule = UnitTestSchedule.objects.get(branch=batch.branch) except ObjectDoesNotExist: logger.error('No Schedule exists for this branch (' + batch.branch.name + '), so no way to figure out who to email') return email_host = ConfigCache.get_config_value('email.host') conn = mail.get_connection(host=email_host) from_address = ConfigCache.get_config_value('email.from') if schedule.email_only_failures and len(failures) == 0: return template = get_template('unit_test_results_email.html') # c = Context({'batch': batch, 'failures': failures, 'long_runners': long_runners, # 'long_runner_classes': long_runner_classes}) c = { 'batch': batch, 'failures': failures, 'long_runners': long_runners, 'long_runner_classes': long_runner_classes } subject = 'Unit test results for ' + batch.branch.name.upper( ) + ' started at ' + str(batch.batch_time) from_email, to = from_address, schedule.results_email_address text_content = 'Please join the 21st century and get an HTML compatible email client to see the content of this email.' html_content = template.render(c) msg = EmailMultiAlternatives(subject, text_content, from_email, [to]) msg.attach_alternative(html_content, "text/html") msg.connection = conn msg.send(fail_silently=False)
def getAgentForBranch(branch, logger = None): if not logger: logger = logging.getLogger('root') user = branch.api_user password = branch.api_pass authkey = branch.api_auth if authkey is None: authkey = '' svcurl = 'https://' + branch.api_env + '.salesforce.com/services/Soap/u/' + CSBase.CS_SF_API_VERSION #branch.api_ver # print("user='******' path='%s' types=[%s] url='%s'", user, path, ' '.join(types), svcurl) partner_wsdl = 'file://' + os.path.join(CSBase.CSCONF_DIR, 'partner.wsdl') meta_wsdl = 'file://' + os.path.join(CSBase.CSCONF_DIR, 'metadata.wsdl') proxy_host = ConfigCache.get_config_value('proxy.host') proxy_port = ConfigCache.get_config_value('proxy.port') if len(proxy_host) > 0 and len(proxy_port) > 0: agent = SalesforceAgent(partner_wsdl, meta_wsdl, clientLogger=logger, proxy_host=proxy_host, proxy_port=proxy_port) else: agent = SalesforceAgent(partner_wsdl, meta_wsdl, clientLogger=logger) agent.login(user, password+authkey,server_url=svcurl) return agent
def get_projects(leaves): logger.debug('Start getting projects') projurl = agileurl+apiurl+'projects' #?' #+ get_page_query_params(1, 200) logger.debug('Retrieving Projects from URL: '+projurl) rest_header['X-Zen-ApiKey'] = ConfigCache.get_config_value('agilezen.apikey') response = requests.get(projurl, headers=rest_header) project_list = {} try: project_list = (response.json())[u'items'] print_proj_tree(project_list) except: logger.debug('No Results Returned') return project_list
def get_projects(leaves): logger.debug('Start getting projects') projurl = agileurl + apiurl + 'projects' #?' #+ get_page_query_params(1, 200) logger.debug('Retrieving Projects from URL: ' + projurl) rest_header['X-Zen-ApiKey'] = ConfigCache.get_config_value( 'agilezen.apikey') response = requests.get(projurl, headers=rest_header) project_list = {} try: project_list = (response.json())[u'items'] print_proj_tree(project_list) except: logger.debug('No Results Returned') return project_list
def get_stories(projectIds): stories = {} start = 1 pagesize = 200 for projId in projectIds: lastPage = False page = start while not (lastPage): storyurl = agileurl + apiurl + 'projects/' + projId + '/stories?' + get_page_query_params( page, pagesize) logger.debug('Retrieving Stories from URL: ' + storyurl) rest_header['X-Zen-ApiKey'] = ConfigCache.get_config_value( 'agilezen.apikey') response = requests.get(storyurl, headers=rest_header) processed_response = response.json() story_list = processed_response[u'items'] count = len(story_list) #processed_response[u'totalItems'] for result in story_list: #print result phase = result[u'phase'] ignorestates = [ u'Backlog', u'Ready', u'Archive', u'Release Candidate / Production' ] if not phase[u'name'] in ignorestates: story = Story() story.rally_id = result[u'id'] story.name = result[u'text'][0:100] story.sprint = result[u'text'][0:3] story.url = agileurl + 'project/' + projId + '/story/%d' % result[ u'id'] try: story.sprint = '%s - %s' % (projId, result[u'deadline']) #story.release_date = result[u'deadline'] except: story.sprint = '%s' % projId logger.debug('no deadline for story %d' % story.rally_id) stories[story.rally_id] = story if count == 0: lastPage = True page += 1 return stories
def get_stories(projectIds): stories = {} start = 1 pagesize = 200 for projId in projectIds: lastPage = False page = start while not(lastPage): storyurl = agileurl+apiurl+'projects/'+ projId +'/stories?'+ get_page_query_params(page, pagesize) logger.debug('Retrieving Stories from URL: '+storyurl) rest_header['X-Zen-ApiKey'] = ConfigCache.get_config_value('agilezen.apikey') response = requests.get(storyurl, headers=rest_header) processed_response = response.json() story_list = processed_response[u'items'] count = len(story_list) #processed_response[u'totalItems'] for result in story_list: #print result phase = result[u'phase'] ignorestates = [u'Backlog', u'Ready', u'Archive', u'Release Candidate / Production'] if not phase[u'name'] in ignorestates: story = Story() story.rally_id = result[u'id'] story.name = result[u'text'][0:100] story.sprint = result[u'text'][0:3] story.url = agileurl+'project/'+ projId +'/story/%d'%result[u'id'] try: story.sprint = '%s - %s' % (projId, result[u'deadline']) #story.release_date = result[u'deadline'] except: story.sprint = '%s'%projId logger.debug('no deadline for story %d'%story.rally_id) stories[story.rally_id] = story if count == 0: lastPage = True page += 1 return stories
def refresh(): projectList = ConfigCache.get_config_value('rally.pickedprojects') logger.debug('projectList:') logger.debug(projectList) if len(projectList) > 0: rallyStories = get_stories(projectList.split(';')) dbstories = Story.objects.filter(rally_id__in=rallyStories.keys()) dbStoryMap = {} for dbstory in dbstories: dbStoryMap[dbstory.rally_id] = dbstory for story in rallyStories.values(): dbstory = story if story.rally_id in dbStoryMap: #logger.debug('Updating [' + story.rally_id + ']') # Override with database version if it exists dbstory = dbStoryMap[story.rally_id] dbstory.name = story.name #else: #logger.debug('Creating [' + story.rally_id + ']') dbstory.sprint = story.sprint dbstory.save()
def stories(request): if request.method == u'POST' and request.POST.__contains__('releaseid'): release = Release.objects.get(id=request.POST['releaseid']) if request.POST.__contains__('storyId'): ids = request.POST.getlist('storyId') sprint_name = request.POST['cboSprints'] print('sprint_name ' + sprint_name) if sprint_name != '': for story in release.stories.all(): if story.sprint == sprint_name: print('removing ' + story.name) release.stories.remove(story) else: release.stories.clear() stories = Story.objects.filter(id__in=ids) for s in stories.all(): if s not in release.stories.all(): # this print was causing a unicode issue adding a story, so commented out # print 'adding ' + s.name release.stories.add(s) release.save() return redirect('/release/' + str(release.id)) if request.method == u'GET' and request.GET.__contains__('delete'): story = Story.objects.get(id=request.GET['delete']) objects = DeployableObject.objects.filter(pending_stories=story) for object in objects: object.pending_stories.remove(story) object.save() story.delete() if request.method == u'GET' and request.GET.__contains__('refresh'): if ConfigCache.get_config_value('agilezen.enabled') == '1': agilezenintegration.refresh() if ConfigCache.get_config_value('rally.enabled') == '1': rallyintegration.refresh() releaseid = '' in_release = {} if request.method == u'GET' and request.GET.__contains__('releaseid'): releaseid = request.GET['releaseid'] if len(releaseid) > 0: release = Release.objects.get(id=request.GET['releaseid']) for story in release.stories.all(): in_release[story.id] = True sprint = '' if request.method == u'GET' and request.GET.__contains__('sprint'): sprint = request.GET['sprint'] sprintList = [] oneYear = timedelta(days=365) oneYearAgo = datetime.now() - oneYear if request.method == u'GET' and request.GET.__contains__('history'): sprints = Story.objects.values('sprint').filter( sprint__isnull=False).order_by('sprint').distinct() else: sprints = Story.objects.values('sprint').filter( sprint__isnull=False, date_added__gte=oneYearAgo).order_by('sprint').distinct() for sprintName in sprints: if len(sprintName['sprint']) > 0 and not sprintList.__contains__( sprintName['sprint']): sprintList.append(sprintName['sprint']) if request.method == u'GET' and request.GET.__contains__('history'): stories = Story.objects.all() else: stories = Story.objects.filter(date_added__gte=oneYearAgo) if len(sprint) > 0: stories = stories.filter(sprint=sprint) stories = stories.order_by('sprint', 'rally_id', 'name') # Need to cast the rally_id to prevent duplicate stories from coming over # different SQL needed for mySQL and SQLite ## MySQL compatible call if ConfigCache.get_config_value('agilezen.enabled') == '1': stories = stories.extra(select={ 'rally_id': 'CAST(rally_id AS SIGNED)' }).extra(order_by=['rally_id']) ## SQLite compatible call # stories = stories.extra(select={'rally_id': 'CAST(rally_id AS INTEGER)'}).extra(order_by = ['rally_id']) stories.select_related() stories_refresh_enabled = ( ConfigCache.get_config_value('rally.enabled') == '1') or (ConfigCache.get_config_value('agilezen.enabled') == '1') data = { 'stories': stories, 'rally_refresh': stories_refresh_enabled, 'releaseid': releaseid, 'in_release': in_release, 'sprintList': sprintList, 'sprint': sprint } return render(request, 'stories.html', data)
def connect(): rally_user = ConfigCache.get_config_value('rally.login') rally_pass = ConfigCache.get_config_value('rally.password') session = Rally(settings.RALLY_SERVER, rally_user, rally_pass) logger.debug('Logging in with username ' + rally_user) return session
def unreleased(request, repo_name, branch_name): branch = Branch.objects.get(repo__name=repo_name, name=branch_name) if request.method == u'GET' and request.GET.__contains__( 'releaseAll') and request.GET['releaseAll'] == 'true': deltas = Delta.objects.exclude(object__release_status='r').filter( object__branch=branch) deltas.select_related() for delta in deltas.all(): delta.object.release_status = 'r' delta.object.save() go = '' search = '' username = '' typeFilter = '' endDate = date.today() startDate = endDate + timedelta(days=-14) objectTypesData = DeployableObject.objects.values('type').order_by( 'type').distinct() objectTypes = list() for type in objectTypesData: if type['type'] != '': objectTypes.append(type['type']) if request.method == u'GET': if request.GET.__contains__('go'): go = 'true' if request.GET.__contains__('search'): search = request.GET['search'] if request.GET.__contains__('username'): username = request.GET['username'] if request.GET.__contains__('startDate'): startDate = datetime.strptime(request.GET['startDate'], "%m/%d/%Y") if request.GET.__contains__('endDate'): endDate = datetime.strptime(request.GET['endDate'], "%m/%d/%Y") if request.GET.__contains__('type'): typeFilter = request.GET['type'] uiEndDate = endDate endDate = endDate + timedelta(days=1) deltas = [] objects = [] deltaMap = {} user = '' changeDate = '' if request.GET.__contains__('go'): deltas = Delta.objects.filter(object__branch=branch).filter( commit__date_added__gte=startDate).filter( commit__date_added__lte=endDate) if len(username) > 0: deltas = deltas.filter(user_change__sfuser__name=username) if len(search) > 0: deltas = deltas.extra(where=[ '(filename LIKE \'%%' + search + '%%\' or type LIKE \'%%' + search + '%%\' or el_type LIKE \'%%' + search + '%%\' or el_subtype LIKE \'%%' + search + '%%\' or el_name LIKE \'%%' + search + '%%\')' ]) if len(typeFilter) > 0: deltas = deltas.extra(where=['type = \'' + typeFilter + '\'']) deltas = deltas.order_by('object__type', 'object__filename', 'object__el_type', 'object__el_subtype', 'object__el_name', 'commit__date_added') logger.debug('Deltas SQL ' + str(deltas.query)) deltas.select_related() for delta in deltas.all(): changelog = deltaMap.get(delta.object) if delta.user_change and delta.user_change.sfuser.name != '': user = '******' + delta.user_change.sfuser.name changeDate = ' at ' + str(delta.user_change.last_update)[:16] else: user = '' changeDate = '' if changelog: if not changelog.endswith(delta.getDeltaType() + user + changeDate): changelog += '\n' + delta.getDeltaType( ) + user + changeDate deltaMap[delta.object] = changelog else: objects.append(delta.object) deltaMap[ delta.object] = delta.getDeltaType() + user + changeDate userList = SalesforceUser.objects.values('name').order_by( 'name').distinct() users = [u['name'] for u in userList] annotations = [] if ConfigCache.get_config_value('show.todo') == '1': todofile = os.path.join(branch.repo.location, '..', 'annotations_' + branch.name + '.txt') try: if os.path.exists(todofile): with open(todofile, 'r') as f: annotations = json.loads(f.read())['annotations'] except: pass data = { 'branch_name': branch_name, 'repo_name': branch.repo.name, 'objects': objects, 'startDate': startDate, 'endDate': uiEndDate, 'deltaMap': deltaMap, 'namestl': namestl, 'users': users, 'search': search, 'username': username, 'go': go, 'objectTypes': objectTypes, 'selectedType': typeFilter, 'todos': annotations } return render(request, 'unreleased.html', data)
def unreleased(request, repo_name, branch_name): branch = Branch.objects.get(repo__name=repo_name, name=branch_name) if request.method == u"GET" and request.GET.__contains__("releaseAll") and request.GET["releaseAll"] == "true": deltas = Delta.objects.exclude(object__release_status="r").filter(object__branch=branch) deltas.select_related() for delta in deltas.all(): delta.object.release_status = "r" delta.object.save() go = "" search = "" username = "" typeFilter = "" endDate = date.today() startDate = endDate + timedelta(days=-14) objectTypesData = DeployableObject.objects.values("type").order_by("type").distinct() objectTypes = list() for type in objectTypesData: if type["type"] != "": objectTypes.append(type["type"]) if request.method == u"GET": if request.GET.__contains__("go"): go = "true" if request.GET.__contains__("search"): search = request.GET["search"] if request.GET.__contains__("username"): username = request.GET["username"] if request.GET.__contains__("startDate"): startDate = datetime.strptime(request.GET["startDate"], "%m/%d/%Y") if request.GET.__contains__("endDate"): endDate = datetime.strptime(request.GET["endDate"], "%m/%d/%Y") if request.GET.__contains__("type"): typeFilter = request.GET["type"] uiEndDate = endDate endDate = endDate + timedelta(days=1) deltas = [] objects = [] deltaMap = {} user = "" changeDate = "" if request.GET.__contains__("go"): deltas = ( Delta.objects.filter(object__branch=branch) .filter(commit__date_added__gte=startDate) .filter(commit__date_added__lte=endDate) ) if len(username) > 0: deltas = deltas.filter(user_change__sfuser__name=username) if len(search) > 0: deltas = deltas.extra( where=[ "(filename LIKE '%%" + search + "%%' or type LIKE '%%" + search + "%%' or el_type LIKE '%%" + search + "%%' or el_subtype LIKE '%%" + search + "%%' or el_name LIKE '%%" + search + "%%')" ] ) if len(typeFilter) > 0: deltas = deltas.extra(where=["type = '" + typeFilter + "'"]) deltas = deltas.order_by( "object__type", "object__filename", "object__el_type", "object__el_subtype", "object__el_name", "commit__date_added", ) logger.debug("Deltas SQL " + str(deltas.query)) deltas.select_related() for delta in deltas.all(): changelog = deltaMap.get(delta.object) if delta.user_change and delta.user_change.sfuser.name != "": user = "******" + delta.user_change.sfuser.name changeDate = " at " + str(delta.user_change.last_update)[:16] else: user = "" changeDate = "" if changelog: if not changelog.endswith(delta.getDeltaType() + user + changeDate): changelog += "\n" + delta.getDeltaType() + user + changeDate deltaMap[delta.object] = changelog else: objects.append(delta.object) deltaMap[delta.object] = delta.getDeltaType() + user + changeDate userList = SalesforceUser.objects.values("name").order_by("name").distinct() users = [u["name"] for u in userList] annotations = [] if ConfigCache.get_config_value("show.todo") == "1": todofile = os.path.join(branch.repo.location, "..", "annotations_" + branch.name + ".txt") try: if os.path.exists(todofile): with open(todofile, "r") as f: annotations = json.loads(f.read())["annotations"] except: pass data = { "branch_name": branch_name, "repo_name": branch.repo.name, "objects": objects, "startDate": startDate, "endDate": uiEndDate, "deltaMap": deltaMap, "namestl": namestl, "users": users, "search": search, "username": username, "go": go, "objectTypes": objectTypes, "selectedType": typeFilter, "todos": annotations, } return render(request, "unreleased.html", data)
def stories(request): if request.method == u"POST" and request.POST.__contains__("releaseid"): release = Release.objects.get(id=request.POST["releaseid"]) if request.POST.__contains__("storyId"): ids = request.POST.getlist("storyId") sprint_name = request.POST["cboSprints"] print("sprint_name " + sprint_name) if sprint_name != "": for story in release.stories.all(): if story.sprint == sprint_name: print("removing " + story.name) release.stories.remove(story) else: release.stories.clear() stories = Story.objects.filter(id__in=ids) for s in stories.all(): if s not in release.stories.all(): # this print was causing a unicode issue adding a story, so commented out # print 'adding ' + s.name release.stories.add(s) release.save() return redirect("/release/" + str(release.id)) if request.method == u"GET" and request.GET.__contains__("delete"): story = Story.objects.get(id=request.GET["delete"]) objects = DeployableObject.objects.filter(pending_stories=story) for object in objects: object.pending_stories.remove(story) object.save() story.delete() if request.method == u"GET" and request.GET.__contains__("refresh"): if ConfigCache.get_config_value("agilezen.enabled") == "1": agilezenintegration.refresh() if ConfigCache.get_config_value("rally.enabled") == "1": rallyintegration.refresh() releaseid = "" in_release = {} if request.method == u"GET" and request.GET.__contains__("releaseid"): releaseid = request.GET["releaseid"] if len(releaseid) > 0: release = Release.objects.get(id=request.GET["releaseid"]) for story in release.stories.all(): in_release[story.id] = True sprint = "" if request.method == u"GET" and request.GET.__contains__("sprint"): sprint = request.GET["sprint"] sprintList = [] oneYear = timedelta(days=365) oneYearAgo = datetime.now() - oneYear if request.method == u"GET" and request.GET.__contains__("history"): sprints = Story.objects.values("sprint").filter(sprint__isnull=False).order_by("sprint").distinct() else: sprints = ( Story.objects.values("sprint") .filter(sprint__isnull=False, date_added__gte=oneYearAgo) .order_by("sprint") .distinct() ) for sprintName in sprints: if len(sprintName["sprint"]) > 0 and not sprintList.__contains__(sprintName["sprint"]): sprintList.append(sprintName["sprint"]) if request.method == u"GET" and request.GET.__contains__("history"): stories = Story.objects.all() else: stories = Story.objects.filter(date_added__gte=oneYearAgo) if len(sprint) > 0: stories = stories.filter(sprint=sprint) stories = stories.order_by("sprint", "rally_id", "name") # Need to cast the rally_id to prevent duplicate stories from coming over # different SQL needed for mySQL and SQLite ## MySQL compatible call if ConfigCache.get_config_value("agilezen.enabled") == "1": stories = stories.extra(select={"rally_id": "CAST(rally_id AS SIGNED)"}).extra(order_by=["rally_id"]) ## SQLite compatible call # stories = stories.extra(select={'rally_id': 'CAST(rally_id AS INTEGER)'}).extra(order_by = ['rally_id']) stories.select_related() stories_refresh_enabled = (ConfigCache.get_config_value("rally.enabled") == "1") or ( ConfigCache.get_config_value("agilezen.enabled") == "1" ) data = { "stories": stories, "rally_refresh": stories_refresh_enabled, "releaseid": releaseid, "in_release": in_release, "sprintList": sprintList, "sprint": sprint, } return render(request, "stories.html", data)