def response(self, request): data = dict(title=self.title, message=self.message, detail=self.detail, traceback=self.traceback) if not request.ajax: data['request'] = request response = render("popup_error.html", request, data) response.status_code = self.error_code return response
def data(request, searchstr = ''): datelist = get_datelist() if searchstr == '': date = datelist[0][0].strftime("%Y-%m-%d") else: date = searchstr dataset = get_data(date) return render("csreport/data.html",request,{ 'dataset': dataset, 'datelist': datelist, 'date': date, 'request': request, })
def updatereport(request): today = datetime.date.today() end_date = today - datetime.timedelta(days=1) start_date = today - datetime.timedelta(days=8) if request.method == "POST": searchstr = request.POST.get("start_date") if searchstr == "": start_date = start_date # return HttpResponseRedirect(urlresolvers.reverse('updatereport')) else: start_date = datetime.datetime.strptime(searchstr, "%Y-%m-%d") searchstr = request.POST.get("end_date") if searchstr == "": end_date = end_date # return HttpResponseRedirect(urlresolvers.reverse('updatereport')) else: end_date = datetime.datetime.strptime(searchstr, "%Y-%m-%d") svnuserset = get_userreport(start_date, end_date) resultset = get_svnreport(start_date, end_date) svnprojects = svnproject.objects.all() svnreportdict = {} for project in svnprojects: if not project.department in svnreportdict: svnreportdict[project.department] = {} for project in svnprojects: svnreportdict[project.department][project.groups] = 0 for row in resultset: svnreportdict[row[0]][row[1]] = int(row[2]) svnreportset = json.dumps(svnreportdict) return render( "svnreport/updatereport.html", request, { "svnuserset": svnuserset, "svnreportdict": svnreportdict, "svnreportset": svnreportset, "end_date": end_date, "start_date": start_date, "request": request, }, )
def data(request, searchstr=""): if searchstr == "": today = datetime.date.today() end_date = today - datetime.timedelta(days=1) start_date = today - datetime.timedelta(days=8) else: result = searchstr_pattern.match(searchstr) start_date, end_date = result.groups(1) start_date = datetime.datetime.strptime(start_date, "%Y-%m-%d") end_date = datetime.datetime.strptime(end_date, "%Y-%m-%d") svndataset = get_svndata(start_date, end_date) return render( "svnreport/data.html", request, {"svndataset": svndataset, "end_date": end_date, "start_date": start_date, "request": request}, )
def process_exception(self, request, exception): import traceback tb = traceback.format_exc() if isinstance(exception, PopupException): return exception.response(request) if isinstance(exception, StructuredException): if request.ajax: response = render_json(exception.response_data) response[MIDDLE_WARE_HEADER] = 'EXCEPTION' response.status_code = getattr(exception, 'error_code', 500) return response else: response = render("error.html", request,dict(error=exception.response_data.get("message"))) response.status_code = getattr(exception, 'error_code', 500) return response return None
def dt_login(request): redirect_to = request.REQUEST.get('next', '/') if request.method == 'POST': data=request.POST if "username" in data and "password" in data: username=data.get("username") password=data.get("password") if username and password : user = auth.authenticate( username=username, password=password ) if user and user.is_active: login(request, user) if request.session.test_cookie_worked(): request.session.delete_test_cookie() return HttpResponseRedirect(redirect_to) else: request.session.set_test_cookie() return render('login.html', request, { 'action': urlresolvers.reverse('codereport.auth.views.dt_login'), 'next': redirect_to, 'login_errors': request.method == 'POST', })
def serve_500_error(request, *args, **kwargs): """Registered handler for 500. We use the debug view to make debugging easier.""" exc_info = sys.exc_info() return render("500.html", request, {'traceback': traceback.extract_tb(exc_info[2])})
def serve_404_error(request, *args, **kwargs): """Registered handler for 404. We just return a simple error""" return render("404.html", request, dict(uri=request.build_absolute_uri()))
def report(request): datelist = get_datelist() date = datelist[0][0].strftime("%Y-%m-%d") if request.method == 'POST': date = request.POST.get('dateselect'); selectdate = date # cpp / java codeline cppcodeline = get_codeline('C/C++',date) javacodeline = get_codeline('Java',date) # cpp /java problem cppproblemline = get_problemline('C/C++',date) javaproblemline = get_problemline('Java',date) # cpp percent cpppercent = [] length = len(cppproblemline) for i in range(length): cpppercent.append([]) for i in range(length): cpppercent[i].append(cppproblemline[i][0]) cpppercent[i].append(float("%.4f" % (1-cppproblemline[i][1]/cppcodeline[i][1])) * 100) # java percent javapercent = [] length = len(javaproblemline) for i in range(length): javapercent.append([]) for i in range(length): javapercent[i].append(javaproblemline[i][0]) javapercent[i].append(float("%.4f" % (1-javaproblemline[i][1]/javacodeline[i][1])) * 100) cppcodeline = json.dumps(cppcodeline) javacodeline = json.dumps(javacodeline) cppproblemline = json.dumps(cppproblemline) javaproblemline = json.dumps(javaproblemline) cpppercent = json.dumps(cpppercent) javapercent = json.dumps(javapercent) #trend info resultset = get_trend() trendset = [] for i in range(0,len(resultset)): trendset.append([]) date = resultset[i][0].strftime("%Y-%m-%d") trendset[i].append(date) trendset[i].append(resultset[i][1]) trendset[i].append(resultset[i][2]) trendset = json.dumps(trendset) return render("csreport/report.html",request,{ 'datelist': datelist, 'date': selectdate, 'cppcodeline': cppcodeline, 'javacodeline': javacodeline, 'cppproblemline': cppproblemline, 'javaproblemline': javaproblemline, 'cpppercent': cpppercent, 'javapercent': javapercent, 'trendset' : trendset, 'request': request, })
def codeline(request): resultset = get_codeline() codelineset = [] for i in range(0, len(resultset)): codelineset.append([]) date = resultset[i][0].strftime("%Y-%m-%d") codelineset[i].append(date) codelineset[i].append(resultset[i][1]) codelineset[i].append(resultset[i][2]) codelineset = json.dumps(codelineset) datelist = get_datelist() date = datelist[0][0].strftime("%Y-%m-%d") departmentdict = {} departmentset = get_department(date) for row in departmentset: (department, language, count) = row if not departmentdict.has_key(department): departmentdict[department] = {} departmentdict[department][language] = count departmentset = json.dumps(departmentdict) # department - groups set dpgroupsdict = {} dpgroupsset = get_department_groups(date) for row in dpgroupsset: (department, groups, count) = row if not dpgroupsdict.has_key(department): dpgroupsdict[department] = {} dpgroupsdict[department][groups] = count dpgroupsset = json.dumps(dpgroupsdict) # languagedict = {} languageset = get_language(date) # for row in languageset: # (language,department,count) = row # if not languagedict.has_key(language): # languagedict[language] = {} # languagedict[language][department]=count languageset = json.dumps(languageset) date = json.dumps(date) count_department = get_count("department", "svnreport_svnproject") count_groups = get_count("groups", "svnreport_svnproject") count_users = get_count("svnuser", "svnreport_svnreport") count_language = get_count("language", "svnreport_codeline") return render( "svnreport/codeline.html", request, { "codelineset": codelineset, "departmentset": departmentset, "dpgroupsset": dpgroupsset, "languageset": languageset, "date": date, "count_department": count_department, "count_groups": count_groups, "count_users": count_users, "count_language": count_language, "request": request, }, )