Revision d8e50a39 api/flavors.py
b/api/flavors.py | ||
---|---|---|
2 | 2 |
# Copyright (c) 2010 Greek Research and Technology Network |
3 | 3 |
# |
4 | 4 |
|
5 |
from synnefo.api.util import * |
|
6 |
from synnefo.db.models import Flavor |
|
7 |
|
|
8 |
from django.conf.urls.defaults import * |
|
5 |
from django.conf.urls.defaults import patterns |
|
9 | 6 |
from django.http import HttpResponse |
10 | 7 |
from django.template.loader import render_to_string |
11 | 8 |
from django.utils import simplejson as json |
12 | 9 |
|
10 |
from synnefo.api.util import get_user, get_request_dict, api_method |
|
11 |
from synnefo.db.models import Flavor |
|
12 |
|
|
13 | 13 |
|
14 | 14 |
urlpatterns = patterns('synnefo.api.flavors', |
15 | 15 |
(r'^(?:/|.json|.xml)?$', 'list_flavors'), |
... | ... | |
39 | 39 |
all_flavors = Flavor.objects.all() |
40 | 40 |
flavors = [flavor_to_dict(flavor, detail) for flavor in all_flavors] |
41 | 41 |
|
42 |
if request.type == 'xml': |
|
43 |
mimetype = 'application/xml' |
|
42 |
if request.serialization == 'xml': |
|
44 | 43 |
data = render_to_string('list_flavors.xml', {'flavors': flavors, 'detail': detail}) |
45 | 44 |
else: |
46 |
mimetype = 'application/json' |
|
47 | 45 |
data = json.dumps({'flavors': {'values': flavors}}) |
48 | 46 |
|
49 |
return HttpResponse(data, mimetype=mimetype, status=200)
|
|
47 |
return HttpResponse(data, status=200) |
|
50 | 48 |
|
51 | 49 |
@api_method('GET') |
52 | 50 |
def get_flavor_details(request, flavor_id): |
... | ... | |
64 | 62 |
except Flavor.DoesNotExist: |
65 | 63 |
raise ItemNotFound |
66 | 64 |
|
67 |
if request.type == 'xml':
|
|
65 |
if request.serialization == 'xml':
|
|
68 | 66 |
data = render_to_string('flavor.xml', {'flavor': flavor}) |
69 | 67 |
else: |
70 | 68 |
data = json.dumps({'flavor': flavor}) |
Also available in: Unified diff