From f6d6ed3eb1f778545c819fa93a7e664ed5c4e445 Mon Sep 17 00:00:00 2001 From: jordan Date: Wed, 20 Apr 2011 14:07:16 +0000 Subject: [PATCH] creating some views for the update checker and creating the functions that get the statistics, creating the skeleton of the statistics XML data dump git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@995 0cfe37f9-358a-4d5e-be75-b63607b5c754 --- forum_modules/updater/base.py | 36 ++++++++++++++++- forum_modules/updater/startup.py | 1 + forum_modules/updater/templates/index.html | 14 +++++++ forum_modules/updater/urls.py | 4 +- forum_modules/updater/views.py | 45 +++++++++++++++++++++- 5 files changed, 95 insertions(+), 5 deletions(-) create mode 100644 forum_modules/updater/startup.py diff --git a/forum_modules/updater/base.py b/forum_modules/updater/base.py index 74d37e5..995c70c 100644 --- a/forum_modules/updater/base.py +++ b/forum_modules/updater/base.py @@ -1,6 +1,40 @@ import string import random +import re + +import urllib2 + +from forum.models import Question +from forum.settings import APP_URL def generate_installation_key(): gen = lambda length: "".join( [random.choice(string.digits+string.letters) for i in xrange(length)]) - return '%s-%s-%s-%s' % (gen(4), gen(4), gen(4), gen(4)) \ No newline at end of file + return '%s-%s-%s-%s' % (gen(4), gen(4), gen(4), gen(4)) + +# To get the site views count we get the SUM of all questions views. +def get_site_views(): + views = 0 + + # Go through all questions and increase the views count + for question in Question.objects.all(): + views += question.view_count + + return views + +def get_server_name(): + url = '%s/' % APP_URL + + try: + # Make the request + request = urllib2.Request(url) + response = urllib2.urlopen(request) + + # Get the response information + response_info = response.info() + + server_name = re.findall("Server: (?P.*)$", str(response_info))[0] + server_name = ''.join(server_name.splitlines()) + + return server_name + except: + return 'Unknown' diff --git a/forum_modules/updater/startup.py b/forum_modules/updater/startup.py new file mode 100644 index 0000000..4164248 --- /dev/null +++ b/forum_modules/updater/startup.py @@ -0,0 +1 @@ +import views diff --git a/forum_modules/updater/templates/index.html b/forum_modules/updater/templates/index.html index 1ddb980..04f20af 100644 --- a/forum_modules/updater/templates/index.html +++ b/forum_modules/updater/templates/index.html @@ -2,6 +2,18 @@ {% load i18n %} +{% block adminjs %} +{{ block.super }} + +{% endblock %} + {% block subtitle %} {% trans "Update Checker" %} {% endblock %} @@ -11,4 +23,6 @@ {% block admincontent %} +{% trans "Check for Updates" %} + {% endblock %} diff --git a/forum_modules/updater/urls.py b/forum_modules/updater/urls.py index 300a589..c3a6c4c 100644 --- a/forum_modules/updater/urls.py +++ b/forum_modules/updater/urls.py @@ -2,8 +2,8 @@ from django.conf.urls.defaults import * from django.views.generic.simple import direct_to_template from django.utils.translation import ugettext as _ -from views import updater_index +from views import updater_index, updater_check urlpatterns = patterns('', - url(r'^%s%s$' % (_('admin/'), _('updater/')), updater_index, name='updater_index'), + url(r'^%s%s%s$' % (_('admin/'), _('updater/'), _('check/')), updater_check, name='updater_check'), ) diff --git a/forum_modules/updater/views.py b/forum_modules/updater/views.py index 60c8f92..2589528 100644 --- a/forum_modules/updater/views.py +++ b/forum_modules/updater/views.py @@ -1,9 +1,16 @@ +import sys + +from django import VERSION as DJANGO_VERSION from django.http import HttpResponse -from base import generate_installation_key +from django.utils.translation import ugettext as _ +from django.utils import simplejson + +from base import get_site_views, get_server_name from settings import SITE_KEY +from forum.settings import APP_URL, SVN_REVISION from forum.views.admin import admin_tools_page, admin_page -@admin_page +@admin_tools_page(_('updater'), _('Update Checker')) def updater_index(request): return ( 'modules/updater/index.html', @@ -11,3 +18,37 @@ def updater_index(request): }, ) + +def updater_check(request): + # Get the SVN Revision + try: + svn_revision = int(SVN_REVISION.replace('SVN-', '')) + except ValueError: + # Here we'll have to find another way of getting the SVN revision + svn_revision = 0 + + statistics = """ + + + + + + + + + + + """ % { + 'site_key' : SITE_KEY, + 'app_url' : APP_URL, + 'svn_revision' : svn_revision, + 'site_views' : get_site_views(), + 'server_name' : get_server_name(), + 'python_version' : ''.join(sys.version.splitlines()), + 'django_version' : str(DJANGO_VERSION), + } + return HttpResponse(statistics, mimetype='text/plain') + + + json = simplejson.dumps({'name' : 'Jordan'}) + return HttpResponse(json, mimetype='application/json') \ No newline at end of file -- 2.45.1