Ejemplo n.º 1
0
def viewBugs(request):
    """ Renders a page allowing users to see all the bugs.  If user is an admin, passes along extra details to allow administration of the bugs.
    """
    if request.method != 'GET':
        return HttpResponse("TODO: 404 here.", status=404)

    nbar = NavigationBar()
    context = nbar.generateNavBar(request)
    context.update({'title':"View bug reports"})
    context.update(csrf(request))  # add cross-site request forgery protection
    context.update({'csrfTokenValue':csrf(request)['csrf_token']})  # add the token a second way
    
    # extra content will be rendered if the user is an admin
    if getUserLevel(request.user.id, "") == 3 :
        context.update({'user_is_admin':True})
        context.update({'openBugs': models.BugReport.objects.filter(active__exact=True).filter(status__exact="O").order_by('dateModified')})
        context.update({'deletedBugs': models.BugReport.objects.filter(active__exact=False)})
        context.update({'numDeletedBugs': models.BugReport.objects.filter(active__exact=False).count()})

        
    # add the list of all bugs to the context
    context.update({'allBugs': models.BugReport.objects.filter(active__exact=True)})
    context.update({'bugStati':[('O', 'Open'), ('RF','Resolved - Fixed'), ('RD','Resolved - Duplicate'), ('RI','Resolved - Invalid'),('RW','Resolved - Will Not Fix'),('C','Closed')]})    


    return render_to_response("viewBugs.html", context)
Ejemplo n.º 2
0
def job_two_assets(request):
	navbar = NavigationBar()
	context = navbar.generateNavBar(request, current_app='dcor')
	context['title'] = 'Two Assets Job'
	context.update(csrf(request))  # add cross-site request forgery protection - useful for POST and javascript
	context.update({'csrfTokenValue':csrf(request)['csrf_token']})  # add the token a second way
		
	form = TwoAssetsForm(request.POST or None)
	context['form'] = form
	if request.method == 'POST':
		if form.is_valid():
			# write file in ~/hipercic/apps/dcor/jobs/
			with open('apps/dcor/jobs/job_' + datetime.today().strftime("%Y%m%d_%H%M%S") + '_params.txt', 'w') as params_file:
				params_file.write(str(form.cleaned_data['start_date']) + '\n')
				params_file.write(str(form.cleaned_data['end_date']) + '\n')
				params_file.write(str(form.cleaned_data['asset1']) + ',')
				params_file.write(str(form.cleaned_data['asset2']) + '\n')
				params_file.write(str(form.cleaned_data['per_asset1']) + ',')
				params_file.write(str(form.cleaned_data['per_asset2']) + '\n')
				params_file.write(str(2)) # default value for portofolio_size

			request.session['job_filename'] = params_file.name
			scp = 'scp ' + CURRENT_HOME_FOLDER + '/hipercic/' + params_file.name + ' ' + BACKEND_SERVER_LOCATION + ':' + BACKEND_FOLDER_NAME + '/jobs/'
			return_code_scp = subprocess.call(scp, shell=True)
		
			head, tail = os.path.split(params_file.name)
			cpp = 'ssh ' + BACKEND_SERVER_LOCATION + ' "cd ' + BACKEND_FOLDER_NAME + '; ./dcor jobs/' + tail + '"'
			return_code_cpp = subprocess.call(cpp, shell=True)
			return render(request, 'base_job_result.html', context)

	return render(request, 'base_job_two_assets.html', context)
Ejemplo n.º 3
0
def job_submit(request):
	navbar = NavigationBar()
	context = navbar.generateNavBar(request, current_app='dcor')
	context['title'] = 'Submit'
	context.update(csrf(request))  # add cross-site request forgery protection - useful for POST and javascript
	context.update({'csrfTokenValue':csrf(request)['csrf_token']})  # add the token a second way
	return render(request, 'base_job_submit.html', context)
Ejemplo n.º 4
0
def bugDetails(request):
    """ Displays the details for a bug, with the bug id indicated by the GET data.
    """

    if request.method == 'GET':  # we should render the page
        try:
            nbar = NavigationBar()
            context = nbar.generateNavBar(request)
            context.update({'title':"Bug Details"}) # the basic title
            context.update(csrf(request))  # add cross-site request forgery protection
            context.update({'csrfTokenValue':csrf(request)['csrf_token']})  # add the token a second way
            
            if getUserLevel(request.user.id, ""):
                context.update({'user_is_admin':True})
                
            # try to get the bug to render
                
            theBug = models.BugReport.objects.get(id__exact=int(request.GET['id']))
            context.update({'bug': theBug})
            
            if not theBug.status == "O":
                context.update({'resolveMessageDefault': theBug.resolvedText})
            
            context.update({'title':"Bug " + str(theBug.id) + " - " + theBug.summary}) # change the title
            return render_to_response("bug.html", context)

        except Exception as e:
            return HttpResponse("Error fetching bug report -- " + str(e) + "<br>TODO: replace this with a 404?", status=400)
        

    elif request.method == 'POST':
        try:
            theBug = models.BugReport.objects.get(id__exact=int(request.POST['id']))
            
            theBug.status=request.POST['newStatus']
            theBug.resolvedText=request.POST['resolutionMessage']

            print request.POST['active']
            
            # handle a request to disable the bug
            if request.POST['active'] == 'false':
                theBug.active = False
            else:
                theBug.active = True


            theBug.save()
            
            return HttpResponse("", status=200)
            
        except Exception as e:
            return HttpResponse("Error modifying bug report - " + str(e), status=400)
        
        
    
    return HttpResponse("")
