]> git.openstreetmap.org Git - osqa.git/commitdiff
creating some views for the update checker and creating the functions that get the...
authorjordan <jordan@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Wed, 20 Apr 2011 14:07:16 +0000 (14:07 +0000)
committerjordan <jordan@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Wed, 20 Apr 2011 14:07:16 +0000 (14:07 +0000)
git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@995 0cfe37f9-358a-4d5e-be75-b63607b5c754

forum_modules/updater/base.py
forum_modules/updater/startup.py [new file with mode: 0644]
forum_modules/updater/templates/index.html
forum_modules/updater/urls.py
forum_modules/updater/views.py

index 74d37e53287f8e47900981859941a88222e815ce..995c70ce2929ce0d0660faa6693f44671943022c 100644 (file)
@@ -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<server_name>.*)$", 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 (file)
index 0000000..4164248
--- /dev/null
@@ -0,0 +1 @@
+import views
index 1ddb980b68bed388bab0db0fa4799d9614c99545..04f20af4922bcdcb3bca7851d5723ebfd1aeff4a 100644 (file)
@@ -2,6 +2,18 @@
 
 {% load i18n %}
 
+{% block adminjs %}
+{{ block.super }}
+<script type="text/javascript">
+$(function() {
+
+    $('#check_for_updates').live('click', function() {
+        alert("Ok")
+    })
+});
+</script>
+{% endblock %}
+
 {% block subtitle %}
     {% trans "Update Checker" %}
 {% endblock %}
@@ -11,4 +23,6 @@
 
 {% block admincontent %}
 
+<a href="javascript:void(0);" id="check_for_updates" class="button">{% trans "Check for Updates" %}</a>
+
 {% endblock %}
index 300a589418cd63ae163d322d268be093c3107983..c3a6c4caf890e473da58c0baf8188078d0b6bfcf 100644 (file)
@@ -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'),
 )
index 60c8f926aaaaef2b678e31a9dac745dba129ce37..2589528227c75f2a7c478a0482d621269f312840 100644 (file)
@@ -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 = """<check>
+    <key value="%(site_key)s" />
+    <app_url value="%(app_url)s" />
+    <svn_revision value="%(svn_revision)d" />
+    <views value="%(site_views)d" />
+    <active_users value="11959" />
+    <server value="%(server_name)s" />
+    <python_version value="%(python_version)s" />
+    <django_version value="%(django_version)s" />
+    <database value="MySQL 5" />
+    <os value="Linux" />
+</check> """ % {
+        '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