add api to add items to basket, with fake values for now
This commit is contained in:
parent
626d142145
commit
174d5c28bb
|
@ -16,8 +16,10 @@
|
|||
|
||||
from django.conf.urls import patterns, include, url
|
||||
|
||||
from .views import RegiesApiView
|
||||
from .views import RegiesApiView, AddBasketItemApiView
|
||||
|
||||
urlpatterns = patterns('',
|
||||
url('^api/lingo/regies$', RegiesApiView.as_view(), name='api-regies'),
|
||||
url('^api/lingo/add-basket-item$', AddBasketItemApiView.as_view(),
|
||||
name='api-add-basket-item'),
|
||||
)
|
||||
|
|
|
@ -14,12 +14,15 @@
|
|||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from decimal import Decimal
|
||||
import json
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
from django.http import HttpResponse
|
||||
from django.views.generic import ListView
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
from django.views.generic import View, ListView
|
||||
|
||||
from .models import Regie
|
||||
from .models import Regie, BasketItem
|
||||
|
||||
class RegiesApiView(ListView):
|
||||
model = Regie
|
||||
|
@ -32,3 +35,26 @@ class RegiesApiView(ListView):
|
|||
json_str = '%s(%s);' % (request.GET['jsonpCallback'], json_str)
|
||||
response.write(json_str)
|
||||
return response
|
||||
|
||||
|
||||
class AddBasketItemApiView(View):
|
||||
http_method_names = ['post', 'options']
|
||||
|
||||
@csrf_exempt
|
||||
def dispatch(self, *args, **kwargs):
|
||||
return super(AddBasketItemApiView, self).dispatch(*args, **kwargs)
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
item = BasketItem()
|
||||
item.amount = Decimal(request.GET.get('amount'))
|
||||
|
||||
# XXX: fill with real values
|
||||
item.user = User.objects.all()[0]
|
||||
item.regie = Regie.objects.all()[0]
|
||||
item.subject = 'foo'
|
||||
item.source_url = 'http://www.example.net'
|
||||
|
||||
item.save()
|
||||
response = HttpResponse(content_type='application/json')
|
||||
response.write(json.dumps({'result': 'success'}))
|
||||
return response
|
||||
|
|
Reference in New Issue