Browse Source

Fix VPN graphs

Baptiste Jonglez 10 years ago
parent
commit
ea9599e63b
1 changed files with 5 additions and 4 deletions
  1. 5 4
      coin/vpn/views.py

+ 5 - 4
coin/vpn/views.py

@@ -2,6 +2,7 @@ import os
 from urllib2 import urlopen
 
 from django.contrib.auth.models import User
+from django.http import HttpResponse
 from django.shortcuts import render_to_response, get_object_or_404
 from django.views.generic.detail import DetailView
 from django.conf import settings
@@ -37,7 +38,7 @@ def get_graph(request, vpn_id, period="daily"):
     """ This get the graph for the associated vpn_id and time period
     """
     vpn = get_object_or_404(VPNSubscription, pk=vpn_id,
-                            administrative_subscription__member__user=request.user)
+                            administrative_subscription__member__user=request.user.id)
     
     time_periods = { 'daily': '-24hours', 'weekly': '-8days', 'monthly': '-32days', 'yearly': '-13months', }
     if period not in time_periods:
@@ -45,8 +46,8 @@ def get_graph(request, vpn_id, period="daily"):
 
     graph_url = os.path.join(settings.GRAPHITE_SERVER,
                 "render/?width=586&height=308&from=%(period)s&" \
-                "target=alias%28scaleToSeconds%28vpn1.%(login)s.downrxbytes%2C1%29%2C%20%22Download%22%29&" \
-                "target=alias%28scaleToSeconds%28vpn1.%(login)s.uptxbytes%2C1%29%2C%20%22Upload%22%29&" \
-                "title=VPN%20Usage%20%(login)s" % \
+                "target=alias%%28scaleToSeconds%%28vpn1.%(login)s.downrxbytes%%2C1%%29%%2C%%20%%22Download%%22%%29&" \
+                "target=alias%%28scaleToSeconds%%28vpn1.%(login)s.uptxbytes%%2C1%%29%%2C%%20%%22Upload%%22%%29&" \
+                "title=VPN%%20Usage%%20%(login)s" % \
                     { 'period': time_periods[period], 'login': vpn.login })
     return HttpResponse(urlopen(graph_url), mimetype="image/png")