Commit 5f64b380 authored by Stefan Marsiske's avatar Stefan Marsiske

Merge pull request #64 from guyzmo/api_branch

Api branch
parents 51b12988 000d1fcf
#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
#class UserResource(ModelResource):
# class Meta:
# queryset = User.objects.all()
# resource_name = 'auth/user'
# excludes = ['email', 'password', 'is_superuser']
class APIResource(ModelResource):
# user = fields.ForeignKey(UserResource, 'user')
class Meta:
queryset = Violation.objects.all()
list_allowed_methods = ['get', 'post']
detail_allowed_methods = ['get', 'post', 'put', 'delete']
resource_name = 'violations'
authorization = DjangoAuthorization()
filtering = {
'country': ALL,
'operator': ALL,
'activationid': ALL,
}
......@@ -188,11 +188,12 @@ def add(request):
'violations': v_list },
context_instance=RequestContext(request))
def ajax(request, country=None, operator=None):
if not operator:
return HttpResponse(json.dumps(sorted(list(set([x.operator for x in Violation.objects.filter(country=country,activationid='')])))))
else:
return HttpResponse(json.dumps(sorted(list(set([x.contract for x in Violation.objects.filter(country=country,activationid='',operator=operator)])))))
# XXX obsoleted by API
#def ajax(request, country=None, operator=None):
# if not operator:
# return HttpResponse(json.dumps(sorted(list(set([x.operator for x in Violation.objects.filter(country=country,activationid='')])))))
# else:
# return HttpResponse(json.dumps(sorted(list(set([x.contract for x in Violation.objects.filter(country=country,activationid='',operator=operator)])))))
def index(request):
v_list = Violation.objects.filter(activationid='',featuredcase__isnull=False).order_by('id').reverse()[:3]
......
......@@ -10,3 +10,4 @@ PIL>=1.1.7
flup>=1.0.3.dev-20110405
BeautifulSoup>=3.2.0
python-twitter==0.8.2
django-tastypie
......@@ -139,6 +139,7 @@ INSTALLED_APPS = (
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
'tastypie',
)
TEMPLATE_CONTEXT_PROCESSORS = ("django.contrib.auth.context_processors.auth",
......
......@@ -5,6 +5,10 @@ from django.contrib import admin
from bt import views as bt
from bt.feeds import RssSiteNewsFeed, AtomSiteNewsFeed
from bt.api import APIResource
api_resource = APIResource()
admin.autodiscover()
......@@ -12,7 +16,8 @@ urlpatterns = patterns('',
(r'^$', bt.index),
(r'^list/$', bt.list_violations),
url(r'^list/(?P<country>[^/]*)(/(?P<operator>[^/]*))?$', bt.filter_violations, name="filter"),
(r'^ajax/(?P<country>[^/]*)(/(?P<operator>[^/]*))?$', bt.ajax),
#(r'^ajax/(?P<country>[^/]*)(/(?P<operator>[^/]*))?$', bt.ajax),
(r'^api/', include(api_resource.urls)),
(r'^add/$', bt.add),
(r'^view/(?P<id>[0-9]*)$', bt.view),
(r'^attach/(?P<id>[0-9]*)$', bt.get_attach),
......
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