On 28/07/2010 18:22, Kieran Farr wrote: > Thanks, David -- you're right on, now I just return an HttpResponse > with result code 404. > > Benedict, could you post the view for /management/statistics/top/user/ > yearly/ that is causing the 403? > > Kieran >
Yes, here it is. Depending on wether the user logged in is staff (ICT) or not, i use a different base toe extend my template from (different menu). @csrf_exempt def stats_top_callers_per_year(request): if ( request.user.is_staff ): extends_from = "management/base.html" else: extends_from = "management/public_base.html" stat_type = "top_callers_per_year" stats_all = {} message=_(u"Top 30 callers per year") class Stats(object): pass current_year = datetime.datetime.now().year archive_year = current_year - 4 years = xrange(archive_year, current_year+1) for year in years: stats_year = [] counts = {} # Initialize count dict # If we don't do this, we get a KeyError for user in User.objects.all(): counts[user]=0 # Count the times an initiator has been calling for i in Call.objects.filter(date_created__year=year): for _init in i.initiator.all(): counts[_init] += 1 # Sort the dictionary count_sorted = sorted(counts.items(), lambda x, y: cmp(x[1], y[1]), reverse=True) # Make the stats ready for the template for user_stat in count_sorted[0:30]: if ( user_stat[1] > 0 ): st = Stats() st.calls = user_stat[1] st.user = user_stat[0] stats_year.append(st) stats_all[year]=stats_year stats_sorted = sorted(stats_all.items(), lambda x, y: cmp(x[0], y[0]), reverse=True) return render_to_response('management/stats.html', {'extends_from': extends_from, 'stats_year': stats_sorted, 'message': message, 'stat': stat_type, 'tab': "top_callers_per_year"}, context_instance=RequestContext(request)) My goal is to be able to automatically login (seems to work) and then call this function so the page is generated before any user hits the page. Regards, Benedict -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.