Revision 314c74e2

b/api/functions.py
31 31
	#	raise Unauthorized()
32 32
	
33 33
	response = HttpResponse(status = 204)
34
	# TODO: Automate the Content-Type reply.
35
	response['Content-Type'] = 'text/plain; charset=UTF-8'
36 34
	response['X-Auth-Token'] = 'eaaafd18-0fed-4b3a-81b4-663c99ec1cbb'
37 35
	# TODO: Do we support redirections?
38 36
	#response['X-Storage-Url'] = 'https://storage.grnet.gr/pithos/v1.0/<some reference>'
......
66 64
		return object_read(request, v_account, v_container, v_object)
67 65
	elif request.method == 'PUT':
68 66
		return object_write(request, v_account, v_container, v_object)
67
	elif request.method == 'POST':
68
		return object_update(request, v_account, v_container, v_object)
69 69
	elif request.method == 'DELETE':
70 70
		return object_delete(request, v_account, v_container, v_object)
71 71
	else:
......
75 75
def account_meta(request, v_account):
76 76
	return HttpResponse("account_meta: %s" % v_account)
77 77

  
78
@api_method('GET')
78
@api_method('GET', format_allowed = True)
79 79
def container_list(request, v_account):
80 80
	return HttpResponse("container_list: %s" % v_account)
81 81

  
......
107 107
def object_write(request, v_account, v_container, v_object):
108 108
	return HttpResponse("object_write: %s %s %s" % (v_account, v_container, v_object))
109 109

  
110
@api_method('POST')
111
def object_update(request, v_account, v_container, v_object):
112
	return HttpResponse("object_update: %s %s %s" % (v_account, v_container, v_object))
113

  
110 114
@api_method('DELETE')
111 115
def object_delete(request, v_account, v_container, v_object):
112 116
	return HttpResponse("object_delete: %s %s %s" % (v_account, v_container, v_object))
b/api/models.py
29 29
class Metadata(models.Model):
30 30
    object = models.ForeignKey(Object)
31 31
    name = models.CharField(max_length = 256)
32
    value = models.CharField(max_length = 1024)
32
    value = models.CharField(max_length = 1024)
33
    date_created = models.DateTimeField(auto_now_add = True)
34
    date_modified = models.DateTimeField(auto_now = True)
b/api/util.py
125 125
#         raise BadRequest('Unsupported Content-Type.')
126 126

  
127 127
def update_response_headers(request, response):
128
#     if request.serialization == 'xml':
129
#         response['Content-Type'] = 'application/xml'
130
#     elif request.serialization == 'atom':
131
#         response['Content-Type'] = 'application/atom+xml'
132
#     else:
133
#         response['Content-Type'] = 'application/json'
134
#     
135
    response['Content-Type'] = 'text/plain; charset=UTF-8'
136
    response['Server'] = 'GRNET Pithos v.0.1'
128
    if request.serialization == 'xml':
129
        response['Content-Type'] = 'application/xml; charset=UTF-8'
130
    elif request.serialization == 'json':
131
        response['Content-Type'] = 'application/json; charset=UTF-8'
132
    else:
133
        response['Content-Type'] = 'text/plain; charset=UTF-8'
134

  
137 135
    if settings.TEST:
138 136
        response['Date'] = format_date_time(time())
139 137

  
......
167 165
    update_response_headers(request, resp)
168 166
    return resp
169 167

  
170
# def request_serialization(request, atom_allowed=False):
171
#     """Return the serialization format requested.
172
#        
173
#        Valid formats are 'json', 'xml' and 'atom' if `atom_allowed` is True.
174
#     """
175
#     
176
#     path = request.path
177
#     
178
#     if path.endswith('.json'):
179
#         return 'json'
180
#     elif path.endswith('.xml'):
181
#         return 'xml'
182
#     elif atom_allowed and path.endswith('.atom'):
183
#         return 'atom'
184
#     
168
def request_serialization(request, format_allowed=False):
169
    """Return the serialization format requested.
170
       
171
       Valid formats are 'text' and 'json', 'xml' if `format_allowed` is True.
172
    """
173
    
174
    if not format_allowed:
175
        return 'text'
176
    
177
    format = request.GET.get('format')
178
    if format == 'json':
179
        return 'json'
180
    elif format == 'xml':
181
        return 'xml'
182
    
185 183
#     for item in request.META.get('HTTP_ACCEPT', '').split(','):
186 184
#         accept, sep, rest = item.strip().partition(';')
187 185
#         if accept == 'application/json':
188 186
#             return 'json'
189 187
#         elif accept == 'application/xml':
190 188
#             return 'xml'
191
#         elif atom_allowed and accept == 'application/atom+xml':
192
#             return 'atom'
193
#     
194
#     return 'json'
189
    
190
    return 'text'
195 191

  
196
def api_method(http_method=None, atom_allowed=False):
192
def api_method(http_method = None, format_allowed = False):
197 193
    """Decorator function for views that implement an API method."""
198 194
    
199 195
    def decorator(func):
200 196
        @wraps(func)
201 197
        def wrapper(request, *args, **kwargs):
202 198
            try:
203
                #request.serialization = request_serialization(request, atom_allowed)
199
                request.serialization = request_serialization(request, format_allowed)
204 200
                if http_method and request.method != http_method:
205 201
                    raise BadRequest('Method not allowed.')
206 202
                

Also available in: Unified diff