forked from MetalBlazer/nicedit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathviews.py
More file actions
35 lines (27 loc) · 981 Bytes
/
views.py
File metadata and controls
35 lines (27 loc) · 981 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import json
from django.http import HttpResponse
from .forms import NicEditImageForm
__all__ = ('upload',)
def upload(request):
if not request.user.is_authenticated():
json_data = json.dumps({
'success': False,
'errors': {'__all__': 'Authentication required'}})
return HttpResponse(json_data, content_type='application/json')
form = NicEditImageForm(request.POST or None, request.FILES or None)
if form.is_valid():
image = form.save()
json_data = json.dumps({
'success': True,
'upload': {
'links': {
'original': image.image.url},
'image': {
'width': image.image.width,
'height': image.image.height}
}
})
else:
json_data = json.dumps({
'success': False, 'errors': form.errors})
return HttpResponse(json_data, content_type='application/json')