Skip to content
This repository has been archived by the owner on Nov 30, 2022. It is now read-only.

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
pennersr committed Feb 14, 2012
0 parents commit a2dc40d
Show file tree
Hide file tree
Showing 11 changed files with 156 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*.pyc
*~
.idea
.project
.pydevproject
build
dist
django_allauth.egg-info
Empty file added jhouston/__init__.py
Empty file.
18 changes: 18 additions & 0 deletions jhouston/admin.py
Original file line number Diff line number Diff line change
@@ -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 changes: 9 additions & 0 deletions jhouston/forms.py
Original file line number Diff line number Diff line change
@@ -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 changes: 45 additions & 0 deletions jhouston/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -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']
Empty file added jhouston/migrations/__init__.py
Empty file.
12 changes: 12 additions & 0 deletions jhouston/models.py
Original file line number Diff line number Diff line change
@@ -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 changes: 19 additions & 0 deletions jhouston/static/js/jhouston.js
Original file line number Diff line number Diff line change
@@ -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 changes: 16 additions & 0 deletions jhouston/tests.py
Original file line number Diff line number Diff line change
@@ -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 changes: 7 additions & 0 deletions jhouston/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.conf.urls.defaults import patterns, url

import views

urlpatterns = patterns('',
url(r'^onerror/$', views.onerror)
)
22 changes: 22 additions & 0 deletions jhouston/views.py
Original file line number Diff line number Diff line change
@@ -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.