Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit a2dc40d49bc868ed8594db666e49c922944162db @pennersr committed Feb 14, 2012
8 .gitignore
@@ -0,0 +1,8 @@
+*.pyc
+*~
+.idea
+.project
+.pydevproject
+build
+dist
+django_allauth.egg-info
0 jhouston/__init__.py
No changes.
18 jhouston/admin.py
@@ -0,0 +1,18 @@
+from django.contrib import admin
+
+from models import ErrorReport
+
+class ErrorReportAdmin(admin.ModelAdmin):
+ search_fields = ('message',
+ 'url',
+ 'user_agent',
+ 'data')
+ date_hierarchy = 'reported_at'
+ list_display = ('reported_at',
+ 'message',
+ 'url',
+ 'line_number',
+ 'user_agent',
+ 'remote_addr')
+
+admin.site.register(ErrorReport, ErrorReportAdmin)
9 jhouston/forms.py
@@ -0,0 +1,9 @@
+from django.forms import ModelForm
+
+from models import ErrorReport
+
+class ErrorReportForm(ModelForm):
+
+ class Meta:
+ fields = ('message', 'url', 'line_number',)
+ model = ErrorReport
45 jhouston/migrations/0001_initial.py
@@ -0,0 +1,45 @@
+# encoding: utf-8
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+class Migration(SchemaMigration):
+
+ def forwards(self, orm):
+
+ # Adding model 'ErrorReport'
+ db.create_table('jhouston_errorreport', (
+ ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+ ('message', self.gf('django.db.models.fields.TextField')(blank=True)),
+ ('reported_at', self.gf('django.db.models.fields.DateTimeField')(auto_now_add=True, blank=True)),
+ ('url', self.gf('django.db.models.fields.URLField')(max_length=255)),
+ ('line_number', self.gf('django.db.models.fields.PositiveIntegerField')()),
+ ('user_agent', self.gf('django.db.models.fields.CharField')(max_length=255)),
+ ('remote_addr', self.gf('django.db.models.fields.IPAddressField')(max_length=15, blank=True)),
+ ('data', self.gf('django.db.models.fields.TextField')(blank=True)),
+ ))
+ db.send_create_signal('jhouston', ['ErrorReport'])
+
+
+ def backwards(self, orm):
+
+ # Deleting model 'ErrorReport'
+ db.delete_table('jhouston_errorreport')
+
+
+ models = {
+ 'jhouston.errorreport': {
+ 'Meta': {'object_name': 'ErrorReport'},
+ 'data': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'line_number': ('django.db.models.fields.PositiveIntegerField', [], {}),
+ 'message': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+ 'remote_addr': ('django.db.models.fields.IPAddressField', [], {'max_length': '15', 'blank': 'True'}),
+ 'reported_at': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+ 'url': ('django.db.models.fields.URLField', [], {'max_length': '255'}),
+ 'user_agent': ('django.db.models.fields.CharField', [], {'max_length': '255'})
+ }
+ }
+
+ complete_apps = ['jhouston']
0 jhouston/migrations/__init__.py
No changes.
12 jhouston/models.py
@@ -0,0 +1,12 @@
+from django.db import models
+
+class ErrorReport(models.Model):
+ message = models.TextField(blank=True)
+ reported_at = models.DateTimeField(auto_now_add=True)
+ url = models.URLField(max_length=255)
+ line_number = models.PositiveIntegerField()
+ user_agent = models.CharField(max_length=255)
+ remote_addr = models.IPAddressField(blank=True)
+ data = models.TextField(blank=True)
+
+
19 jhouston/static/js/jhouston.js
@@ -0,0 +1,19 @@
+(function() {
+ var prevOnError = window.onerror;
+ window.onerror = function (errorMsg, url, lineNumber) {
+ if (typeof(jQuery) != 'undefined') {
+ jQuery.ajax({ url: '/jhouston/onerror/',
+ type: 'POST',
+ data: {
+ message: errorMsg,
+ line_number: lineNumber,
+ url: url
+ }
+ });
+ }
+ if (prevOnError) {
+ return prevOnError(errorMsg, url, lineNumber);
+ }
+ return false;
+ }
+})();
16 jhouston/tests.py
@@ -0,0 +1,16 @@
+"""
+This file demonstrates writing tests using the unittest module. These will pass
+when you run "manage.py test".
+
+Replace this with more appropriate tests for your application.
+"""
+
+from django.test import TestCase
+
+
+class SimpleTest(TestCase):
+ def test_basic_addition(self):
+ """
+ Tests that 1 + 1 always equals 2.
+ """
+ self.assertEqual(1 + 1, 2)
7 jhouston/urls.py
@@ -0,0 +1,7 @@
+from django.conf.urls.defaults import patterns, url
+
+import views
+
+urlpatterns = patterns('',
+ url(r'^onerror/$', views.onerror)
+)
22 jhouston/views.py
@@ -0,0 +1,22 @@
+from django.http import HttpResponse
+from django.views.decorators.csrf import csrf_exempt
+
+from forms import ErrorReportForm
+
+@csrf_exempt
+def onerror(request):
+ if request.method != 'POST':
+ ret = HttpResponse(content="Sorry, we accept POST only", status=400)
+ else:
+ form = ErrorReportForm(request.POST)
+ if form.is_valid():
+ report = form.save(commit=False)
+ report.remote_addr = request.META['REMOTE_ADDR']
+ report.user_agent = request.META['HTTP_USER_AGENT']
+ report.save()
+ ret = HttpResponse(content='Thanks for reporting',
+ status=201)
+ else:
+ ret = HttpResponse(content=form._errors, status=400)
+ return ret
+

0 comments on commit a2dc40d

Please sign in to comment.