Ejemplo n.º 5
0
 def index(self, request, extra_context=None):
     """
     Displays the main admin index page, which lists all of the installed
     apps that have been registered in this site.
     """
     nav=NavigationBar()
     context = nav.generateNavBar(request)
     #context.update(extra_context or {})
     context_instance = template.RequestContext(request, current_app=self.name)
     return render_to_response(self.index_template or 'admin/index.html', context,
         context_instance=context_instance
     )
Ejemplo n.º 6
0
def job_result(request):
	navbar = NavigationBar()
	context = navbar.generateNavBar(request, current_app='dcor')
	context['title'] = 'Job result'
	context.update(csrf(request))  # add cross-site request forgery protection - useful for POST and javascript
	context.update({'csrfTokenValue':csrf(request)['csrf_token']})  # add the token a second way

	job_filename = request.session['job_filename']
	with open(job_filename, 'r') as job_parameters_file:
		for line_number, line in enumerate(job_parameters_file):
			if line_number == 0:
				context['param_start_date'] = line.rstrip()
			if line_number == 1:
				context['param_stop_date'] = line.rstrip()
			if line_number == 2:
				context['param_assets'] = line.rstrip()
			if line_number == 3:
				context['param_percentages'] = line.rstrip()

	two_assets_mode = False
	if context['param_percentages'] != 'void':
		two_assets_mode = True
		
	if (two_assets_mode):
		context['two_assets_mode'] = 'true' 
	else:
		context['two_assets_mode'] = 'false' 

	job_result_filename = job_filename[:-4] + '_results.txt'
	context['job_result_filename'] = job_result_filename	
	with open(job_result_filename, 'r') as job_result_file:
		for line_number, line in enumerate(job_result_file):
			if line_number == 0:
				context['return_value'] = line.rstrip()
			if line_number == 1:
				context['result_start_date'] = line.rstrip()
			if line_number == 2:
				context['result_stop_date'] = line.rstrip()
			if line_number == 3:
				context['result_combination'] = line.rstrip()
			if line_number == 4:
				context['result_percentages'] = line.rstrip()
			if line_number == 5:
				context['portfolio_distribution'] = '[' + line.rstrip() + ']'
	return render_to_response('base_job_result.html', context)
Ejemplo n.º 7
0
def deletedBugs(request):
    """ Renders a page showing the inactive bugs... but note that the template filters so it only displays for users with proper permissions.
    """
    if request.method != 'GET':
        return HttpResponse("TODO: 404 here.", status=404)

    nbar = NavigationBar()
    context = nbar.generateNavBar(request)
    context.update({'title':"View Inactive Bugs"})
    context.update(csrf(request))  # add cross-site request forgery protection
    context.update({'csrfTokenValue':csrf(request)['csrf_token']})  # add the token a second way
    
    # extra content will be rendered if the user is an admin
    if getUserLevel(request.user.id, "") == 3 :
        context.update({'user_is_admin':True})
        
    # add the list of all bugs to the context -- inactive bugs only!
    context.update({'allBugs': models.BugReport.objects.filter(active__exact=False)})
    
    return render_to_response("deletedBugs.html", context)
Ejemplo n.º 8
0
def submit(request):
    """ Renders the page and handles POST requests for creating a new BugReport
    """
    if request.method == 'GET':  # we should render the page
        nbar = NavigationBar()
        context = nbar.generateNavBar(request)
        context.update({'title':"Write a bug report"})
        context.update(csrf(request))  # add cross-site request forgery protection
        context.update({'csrfTokenValue':csrf(request)['csrf_token']})  # add the token a second way

        # decode the GET data we'll want as default values... which URL are we coming from?
        try:  href = request.GET['href']
        except Exception:  href = ""

        # add default data to context
        context.update({ 'href': href, 'bugTypeChoices': models.BugReport.BUG_TYPE_CHOICES} )
        
        return render_to_response("submit.html", context)

    elif request.method == 'POST':
        # try to decode the POST data to get our information
        try:
            # create the new object!
            newBug = models.BugReport( user = request.user,
                                       webBrowserData = request.POST['webBrowserData'],
                                       hipercicVersion = request.POST['hipercicVersion'],
                                       sourceUrl = request.POST['sourceUrl'],
                                       summary = request.POST['summary'],                                      
                                       reportText = request.POST['reportText'],
                                       bugType = request.POST['bugType'], )

            newBug.save()
            print "bugs/submit: saved new bug id " + str(newBug.id)
            
            return HttpResponse("",status=200)
            
        except Exception as e:
            print "bugs/submit: Error: " + str(e)
            return HttpResponse("Error creating bug object - " + str(e), status=400)
    
    return HttpResponse("Badly formed Http Request to " + str(request.path),status=403)
Ejemplo n.º 9
0
def etf_explanations(request):
	navbar = NavigationBar()
	context = navbar.generateNavBar(request, current_app='dcor')
	context['title'] = 'ETF Explanations'
	return render_to_response('base_etf_explanations.html', context)
Ejemplo n.º 10
0
def glossary(request):
	navbar = NavigationBar()
	context = navbar.generateNavBar(request, current_app='dcor')
	context['title'] = 'Glossary'
	return render_to_response('base_glossary.html', context)
Ejemplo n.º 11
0
def about_project(request):
	navbar = NavigationBar()
	context = navbar.generateNavBar(request, current_app='dcor')
	context['title'] = 'About Project'
	return render_to_response('base_about_project.html', context)