This repository has been archived by the owner on Nov 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a2dc40d
Showing
11 changed files
with
156 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|