Commit 7d8e7565 authored by Olivier Girardot's avatar Olivier Girardot

adding south + properly migrated data to new schema with ForeignKey to...

adding south + properly migrated data to new schema with ForeignKey to operator table with logo pic + refactored api with proper operator resource
parent 0f6e8f27
......@@ -7,7 +7,7 @@ class CommentInline(admin.TabularInline):
class ViolationAdmin(admin.ModelAdmin):
list_display = ('state', 'country', 'operator', 'contract', 'resource_name', 'media', 'activationid')
list_filter = ('state', 'operator', 'contract', 'resource_name', 'media', 'country')
list_filter = ('state', 'operator_ref', 'contract', 'resource_name', 'media', 'country')
inlines = [CommentInline, ]
admin.site.register(models.Violation, ViolationAdmin)
......@@ -22,9 +22,15 @@ admin.site.register(models.Attachment, AttachmentAdmin)
class ConfirmationAdmin(admin.ModelAdmin):
list_display = ('violation', 'key')
list_filter = ('violation__operator', 'violation__contract', 'violation__resource_name', 'violation__media', 'violation__country')
list_filter = ('violation__operator_ref', 'violation__contract', 'violation__resource_name', 'violation__media', 'violation__country')
admin.site.register(models.Confirmation, ConfirmationAdmin)
class FeaturedCaseAdmin(admin.ModelAdmin):
pass
admin.site.register(models.FeaturedCase, FeaturedCaseAdmin)
class OperatorAdmin(admin.ModelAdmin):
list_display = ("__unicode__", "reported_violations")
search_fields = ('name', )
pass
admin.site.register(models.Operator, OperatorAdmin)
\ No newline at end of file
#from django.contrib.auth.models import User
from tastypie import fields
from tastypie.authorization import DjangoAuthorization
from tastypie.resources import ModelResource, ALL#, ALL_WITH_RELATIONS
from bt.models import Violation
from tastypie.resources import ModelResource, ALL, ALL_WITH_RELATIONS
from bt.models import Violation, Operator
#class UserResource(ModelResource):
......@@ -11,8 +11,21 @@ from bt.models import Violation
# resource_name = 'auth/user'
# excludes = ['email', 'password', 'is_superuser']
class OperatorResource(ModelResource):
class Meta:
queryset = Operator.objects.all()
list_allowed_methods = ['get', 'post']
detail_allowed_methods = ['get', 'post', 'put', 'delete']
resource_name = 'operators'
authorization = DjangoAuthorization()
filtering = {
'name': ALL,
}
class APIResource(ModelResource):
operator = fields.ForeignKey(OperatorResource, 'operator_ref')
# user = fields.ForeignKey(UserResource, 'user')
class Meta:
......@@ -23,7 +36,6 @@ class APIResource(ModelResource):
authorization = DjangoAuthorization()
filtering = {
'country': ALL,
'operator': ALL,
'operator_ref': ALL_WITH_RELATIONS,
'activationid': ALL,
}
# -*- coding: 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 'Violation'
db.create_table('bt_violation', (
('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
('country', self.gf('django.db.models.fields.CharField')(max_length=2)),
('operator', self.gf('django.db.models.fields.CharField')(max_length=256)),
('contract', self.gf('django.db.models.fields.CharField')(max_length=256, blank=True)),
('resource', self.gf('django.db.models.fields.CharField')(max_length=20, blank=True)),
('resource_name', self.gf('django.db.models.fields.CharField')(max_length=4096, blank=True)),
('type', self.gf('django.db.models.fields.CharField')(max_length=20, blank=True)),
('media', self.gf('django.db.models.fields.CharField')(max_length=20, blank=True)),
('temporary', self.gf('django.db.models.fields.BooleanField')(default=False)),
('contractual', self.gf('django.db.models.fields.BooleanField')(default=False)),
('contract_excerpt', self.gf('django.db.models.fields.TextField')(blank=True)),
('loophole', self.gf('django.db.models.fields.BooleanField')(default=False)),
('activationid', self.gf('django.db.models.fields.CharField')(max_length=128, blank=True)),
('state', self.gf('django.db.models.fields.CharField')(default='new', max_length=20, blank=True)),
('editorial', self.gf('django.db.models.fields.TextField')(blank=True)),
))
db.send_create_signal('bt', ['Violation'])
# Adding model 'Comment'
db.create_table('bt_comment', (
('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
('submitter_email', self.gf('django.db.models.fields.EmailField')(max_length=75)),
('submitter_name', self.gf('django.db.models.fields.CharField')(max_length=20)),
('consent', self.gf('django.db.models.fields.BooleanField')(default=False)),
('comment', self.gf('django.db.models.fields.TextField')()),
('timestamp', self.gf('django.db.models.fields.DateTimeField')()),
('violation', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['bt.Violation'])),
))
db.send_create_signal('bt', ['Comment'])
# Adding model 'Attachment'
db.create_table('bt_attachment', (
('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
('storage', self.gf('django.db.models.fields.files.FileField')(max_length=100)),
('name', self.gf('django.db.models.fields.CharField')(max_length=512)),
('type', self.gf('django.db.models.fields.CharField')(max_length=512)),
('comment', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['bt.Comment'])),
))
db.send_create_signal('bt', ['Attachment'])
# Adding model 'Confirmation'
db.create_table('bt_confirmation', (
('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
('key', self.gf('django.db.models.fields.CharField')(max_length=64, blank=True)),
('email', self.gf('django.db.models.fields.EmailField')(max_length=75)),
('violation', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['bt.Violation'])),
))
db.send_create_signal('bt', ['Confirmation'])
# Adding model 'FeaturedCase'
db.create_table('bt_featuredcase', (
('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
('case', self.gf('django.db.models.fields.related.OneToOneField')(to=orm['bt.Violation'], unique=True)),
))
db.send_create_signal('bt', ['FeaturedCase'])
def backwards(self, orm):
# Deleting model 'Violation'
db.delete_table('bt_violation')
# Deleting model 'Comment'
db.delete_table('bt_comment')
# Deleting model 'Attachment'
db.delete_table('bt_attachment')
# Deleting model 'Confirmation'
db.delete_table('bt_confirmation')
# Deleting model 'FeaturedCase'
db.delete_table('bt_featuredcase')
models = {
'bt.attachment': {
'Meta': {'object_name': 'Attachment'},
'comment': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['bt.Comment']"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '512'}),
'storage': ('django.db.models.fields.files.FileField', [], {'max_length': '100'}),
'type': ('django.db.models.fields.CharField', [], {'max_length': '512'})
},
'bt.comment': {
'Meta': {'object_name': 'Comment'},
'comment': ('django.db.models.fields.TextField', [], {}),
'consent': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'submitter_email': ('django.db.models.fields.EmailField', [], {'max_length': '75'}),
'submitter_name': ('django.db.models.fields.CharField', [], {'max_length': '20'}),
'timestamp': ('django.db.models.fields.DateTimeField', [], {}),
'violation': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['bt.Violation']"})
},
'bt.confirmation': {
'Meta': {'object_name': 'Confirmation'},
'email': ('django.db.models.fields.EmailField', [], {'max_length': '75'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'key': ('django.db.models.fields.CharField', [], {'max_length': '64', 'blank': 'True'}),
'violation': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['bt.Violation']"})
},
'bt.featuredcase': {
'Meta': {'object_name': 'FeaturedCase'},
'case': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['bt.Violation']", 'unique': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
},
'bt.violation': {
'Meta': {'object_name': 'Violation'},
'activationid': ('django.db.models.fields.CharField', [], {'max_length': '128', 'blank': 'True'}),
'contract': ('django.db.models.fields.CharField', [], {'max_length': '256', 'blank': 'True'}),
'contract_excerpt': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
'contractual': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'country': ('django.db.models.fields.CharField', [], {'max_length': '2'}),
'editorial': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'loophole': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'media': ('django.db.models.fields.CharField', [], {'max_length': '20', 'blank': 'True'}),
'operator': ('django.db.models.fields.CharField', [], {'max_length': '256'}),
'resource': ('django.db.models.fields.CharField', [], {'max_length': '20', 'blank': 'True'}),
'resource_name': ('django.db.models.fields.CharField', [], {'max_length': '4096', 'blank': 'True'}),
'state': ('django.db.models.fields.CharField', [], {'default': "'new'", 'max_length': '20', 'blank': 'True'}),
'temporary': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'type': ('django.db.models.fields.CharField', [], {'max_length': '20', 'blank': 'True'})
}
}
complete_apps = ['bt']
\ No newline at end of file
# -*- coding: 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 'Operator'
db.create_table('bt_operator', (
('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
('name', self.gf('django.db.models.fields.CharField')(max_length=256)),
('logo', self.gf('django.db.models.fields.files.ImageField')(max_length=100, null=True, blank=True)),
))
db.send_create_signal('bt', ['Operator'])
# Adding field 'Violation.operator_ref'
db.add_column('bt_violation', 'operator_ref',
self.gf('django.db.models.fields.related.ForeignKey')(related_name='violations', null=True, to=orm['bt.Operator']),
keep_default=False)
def backwards(self, orm):
# Deleting model 'Operator'
db.delete_table('bt_operator')
# Deleting field 'Violation.operator_ref'
db.delete_column('bt_violation', 'operator_ref_id')
models = {
'bt.attachment': {
'Meta': {'object_name': 'Attachment'},
'comment': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['bt.Comment']"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '512'}),
'storage': ('django.db.models.fields.files.FileField', [], {'max_length': '100'}),
'type': ('django.db.models.fields.CharField', [], {'max_length': '512'})
},
'bt.comment': {
'Meta': {'object_name': 'Comment'},
'comment': ('django.db.models.fields.TextField', [], {}),
'consent': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'submitter_email': ('django.db.models.fields.EmailField', [], {'max_length': '75'}),
'submitter_name': ('django.db.models.fields.CharField', [], {'max_length': '20'}),
'timestamp': ('django.db.models.fields.DateTimeField', [], {}),
'violation': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['bt.Violation']"})
},
'bt.confirmation': {
'Meta': {'object_name': 'Confirmation'},
'email': ('django.db.models.fields.EmailField', [], {'max_length': '75'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'key': ('django.db.models.fields.CharField', [], {'max_length': '64', 'blank': 'True'}),
'violation': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['bt.Violation']"})
},
'bt.featuredcase': {
'Meta': {'object_name': 'FeaturedCase'},
'case': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['bt.Violation']", 'unique': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
},
'bt.operator': {
'Meta': {'object_name': 'Operator'},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'logo': ('django.db.models.fields.files.ImageField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '256'})
},
'bt.violation': {
'Meta': {'object_name': 'Violation'},
'activationid': ('django.db.models.fields.CharField', [], {'max_length': '128', 'blank': 'True'}),
'contract': ('django.db.models.fields.CharField', [], {'max_length': '256', 'blank': 'True'}),
'contract_excerpt': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
'contractual': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'country': ('django.db.models.fields.CharField', [], {'max_length': '2'}),
'editorial': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'loophole': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'media': ('django.db.models.fields.CharField', [], {'max_length': '20', 'blank': 'True'}),
'operator': ('django.db.models.fields.CharField', [], {'max_length': '256'}),
'operator_ref': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'violations'", 'null': 'True', 'to': "orm['bt.Operator']"}),
'resource': ('django.db.models.fields.CharField', [], {'max_length': '20', 'blank': 'True'}),
'resource_name': ('django.db.models.fields.CharField', [], {'max_length': '4096', 'blank': 'True'}),
'state': ('django.db.models.fields.CharField', [], {'default': "'new'", 'max_length': '20', 'blank': 'True'}),
'temporary': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'type': ('django.db.models.fields.CharField', [], {'max_length': '20', 'blank': 'True'})
}
}
complete_apps = ['bt']
\ No newline at end of file
# -*- coding: utf-8 -*-
import datetime
from south.db import db
from south.v2 import DataMigration
from django.db import models
class Migration(DataMigration):
def forwards(self, orm):
"Populate new operator foreign key field"
for violation in orm['bt.Violation'].objects.all():
operator, created = orm['bt.Operator'].objects.get_or_create(name=violation.operator)
violation.operator_ref = operator
violation.save()
def backwards(self, orm):
"No need for backward pass"
pass
models = {
'bt.attachment': {
'Meta': {'object_name': 'Attachment'},
'comment': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['bt.Comment']"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '512'}),
'storage': ('django.db.models.fields.files.FileField', [], {'max_length': '100'}),
'type': ('django.db.models.fields.CharField', [], {'max_length': '512'})
},
'bt.comment': {
'Meta': {'object_name': 'Comment'},
'comment': ('django.db.models.fields.TextField', [], {}),
'consent': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'submitter_email': ('django.db.models.fields.EmailField', [], {'max_length': '75'}),
'submitter_name': ('django.db.models.fields.CharField', [], {'max_length': '20'}),
'timestamp': ('django.db.models.fields.DateTimeField', [], {}),
'violation': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['bt.Violation']"})
},
'bt.confirmation': {
'Meta': {'object_name': 'Confirmation'},
'email': ('django.db.models.fields.EmailField', [], {'max_length': '75'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'key': ('django.db.models.fields.CharField', [], {'max_length': '64', 'blank': 'True'}),
'violation': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['bt.Violation']"})
},
'bt.featuredcase': {
'Meta': {'object_name': 'FeaturedCase'},
'case': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['bt.Violation']", 'unique': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
},
'bt.operator': {
'Meta': {'object_name': 'Operator'},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'logo': ('django.db.models.fields.files.ImageField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '256'})
},
'bt.violation': {
'Meta': {'object_name': 'Violation'},
'activationid': ('django.db.models.fields.CharField', [], {'max_length': '128', 'blank': 'True'}),
'contract': ('django.db.models.fields.CharField', [], {'max_length': '256', 'blank': 'True'}),
'contract_excerpt': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
'contractual': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'country': ('django.db.models.fields.CharField', [], {'max_length': '2'}),
'editorial': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'loophole': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'media': ('django.db.models.fields.CharField', [], {'max_length': '20', 'blank': 'True'}),
'operator': ('django.db.models.fields.CharField', [], {'max_length': '256'}),
'operator_ref': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'violations'", 'null': 'True', 'to': "orm['bt.Operator']"}),
'resource': ('django.db.models.fields.CharField', [], {'max_length': '20', 'blank': 'True'}),
'resource_name': ('django.db.models.fields.CharField', [], {'max_length': '4096', 'blank': 'True'}),
'state': ('django.db.models.fields.CharField', [], {'default': "'new'", 'max_length': '20', 'blank': 'True'}),
'temporary': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'type': ('django.db.models.fields.CharField', [], {'max_length': '20', 'blank': 'True'})
}
}
complete_apps = ['bt']
symmetrical = True
# -*- coding: 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):
# Deleting field 'Violation.operator'
db.delete_column('bt_violation', 'operator')
# Changing field 'Violation.operator_ref'
db.alter_column('bt_violation', 'operator_ref_id', self.gf('django.db.models.fields.related.ForeignKey')(default=0, to=orm['bt.Operator']))
def backwards(self, orm):
# Adding field 'Violation.operator'
db.add_column('bt_violation', 'operator',
self.gf('django.db.models.fields.CharField')(default=0, max_length=256),
keep_default=False)
# Changing field 'Violation.operator_ref'
db.alter_column('bt_violation', 'operator_ref_id', self.gf('django.db.models.fields.related.ForeignKey')(null=True, to=orm['bt.Operator']))
models = {
'bt.attachment': {
'Meta': {'object_name': 'Attachment'},
'comment': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['bt.Comment']"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '512'}),
'storage': ('django.db.models.fields.files.FileField', [], {'max_length': '100'}),
'type': ('django.db.models.fields.CharField', [], {'max_length': '512'})
},
'bt.comment': {
'Meta': {'object_name': 'Comment'},
'comment': ('django.db.models.fields.TextField', [], {}),
'consent': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'submitter_email': ('django.db.models.fields.EmailField', [], {'max_length': '75'}),
'submitter_name': ('django.db.models.fields.CharField', [], {'max_length': '20'}),
'timestamp': ('django.db.models.fields.DateTimeField', [], {}),
'violation': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['bt.Violation']"})
},
'bt.confirmation': {
'Meta': {'object_name': 'Confirmation'},
'email': ('django.db.models.fields.EmailField', [], {'max_length': '75'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'key': ('django.db.models.fields.CharField', [], {'max_length': '64', 'blank': 'True'}),
'violation': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['bt.Violation']"})
},
'bt.featuredcase': {
'Meta': {'object_name': 'FeaturedCase'},
'case': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['bt.Violation']", 'unique': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
},
'bt.operator': {
'Meta': {'object_name': 'Operator'},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'logo': ('django.db.models.fields.files.ImageField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '256'})
},
'bt.violation': {
'Meta': {'object_name': 'Violation'},
'activationid': ('django.db.models.fields.CharField', [], {'max_length': '128', 'blank': 'True'}),
'contract': ('django.db.models.fields.CharField', [], {'max_length': '256', 'blank': 'True'}),
'contract_excerpt': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
'contractual': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'country': ('django.db.models.fields.CharField', [], {'max_length': '2'}),
'editorial': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'loophole': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'media': ('django.db.models.fields.CharField', [], {'max_length': '20', 'blank': 'True'}),
'operator_ref': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'violations'", 'to': "orm['bt.Operator']"}),
'resource': ('django.db.models.fields.CharField', [], {'max_length': '20', 'blank': 'True'}),
'resource_name': ('django.db.models.fields.CharField', [], {'max_length': '4096', 'blank': 'True'}),
'state': ('django.db.models.fields.CharField', [], {'default': "'new'", 'max_length': '20', 'blank': 'True'}),
'temporary': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'type': ('django.db.models.fields.CharField', [], {'max_length': '20', 'blank': 'True'})
}
}
complete_apps = ['bt']
\ No newline at end of file
......@@ -59,9 +59,24 @@ STATUS = (
('closed', _('Closed')),
)
class Operator(models.Model):
"""
Define the concept of an internet provider/network operator
"""
name = models.CharField(max_length=256)
logo = models.ImageField(upload_to='operator_logo', null=True, blank=True)
def reported_violations(self):
return self.violations.count()
reported_violations.short_description = 'Reported Violations'
def __unicode__(self):
return self.name
class Violation(models.Model):
country = models.CharField(max_length=2, choices=COUNTRIES)
operator = models.CharField(max_length=256)
operator_ref = models.ForeignKey(Operator, related_name="violations")
contract = models.CharField(max_length=256, blank=True)
resource = models.CharField(max_length=20, choices=RESOURCES, blank=True)
resource_name = models.CharField(max_length=4096, blank=True)
......@@ -81,6 +96,10 @@ class Violation(models.Model):
class Admin:
pass
@property
def operator(self):
return self.operator_ref.name
@models.permalink
def get_absolute_url(self):
return ('violation_url', (),
......
......@@ -141,9 +141,10 @@ def add(request):
if form.is_valid():
msg=_("Thank you for submitting a new report. To finalize your submission please confirm using your validation key.\nYour verification key is %s/%s%s\nPlease note that reports are moderated, it might take some time before your report appears online. Thank you for your patience.")
actid=sendverifymail('activate?key=',form.cleaned_data['email'], msg)
operator, created = Operator.objects.get_or_create(name=form.cleaned_data['operator'])
v=Violation(
country = form.cleaned_data['country'],
operator = form.cleaned_data['operator'],
operator_ref = operator,
contract = form.cleaned_data['contract'],
resource = form.cleaned_data['resource'],
resource_name = form.cleaned_data['resource_name'],
......@@ -207,8 +208,8 @@ def index(request):
confirms=sorted([(i['total'],i['country'])
for i in Violation.objects.values('country').filter(activationid='').exclude(state__in=['closed', 'ooscope', 'duplicate']).annotate(total=Count('confirmation'))],
reverse=True)
operators=sorted([(i['total'],i['operator'])
for i in Violation.objects.values('operator').filter(activationid='').exclude(state__in=['closed', 'ooscope', 'duplicate']).annotate(total=Count('confirmation'))],
operators=sorted([(i['total'],i['operator_ref__name'])
for i in Violation.objects.values('operator_ref__name').filter(activationid='').exclude(state__in=['closed', 'ooscope', 'duplicate']).annotate(total=Count('confirmation'))],
reverse=True)
return render_to_response(
......@@ -225,9 +226,9 @@ def filter_violations(request, country, operator=None):
if not operator:
violations = Violation.objects.filter(activationid='', country=country)
if not violations.count():
violations = Violation.objects.filter(activationid='', operator=country)
violations = Violation.objects.filter(activationid='', operator_ref__name=country)
else:
violations = Violation.objects.filter(activationid='', country=country, operator=operator)
violations = Violation.objects.filter(activationid='', country=country, operator_ref__name=operator)
if not request.GET.get('all'):
violations = violations.exclude(state__in=['duplicate', 'closed'])
countries=sorted([(i['total'],i['country'])
......@@ -281,7 +282,7 @@ def lookup(request):
if form.is_valid():
v=Violation.objects.filter(
country = form.cleaned_data['country'],
operator = form.cleaned_data['operator'],
operator_ref__name = form.cleaned_data['operator'],
contract = form.cleaned_data['contract'],
media = form.cleaned_data['media'],
activationid = ''
......
......@@ -11,3 +11,4 @@ flup>=1.0.3.dev-20110405
BeautifulSoup>=3.2.0
python-twitter==0.8.2
django-tastypie
South>=0.7.6
......@@ -140,6 +140,7 @@ INSTALLED_APPS = (
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
'tastypie',
'south',
)
TEMPLATE_CONTEXT_PROCESSORS = ("django.contrib.auth.context_processors.auth",
......
......@@ -5,10 +5,10 @@ from django.contrib import admin
from bt import views as bt
from bt.feeds import RssSiteNewsFeed, AtomSiteNewsFeed
from bt.api import APIResource
from bt.api import APIResource, OperatorResource
api_resource = APIResource()
operator_api_resource = OperatorResource()
admin.autodiscover()
......@@ -81,6 +81,8 @@ urlpatterns = patterns('',
include(admin.site.urls)),
url(r'^api/',
include(api_resource.urls)),
url(r'^api/',
include(operator_api_resource.urls)),
)
if settings.DEV_SERVER:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment