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)
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("")
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)